List of usage examples for android.view MenuItem isChecked
public boolean isChecked();
From source file:de.vanita5.twittnuker.activity.FiltersActivity.java
@Override public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { case MENU_HOME: { navigateUpFromSameTask();/*w ww . ja v a 2 s.c o m*/ return true; } case MENU_ADD: { final Fragment f = mAdapter.getItem(mViewPager.getCurrentItem()); if (!(f instanceof BaseFiltersFragment)) return true; final Bundle args = new Bundle(); if (f instanceof FilteredUsersFragment) { final Intent intent = new Intent(INTENT_ACTION_SELECT_USER); intent.setClass(this, UserListSelectorActivity.class); intent.putExtra(EXTRA_ACCOUNT_ID, getDefaultAccountId(this)); startActivityForResult(intent, REQUEST_SELECT_USER); return true; } if (f instanceof FilteredSourcesFragment) { args.putInt(EXTRA_AUTO_COMPLETE_TYPE, AUTO_COMPLETE_TYPE_SOURCES); } args.putParcelable(EXTRA_URI, ((BaseFiltersFragment) f).getContentUri()); final AddItemFragment dialog = new AddItemFragment(); dialog.setArguments(args); dialog.show(getSupportFragmentManager(), "add_rule"); return true; } case R.id.enable_in_home_timeline: { final SharedPreferences.Editor editor = mPreferences.edit(); editor.putBoolean(KEY_FILTERS_IN_HOME_TIMELINE, !item.isChecked()); editor.apply(); break; } case R.id.enable_in_mentions: { final SharedPreferences.Editor editor = mPreferences.edit(); editor.putBoolean(KEY_FILTERS_IN_MENTIONS, !item.isChecked()); editor.apply(); break; } case R.id.enable_for_rts: { final SharedPreferences.Editor editor = mPreferences.edit(); editor.putBoolean(KEY_FILTERS_FOR_RTS, !item.isChecked()); editor.apply(); break; } } return false; }
From source file:org.sufficientlysecure.keychain.ui.EncryptFilesFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.encrypt_save: { hideKeyboard();/*from w w w . j a va 2 s . c o m*/ mAfterEncryptAction = AfterEncryptAction.SAVE; cryptoOperation(new CryptoInputParcel(new Date())); break; } case R.id.encrypt_share: { hideKeyboard(); mAfterEncryptAction = AfterEncryptAction.SHARE; cryptoOperation(new CryptoInputParcel(new Date())); break; } case R.id.encrypt_copy: { hideKeyboard(); mAfterEncryptAction = AfterEncryptAction.COPY; cryptoOperation(new CryptoInputParcel(new Date())); break; } case R.id.check_use_armor: { toggleUseArmor(item, !item.isChecked()); break; } case R.id.check_delete_after_encrypt: { item.setChecked(!item.isChecked()); mDeleteAfterEncrypt = item.isChecked(); break; } case R.id.check_enable_compression: { toggleEnableCompression(item, !item.isChecked()); break; } case R.id.check_encrypt_filenames: { toggleEncryptFilenamesCheck(item, !item.isChecked()); break; } // case R.id.check_hidden_recipients: { // mHiddenRecipients = item.isChecked(); // notifyUpdate(); // break; // } default: { return super.onOptionsItemSelected(item); } } return true; }
From source file:com.google.android.apps.forscience.whistlepunk.project.ProjectDetailsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == android.R.id.home) { Intent upIntent = NavUtils.getParentActivityIntent(getActivity()); upIntent.putExtra(MainActivity.ARG_SELECTED_NAV_ITEM_ID, R.id.navigation_item_projects); upIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), mProjectCover, mProjectId); getActivity().startActivity(upIntent, options.toBundle()); return true; } else if (id == R.id.action_edit_project) { UpdateProjectActivity.launch(getActivity(), mProjectId, false /* not new */); return true; } else if (id == R.id.action_archive_project || id == R.id.action_unarchive_project) { setProjectArchived(id == R.id.action_archive_project); return true; } else if (id == R.id.action_delete_project) { confirmDelete();//from w ww.jav a 2 s . com return true; } else if (id == R.id.action_include_archived) { item.setChecked(!item.isChecked()); mIncludeArchived = item.isChecked(); loadExperiments(); return true; } return super.onOptionsItemSelected(item); }
From source file:com.money.manager.ex.account.AccountTransactionListFragment.java
private boolean isStatusSelectionHandled(MenuItem item) { int id = item.getItemId(); boolean result = true; // turn filters on/off TransactionStatuses status = null;/*from www. j a va 2 s .c o m*/ switch (id) { case R.id.menu_none: status = TransactionStatuses.NONE; break; case R.id.menu_reconciled: status = TransactionStatuses.RECONCILED; break; case R.id.menu_void: status = TransactionStatuses.VOID; break; case R.id.menu_follow_up: status = TransactionStatuses.FOLLOWUP; break; case R.id.menu_duplicate: status = TransactionStatuses.DUPLICATE; break; default: // not handled here. result = false; break; } if (result) { if (item.isChecked()) { // remove filter mFilter.transactionStatus.filter.remove(status.getCode()); item.setChecked(false); } else { // add filter mFilter.transactionStatus.filter.add(status.getCode()); item.setChecked(true); } loadTransactions(); } return result; }
From source file:org.jak_linux.dns66.MainActivity.java
@Override public boolean onOptionsItemSelected(final MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. switch (item.getItemId()) { case R.id.action_restore: config = FileHelper.loadPreviousSettings(this); FileHelper.writeSettings(this, MainActivity.config); reload();/* w ww . ja va2s .c o m*/ break; case R.id.action_refresh: refresh(); break; case R.id.action_load_defaults: config = FileHelper.loadDefaultSettings(this); reload(); FileHelper.writeSettings(this, MainActivity.config); break; case R.id.action_import: Intent intent = new Intent().setType("*/*").setAction(Intent.ACTION_OPEN_DOCUMENT) .addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult(intent, REQUEST_FILE_OPEN); break; case R.id.action_export: Intent exportIntent = new Intent(Intent.ACTION_CREATE_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE) .setType("*/*").putExtra(Intent.EXTRA_TITLE, "dns66.json"); startActivityForResult(exportIntent, REQUEST_FILE_STORE); break; case R.id.setting_show_notification: // If we are enabling notifications, we do not need to show a dialog. if (!item.isChecked()) { item.setChecked(!item.isChecked()); MainActivity.config.showNotification = item.isChecked(); FileHelper.writeSettings(MainActivity.this, MainActivity.config); break; } new AlertDialog.Builder(this).setIcon(R.drawable.ic_warning) .setTitle(R.string.disable_notification_title).setMessage(R.string.disable_notification_message) .setPositiveButton(R.string.disable_notification_ack, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { item.setChecked(!item.isChecked()); MainActivity.config.showNotification = item.isChecked(); FileHelper.writeSettings(MainActivity.this, MainActivity.config); } }).setNegativeButton(R.string.disable_notification_nak, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { } }).show(); break; case R.id.action_about: Intent infoIntent = new Intent(this, InfoActivity.class); startActivity(infoIntent); break; } return super.onOptionsItemSelected(item); }
From source file:com.example.intern01.driverlicense.activity.MainActivity.java
private void setUpNavigationView() { //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { // This method will trigger on item Click of navigation menu @Override//ww w. ja va 2 s .co m public boolean onNavigationItemSelected(MenuItem menuItem) { //Check to see which item was being clicked and perform appropriate action switch (menuItem.getItemId()) { //Replacing the main content with ContentFragment Which is our Inbox View; case R.id.nav_profile: navItemIndex = 0; CURRENT_TAG = TAG_PROFILE; break; case R.id.nav_cars: navItemIndex = 1; CURRENT_TAG = TAG_CARS; break; case R.id.nav_about: navItemIndex = 2; CURRENT_TAG = TAG_ABOUT; break; case R.id.nav_logout: navItemIndex = 3; getSharedPreferences("loginC", MODE_PRIVATE).edit().putString("lc_email", null) .putString("lc_pass", null).apply(); auth.signOut(); LoginManager.getInstance().logOut(); Intent i = new Intent(context, LoginActivity.class); context.startActivity(i); finish(); //CURRENT_TAG = TAG_; break; default: navItemIndex = 0; } //Checking if the item is in checked state or not, if not make it in checked state if (menuItem.isChecked()) { menuItem.setChecked(false); } else { menuItem.setChecked(true); } menuItem.setChecked(true); loadHomeFragment(); return true; } }); ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.openDrawer, R.string.closeDrawer) { @Override public void onDrawerClosed(View drawerView) { // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank super.onDrawerClosed(drawerView); } @Override public void onDrawerOpened(View drawerView) { // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank super.onDrawerOpened(drawerView); } }; //Setting the actionbarToggle to drawer layout //drawer.setDrawerListener(actionBarDrawerToggle); //calling sync state is necessary or else your hamburger icon wont show up actionBarDrawerToggle.syncState(); }
From source file:at.ac.tuwien.detlef.activities.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Intent intent;/*ww w . j ava 2 s . com*/ switch (item.getItemId()) { case R.id.licenses: intent = new Intent(this, LicensesActivity.class); startActivity(intent); break; case R.id.settings: intent = new Intent(this, SettingsActivity.class); startActivity(intent); break; case R.id.playlist: intent = new Intent(this, PlaylistActivity.class); startActivity(intent); break; case R.id.refresh: onRefreshPressed(); break; case R.id.add_new_podcast: intent = new Intent(this, AddPodcastActivity.class); startActivityForResult(intent, PODCAST_ADD_REQUEST_CODE); break; case R.id.menu_show_only_new_episodes: item.setChecked(!item.isChecked()); getEpisodeListFragment().setReadFilter(item.isChecked()); // getEpisodeListFragment().set break; case R.id.sort: android.support.v4.app.DialogFragment dialog = new EpisodeListSortDialogFragment(); dialog.show(getSupportFragmentManager(), "EpisodeListSortDialogFragment"); break; default: break; } return true; }
From source file:org.totschnig.myexpenses.activity.MyExpenses.java
protected boolean handleAccountsGrouping(MenuItem item) { AccountGrouping newGrouping = null;// ww w . j ava 2 s.c o m switch (item.getItemId()) { case R.id.GROUPING_ACCOUNTS_CURRENCY_COMMAND: newGrouping = AccountGrouping.CURRENCY; break; case R.id.GROUPING_ACCOUNTS_TYPE_COMMAND: newGrouping = AccountGrouping.TYPE; break; case R.id.GROUPING_ACCOUNTS_NONE_COMMAND: newGrouping = AccountGrouping.NONE; break; } if (newGrouping != null) { if (!item.isChecked()) { PrefKey.ACCOUNT_GROUPING.putString(newGrouping.name()); item.setChecked(true); if (mManager.getLoader(ACCOUNTS_CURSOR) != null && !mManager.getLoader(ACCOUNTS_CURSOR).isReset()) mManager.restartLoader(ACCOUNTS_CURSOR, null, this); else mManager.initLoader(ACCOUNTS_CURSOR, null, this); } return true; } return false; }
From source file:com.google.android.apps.forscience.whistlepunk.project.experiment.ExperimentDetailsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); if (itemId == android.R.id.home) { goToProjectDetails();//from www.j a va 2s . c o m return true; } else if (itemId == R.id.action_edit_experiment) { UpdateExperimentActivity.launch(getActivity(), mExperimentId, false /* not new */); return true; } else if (itemId == R.id.action_archive_experiment || itemId == R.id.action_unarchive_experiment) { setExperimentArchived(item.getItemId() == R.id.action_archive_experiment); return true; } else if (itemId == R.id.action_experiment_add_note) { launchLabelAdd(); return true; } else if (itemId == R.id.action_include_archived) { item.setChecked(!item.isChecked()); mIncludeArchived = item.isChecked(); loadExperimentData(mExperiment); return true; } else if (itemId == R.id.action_delete_experiment) { confirmDelete(); } return super.onOptionsItemSelected(item); }
From source file:org.thaliproject.nativetest.app.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); boolean wasConsumed = false; PeerProperties peerProperties = null; if (mPeerListFragment != null) { peerProperties = mPeerListFragment.getSelectedPeerProperties(); }/*from w w w . j av a 2 s .c o m*/ PeerAndConnectionModel model = PeerAndConnectionModel.getInstance(); switch (id) { case R.id.action_connect: onConnectRequest(peerProperties); // Has a null check wasConsumed = true; break; case R.id.action_disconnect: if (peerProperties != null) { if (model.closeConnection(peerProperties)) { wasConsumed = true; } } break; case R.id.action_send_data: onSendDataRequest(peerProperties); // Has a null check wasConsumed = true; break; case R.id.action_kill_all_connections: model.closeAllConnections(); wasConsumed = true; break; case R.id.action_start_bluetooth_device_discovery: mConnectionEngine.startBluetoothDeviceDiscovery(); break; case R.id.action_make_device_discoverable: mConnectionEngine.makeDeviceDiscoverable(); break; case R.id.action_reset: destroyEngine(); createAndStartEngine(); break; case R.id.action_force_screen_on: item.setChecked(!item.isChecked()); if (item.isChecked()) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } else { getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } preferences.edit().putBoolean(PREF_KEY_SCREEN_ON, item.isChecked()).commit(); break; case R.id.action_refresh: mPeerListFragment.onDataChanged(); break; } return wasConsumed || super.onOptionsItemSelected(item); }