List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:com.money.manager.ex.account.AccountTransactionListFragment.java
private void selectCurrentStatus(Menu menu) { MenuItem toolbarItem = menu.findItem(R.id.menuTransactionStatusSelector); if (toolbarItem == null) return;/*from www . ja v a 2 s .co m*/ SubMenu subMenu = toolbarItem.getSubMenu(); for (int i = 0; i < subMenu.size(); i++) { MenuItem subItem = subMenu.getItem(i); int menuId = subItem.getItemId(); if (mFilter.transactionStatus.contains(menuId)) { subItem.setChecked(true); } } }
From source file:com.adkdevelopment.e_contact.ui.MainActivity.java
/** * Initialises Navigation Drawer and adds links movement to the footer * sets listener on an item click in the Drawer *//* w w w. j av a 2s . c o m*/ private void initNavigationDrawer() { // Make links work in the Drawer mFooterLinks.setMovementMethod(LinkMovementMethod.getInstance()); // add listener to the buttons in the navigation drawer mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.drawer_map: if (Utilities.checkPlayServices(MainActivity.this)) { Intent intent = new Intent(MainActivity.this, MapsActivity.class); startActivity(intent); } mDrawerLayout.closeDrawers(); return false; case R.id.login_button: startActivity(new Intent(MainActivity.this, LoginActivity.class)); return true; case R.id.profile_button: startActivity(new Intent(MainActivity.this, ProfileActivity.class)); return true; default: item.setChecked(true); mDrawerLayout.closeDrawers(); return true; } } }); }
From source file:de.tap.easy_xkcd.fragments.overview.OverviewListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_boomark: super.goToComic(bookmark - 1); break;//from ww w.j a v a 2 s.c o m case R.id.action_unread: databaseManager.setComicsUnread(); setupAdapter(); break; case R.id.action_favorite: if (prefHelper.overviewFav()) { item.setIcon(R.drawable.ic_favorite_outline); item.setTitle(R.string.nv_favorites); } else { item.setIcon(R.drawable.ic_action_favorite); item.setTitle(R.string.action_overview); } prefHelper.setOverviewFav(!prefHelper.overviewFav()); getActivity().invalidateOptionsMenu(); setupAdapter(); break; case R.id.action_hide_read: item.setChecked(!item.isChecked()); prefHelper.setHideRead(item.isChecked()); setupAdapter(); break; } return super.onOptionsItemSelected(item); }
From source file:com.owncloud.android.ui.fragment.contactsbackup.ContactListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { boolean retval; ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity(); switch (item.getItemId()) { case android.R.id.home: contactsPreferenceActivity.onBackPressed(); retval = true;/* ww w . j ava 2 s . c o m*/ break; case R.id.action_select_all: item.setChecked(!item.isChecked()); setSelectAllMenuItem(item, item.isChecked()); contactListAdapter.selectAllFiles(item.isChecked()); retval = true; break; default: retval = super.onOptionsItemSelected(item); break; } return retval; }
From source file:com.ptr.folding.sample.FoldingLayoutActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.animate_fold: animateFold();// w ww.ja va 2s . co m break; case R.id.toggle_orientation: mOrientation = (mOrientation == Orientation.HORIZONTAL) ? Orientation.VERTICAL : Orientation.HORIZONTAL; item.setTitle((mOrientation == Orientation.HORIZONTAL) ? R.string.vertical : R.string.horizontal); // mTranslation = 0; mFoldLayout.setOrientation(mOrientation); break; case R.id.camera_feed: if (IS_ISC) { mIsCameraFeed = !mIsCameraFeed; item.setTitle(mIsCameraFeed ? R.string.static_image : R.string.camera_feed); item.setChecked(mIsCameraFeed); if (mIsCameraFeed) { // mFoldLayout.removeView(mImageView); // mFoldLayout.addView(mTextureView, // new ViewGroup.LayoutParams(mFoldLayout.getWidth(), // mFoldLayout.getHeight())); } else { //mFoldLayout.removeView(mTextureView); //mFoldLayout.addView(mImageView, new ViewGroup.LayoutParams( // mFoldLayout.getWidth(), mFoldLayout.getHeight())); } // mTranslation = 0; } break; case R.id.sepia: mIsSepiaOn = !mIsSepiaOn; item.setChecked(mIsSepiaOn); if (mIsSepiaOn && mFoldLayout.getFoldFactor() != 0) { setSepiaLayer(mFoldLayout.getChildAt(0), true); } else { setSepiaLayer(mFoldLayout.getChildAt(0), false); } break; default: break; } return super.onOptionsItemSelected(item); }
From source file:com.master.metehan.filtereagle.ActivityLog.java
@Override public boolean onOptionsItemSelected(MenuItem item) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final File pcap_file = new File(getCacheDir(), "netguard.pcap"); switch (item.getItemId()) { case android.R.id.home: Log.i(TAG, "Up"); NavUtils.navigateUpFromSameTask(this); return true; case R.id.menu_protocol_udp: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("proto_udp", item.isChecked()).apply(); updateAdapter();//from w w w.j av a2s .co m return true; case R.id.menu_protocol_tcp: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("proto_tcp", item.isChecked()).apply(); updateAdapter(); return true; case R.id.menu_protocol_other: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("proto_other", item.isChecked()).apply(); updateAdapter(); return true; case R.id.menu_traffic_allowed: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("traffic_allowed", item.isChecked()).apply(); updateAdapter(); return true; case R.id.menu_traffic_blocked: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("traffic_blocked", item.isChecked()).apply(); updateAdapter(); return true; case R.id.menu_log_live: item.setChecked(!item.isChecked()); live = item.isChecked(); if (live) { DatabaseHelper.getInstance(this).addLogChangedListener(listener); updateAdapter(); } else DatabaseHelper.getInstance(this).removeLogChangedListener(listener); return true; case R.id.menu_refresh: updateAdapter(); return true; case R.id.menu_log_resolve: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("resolve", item.isChecked()).apply(); adapter.setResolve(item.isChecked()); adapter.notifyDataSetChanged(); return true; case R.id.menu_log_organization: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("organization", item.isChecked()).apply(); adapter.setOrganization(item.isChecked()); adapter.notifyDataSetChanged(); return true; case R.id.menu_pcap_enabled: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("pcap", item.isChecked()).apply(); ServiceSinkhole.setPcap(item.isChecked(), ActivityLog.this); return true; case R.id.menu_pcap_export: startActivityForResult(getIntentPCAPDocument(), REQUEST_PCAP); return true; case R.id.menu_log_clear: new AsyncTask<Object, Object, Object>() { @Override protected Object doInBackground(Object... objects) { DatabaseHelper.getInstance(ActivityLog.this).clearLog(); if (prefs.getBoolean("pcap", false)) { ServiceSinkhole.setPcap(false, ActivityLog.this); if (pcap_file.exists() && !pcap_file.delete()) Log.w(TAG, "Delete PCAP failed"); ServiceSinkhole.setPcap(true, ActivityLog.this); } else { if (pcap_file.exists() && !pcap_file.delete()) Log.w(TAG, "Delete PCAP failed"); } return null; } @Override protected void onPostExecute(Object result) { if (running) updateAdapter(); } }.execute(); return true; case R.id.menu_log_support: Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://github.com/M66B/NetGuard/blob/master/FAQ.md#FAQ27")); if (getPackageManager().resolveActivity(intent, 0) != null) startActivity(intent); return true; default: return super.onOptionsItemSelected(item); } }
From source file:eu.faircode.adblocker.ActivityLog.java
@Override public boolean onOptionsItemSelected(MenuItem item) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final File pcap_file = new File(getCacheDir(), "adblocker.pcap"); switch (item.getItemId()) { case android.R.id.home: Log.i(TAG, "Up"); NavUtils.navigateUpFromSameTask(this); return true; case R.id.menu_protocol_udp: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("proto_udp", item.isChecked()).apply(); updateAdapter();/*w w w . j a va2 s. c o m*/ return true; case R.id.menu_protocol_tcp: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("proto_tcp", item.isChecked()).apply(); updateAdapter(); return true; case R.id.menu_protocol_other: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("proto_other", item.isChecked()).apply(); updateAdapter(); return true; case R.id.menu_traffic_allowed: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("traffic_allowed", item.isChecked()).apply(); updateAdapter(); return true; case R.id.menu_traffic_blocked: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("traffic_blocked", item.isChecked()).apply(); updateAdapter(); return true; case R.id.menu_log_live: item.setChecked(!item.isChecked()); live = item.isChecked(); if (live) { DatabaseHelper.getInstance(this).addLogChangedListener(listener); updateAdapter(); } else DatabaseHelper.getInstance(this).removeLogChangedListener(listener); return true; case R.id.menu_refresh: updateAdapter(); return true; case R.id.menu_log_resolve: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("resolve", item.isChecked()).apply(); adapter.setResolve(item.isChecked()); adapter.notifyDataSetChanged(); return true; case R.id.menu_log_organization: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("organization", item.isChecked()).apply(); adapter.setOrganization(item.isChecked()); adapter.notifyDataSetChanged(); return true; case R.id.menu_pcap_enabled: item.setChecked(!item.isChecked()); prefs.edit().putBoolean("pcap", item.isChecked()).apply(); ServiceSinkhole.setPcap(item.isChecked(), ActivityLog.this); return true; case R.id.menu_pcap_export: startActivityForResult(getIntentPCAPDocument(), REQUEST_PCAP); return true; case R.id.menu_log_clear: new AsyncTask<Object, Object, Object>() { @Override protected Object doInBackground(Object... objects) { DatabaseHelper.getInstance(ActivityLog.this).clearLog(); if (prefs.getBoolean("pcap", false)) { ServiceSinkhole.setPcap(false, ActivityLog.this); if (pcap_file.exists() && !pcap_file.delete()) Log.w(TAG, "Delete PCAP failed"); ServiceSinkhole.setPcap(true, ActivityLog.this); } else { if (pcap_file.exists() && !pcap_file.delete()) Log.w(TAG, "Delete PCAP failed"); } return null; } @Override protected void onPostExecute(Object result) { if (running) updateAdapter(); } }.execute(); return true; case R.id.menu_log_support: Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://github.com/M66B/NetGuard/blob/master/FAQ.md#FAQ27")); if (getPackageManager().resolveActivity(intent, 0) != null) startActivity(intent); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.ultramegasoft.flavordex2.fragment.EntryListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: final EntryListActivity activity = (EntryListActivity) getActivity(); if (activity != null) { activity.onCatSelected(-1, false); }//from ww w. j a v a2s . co m return true; case R.id.menu_sort_name: item.setChecked(true); setSort(Tables.Entries.TITLE); return true; case R.id.menu_sort_date: item.setChecked(true); setSort(Tables.Entries.DATE); return true; case R.id.menu_sort_rating: item.setChecked(true); setSort(Tables.Entries.RATING); return true; case R.id.menu_add_entry: if (mCatName != null) { addEntry(mCatId, mCatName); } else { final FragmentManager fm = getFragmentManager(); if (fm != null) { CatListDialog.showDialog(fm, this, REQUEST_SELECT_CAT); } } return true; } return super.onOptionsItemSelected(item); }
From source file:com.nadmm.airports.ActivityBase.java
private void setupNavDrawer() { int selfItem = getSelfNavDrawerItem(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); if (mDrawerLayout == null) { return;/*from w w w . j av a 2 s . c o m*/ } mDrawerLayout.setStatusBarBackgroundColor(ContextCompat.getColor(this, R.color.color_primary_dark)); mNavigationView = (NavigationView) mDrawerLayout.findViewById(R.id.navdrawer); if (selfItem == NAVDRAWER_ITEM_INVALID) { // do not show a nav drawer if (mNavigationView != null) { ((ViewGroup) mNavigationView.getParent()).removeView(mNavigationView); } mDrawerLayout = null; return; } mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, getActionBarToolbar(), R.string.drawer_open, R.string.drawer_close) { public void onDrawerClosed(View view) { supportInvalidateOptionsMenu(); onNavDrawerStateChanged(false, false); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { onNavDrawerStateChanged(true, false); supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); mDrawerLayout.addDrawerListener(mDrawerToggle); updateDrawerToggle(); // Initialize navigation drawer mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem item) { item.setChecked(true); final int id = item.getItemId(); if (id != getSelfNavDrawerItem()) { // Launch the target Activity after a short delay to allow the drawer close // animation to finish without stutter mHandler.postDelayed(new Runnable() { @Override public void run() { goToNavDrawerItem(id); } }, NAVDRAWER_LAUNCH_DELAY); } mDrawerLayout.closeDrawer(GravityCompat.START); return false; } }); MenuItem item = mNavigationView.getMenu().findItem(selfItem); item.setChecked(true); }
From source file:com.google.android.apps.muzei.gallery.GallerySettingsActivity.java
@Override public boolean onOptionsItemSelected(final MenuItem item) { int itemId = item.getItemId(); int rotateMin = sRotateMinsByMenuId.get(itemId, -1); if (rotateMin != -1) { GalleryArtSource.getSharedPreferences(GallerySettingsActivity.this).edit() .putInt(GalleryArtSource.PREF_ROTATE_INTERVAL_MIN, rotateMin).apply(); item.setChecked(true); return true; }/* w ww . j av a2s.c om*/ if (itemId == R.id.action_import_photos) { if (mGetContentActivites.size() == 1) { // Just start the one ACTION_GET_CONTENT app requestGetContent(mGetContentActivites.get(0)); } else { // Let the user pick which app they want to import photos from PackageManager packageManager = getPackageManager(); final CharSequence[] items = new CharSequence[mGetContentActivites.size()]; for (int h = 0; h < mGetContentActivites.size(); h++) { items[h] = mGetContentActivites.get(h).loadLabel(packageManager); } new AlertDialog.Builder(this).setTitle(R.string.gallery_import_dialog_title) .setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { requestGetContent(mGetContentActivites.get(which)); } }).show(); } return true; } else if (itemId == R.id.action_clear_photos) { runOnHandlerThread(new Runnable() { @Override public void run() { getContentResolver().delete(GalleryContract.ChosenPhotos.CONTENT_URI, null, null); } }); return true; } return super.onOptionsItemSelected(item); }