Advertisement
Guest User

Vilen

a guest
Nov 14th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.83 KB | None | 0 0
  1. package com.holdbetter.firstandroidprojects1;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4. import androidx.core.content.ContextCompat;
  5.  
  6. import android.content.Context;
  7. import android.content.Intent;
  8. import android.content.res.Resources;
  9. import android.graphics.Typeface;
  10. import android.graphics.drawable.Drawable;
  11. import android.os.Bundle;
  12. import android.util.Log;
  13. import android.view.Gravity;
  14. import android.view.View;
  15. import android.view.ViewGroup;
  16. import android.widget.Button;
  17. import android.widget.LinearLayout;
  18. import android.widget.TextView;
  19. import android.widget.Toast;
  20.  
  21. public class Programming extends AppCompatActivity
  22. {
  23.     final String TAG = "Я крутой";
  24.  
  25.     @Override
  26.     protected void onCreate(Bundle savedInstanceState)
  27.     {
  28.         super.onCreate(savedInstanceState);
  29.         //setContentView(R.layout.activity_programming);
  30.  
  31.         //Context
  32.         //Activity lifecycle
  33.  
  34.  
  35.         LinearLayout ll = new LinearLayout(this);
  36.         ll.setOrientation(LinearLayout.VERTICAL);
  37.         ll.setPadding(160, 160, 160, 160);
  38.  
  39.  
  40.  
  41.         Context context = ll.getContext(); //контекст активити
  42.         //getResources().getColor(R.color.vilenColor);
  43.         Context b = this.getApplicationContext(); //контекст приложения
  44.  
  45.  
  46.         TextView txt = new TextView(this);
  47.         txt.setText("Vilen creates TextView");
  48.         txt.setTypeface(txt.getTypeface(), Typeface.BOLD_ITALIC);
  49.         txt.setGravity(Gravity.CENTER_HORIZONTAL);
  50.         txt.setTag("Tag");
  51.         txt.setTextColor(b.getResources().getColor(R.color.yuliaDelaetNePonatnoeLico));
  52.         //txt.setTextColor(context.getResources().getColor(R.color.vilenColor));
  53.  
  54.  
  55.         Button btn = new Button(this);
  56.         btn.setText("Увеличь на 1");
  57.         btn.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
  58.  
  59.         btn.setOnClickListener(new View.OnClickListener() {
  60.             @Override
  61.             public void onClick(View v) {
  62.                 TextView t = ((TextView)((LinearLayout)v.getParent()).findViewWithTag("Tag"));
  63.                 t.setText(t.getText() + "a");
  64.             }
  65.         });
  66.  
  67.         /*Intent i = new Intent();*/
  68.  
  69.         //Drawable draw = ContextCompat.getDrawable(this, R.color.vilenColor);
  70.         //Drawable draw = getApplicationContext().getDrawable(R.color.vilenColor);
  71.  
  72.         Button btn2 = new Button(this);
  73.         btn2.setText("Уменьши на 1");
  74.         btn2.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
  75.         btn2.setOnClickListener(new View.OnClickListener() {
  76.             @Override
  77.             public void onClick(View v) {
  78.                 TextView t = ((TextView)((LinearLayout)v.getParent()).findViewWithTag("Tag"));
  79.                 t.setText(t.getText().subSequence(0, t.length() - 1));
  80.             }
  81.         });
  82.  
  83.         Button btn3 = new Button(this);
  84.         btn3.setText("Перейти на следующую страницу");
  85.         btn3.setOnClickListener(new View.OnClickListener() {
  86.             @Override
  87.             public void onClick(View v) {
  88.                     Intent i = new Intent(v.getContext(), MainActivity.class);
  89.  
  90.                     int[] integers = { 10, 19, 22};
  91.  
  92.                     i.putExtra("shortKey", integers);
  93.  
  94.                     startActivity(i);
  95.             }
  96.         });
  97.  
  98.         ll.addView(txt);
  99.         ll.addView(btn);
  100.         ll.addView(btn2);
  101.         ll.addView(btn3);
  102.  
  103.  
  104.  
  105.  
  106.         setContentView(ll);
  107.  
  108.         /*Context res1 = txt.getContext();*/
  109.     }
  110.  
  111.     @Override
  112.     protected void onResume() {
  113.         super.onResume();
  114.  
  115.         Log.i(TAG, "Активити запущено");
  116.         Toast.makeText(this, "Активити запущено", Toast.LENGTH_SHORT).show();
  117.     }
  118.  
  119.     @Override
  120.     protected void onPause() {
  121.         super.onPause();
  122.  
  123.         Log.i(TAG, "Активити приостановлено");
  124.         Toast.makeText(this, "Активити приостановлено", Toast.LENGTH_SHORT).show();
  125.     }
  126.  
  127.     @Override
  128.     protected void onStop() {
  129.         super.onStop();
  130.  
  131.         Log.i(TAG, "Активити приостановлено и остановлено");
  132.         Toast.makeText(this, "Активити приостановлено и остановлено", Toast.LENGTH_SHORT).show();
  133.     }
  134.  
  135.     @Override
  136.     protected void onRestart() {
  137.         super.onRestart();
  138.  
  139.         Log.i(TAG, "Активити рестарт");
  140.         Toast.makeText(this, "Активити рестарт", Toast.LENGTH_SHORT).show();
  141.     }
  142.  
  143.     void pressBtn(View v)
  144.     {
  145.         TextView t = ((TextView)((LinearLayout)v.getParent()).findViewWithTag("Tag"));
  146.         t.setText(t.getText() + "a");
  147.     }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement