use of com.example.android.batchstepsensor.cardstream.StreamRetentionFragment 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);
}
}
Aggregations