Java Code Examples for androidx.core.app.NavUtils#navigateUpTo()

The following examples show how to use androidx.core.app.NavUtils#navigateUpTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditTriggerFragment.java    From science-journal with Apache License 2.0 6 votes vote down vote up
private void goToParent() {
  if (getActivity() == null) {
    return;
  }
  // To restart the TriggerListActivity, need to pass back the trigger and layout info.
  Intent upIntent = NavUtils.getParentActivityIntent(getActivity());
  upIntent.putExtra(TriggerListActivity.EXTRA_ACCOUNT_KEY, appAccount.getAccountKey());
  upIntent.putExtra(TriggerListActivity.EXTRA_SENSOR_ID, sensorId);
  upIntent.putExtra(TriggerListActivity.EXTRA_EXPERIMENT_ID, experimentId);
  upIntent.putExtra(TriggerListActivity.EXTRA_LAYOUT_POSITION, sensorLayoutPosition);
  upIntent.putExtra(
      TriggerListActivity.EXTRA_TRIGGER_ORDER,
      getArguments().getStringArrayList(TriggerListActivity.EXTRA_TRIGGER_ORDER));
  if (getActivity() != null) {
    NavUtils.navigateUpTo(getActivity(), upIntent);
  } else {
    Log.e(TAG, "Can't exit activity because it's no longer there.");
  }
}
 
Example 2
Source File: AppcompatActivity.java    From ui with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case android.R.id.home:
		// Navigate "up" the demo structure to the launchpad activity.
		// See http://developer.android.com/design/patterns/navigation.html for more.
		NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class));
		return true;

	case R.id.action_previous:
		// Go to the previous step in the wizard. If there is no previous step,
		// setCurrentItem will do nothing.
		viewPager.setCurrentItem(viewPager.getCurrentItem() - 1);
		return true;

	case R.id.action_next:
		// Advance to the next step in the wizard. If there is no next step, setCurrentItem
		// will do nothing.
		viewPager.setCurrentItem(viewPager.getCurrentItem() + 1);
		return true;
	}

	return super.onOptionsItemSelected(item);
}
 
Example 3
Source File: CardFlipActivity.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            // Navigate "up" the demo structure to the launchpad activity.
            // See http://developer.android.com/design/patterns/navigation.html for more.
            NavUtils.navigateUpTo(this, new Intent(this, AnimationsDemo.class));
            return true;

        case R.id.action_flip:
            flipCard();
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 4
Source File: CrossfadeActivity.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            // Navigate "up" the demo structure to the launchpad activity.
            // See http://developer.android.com/design/patterns/navigation.html for more.
            NavUtils.navigateUpTo(this, new Intent(this, AnimationsDemo.class));
            return true;

        case R.id.action_toggle:
            // Toggle whether content is loaded.
            mContentLoaded = !mContentLoaded;
            showContentOrLoadingIndicator(mContentLoaded);
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 5
Source File: ScreenSlideActivity.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            // Navigate "up" the demo structure to the launchpad activity.
            // See http://developer.android.com/design/patterns/navigation.html for more.
            NavUtils.navigateUpTo(this, new Intent(this, AnimationsDemo.class));
            return true;

        case R.id.action_previous:
            // Go to the previous step in the wizard. If there is no previous step,
            // setCurrentItem will do nothing.
            mPager.setCurrentItem(mPager.getCurrentItem() - 1);
            return true;

        case R.id.action_next:
            // Advance to the next step in the wizard. If there is no next step, setCurrentItem
            // will do nothing.
            mPager.setCurrentItem(mPager.getCurrentItem() + 1);
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 6
Source File: LayoutChangesActivity.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            // Navigate "up" the demo structure to the launchpad activity.
            // See http://developer.android.com/design/patterns/navigation.html for more.
            NavUtils.navigateUpTo(this, new Intent(this, AnimationsDemo.class));
            return true;

        case R.id.action_add_item:
            // Hide the "empty" view since there is now at least one item in the list.
            findViewById(android.R.id.empty).setVisibility(View.GONE);
            addItem();
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 7
Source File: PostItemDetailActivity.java    From mimi-reader with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    // This ID represents the Home or Up button. In the case of this
    // activity, the Up button is shown. Use NavUtils to allow users
    // to navigate up one level in the application structure. For
    // more details, see the Navigation pattern on Android Design:
    //
    // http://developer.android.com/design/patterns/navigation.html#up-vs-back
    //
    final Intent listIntent = new Intent(this, PostItemListActivity.class);
    if (NavUtils.shouldUpRecreateTask(this, listIntent)) {
        final TaskStackBuilder taskStack = TaskStackBuilder.create(this);
        taskStack.addNextIntent(listIntent);
        taskStack.startActivities();
    } else {
        NavUtils.navigateUpTo(this, listIntent);
    }
}
 
