List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:com.smc.tw.waltz.MainActivity.java
@Override public boolean onNavigationItemSelected(MenuItem menuItem) { if (DEBUG)/*from w w w. java 2 s .co m*/ Log.d(TAG, "onNavigationItemSelected m:" + menuItem); menuItem.setChecked(true); int id = menuItem.getItemId(); if (DEBUG) Log.d(TAG, "onNavigationItemSelected i:" + id); if (DEBUG) Log.d(TAG, "onNavigationItemSelected c:" + mFragmentManager.getBackStackEntryCount()); while (mFragmentManager.getBackStackEntryCount() > 0) { try { mFragmentManager.popBackStackImmediate(); } catch (IllegalStateException e) { } } mDevicePagerFragment.clearAllFragment(); mDevicePagerFragment.notifyDataSetChanged(); switch (id) { case R.id.navigation_device_list: { showDeviceList(); break; } case R.id.navigation_dropbox: { showDropboxAssociation(); break; } case R.id.navigation_signin: { mForceSignIn = true; SignIn(); break; } case R.id.navigation_signout: { showSignOutDialog(); break; } case R.id.navigation_help: { showHelp(); break; } case R.id.navigation_about: { showAbout(); break; } default: break; } mDrawerLayout.closeDrawer(GravityCompat.START); return true; }
From source file:com.eveningoutpost.dexdrip.Home.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_home, menu); //wear integration if (!prefs.getBoolean("wear_sync", false)) { menu.removeItem(R.id.action_open_watch_settings); menu.removeItem(R.id.action_resend_last_bg); menu.removeItem(R.id.action_sync_watch_db);//KS }//from ww w. j a v a 2 s . c o m //speak readings MenuItem menuItem = menu.findItem(R.id.action_toggle_speakreadings); if (prefs.getBoolean("bg_to_speech_shortcut", false)) { menuItem.setVisible(true); if (prefs.getBoolean("bg_to_speech", false)) { menuItem.setChecked(true); } else { menuItem.setChecked(false); } } else { menuItem.setVisible(false); } menu.findItem(R.id.showmap).setVisible(prefs.getBoolean("plus_extra_features", false)); menu.findItem(R.id.parakeetsetup).setVisible(prefs.getBoolean("plus_extra_features", false)); boolean result = super.onCreateOptionsMenu(menu); return result; }
From source file:com.oakesville.mythling.MediaActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { if (modeSwitch) onBackPressed();/* w w w . jav a 2 s . c o m*/ else NavUtils.navigateUpFromSameTask(this); return true; } try { if (sortMenuItem != null) sortMenuItem.setTitle(Localizer.getSortLabel(appSettings.getMediaSettings().getSortType())); if (viewMenuItem != null) viewMenuItem.setIcon(appSettings.getMediaSettings().getViewIcon()); if (item.getItemId() == R.id.media_music) { ViewType oldView = appSettings.getMediaSettings().getViewType(); appSettings.setMediaType(MediaType.music); item.setChecked(true); mediaMenuItem.setTitle(Localizer.getMediaLabel(MediaType.music)); showViewMenu(supportsViewMenu()); showSortMenu(supportsSort()); ViewType newView = appSettings.getMediaSettings().getViewType(); if (oldView != newView) applyViewChange(oldView, newView); else refresh(); return true; } else if (item.getItemId() == R.id.media_videos) { ViewType oldView = appSettings.getMediaSettings().getViewType(); appSettings.setMediaType(MediaType.videos); item.setChecked(true); mediaMenuItem.setTitle(Localizer.getMediaLabel(MediaType.videos)); showViewMenu(supportsViewMenu()); showSortMenu(supportsSort()); ViewType newView = appSettings.getMediaSettings().getViewType(); if (oldView != newView) applyViewChange(oldView, newView); else refresh(); return true; } else if (item.getItemId() == R.id.media_recordings) { ViewType oldView = appSettings.getMediaSettings().getViewType(); appSettings.setMediaType(MediaType.recordings); // clears view type item.setChecked(true); mediaMenuItem.setTitle(Localizer.getMediaLabel(MediaType.recordings)); showViewMenu(supportsViewMenu()); showSortMenu(supportsSort()); ViewType newView = appSettings.getMediaSettings().getViewType(); if (oldView != newView) applyViewChange(oldView, newView); else refresh(); return true; } else if (item.getItemId() == R.id.media_tv) { ViewType oldView = appSettings.getMediaSettings().getViewType(); appSettings.setMediaType(MediaType.liveTv); // clears view type item.setChecked(true); mediaMenuItem.setTitle(Localizer.getMediaLabel(MediaType.liveTv)); showViewMenu(supportsViewMenu()); showSortMenu(supportsSort()); ViewType newView = appSettings.getMediaSettings().getViewType(); if (oldView != newView) applyViewChange(oldView, newView); else refresh(); return true; } else if (item.getItemId() == R.id.media_movies) { ViewType oldView = appSettings.getMediaSettings().getViewType(); appSettings.setMediaType(MediaType.movies); item.setChecked(true); mediaMenuItem.setTitle(Localizer.getMediaLabel(MediaType.movies)); showViewMenu(supportsViewMenu()); showSortMenu(supportsSort()); ViewType newView = appSettings.getMediaSettings().getViewType(); if (oldView != newView) applyViewChange(oldView, newView); else refresh(); return true; } else if (item.getItemId() == R.id.media_tv_series) { ViewType oldView = appSettings.getMediaSettings().getViewType(); appSettings.setMediaType(MediaType.tvSeries); item.setChecked(true); mediaMenuItem.setTitle(Localizer.getMediaLabel(MediaType.tvSeries)); showViewMenu(supportsViewMenu()); showSortMenu(supportsSort()); ViewType newView = appSettings.getMediaSettings().getViewType(); if (oldView != newView) applyViewChange(oldView, newView); else refresh(); return true; } else if (item.getItemId() == R.id.sort_byTitle) { appSettings.setSortType(SortType.byTitle); item.setChecked(true); sortMenuItem.setTitle(R.string.menu_byTitle); sort(); return true; } else if (item.getItemId() == R.id.sort_byDate) { appSettings.setSortType(SortType.byDate); item.setChecked(true); sortMenuItem.setTitle(R.string.menu_byDate); sort(); return true; } else if (item.getItemId() == R.id.sort_byRating) { appSettings.setSortType(SortType.byRating); item.setChecked(true); sortMenuItem.setTitle(R.string.menu_byRating); sort(); return true; } else if (item.getItemId() == R.id.sort_byChannel) { appSettings.setSortType(SortType.byChannel); item.setChecked(true); sortMenuItem.setTitle(R.string.menu_byChannel); sort(); return true; } else if (item.getItemId() == R.id.sort_byCallsign) { appSettings.setSortType(SortType.byCallsign); item.setChecked(true); sortMenuItem.setTitle(R.string.menu_byCallsign); sort(); return true; } else if (item.getItemId() == R.id.view_list) { appSettings.setViewType(ViewType.list); item.setChecked(true); viewMenuItem.setIcon(R.drawable.ic_menu_list); goListView(); return true; } else if (item.getItemId() == R.id.view_detail) { appSettings.setViewType(ViewType.detail); item.setChecked(true); viewMenuItem.setIcon(R.drawable.ic_menu_detail); goDetailView(); return true; } else if (item.getItemId() == R.id.view_split) { ViewType oldView = appSettings.getMediaSettings().getViewType(); appSettings.setViewType(ViewType.split); item.setChecked(true); viewMenuItem.setIcon(R.drawable.ic_menu_split); goSplitView(); if (oldView == ViewType.list) initSplitView(); return true; } else if (item.getItemId() == R.id.menu_refresh) { refresh(); return true; } else if (item.getItemId() == R.id.menu_settings) { startActivity(new Intent(this, PrefsActivity.class)); return true; } else if (item.getItemId() == R.id.menu_search) { return onSearchRequested(); } else if (item.getItemId() == R.id.menu_guide) { startActivity( new Intent(this, appSettings.isFireTv() ? FireTvEpgActivity.class : EpgActivity.class)); return true; } else if (item.getItemId() == R.id.menu_help) { String url = getString(R.string.url_help); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url), getApplicationContext(), WebViewActivity.class)); return true; } else if (item.getItemId() == R.id.menu_stop) { Intent stopMusic = new Intent(this, MusicPlaybackService.class); stopMusic.setAction(MusicPlaybackService.ACTION_STOP); startService(stopMusic); return true; } } catch (BadSettingsException ex) { stopProgress(); Toast.makeText(getApplicationContext(), getString(R.string.bad_setting_) + "\n" + ex.getMessage(), Toast.LENGTH_LONG).show(); } catch (Exception ex) { Log.e(TAG, ex.getMessage(), ex); if (getAppSettings().isErrorReportingEnabled()) new Reporter(ex).send(); stopProgress(); Toast.makeText(getApplicationContext(), getString(R.string.error_) + ex.toString(), Toast.LENGTH_LONG) .show(); } return super.onOptionsItemSelected(item); }
From source file:com.spydiko.rotationmanager.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_settings: // Refresh button // if(AppSpecificOrientation.LOG) Log.d(TAG, "action_settings"); packageManager = getPackageManager(); UpdateData updateData = new UpdateData(); this.adapter = new InteractiveArrayAdapter(this, activities, (AppSpecificOrientation) getApplication()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) updateData.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null); else//w ww . j a va 2s . co m updateData.execute((Void[]) null); // if(AppSpecificOrientation.LOG) Log.d(TAG, "execute"); lv.setAdapter(adapter); break; case R.id.itemToggleService: // Play - Stop Service // if(AppSpecificOrientation.LOG) Log.d(TAG, "entered"); if (AppSpecificOrientation.isServiceRunning()) { item.setTitle(R.string.titleServiceStop); // item.setIcon(android.R.drawable.ic_media_play); stopService(new Intent(this, NewOrieService.class)); AppSpecificOrientation.setServiceRunning(false); // if(AppSpecificOrientation.LOG) Log.d(TAG, "if"); // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) item.setIcon(R.drawable.ic_off_button_rotation_manager); } else { item.setTitle(R.string.titleServiceStart); // item.setIcon(android.R.drawable.ic_media_pause); startService(new Intent(this, NewOrieService.class)); Toast toast = Toast.makeText(this, getString(R.string.notification_text), Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0); toast.show(); // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) item.setIcon(R.drawable.ic_on_button_rotation_manager); // if(AppSpecificOrientation.LOG) Log.d(TAG, "else"); } break; case R.id.setOnBoot: // Set broadcast receiver on or off if (AppSpecificOrientation.getBoot()) { item.setChecked(false); AppSpecificOrientation.setBoot(false); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) item.setIcon(android.R.drawable.button_onoff_indicator_off); // if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to false"); } else { item.setChecked(true); AppSpecificOrientation.setBoot(true); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) item.setIcon(android.R.drawable.button_onoff_indicator_on); // if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to true"); } break; case R.id.howTo: // Open How To Activity startActivityForResult((new Intent(this, HowToActivity.class)), 1); break; case R.id.about: // Open About Activity startActivityForResult((new Intent(this, AboutActivity.class)), 1); break; case R.id.donate: startActivity(new Intent(this, DonateActivity.class)); break; case R.id.permNotification: if (AppSpecificOrientation.isPermNotification()) { item.setChecked(false); AppSpecificOrientation.setPermNotification(false); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) item.setIcon(android.R.drawable.button_onoff_indicator_off); // if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to false"); if (AppSpecificOrientation.isServiceRunning()) startService(new Intent(this, NewOrieService.class)); } else { item.setChecked(true); AppSpecificOrientation.setPermNotification(true); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) item.setIcon(android.R.drawable.button_onoff_indicator_on); // if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to true"); if (AppSpecificOrientation.isServiceRunning()) startService(new Intent(this, NewOrieService.class)); } break; case R.id.license: startActivity(new Intent(this, License.class)); break; case android.R.id.home: menu.toggle(); return true; } return true; }
From source file:com.vinidsl.navigationviewdemo.MainActivity.java
private void setupDrawerContent(final NavigationView navigationView) { //navigationView.getMenu().findItem(R.id.nav_home).setChecked(false); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override//from ww w. j ava 2 s. c om public boolean onNavigationItemSelected(MenuItem menuItem) { switch (menuItem.getItemId()) { /*case R.id.aditional1: Snackbar.make(navigationView, "Item adicional 1 seleccionado", Snackbar.LENGTH_LONG).show(); return true; case R.id.aditional2: Snackbar.make(navigationView, "Item adicional 2 seleccionado", Snackbar.LENGTH_LONG).show(); return true;*/ case R.id.nav_calendario: CalendarioFragment calendarioFragment = new CalendarioFragment(); MuestraFragment(calendarioFragment); //Snackbar.make(navigationView, "Item calendario seleccionado", Snackbar.LENGTH_LONG).show(); break; case R.id.nav_ferias_int: Ferias_Int ferias_int = new Ferias_Int(); MuestraFragment(ferias_int); //Creamos el Intent // Intent intent = // new Intent(MainActivity.this, ClasePrueba.class); //Creamos la informacin a pasar entre actividades //Bundle b = new Bundle(); //Aadimos la informacin al intent //intent.putExtras(b); //Iniciamos la nueva actividad //startActivity(intent); //Snackbar.make(navigationView, "Item principal seleccionado", Snackbar.LENGTH_LONG).show(); break; case R.id.nav_ferias_nac: Ferias_Nac fragment = new Ferias_Nac(); MuestraFragment(fragment); //Snackbar.make(navigationView, "Item calendario seleccionado", Snackbar.LENGTH_LONG).show(); break; case R.id.nav_mis_eventos: /*NoticiasFragment noticias = new NoticiasFragment(); MuestraFragment(noticias);*/ /*Intent prog = new Intent(act, Eventos.class); startActivity(prog);*/ Eventos fragMisEventos = new Eventos(); MuestraFragment(fragMisEventos); //Snackbar.make(navigationView, "Item msica seleccionado", Snackbar.LENGTH_LONG).show(); break; case R.id.nav_mi_perfil: //Registro fragRegistro = new Registro(); PerfilFragment fragRegistro = new PerfilFragment(); MuestraFragment(fragRegistro); //Perfil fragRegistro = new Perfil(); //MuestraFragment(fragRegistro); break; } menuItem.setChecked(true); mDrawerLayout.closeDrawers(); return true; } }); }
From source file:org.de.jmg.learn.MainActivity.java
public void setMnuReverse() { if (OptionsMenu != null) { MenuItem item = OptionsMenu.findItem(R.id.mnuAskReverse); boolean isAction = false; if (ActionMenu != null) { MenuBuilder mm = (MenuBuilder) ActionMenu.getMenu(); if (mm.getActionItems().contains(item)) { isAction = true;//from w w w . ja v a2 s.c o m } } if (vok != null) { item.setChecked(vok.reverse); if (isAction) { if (vok.reverse) { item.setIcon(android.R.drawable.ic_menu_revert); } else { item.setIcon(android.R.drawable.ic_media_rew); } } } else if (isAction) { item.setIcon(android.R.drawable.ic_media_rew); } } }
From source file:cz.martykan.webtube.MenuHelper.java
@Override public boolean onMenuItemClick(final MenuItem item) { switch (item.getItemId()) { case R.id.action_web: context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(webView.getUrl()))); return true; case R.id.action_refresh: webView.reload();//w w w . j a v a2 s.co m return true; case R.id.action_home: homepageTutorial(); webView.loadUrl(sp.getString("homepage", "https://m.youtube.com/")); return true; case R.id.action_set_as_home: Snackbar.make(appWindow, context.getString(R.string.homePageSet), Snackbar.LENGTH_LONG).show(); SharedPreferences.Editor editor = sp.edit(); editor.putString("homepage", webView.getUrl()); editor.commit(); return true; case R.id.action_bookmarks: drawerLayout.openDrawer(bookmarksPanel); return true; case R.id.action_share: if (!webView.getUrl().contains("/watch")) { show_noVideo_dialog(); } else { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_TEXT, webView.getUrl()); shareIntent.setType("text/plain"); context.startActivity( Intent.createChooser(shareIntent, context.getResources().getText(R.string.share_with))); } return true; case R.id.action_cast_to_kodi: if (!webView.getUrl().contains("/watch")) { show_noVideo_dialog(); } else { try { /* The following code is based on an extract from the source code of NewPipe (v0.7.2) (https://github.com/theScrabi/NewPipe), which is also licenced under version 3 of the GNU General Public License as published by the Free Software Foundation. The copyright owner of the original code is Christian Schabesberger <chris.schabesberger@mailbox.org>. All modifications were made on 06-Jan-2016 */ Intent intent = new Intent(Intent.ACTION_VIEW); intent.setPackage("org.xbmc.kore"); intent.setData(Uri.parse(webView.getUrl().replace("https", "http"))); context.startActivity(intent); /* End of the modified NewPipe code extract */ } catch (Exception e) { e.printStackTrace(); } } return true; case R.id.action_backgroundPlay: if (sp.getBoolean(BackgroundPlayHelper.PREF_BACKGROUND_PLAY_ENABLED, true)) { backgroundPlayHelper.disableBackgroundPlay(); item.setChecked(false); } else { backgroundPlayHelper.enableBackgroundPlay(); item.setChecked(true); } return true; case R.id.action_tor: final MenuItem cookieItem = actionMenu.getMenu().findItem(R.id.action_accept_cookies); try { if (sp.getBoolean(TorHelper.PREF_TOR_ENABLED, false)) { torHelper.torDisable(); item.setChecked(false); cookieItem.setChecked(sp.getBoolean(PREF_COOKIES_ENABLED, true)).setEnabled(true); } else { AlertDialog alert = new AlertDialog.Builder(context).create(); alert.setTitle(context.getString(R.string.enableTor) + "?"); alert.setMessage(context.getString(R.string.torWarning)); alert.setCancelable(false); alert.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(R.string.enable), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { torHelper.torEnable(); item.setChecked(true); cookieItem.setChecked(false).setEnabled(false); } }); alert.setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(android.R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { item.setChecked(false); } }); alert.show(); } } catch (Exception e) { Log.d("WebTube", e.getMessage()); } return true; case R.id.action_download: if (!webView.getUrl().contains("/watch")) { show_noVideo_dialog(); } else { new Downloader(context).download(webView.getUrl()); } return true; case R.id.action_accept_cookies: if (sp.getBoolean(PREF_COOKIES_ENABLED, true)) { CookieHelper.acceptCookies(webView, false); CookieHelper.deleteCookies(); item.setChecked(false); } else { CookieHelper.acceptCookies(webView, true); item.setChecked(true); } SharedPreferences.Editor spEdit = sp.edit(); spEdit.putBoolean(PREF_COOKIES_ENABLED, !sp.getBoolean(PREF_COOKIES_ENABLED, true)); spEdit.commit(); return true; } return false; }
From source file:com.nononsenseapps.feeder.ui.FeedFragment.java
@Override public boolean onOptionsItemSelected(MenuItem menuItem) { final long id = menuItem.getItemId(); if (id == R.id.action_sync) { // Sync all feeds when menu button pressed RssContentProvider.RequestSync(); return true; } else if (id == R.id.action_edit_feed && this.id > 0) { Intent i = new Intent(getActivity(), EditFeedActivity.class); // TODO do not animate the back movement here i.putExtra(EditFeedActivity.SHOULD_FINISH_BACK, true); i.putExtra(EditFeedActivity._ID, this.id); i.putExtra(EditFeedActivity.TITLE, customTitle); i.putExtra(EditFeedActivity.TAG, tag); i.setData(Uri.parse(url));/* w w w . ja v a 2 s . c o m*/ startActivity(i); return true; } else if (id == R.id.action_add_templated && this.id > 0) { Intent i = new Intent(getActivity(), EditFeedActivity.class); // TODO do not animate the back movement here i.putExtra(EditFeedActivity.SHOULD_FINISH_BACK, true); i.putExtra(EditFeedActivity.TEMPLATE, true); //i.putExtra(EditFeedActivity.TITLE, title); i.putExtra(EditFeedActivity.TAG, tag); i.setData(Uri.parse(url)); startActivity(i); return true; } else if (id == R.id.action_delete_feed && this.id > 0) { getActivity().getContentResolver().delete(FeedSQL.URI_FEEDS, Util.WHEREIDIS, Util.LongsToStringArray(this.id)); RssContentProvider.notifyAllUris(getActivity()); // Tell activity to open another fragment ((FeedActivity) getActivity()).loadFirstFeedInDB(true); return true; } // else if (id == R.id.action_mark_as_read) { // markAsRead(); // return true; // } else if (id == R.id.action_only_unread) { final boolean onlyUnread = !menuItem.isChecked(); PrefUtils.setPrefShowOnlyUnread(getActivity(), onlyUnread); menuItem.setChecked(onlyUnread); if (onlyUnread) { menuItem.setIcon(R.drawable.ic_action_visibility_off); } else { menuItem.setIcon(R.drawable.ic_action_visibility); } menuItem.setTitle(onlyUnread ? R.string.show_unread_items : R.string.show_all_items); //getActivity().invalidateOptionsMenu(); // Restart loader getLoaderManager().restartLoader(FEEDITEMS_LOADER, new Bundle(), this); return true; } else { return super.onOptionsItemSelected(menuItem); } }
From source file:com.abhijitvalluri.android.fitnotifications.HomeActivity.java
private void selectDrawerItem(MenuItem menuItem) { // Create a new fragment and specify the fragment to show based on nav item clicked final Fragment frag; Fragment currFrag = getSupportFragmentManager().findFragmentById(R.id.flContent); boolean isInfoFragment = false; if (currFrag instanceof InfoFragment) { isInfoFragment = true;//from w ww .ja v a 2s. c o m } setTitle(menuItem.getTitle()); switch (menuItem.getItemId()) { case R.id.nav_home: setTitle(R.string.app_name); frag = new HomeFragment(); break; case R.id.nav_about_app: if (isInfoFragment) { ((InfoFragment) currFrag).updateWebViewContent(getString(R.string.about_app_text)); frag = null; } else { frag = InfoFragment.newInstance(getString(R.string.about_app_text)); } break; case R.id.nav_whats_new: if (isInfoFragment) { ((InfoFragment) currFrag).updateWebViewContent(getString(R.string.whats_new_text)); frag = null; } else { frag = InfoFragment.newInstance(getString(R.string.whats_new_text)); } break; case R.id.nav_faqs: if (isInfoFragment) { ((InfoFragment) currFrag).updateWebViewContent(getString(R.string.faqs_text)); frag = null; } else { frag = InfoFragment.newInstance(getString(R.string.faqs_text)); } break; case R.id.nav_manual_setup: if (isInfoFragment) { ((InfoFragment) currFrag).updateWebViewContent(getString(R.string.instructions_text)); frag = null; } else { frag = InfoFragment.newInstance(getString(R.string.instructions_text)); } break; case R.id.nav_opensource: if (isInfoFragment) { ((InfoFragment) currFrag).updateWebViewContent(getString(R.string.opensource_text)); frag = null; } else { frag = InfoFragment.newInstance(getString(R.string.opensource_text)); } break; case R.id.nav_contact: setTitle(menuItem.getTitle()); if (isInfoFragment) { ((InfoFragment) currFrag).updateWebViewContent(getString(R.string.contact_us_text)); frag = null; } else { frag = InfoFragment.newInstance(getString(R.string.contact_us_text)); } break; default: // something unexpected has happened Log it may be? return; } // Highlight the selected item has been done by NavigationView menuItem.setChecked(true); // Set action bar title if (frag != null) { mDrawerToggle.runWhenIdle(new Runnable() { @Override public void run() { // Insert the fragment by replacing any existing fragment FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager.beginTransaction().replace(R.id.flContent, frag).commit(); } }); } // Close the navigation drawer mDrawerLayout.closeDrawers(); }
From source file:com.landenlabs.all_devtool.PackageFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int pos = -1; int id = item.getItemId(); int show = m_show; switch (id) { case R.id.package_user: show = SHOW_USER;/*from ww w.j a v a 2 s . c o m*/ break; case R.id.package_system: show = SHOW_SYS; break; case R.id.package_pref: show = SHOW_PREF; break; case R.id.package_cache: show = SHOW_CACHE; break; case R.id.package_lib: show = SHOW_LIB; break; case R.id.package_uninstall: if (m_uninstallResId == R.string.package_del_cache) deleteCaches(); else uninstallPackages(); break; case R.id.package_uncheck_all: uncheckAll(); break; case R.id.package_collapseAll: collapseAll(); m_expand_collapse_toggle.setChecked(false); break; case R.id.package_expandAll: expandAll(); m_expand_collapse_toggle.setChecked(true); break; case 0: break; default: item.setChecked(true); pos = Arrays.asList(getResources().getStringArray(R.array.pkg_sort_array)).indexOf(item.getTitle()); m_sortSpinner.setSelection(pos); this.m_sortBy = id; Message msgObj = m_handler.obtainMessage(MSG_SORT_LIST); m_handler.sendMessage(msgObj); break; } if (m_show != show) { m_show = show; item.setChecked(true); m_loadSpinner.setSelection(m_show); // updateList(); } return super.onOptionsItemSelected(item); }