|
| 1 | +package com.meetme.android.multistateview.sample; |
| 2 | + |
| 3 | +import android.os.Bundle; |
| 4 | +import android.support.v7.app.ActionBarActivity; |
| 5 | +import android.view.Menu; |
| 6 | +import android.view.MenuItem; |
| 7 | +import android.widget.TextView; |
| 8 | + |
| 9 | +import com.meetme.android.multistateview.MultiStateView; |
| 10 | + |
| 11 | + |
| 12 | +public class MainActivity extends ActionBarActivity { |
| 13 | + MultiStateView.ContentState mState; |
| 14 | + |
| 15 | + private MultiStateView mMultiStateView; |
| 16 | + |
| 17 | + private TextView mExampleOfHowToGetContentView; |
| 18 | + |
| 19 | + private TextView mStateView; |
| 20 | + |
| 21 | + @Override |
| 22 | + protected void onCreate(Bundle savedInstanceState) { |
| 23 | + super.onCreate(savedInstanceState); |
| 24 | + setContentView(R.layout.activity_main); |
| 25 | + |
| 26 | + mStateView = (TextView) findViewById(R.id.state); |
| 27 | + mMultiStateView = (MultiStateView) findViewById(R.id.content); |
| 28 | + mState = mMultiStateView.getState(); |
| 29 | + setStateText(mState); |
| 30 | + mExampleOfHowToGetContentView = (TextView) mMultiStateView.getContentView(); |
| 31 | + } |
| 32 | + |
| 33 | + private void setStateText(MultiStateView.ContentState state) { |
| 34 | + mStateView.setText(String.format("State: %s", state)); |
| 35 | + } |
| 36 | + |
| 37 | + |
| 38 | + @Override |
| 39 | + public boolean onCreateOptionsMenu(Menu menu) { |
| 40 | + // Inflate the menu; this adds items to the action bar if it is present. |
| 41 | + getMenuInflater().inflate(R.menu.main, menu); |
| 42 | + return true; |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + public boolean onOptionsItemSelected(MenuItem item) { |
| 47 | + // Handle action bar item clicks here. The action bar will |
| 48 | + // automatically handle clicks on the Home/Up button, so long |
| 49 | + // as you specify a parent activity in AndroidManifest.xml. |
| 50 | + int id = item.getItemId(); |
| 51 | + if (id == R.id.action_rotate_state) { |
| 52 | + // This is only done because we're rotating state; you'd typically just call direct to mMultiStateView#setState(ContentState) |
| 53 | + MultiStateView.ContentState newState = MultiStateView.ContentState.values()[(mState.ordinal() + 1) % MultiStateView.ContentState.values().length]; |
| 54 | + |
| 55 | + setState(newState); |
| 56 | + return true; |
| 57 | + } |
| 58 | + return super.onOptionsItemSelected(item); |
| 59 | + } |
| 60 | + |
| 61 | + public void setState(MultiStateView.ContentState state) { |
| 62 | + setStateText(state); |
| 63 | + mMultiStateView.setState(state); |
| 64 | + mState = state; |
| 65 | + } |
| 66 | + |
| 67 | +} |
0 commit comments