Example 8
Source File: FeedActivity.java    From android-mvvm-architecture with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        // Respond to the action bar's Up/Home button
        case android.R.id.home:
            Intent upIntent = NavUtils.getParentActivityIntent(this);
            upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                // This activity is NOT part of this app's task, so create a new task
                // when navigating up, with a synthesized back stack.
                TaskStackBuilder.create(this)
                        // Add all of this activity's parents to the back stack
                        .addNextIntentWithParentStack(upIntent)
                        // Navigate up to the closest parent
                        .startActivities();
            } else {
                // This activity is part of this app's task, so simply
                // navigate up to the logical parent activity.
                NavUtils.navigateUpTo(this, upIntent);
            }
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 9
Source File: ExperimentDetailsFragment.java    From science-journal with Apache License 2.0 5 votes vote down vote up
private void goToExperimentList() {
  if (getActivity() == null) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
      Log.d(TAG, "goToExperimentList called on null activity");
    }
    return;
  }

  if (claimExperimentsMode) {
    getActivity().finish();
    return;
  }

  Intent upIntent =
      getActivity() == null ? null : NavUtils.getParentActivityIntent(getActivity());
  if (upIntent == null) {
    // This is cheating a bit.  Currently, upIntent has only been observed to be null
    // when we're using panes mode, so here we just assume usePanes==true.
    Intent intent =
        MainActivity.launchIntent(getActivity(), R.id.navigation_item_experiments, true);
    getActivity().startActivity(intent);
    getActivity().finish();
    return;
  }
  if (NavUtils.shouldUpRecreateTask(getActivity(), upIntent)
      || getArguments().getBoolean(ARG_CREATE_TASK, false)) {
    upIntent.putExtra(MainActivity.ARG_SELECTED_NAV_ITEM_ID, R.id.navigation_item_experiments);
    upIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    // TODO: Transition animation
    TaskStackBuilder.create(getActivity())
        .addNextIntentWithParentStack(upIntent)
        .startActivities();
  } else {
    NavUtils.navigateUpTo(getActivity(), upIntent);
  }
}
 
Example 10
Source File: UpdateRunFragment.java    From science-journal with Apache License 2.0 5 votes vote down vote up
private void returnToRunReview() {
  Intent upIntent = NavUtils.getParentActivityIntent(getActivity());
  upIntent.putExtra(RunReviewActivity.EXTRA_FROM_RECORD, false);
  upIntent.putExtra(RunReviewFragment.ARG_ACCOUNT_KEY, appAccount.getAccountKey());
  upIntent.putExtra(RunReviewFragment.ARG_START_LABEL_ID, runId);
  upIntent.putExtra(RunReviewFragment.ARG_EXPERIMENT_ID, experimentId);
  upIntent.putExtra(RunReviewFragment.ARG_CLAIM_EXPERIMENTS_MODE, false);
  NavUtils.navigateUpTo(getActivity(), upIntent);
}
 
Example 11
Source File: LicenseActivity.java    From science-journal with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
  if (item.getItemId() == android.R.id.home) {
    if (getSupportFragmentManager().popBackStackImmediate()) {
      return true;
    } else {
      Intent intent =
          SettingsActivity.getLaunchIntent(
              this, getString(R.string.action_about), SettingsActivity.TYPE_ABOUT);
      NavUtils.navigateUpTo(this, intent);
      return true;
    }
  }
  return super.onOptionsItemSelected(item);
}
 
