android.support.v4.app.NavUtils Java Examples

The following examples show how to use android.support.v4.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: SettingsActivity.java    From android with MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (NavUtils.shouldUpRecreateTask(this, upIntent) || isTaskRoot()) {
            // This activity is NOT part of this app's task, so create a new task
            // when navigating up, with a synthesized back stack.
            // This is probably because we opened settings from the notification.
            TaskStackBuilder.create(this)
                    // Add all of this activity's parents to the back stack
                    .addNextIntentWithParentStack(upIntent)
                    // Navigate up to the closest parent
                    .startActivities();
        } else {
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #2
Source File: MapActivity.java    From android-map_list with MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            Intent upIntent = NavUtils.getParentActivityIntent(this);

            if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                TaskStackBuilder.create(this)
                        .addNextIntentWithParentStack(upIntent)
                        .startActivities();
            } else {
                NavUtils.navigateUpTo(this, upIntent);
            }

            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example #3
Source File: FilterEventACTIVITY.java    From ALLGO 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:
            Intent upIntent = new Intent(this, HomeACTIVITY.class);
            if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                TaskStackBuilder.from(this)
                        //如果这里有很多原始的Activity,它们应该被添加在这里
                        .addNextIntent(upIntent)
                        .startActivities();
                finish();
            } else {
                NavUtils.navigateUpTo(this, upIntent);
            }
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #4
Source File: DebatesActivity.java    From kaif-android 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:
      Intent upIntent = NavUtils.getParentActivityIntent(this);
      if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
        TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
      } else {
        upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        NavUtils.navigateUpTo(this, upIntent);
      }
      return true;
    case R.id.action_open_link:
      Intent intent = new Intent(Intent.ACTION_VIEW);
      intent.setData(article.getPermaLink());
      intent.addCategory(Intent.CATEGORY_BROWSABLE);
      this.startActivity(intent);
      return true;
  }

  return super.onOptionsItemSelected(item);
}
 
Example #5
Source File: DisplaySingleColorActivity.java    From coursera-android with MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home: {
            Toast toast = Toast.makeText(
                    this, getString(R.string.shortcut_string), Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();

            // Navigate up to parent Activity and finish this
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
    }
    return super.onOptionsItemSelected(item);
}
 
Example #6
Source File: BaseActivity.java    From Sky31Radio with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Timber.i("onCreate");
    AVAnalytics.trackAppOpened(getIntent());
    setContentView(provideContentViewId());
    ButterKnife.inject(this);
    if(toolbar!=null){
        setSupportActionBar(toolbar);
    }
    if(!TextUtils.isEmpty(NavUtils.getParentActivityName(this))){
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    if(Build.VERSION.SDK_INT <= 19){
        tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setNavigationBarTintEnabled(true);
        tintManager.setStatusBarTintColor(getResources().getColor(R.color.primary_dark));
    }
}
 
Example #7
Source File: SearchActivity.java    From android-discourse 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:
            // 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.navigateUpFromSameTask(this);
        case R.id.action_search:
            L.i();
            return false;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #8
Source File: UserSelectActivity.java    From WeChatMomentStat-Android with GNU General Public License v3.0 6 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.toggle_select_all_menu_btn:
            for (int i=0;i<checkBoxList.size();i++) {
                checkBoxList.get(i).setChecked(!isSelectedAll);
            }
            isSelectedAll = !isSelectedAll;
            return true;
        case R.id.user_select_done_menu_btn:
            doneSelectingUsers();
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #9
Source File: SettingsActivity.java    From openvidonn with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == android.R.id.home) {
        // 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
        //
        // TODO: If Settings has multiple levels, Up should navigate up
        // that hierarchy.
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #10
Source File: BaseTitleActivity.java    From Tok-Android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * default method to finish activity,
 * it can be changed by override
 */
public void onFinish() {
    if (isSupportTaskBack()) {
        moveTaskToBack(true);
    } else {
        String parentActivityName = NavUtils.getParentActivityName(this);
        if (parentActivityName != null && !SystemUtils.isActivityRunning(this,
            parentActivityName)) {
            PageJumpIn.jumpActivity(this, parentActivityName);
            finish();
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            finishAfterTransition();
        } else {
            finish();
        }
    }
}
 
Example #11
Source File: WeatherForecastActivity.java    From good-weather with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_forecast_refresh:
            if (mConnectionDetector.isNetworkAvailableAndConnected()) {
                getWeather();
                setVisibleUpdating(true);
            } else {
                Toast.makeText(WeatherForecastActivity.this,
                               R.string.connection_not_found,
                               Toast.LENGTH_SHORT).show();
            }
            return true;
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #12
Source File: LayoutChangesActivity.java    From AndroidTrainingCode 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_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 #13
Source File: textActivity.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:
		 Intent upIntent = new Intent(this, Fd2v11.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;
	}
	return super.onOptionsItemSelected(item);
}
 
