androidx.core.app.NavUtils Java Examples

The following examples show how to use androidx.core.app.NavUtils. 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: 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 #2
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 #3
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 #4
Source File: DetailsActivity.java    From tracker-control-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();// Respond to the action bar's Up/Home button
    if (itemId == android.R.id.home) {
        NavUtils.navigateUpFromSameTask(this);
        return true;
    } else if (itemId == R.id.action_export_csv) {
        if (hasPermissions()) {
            exportCsv();
        }
        return true;
    } else if (itemId == R.id.action_launch) {
        PackageManager pm = getPackageManager();
        Intent intent = pm.getLaunchIntentForPackage(appPackageName);
        final Intent launch = (intent == null ||
                intent.resolveActivity(pm) == null ? null : intent);
        if (launch != null)
            startActivity(launch);
    }
    return super.onOptionsItemSelected(item);
}
 
Example #5
Source File: RunReviewFragment.java    From science-journal with Apache License 2.0 6 votes vote down vote up
@Override
public void requestDelete(Bundle extras) {
  experiment.deleteTrial(getTrial(), getActivity(), appAccount);
  getDataController()
      .updateExperiment(
          experimentId,
          new LoggingConsumer<Success>(TAG, "Deleting new trial") {
            @Override
            public void success(Success value) {
              if (claimExperimentsMode) {
                WhistlePunkApplication.getUsageTracker(getActivity())
                    .trackEvent(
                        TrackerConstants.CATEGORY_CLAIMING_DATA,
                        TrackerConstants.ACTION_DELETE_TRIAL,
                        null,
                        0);
              }
              // Go back to the observe & record.
              Intent intent = new Intent(getActivity(), SensorFragment.class);
              NavUtils.navigateUpTo(getActivity(), intent);
            }
          });
}
 
Example #6
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 #7
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 #8
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 #9
Source File: ExampleMaterialAboutFragmentActivity.java    From material-about-library with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_example_material_about_fragment);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportFragmentManager().beginTransaction()
            .replace(R.id.container, ExampleMaterialAboutFragment.newInstance(new ExampleMaterialAboutFragment()))
            .commit();

    setTitle("About Fragment Activity");

    if (NavUtils.getParentActivityName(this) != null) {
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    }

}
 
Example #10
Source File: AppUtils.java    From MaterialProgressBar with Apache License 2.0 6 votes vote down vote up
public static void navigateUp(Activity activity, Bundle extras) {
    Intent upIntent = NavUtils.getParentActivityIntent(activity);
    if (upIntent != null) {
        if (extras != null) {
            upIntent.putExtras(extras);
        }
        if (NavUtils.shouldUpRecreateTask(activity, 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(activity)
                    // 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.
            // According to http://stackoverflow.com/a/14792752/2420519
            //NavUtils.navigateUpTo(activity, upIntent);
            upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            activity.startActivity(upIntent);
        }
    }
    activity.finish();
}
 
Example #11
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 #12
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 #13
Source File: ActivitySettings.java    From NetGuard with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            Log.i(TAG, "Up");
            NavUtils.navigateUpFromSameTask(this);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example #14
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 #15
Source File: AppCompatPreferenceActivity.java    From busybox with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #16
Source File: EditTaskActivity.java    From opentasks 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:
            NavUtils.navigateUpFromSameTask(this);
            return true;
        default:
            break;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #17
Source File: ActivityPro.java    From NetGuard with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            Log.i(TAG, "Up");
            NavUtils.navigateUpFromSameTask(this);
            return true;
        case R.id.menu_challenge:
            menu_challenge();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example #18
Source File: ApplozicSetting.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Intent getParentActivityIntent(Activity sourceActivity) {
    String parentActivityName = sharedPreferences.getString(PARENT_ACTIVITY_INTENT, null);

    try {
        if (parentActivityName != null) {
            final ComponentName target = new ComponentName(sourceActivity, parentActivityName);
            return new Intent().setComponent(target);
        } else {
            return NavUtils.getParentActivityIntent(sourceActivity);
        }
    } catch (Exception e) {
        e.printStackTrace();
        return NavUtils.getParentActivityIntent(sourceActivity);
    }
}
 
Example #19
Source File: MobiComKitPeopleActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int i = item.getItemId();
    if (i == android.R.id.home) {
        NavUtils.navigateUpFromSameTask(this);
        return true;
        // For platforms earlier than Android 3.0, triggers the search activity
    } else if (i == R.id.menu_search) {// if (!Utils.hasHoneycomb()) {
        onSearchRequested();
        //}

    }
    return super.onOptionsItemSelected(item);
}
 
Example #20
Source File: MovieDetailsActivity.java    From MovieGuide with MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
    }
    return super.onOptionsItemSelected(item);
}
 
Example #21
Source File: BenchmarkResultActivity.java    From BlurTestAndroid 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:
            if (Build.VERSION.SDK_INT >= 16) {
                NavUtils.navigateUpFromSameTask(this);
            } else {
                finish();
            }
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #22
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 #23
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 #24
Source File: VideoActivity.java    From evercam-android with GNU Affero General Public License v3.0 5 votes vote down vote up
/************************
 * Private Methods
 ************************/

private void navigateBackToCameraList() {
    if (CamerasActivity.activity == null) {
        if (android.os.Build.VERSION.SDK_INT >= 16) {
            Intent upIntent = NavUtils.getParentActivityIntent(this);
            TaskStackBuilder.create(this)
                    .addNextIntentWithParentStack(upIntent)
                    .startActivities();
        }
    }

    finish();
}
 
Example #25
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 #26
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 #27
Source File: DetailFragment.java    From wear-os-samples 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:
            // Some small additions to handle "up" navigation correctly
            Intent upIntent = NavUtils.getParentActivityIntent(getActivity());
            upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

            // Check if up activity needs to be created (usually when
            // detail screen is opened from a notification or from the
            // Wearable app
            if (NavUtils.shouldUpRecreateTask(getActivity(), upIntent)
                    || getActivity().isTaskRoot()) {

                // Synthesize parent stack
                TaskStackBuilder.create(getActivity())
                        .addNextIntentWithParentStack(upIntent)
                        .startActivities();
            }

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                // On Lollipop+ we finish so to run the nice animation
                getActivity().finishAfterTransition();
                return true;
            }

            // Otherwise let the system handle navigating "up"
            return false;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #28
Source File: ActivitySettings.java    From tracker-control-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            Log.i(TAG, "Up");
            NavUtils.navigateUpFromSameTask(this);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example #29
Source File: ImageDetailActivity.java    From graphics-samples 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:
            NavUtils.navigateUpFromSameTask(this);
            return true;
        case R.id.clear_cache:
            mImageFetcher.clearCache();
            Toast.makeText(
                    this, R.string.clear_cache_complete_toast, Toast.LENGTH_SHORT).show();
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #30
Source File: SettingsActivity.java    From abnd-track-pomodoro-timer-app with MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
            overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
            return true;
    }
    return super.onOptionsItemSelected(item);
}