Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static final String TAG = "MainActivity";
- private MainPresenter mMainPresenter;
- private TextView mTextView_ShowVal;
- private Button mButton_IncreaseVal;
- private EditText mEditText_SetNum;
- private Button mButton_SetEditTextVal;
- private TextView mTextViewSomeText;
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- Log.d(TAG, "ON CREATE");
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- bindXML();
- read();
- if (mMainPresenter == null)
- {
- mMainPresenter = new MainPresenterImpl(this);
- }
- else
- {
- mMainPresenter.setNewViewObj(this);
- }
- mMainPresenter.onCreate();
- setListeners();
- }
- public void read(){
- Log.d(TAG, "read()");
- ObjectInputStream input;
- String filename = "testFilemost.srl";
- try {
- input = new ObjectInputStream(new FileInputStream(new File(new File(getFilesDir(),"")+File.separator+filename)));
- mMainPresenter = (MainPresenter) input.readObject();
- input.close();
- } catch (StreamCorruptedException e) {
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- public void write(){
- Log.d(TAG, "write()");
- String filename = "testFilemost.srl";
- ObjectOutput out = null;
- try {
- out = new ObjectOutputStream(new FileOutputStream(new File(getFilesDir(),"")+File.separator+filename));
- out.writeObject(mMainPresenter);
- out.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- @Override
- protected void onPause()
- {
- Log.d(TAG, "ON PAUSE");
- write();
- mMainPresenter = null;
- read();
- super.onPause();
- }
- @Override
- protected void onStart()
- {
- Log.d(TAG, "ON START");
- read();
- super.onStart();
- }
- @Override
- protected void onStop()
- {
- Log.d(TAG, "ON STOP");
- super.onStop();
- }
- @Override
- protected void onDestroy()
- {
- Log.d(TAG, "ON DESTROY");
- super.onDestroy();
- }
- @Override
- protected void onResume()
- {
- Log.d(TAG, "ON RESUME");
- mMainPresenter.onResume();
- super.onResume();
- }
- @Override
- public String getTextEditText()
- {
- return mEditText_SetNum.getText().toString();
- }
- @Override
- public void setTextTextView(String text)
- {
- Log.d(TAG, "text = " + text);
- mTextView_ShowVal.setText(text);
- }
- public void setListeners()
- {
- mButton_IncreaseVal.setOnClickListener(new View.OnClickListener()
- {
- @Override
- public void onClick(View v)
- {
- mMainPresenter.executeClickIncreaseBtn();
- }
- });
- mButton_SetEditTextVal.setOnClickListener(new View.OnClickListener()
- {
- @Override
- public void onClick(View v)
- {
- mMainPresenter.executeClickSetValBtn();
- }
- });
- }
- public void bindXML()
- {
- mTextView_ShowVal = (TextView) findViewById(R.id.textView_ShowNum);
- mButton_IncreaseVal = (Button) findViewById(R.id.button_IncreaseNum);
- mEditText_SetNum = (EditText) findViewById(R.id.editText_SetNum);
- mButton_SetEditTextVal = (Button) findViewById(R.id.button_SetEditTextVal);
- mTextViewSomeText = (TextView) findViewById(R.id.someText);
- }
- }
- public class MainPresenterImpl implements MainPresenter, Serializable
- {
- private static final String TAG = "MainPresenterImpl";
- private MainView mMainView;
- private ExperimentObject mValueObject = new ExperimentObject(0);
- public MainPresenterImpl(MainActivity mainActivity)
- {
- mMainView = mainActivity;
- }
- @Override
- public void onCreate()
- {
- }
- @Override
- public void onResume()
- {
- }
- @Override
- public void setNewViewObj(MainView newViewObj)
- {
- mMainView = newViewObj;
- mMainView.setTextTextView(Integer.toString(mValueObject.getValue()));
- }
- @Override
- public void executeClickIncreaseBtn()
- {
- mValueObject.setValue( mValueObject.getValue() + 1 );
- mMainView.setTextTextView(Integer.toString(mValueObject.getValue()));
- }
- @Override
- public void executeClickSetValBtn()
- {
- String valueStr = mMainView.getTextEditText().toString();
- int value = Integer.parseInt(valueStr);
- mValueObject.setValue(value);
- mMainView.setTextTextView(valueStr);
- }
- }
Add Comment
Please, Sign In to add comment