Example 12
Source File: ZoomActivity.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            // Navigate "up" the demo structure to the launchpad activity.
            // See http://developer.android.com/design/patterns/navigation.html for more.
            NavUtils.navigateUpTo(this, new Intent(this, AnimationsDemo.class));
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 13
Source File: FragMenuActivity.java    From ui with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {

	case android.R.id.home:
		Intent upIntent = new Intent(this, MainActivity.class);
		// This ID represents the Home or Up button. In the case of this
		// activity, the Up button is shown. Use NavUtils to allow users
		// to navigate up one level in the application structure. For
		// more details, see the Navigation pattern on Android Design:
		//
		// http://developer.android.com/design/patterns/navigation.html#up-vs-back
		//
		NavUtils.navigateUpTo(this,	upIntent);
		return true;
	case R.id.frag1:
		if (!isfrag1) {
			getSupportFragmentManager().beginTransaction()
			.replace(R.id.text_container, one).commit();
			isfrag1 = true;
			supportInvalidateOptionsMenu();
		}
		return true;
	case R.id.frag2:
		if (isfrag1) {
			getSupportFragmentManager().beginTransaction()
			.replace(R.id.text_container, two).commit();
			isfrag1 = false;
			supportInvalidateOptionsMenu();
		}
		return true;
	}
	return super.onOptionsItemSelected(item);
}
 
Example 14
Source File: ActionMenuActivity.java    From ui with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case android.R.id.home:
		// Navigate "up" the demo structure to the launchpad activity.
		// See http://developer.android.com/design/patterns/navigation.html for more.
		NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class));
		return true;
	default:
		return super.onOptionsItemSelected(item);
	}
}
 
Example 15
Source File: ErrorActivity.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
private void goToReturnActivity() {
    Class<? extends Activity> checkedReturnActivity = getReturnActivity(returnActivity);
    if (checkedReturnActivity == null) {
        super.onBackPressed();
    } else {
        Intent intent = new Intent(this, checkedReturnActivity);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        NavUtils.navigateUpTo(this, intent);
    }
}
 
Example 16
Source File: PostItemDetailActivity.java    From mimi-reader with Apache License 2.0 4 votes vote down vote up
@Subscribe
public void homeButtonPressed(HomeButtonPressedEvent event) {
    NavUtils.navigateUpTo(this, new Intent(this, PostItemListActivity.class));
}
 
Example 17
Source File: AppCompatPreferenceActivity.java    From EhViewer with Apache License 2.0 2 votes vote down vote up
/**
 * Navigate from sourceActivity to the activity specified by upIntent, finishing sourceActivity
 * in the process. upIntent will have the flag {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_TOP} set
 * by this method, along with any others required for proper up navigation as outlined
 * in the Android Design Guide.
 *
 * <p>This method should be used when performing up navigation from within the same task
 * as the destination. If up navigation should cross tasks in some cases, see
 * {@link #supportShouldUpRecreateTask(android.content.Intent)}.</p>
 *
 * @param upIntent An intent representing the target destination for up navigation
 */
public void supportNavigateUpTo(@NonNull Intent upIntent) {
    NavUtils.navigateUpTo(this, upIntent);
}
 
Example 18
Source File: AppCompatPreferenceActivity.java    From MHViewer with Apache License 2.0 2 votes vote down vote up
/**
 * Navigate from sourceActivity to the activity specified by upIntent, finishing sourceActivity
 * in the process. upIntent will have the flag {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_TOP} set
 * by this method, along with any others required for proper up navigation as outlined
 * in the Android Design Guide.
 *
 * <p>This method should be used when performing up navigation from within the same task
 * as the destination. If up navigation should cross tasks in some cases, see
 * {@link #supportShouldUpRecreateTask(android.content.Intent)}.</p>
 *
 * @param upIntent An intent representing the target destination for up navigation
 */
public void supportNavigateUpTo(@NonNull Intent upIntent) {
    NavUtils.navigateUpTo(this, upIntent);
}