List of usage examples for android.view MenuItem isChecked
public boolean isChecked();
From source file:com.murrayc.galaxyzoo.app.QuestionFragment.java
@Override public boolean onOptionsItemSelected(final MenuItem item) { // handle item selection switch (item.getItemId()) { case R.id.option_menu_item_examples: doExamples();//from w ww . j a va2 s.c om return true; case R.id.option_menu_item_favorite: final boolean checked = !item.isChecked(); //Note: //"Icon menu" (TODO: What is that?) items don't actually show a checked state, //but it seems to work in the menu though not as an action in the action bar. //See http://developer.android.com/guide/topics/ui/menus.html#checkable item.setChecked(checked); //TODO: Use pretty icons instead: /* //Show an icon to indicate checkedness instead: //See http://developer.android.com/guide/topics/ui/menus.html#checkable if (checked) { item.setIcon(android.R.drawable.ic_menu_save); //A silly example. } else { item.setIcon(android.R.drawable.ic_menu_add); //A silly example. } */ mClassificationInProgress.setFavorite(checked); return true; case R.id.option_menu_item_restart: restartClassification(); return true; case R.id.option_menu_item_discuss: UiUtils.openDiscussionPage(getActivity(), getZooniverseId()); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.zhengde163.netguard.ActivityMain.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Log.i(TAG, "Menu=" + item.getTitle()); // Handle item selection SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); switch (item.getItemId()) { case R.id.menu_app_user: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("show_user", item.isChecked()).apply(); return true; case R.id.menu_app_system: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("show_system", item.isChecked()).apply(); return true; case R.id.menu_app_nointernet: boolean nointernet = prefs.getBoolean("show_nointernet", true); nointernet = !nointernet;//w ww. j ava 2s.c o m if (nointernet) item.setIcon(R.drawable.checked); else item.setIcon(R.drawable.check); prefs.edit().putBoolean("show_nointernet", nointernet).apply(); return true; case R.id.menu_app_disabled: boolean disabled = prefs.getBoolean("show_disabled", true); disabled = !disabled; if (disabled) item.setIcon(R.drawable.checked); else item.setIcon(R.drawable.check); prefs.edit().putBoolean("show_disabled", disabled).apply(); return true; case R.id.menu_sort_name: item.setChecked(true); item.setIcon(R.drawable.singlechecked); menu_data.setIcon(R.drawable.singlecheck); prefs.edit().putString("sort", "name").apply(); return true; case R.id.menu_sort_data: item.setChecked(true); item.setIcon(R.drawable.singlechecked); menu_name.setIcon(R.drawable.singlecheck); prefs.edit().putString("sort", "data").apply(); return true; case R.id.menu_log: startActivity(new Intent(this, ActivityLog.class)); return true; case R.id.menu_settings: startActivity(new Intent(this, ActivitySettings.class)); return true; case R.id.menu_legend: menu_legend(); return true; case R.id.login_again: startActivity(new Intent(ActivityMain.this, LoginAgain.class)); return true; default: return super.onOptionsItemSelected(item); } }
From source file:net.potterpcs.recipebook.RecipeBookActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { boolean descending = false; switch (item.getItemId()) { case R.id.menunew: onNewItemSelected(item);/*from w w w.j a v a 2 s . c om*/ return true; case R.id.menuhelp: onHelpItemSelected(item); return true; case R.id.menuprefs: onPreferences(item); return true; case R.id.menusearch: onSearchRequested(); return true; case R.id.menusearchtag: onSearchByTag(); return true; case R.id.menusearchtime: onSearchByTime(); return true; case R.id.menushowall: onShowAllRecipes(item); return true; case R.id.menuexport: onExportRecipes(item); case R.id.menuimport: onImportFileList(item); // Sort direction items (only one active at a time) case R.id.menusortdescending: descending = true; // fall-through on purpose case R.id.menusortascending: item.setChecked(!item.isChecked()); startSortActivity(sortKey, descending); return true; // Sort criteria items (only one active at a time) case R.id.menusortname: case R.id.menusortrating: case R.id.menusorttime: case R.id.menusortdate: item.setChecked(!item.isChecked()); startSortActivity(item.getItemId(), sortDescending); return true; default: return super.onOptionsItemSelected(item); } }
From source file:org.totschnig.myexpenses.activity.MyExpenses.java
protected boolean handleGrouping(MenuItem item) { Grouping newGrouping = Utils.getGroupingFromMenuItemId(item.getItemId()); if (newGrouping != null) { if (!item.isChecked()) { PrefKey.ACCOUNT_GROUPING.putString(newGrouping.name()); item.setChecked(true);// ww w. java 2s . c o m if (mAccountId < 0) { AggregateAccount.getInstanceFromDb(mAccountId).persistGrouping(newGrouping); } else { Account.getInstanceFromDb(mAccountId).persistGrouping(newGrouping); } } return true; } return false; }
From source file:com.android.purenexussettings.TinkerActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // toggle nav drawer on selecting action bar app icon/title if (mDrawerToggle.onOptionsItemSelected(item)) { return true; }/*from ww w. ja v a 2 s . c o m*/ // Handle action bar actions click switch (item.getItemId()) { case R.id.action_about: if (mItemPosition != 0) { myHandler.removeCallbacksAndMessages(null); mMenu = true; removeCurrent(); // below replicates the visual delay seen when launching frags from navdrawer myHandler.postDelayed(new Runnable() { @Override public void run() { displayView(0); } }, 400); } return true; case R.id.action_launchhide: boolean checked = item.isChecked(); item.setChecked(!checked); setLauncherIconEnabled(checked); return true; default: return super.onOptionsItemSelected(item); } }
From source file:org.whisperim.android.ui.ChatWindow.java
@Override public boolean onMenuItemClick(MenuItem item) { if (item.getItemId() == SEND_KEY) { Base64 b64 = new Base64(); Message keyMsg;//w ww. j av a 2s .c o m if (parent_.haveKey(buddy_)) { keyMsg = new Message( new Buddy(buddy_.getAssociatedLocalHandle(), buddy_.getAssociatedLocalHandle(), buddy_.getProtocolID()), buddy_, "<whisperim keyspec=" + new String(b64.encode(parent_.getMyKey().getEncoded())) + "-- havekey=true-- />", buddy_.getProtocolID(), Calendar.getInstance().getTime()); } else { keyMsg = new Message( new Buddy(buddy_.getAssociatedLocalHandle(), buddy_.getAssociatedLocalHandle(), buddy_.getProtocolID()), buddy_, "<whisperim keyspec=" + new String(b64.encode(parent_.getMyKey().getEncoded())) + "-- />", buddy_.getProtocolID(), Calendar.getInstance().getTime()); } parent_.sendMessage(keyMsg); return true; } else if (item.getItemId() == ENCRYPTION) { final MenuItem item2 = item; if (!item.isChecked()) { if (parent_.haveKey(buddy_)) { handler_.post(new Runnable() { @Override public void run() { parent_.enableEncryption(buddy_); item2.setChecked(true); } }); return true; } else { } } else { parent_.disableEncryption(buddy_); item.setChecked(false); } } return false; }
From source file:org.totschnig.myexpenses.activity.MyExpenses.java
protected boolean handleSortOption(MenuItem item) { String newSortOrder = Utils.getSortOrderFromMenuItemId(item.getItemId()); if (newSortOrder != null) { if (!item.isChecked()) { PrefKey.SORT_ORDER_ACCOUNTS.putString(newSortOrder); item.setChecked(true);// w w w . ja v a 2 s . c o m if (mManager.getLoader(ACCOUNTS_CURSOR) != null && !mManager.getLoader(ACCOUNTS_CURSOR).isReset()) { mManager.restartLoader(ACCOUNTS_CURSOR, null, this); } else { mManager.initLoader(ACCOUNTS_CURSOR, null, this); } if (item.getItemId() == R.id.SORT_CUSTOM_COMMAND) { MessageDialogFragment .newInstance(R.string.dialog_title_information, R.string.dialog_info_custom_sort, MessageDialogFragment.Button.okButton(), null, null) .show(getSupportFragmentManager(), "CUSTOM_SORT_INFO"); } } return true; } return false; }
From source file:nhannt.musicplayer.ui.home.HomeActivity.java
private void setupNavigationView() { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override//from w w w. j a v a 2 s . c o m public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.btn_lib_nav: navItemIndex = 0; CURRENT_TAG = TAG_LIBRARY; break; case R.id.btn_playlist_nav: CURRENT_TAG = TAG_PLAYLISTS; navItemIndex = 1; break; case R.id.btn_play_queue_nav: CURRENT_TAG = TAG_PLAYING_QUEUE; navItemIndex = 2; break; case R.id.btn_now_playing_nav: navItemIndex = 3; startActivity(new Intent(HomeActivity.this, PlayBackActivity.class)); drawerLayout.closeDrawers(); return true; case R.id.btn_about_nav: break; case R.id.btn_license_nav: break; case R.id.btn_feedback_nav: break; default: navItemIndex = 0; } if (item.isChecked()) { item.setChecked(false); } else { item.setChecked(true); } item.setChecked(true); loadHomeFragment(); return true; } }); }
From source file:com.granita.tasks.TaskListActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { //custom start if (item.getItemId() == R.id.removeads) { mHelper.launchPurchaseFlow(this, ITEM_SKU, 10001, mPurchaseFinishedListener, "mypurchasetoken"); }/*www.j a v a 2s .co m*/ if (item.getItemId() == R.id.add_account) { Intent myIntent = new Intent(); myIntent.setClassName("com.granita.icloudcalsync", "com.granita.caldavsync.ui.setup.AddAccountActivity"); startActivity(myIntent); } //custom end if (item.getItemId() == R.id.menu_visible_list) { Intent settingsIntent = new Intent(getBaseContext(), SyncSettingsActivity.class); startActivity(settingsIntent); return true; } else if (item.getItemId() == R.id.menu_alarms) { // set and save state boolean activatedAlarms = !item.isChecked(); item.setChecked(activatedAlarms); AlarmBroadcastReceiver.setAlarmPreference(this, activatedAlarms); return true; } else { return super.onOptionsItemSelected(item); } }
From source file:io.mapsquare.osmcontributor.ui.activities.MapActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_map); ((OsmTemplateApplication) getApplication()).getOsmTemplateComponent().inject(this); ButterKnife.bind(this); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); setSupportActionBar(toolbar);//from ww w. ja v a 2 s . co m eventBus.post(new UpdateFirstConnectionEvent()); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { switch (menuItem.getGroupId()) { case R.id.drawer_options_group: onOptionsClick(menuItem); break; case R.id.sync: onOptionsSyncClick(menuItem); break; } return true; } }); filterView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { if (menuItem.getItemId() == R.id.select_all_item) { selectAllMenuItem.setChecked(!selectAllMenuItem.isChecked()); onSelectAllClick(); } else if (menuItem.getItemId() != R.id.display_open_notes_item && menuItem.getItemId() != R.id.display_closed_notes_item) { menuItem.setChecked(!menuItem.isChecked()); onFilterItemClick(menuItem); } else { menuItem.setChecked(!menuItem.isChecked()); onNoteItemClick(menuItem); } return true; } }); selectAllMenuItem = filterView.getMenu().findItem(R.id.select_all_item); if (!FlavorUtils.isPoiStorage() && configManager.hasPoiModification()) { navigationView.getMenu().findItem(R.id.edit_way).setVisible(true); } if (configManager.hasPoiAddition()) { navigationView.getMenu().findItem(R.id.replay_tuto_menu).setVisible(true); } navigationView.getMenu().findItem(R.id.save_changes).setEnabled(false); drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() { @Override public void onDrawerSlide(View drawerView, float slideOffset) { } @Override public void onDrawerOpened(View drawerView) { eventBus.post(new PleaseTellIfDbChanges()); } @Override public void onDrawerClosed(View drawerView) { } @Override public void onDrawerStateChanged(int newState) { } }); navigationView.getMenu().findItem(R.id.manage_poi_types) .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { startPoiTypeEditionActivity(); return true; } }); // Get the arpi fragment. arpiGlFragment = (ArpiGlFragment) getFragmentManager().findFragmentById(R.id.engine_fragment); getFragmentManager().beginTransaction().hide(arpiGlFragment).commit(); if (sharedPreferences.getBoolean(getString(R.string.easter_egg), false)) { navigationView.getMenu().findItem(R.id.arpi_view).setVisible(true); } }