Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. package ru.mephi.testapplication;
  2.  
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.support.design.widget.FloatingActionButton;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.support.v7.widget.Toolbar;
  8. import android.util.Log;
  9. import android.view.View;
  10. import android.widget.EditText;
  11.  
  12. import java.util.Random;
  13.  
  14. /**
  15. * Created by hpc on 2/12/16.
  16. */
  17. public abstract class BaseActivity extends AppCompatActivity {
  18.  
  19. private Random random = new Random();
  20. private StringBuilder result = new StringBuilder();
  21. private Class mIntentActivity;
  22. private String TAG;
  23.  
  24. @Override
  25. protected void onCreate(Bundle savedInstanceState) {
  26. super.onCreate(savedInstanceState);
  27. setContentView(R.layout.activity_first);
  28. Log.i(TAG, "onCreate");
  29. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  30. setSupportActionBar(toolbar);
  31.  
  32. FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  33. fab.setOnClickListener(new View.OnClickListener() {
  34. @Override
  35. public void onClick(View view) {
  36. Intent intent = new Intent(BaseActivity.this, mIntentActivity);
  37. startActivity(intent);
  38. }
  39. });
  40.  
  41. }
  42.  
  43.  
  44. public void setIntentActivity(Class clazz){
  45. mIntentActivity = clazz;
  46. }
  47.  
  48. public void setTag(String tag){
  49. this.TAG = tag;
  50. }
  51.  
  52. public void randomizeAndSet(){
  53. if (result.toString().equals("")) result.append(random.nextInt(20000) + 1);
  54.  
  55. ((EditText) findViewById(R.id.myedittext)).setText(result.toString());
  56. }
  57.  
  58. @Override
  59. protected void onStart() {
  60. super.onStart();
  61. Log.i(TAG, "onStart");
  62. }
  63.  
  64. @Override
  65. protected void onResume(){
  66. Log.i(TAG, "onResume");
  67. randomizeAndSet();
  68.  
  69. super.onResume();
  70. }
  71.  
  72. @Override
  73. protected void onPause(){
  74. super.onPause();
  75. Log.i(TAG, "onPause");
  76. }
  77.  
  78. @Override
  79. protected void onStop(){
  80. super.onStop();
  81. Log.i(TAG, "onStop");
  82. }
  83.  
  84. @Override
  85. protected void onDestroy(){
  86. super.onDestroy();
  87. Log.i(TAG, "onDestroy");
  88. }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement