Search in sources :

Example 1 with CardStreamState

use of com.example.android.batchstepsensor.cardstream.CardStreamState in project Android-Developers-Samples by johnjohndoe.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    FragmentManager fm = getSupportFragmentManager();
    BatchStepSensorFragment fragment = (BatchStepSensorFragment) fm.findFragmentByTag(FRAGTAG);
    if (fragment == null) {
        FragmentTransaction transaction = fm.beginTransaction();
        fragment = new BatchStepSensorFragment();
        transaction.add(fragment, FRAGTAG);
        transaction.commit();
    }
    // Use fragment as click listener for cards, but must implement correct interface
    if (!(fragment instanceof OnCardClickListener)) {
        throw new ClassCastException("BatchStepSensorFragment must " + "implement OnCardClickListener interface.");
    }
    OnCardClickListener clickListener = (OnCardClickListener) fm.findFragmentByTag(FRAGTAG);
    mRetentionFragment = (StreamRetentionFragment) fm.findFragmentByTag(RETENTION_TAG);
    if (mRetentionFragment == null) {
        mRetentionFragment = new StreamRetentionFragment();
        fm.beginTransaction().add(mRetentionFragment, RETENTION_TAG).commit();
    } else {
        // If the retention fragment already existed, we need to pull some state.
        // pull state out
        CardStreamState state = mRetentionFragment.getCardStream();
        // dump it in CardStreamFragment.
        mCardStreamFragment = (CardStreamFragment) fm.findFragmentById(R.id.fragment_cardstream);
        mCardStreamFragment.restoreState(state, clickListener);
    }
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction) CardStreamState(com.example.android.batchstepsensor.cardstream.CardStreamState) StreamRetentionFragment(com.example.android.batchstepsensor.cardstream.StreamRetentionFragment) OnCardClickListener(com.example.android.batchstepsensor.cardstream.OnCardClickListener)

Example 2 with CardStreamState

use of com.example.android.batchstepsensor.cardstream.CardStreamState in project Android-Developers-Samples by johnjohndoe.

the class MainActivity method onSaveInstanceState.

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    CardStreamState state = getCardStream().dumpState();
    mRetentionFragment.storeCardStream(state);
}
Also used : CardStreamState(com.example.android.batchstepsensor.cardstream.CardStreamState)

Aggregations

CardStreamState (com.example.android.batchstepsensor.cardstream.CardStreamState)2 FragmentManager (android.support.v4.app.FragmentManager)1 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 OnCardClickListener (com.example.android.batchstepsensor.cardstream.OnCardClickListener)1 StreamRetentionFragment (com.example.android.batchstepsensor.cardstream.StreamRetentionFragment)1