Example #14
Source File: CrossfadeActivity.java    From AndroidTrainingCode 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_toggle:
            // Toggle whether content is loaded.
            mContentLoaded = !mContentLoaded;
            showContentOrLoadingIndicator(mContentLoaded);
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example #15
Source File: MusicTrackListActivity.java    From PlayMusicExporter with MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == android.R.id.home) {
        // 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, new Intent(this, MusicContainerListActivity.class));
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #16
Source File: ActionbarActivity.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 #17
Source File: FeedActivity.java    From android-mvp-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 #18
Source File: SettingsActivity.java    From NetworkMapper with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == android.R.id.home) {
        // 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
        //
        // TODO: If Settings has multiple levels, Up should navigate up
        // that hierarchy.
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #19
Source File: SettingsActivity.java    From XMouse with MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

        case android.R.id.home:
            // 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
            //
            // TODO: If Settings has multiple levels, Up should navigate up
            // that hierarchy.
            NavUtils.navigateUpFromSameTask(this);
            return true;

    }
    return super.onOptionsItemSelected(item);
}
 
Example #20
Source File: RecipeItemDetailActivity.java    From android-recipes-app 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:
		// 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, new Intent(this, RecipeItemListActivity.class));
		return true;
	}
	return super.onOptionsItemSelected(item);
}
 
Example #21
Source File: SettingsActivity.java    From ScreenShift with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == android.R.id.home) {
        // 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
        //
        // TODO: If Settings has multiple levels, Up should navigate up
        // that hierarchy.
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #22
Source File: CategoryActivity.java    From android-discourse 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:
            // 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.navigateUpFromSameTask(this);
            // finish();
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #23
Source File: Verify.java    From Women-Safety-App with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case android.R.id.home:
		// 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.navigateUpFromSameTask(this);
		return true;
	}
	return super.onOptionsItemSelected(item);
}
 
Example #24
Source File: WifiListActivity.java    From wifi_backend with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final int id = item.getItemId();

    if (id == android.R.id.home) {
        // 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.navigateUpFromSameTask(this);
        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example #25
Source File: UserActivity.java    From v2ex-daily-android 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:
            Intent upIntent = NavUtils.getParentActivityIntent(this);
            if(NavUtils.shouldUpRecreateTask(this, upIntent)){
                TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
            }else{
                upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                NavUtils.navigateUpTo(this, upIntent);
            }
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example #26
Source File: SimpleEq.java    From mobile-manager-tool with MIT License 5 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:
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #27
Source File: SnippetDetailActivity.java    From Android-REST-API-Explorer with MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == android.R.id.home) {
        NavUtils.navigateUpTo(this, new Intent(this, SnippetListActivity.class));
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #28
Source File: ContentActivity.java    From ankihelper with GNU General Public License v3.0 5 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:
            NavUtils.navigateUpFromSameTask(this);
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #29
Source File: SearchActivity.java    From good-weather 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:
            NavUtils.navigateUpFromSameTask(this);
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example #30
Source File: ImageDetailActivity.java    From android-DisplayingBitmaps 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);
}