@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fex_list); // retrieve argument and pass it to fragment mWorkout = (Workout) getIntent().getExtras().getSerializable(ARG_WORKOUT); FExListFragment fragment = (FExListFragment) getSupportFragmentManager().findFragmentById(R.id.exercise_list); fragment.setWorkout(mWorkout); // Show the Up button in the action bar. getSupportActionBar().setDisplayHomeAsUpEnabled(true); if (findViewById(R.id.exercise_detail_container) != null) { // The detail container view will be present only in the // large-screen layouts (res/values-large and // res/values-sw600dp). If this view is present, then the // activity should be in two-pane mode. mTwoPane = true; // In two-pane mode, list items should be given the // 'activated' state when touched. ((FExListFragment) getSupportFragmentManager().findFragmentById(R.id.exercise_list)) .setActivateOnItemClick(true); } }
@Override public void onEntryEdited(FitnessExercise fitnessExercise) { Log.d(TAG, "onEntryEdited()"); mWorkout.updateFitnessExercise(fitnessExercise); DataProvider dataProvider = new DataProvider(getActivity()); dataProvider.saveWorkoutAsync(mWorkout); FExListFragment fragment = (FExListFragment) getFragmentManager().findFragmentById(R.id.exercise_list); if (fragment != null) { Log.d(TAG, "updating FExListFragment"); // either notify list fragment if it's there (on tablets) fragment.setWorkout(mWorkout); } else { Log.d(TAG, "setting Intent for FExListActivity"); // or return intent if list fragment is not visible (on small // screens) Intent i = new Intent(); i.putExtra(FExListActivity.ARG_WORKOUT, mWorkout); this.getActivity().setResult(Activity.RESULT_OK, i); } mExercise = fitnessExercise; updateTrainingEntries(); }
protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.v(TAG, "onActivityResult()"); if (requestCode == RESULT_WORKOUT) { if (resultCode == RESULT_OK) { // Workout has been changed, so update data mWorkout = (Workout) data.getSerializableExtra(FExListActivity.ARG_WORKOUT); Log.v(TAG, "updating Workout of FExListActivity:\n" + mWorkout.toDebugString()); // update in fragment too FExListFragment fragment = (FExListFragment) getSupportFragmentManager().findFragmentById(R.id.exercise_list); if (fragment != null) { Log.d(TAG, "updating FExListFragment"); // either notify list fragment if it's there (on tablets) fragment.setWorkout(mWorkout); } else { Log.e(TAG, "Did not find FExListFragment"); } } } }