Android Open Source - Android-Counter-Application Counter History Activity






From Project

Back to project page Android-Counter-Application.

License

The source code is released under:

GNU General Public License

If you think the Android project Android-Counter-Application listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ca.ualberta.cs.artem_counter;
//from   w w w .j  a  v  a 2s .  c om
import android.app.ActionBar;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.widget.ArrayAdapter;

public class CounterHistoryActivity extends FragmentActivity implements
ActionBar.OnNavigationListener {

  /**
   * The serialization (saved instance state) Bundle key representing the
   * current dropdown position.
   */
  private static final String STATE_SELECTED_NAVIGATION_ITEM = "selected_navigation_item";
  private int COUNTER_INDEX;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_counter_history);

    //Get which counter requested this activity
    Intent intent = getIntent();
    COUNTER_INDEX = intent.getIntExtra("temp", 0);

    // Set up the action bar to show a dropdown list.
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    // Show the Up button in the action bar.
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Set up the dropdown list navigation in the action bar.
    actionBar.setListNavigationCallbacks(
        // Specify a SpinnerAdapter to populate the dropdown list.
        new ArrayAdapter<String>(actionBar.getThemedContext(),
            android.R.layout.simple_list_item_1,
            android.R.id.text1, new String[] {
          getString(R.string.title_section1),
          getString(R.string.title_section2),
          getString(R.string.title_section3),
          getString(R.string.title_section4), }), this);
  }

  @Override
  public void onRestoreInstanceState(Bundle savedInstanceState) {
    // Restore the previously serialized current dropdown position.
    if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) {
      getActionBar().setSelectedNavigationItem(
          savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM));
    }
  }

  @Override
  public void onSaveInstanceState(Bundle outState) {
    // Serialize the current dropdown position.
    outState.putInt(STATE_SELECTED_NAVIGATION_ITEM, getActionBar()
        .getSelectedNavigationIndex());
  }

  @Override
  public boolean onNavigationItemSelected(int position, long id) {
    // When the given dropdown item is selected, show its contents in the
    // container view.
    Fragment fragment = new CounterHistoryFragment();
    Bundle args = new Bundle();
    args.putInt(CounterHistoryFragment.ARG_SECTION_NUMBER, position + 1);
    args.putInt(CounterHistoryFragment.counterIndex, COUNTER_INDEX);
    fragment.setArguments(args);
    getSupportFragmentManager().beginTransaction()
    .replace(R.id.container, fragment).commit();
    return true;
  }
}




Java Source Code List

ca.ualberta.cs.artem_counter.CounterAdapter.java
ca.ualberta.cs.artem_counter.CounterHistoryActivity.java
ca.ualberta.cs.artem_counter.CounterHistoryFragment.java
ca.ualberta.cs.artem_counter.CounterHistory.java
ca.ualberta.cs.artem_counter.CounterListActivity.java
ca.ualberta.cs.artem_counter.CounterList.java
ca.ualberta.cs.artem_counter.Counter.java