Java Code Examples for android.view.MenuItem#setChecked()
The following examples show how to use
android.view.MenuItem#setChecked() .
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: FragmentExpandableMultiLevel.java From FlexibleAdapter with Apache License 2.0 | 6 votes |
@SuppressWarnings("ConstantConditions") @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_recursive_collapse) { if (mAdapter.isRecursiveCollapse()) { mAdapter.setRecursiveCollapse(false); item.setChecked(false); Snackbar.make(getView(), "Recursive-Collapse is disabled", Snackbar.LENGTH_SHORT).show(); } else { mAdapter.setRecursiveCollapse(true); item.setChecked(true); Snackbar.make(getView(), "Recursive-Collapse is enabled", Snackbar.LENGTH_SHORT).show(); } } return super.onOptionsItemSelected(item); }
Example 2
Source File: AlbumsFragment.java From RetroMusicPlayer with GNU General Public License v3.0 | 6 votes |
private boolean handleSortOrderMenuItem(@NonNull MenuItem item) { String sortOrder = null; switch (item.getItemId()) { case R.id.action_sort_order_album: sortOrder = AlbumSortOrder.ALBUM_A_Z; break; case R.id.action_sort_order_album_desc: sortOrder = AlbumSortOrder.ALBUM_Z_A; break; case R.id.action_sort_order_artist: sortOrder = AlbumSortOrder.ALBUM_ARTIST; break; } if (sortOrder != null) { item.setChecked(true); setSaveSortOrder(sortOrder); } return true; }
Example 3
Source File: FileExplorerActivity.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { Pref pref = Pref.getInstance(this); int id = item.getItemId(); if (id == R.id.show_hidden_files_menu) { item.setChecked(!item.isChecked()); pref.setShowHiddenFiles(item.isChecked()); } else if (id == R.id.sort_by_name_menu) { item.setChecked(true); pref.setFileSortType(FileListSorter.SORT_NAME); } else if (id == R.id.sort_by_datetime_menu) { item.setChecked(true); pref.setFileSortType(FileListSorter.SORT_DATE); } else if (id == R.id.sort_by_size_menu) { item.setChecked(true); pref.setFileSortType(FileListSorter.SORT_SIZE); } else if (id == R.id.sort_by_type_menu) { item.setChecked(true); pref.setFileSortType(FileListSorter.SORT_TYPE); } return super.onOptionsItemSelected(item); }
Example 4
Source File: MainActivity.java From easyLUT with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_identity: item.setChecked(!item.isChecked()); if (item.isChecked()) { setImage(R.drawable.identity_square_8); } else { setImage(R.drawable.landscape); } return true; case R.id.action_full_res: item.setChecked(!item.isChecked()); fullRes = item.isChecked(); setImage(originalBitmap, 0); return true; } return super.onOptionsItemSelected(item); }
Example 5
Source File: Home.java From xDrip-Experimental with GNU General Public License v3.0 | 6 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_home, menu); //wear integration if (!mPreferences.getBoolean("wear_sync", false)) { menu.removeItem(R.id.action_open_watch_settings); menu.removeItem(R.id.action_resend_last_bg); } //speak readings MenuItem menuItem = menu.findItem(R.id.action_toggle_speakreadings); if(mPreferences.getBoolean("bg_to_speech_shortcut", false)){ menuItem.setVisible(true); if(mPreferences.getBoolean("bg_to_speech", false)){ menuItem.setChecked(true); } else { menuItem.setChecked(false); } } else { menuItem.setVisible(false); } return super.onCreateOptionsMenu(menu); }
Example 6
Source File: WalletActivity.java From xmrwallet with Apache License 2.0 | 6 votes |
void updateAccountsList() { final Wallet wallet = getWallet(); Menu menu = accountsView.getMenu(); menu.removeGroup(R.id.accounts_list); final int n = wallet.getNumAccounts(); final boolean showBalances = (n > 1) && !isStreetMode(); for (int i = 0; i < n; i++) { final String label = (showBalances ? getString(R.string.label_account, wallet.getAccountLabel(i), Helper.getDisplayAmount(wallet.getBalance(i), 2)) : wallet.getAccountLabel(i)); final MenuItem item = menu.add(R.id.accounts_list, getAccountId(i), 2 * i, label); item.setIcon(R.drawable.ic_account_balance_wallet_black_24dp); if (i == wallet.getAccountIndex()) item.setChecked(true); } menu.setGroupCheckable(R.id.accounts_list, true, true); }
Example 7
Source File: WorldMapDialog.java From SuntimesWidget with GNU General Public License v3.0 | 6 votes |
@Override public boolean onMenuItemClick(MenuItem item) { Context context = getContext(); if (context == null) { return false; } switch (item.getItemId()) { case R.id.mapSpeed_1d: WorldMapWidgetSettings.saveWorldMapPref(context, 0, WorldMapWidgetSettings.PREF_KEY_WORLDMAP_SPEED1D, WorldMapWidgetSettings.MAPTAG_3x2, true); item.setChecked(true); updateViews(); return true; case R.id.mapSpeed_15m: WorldMapWidgetSettings.saveWorldMapPref(context, 0, WorldMapWidgetSettings.PREF_KEY_WORLDMAP_SPEED1D, WorldMapWidgetSettings.MAPTAG_3x2, false); item.setChecked(true); updateViews(); return true; default: return false; } }
Example 8
Source File: MainActivity.java From design-support-demo with Apache License 2.0 | 6 votes |
/** * Handles clicks on the navigation menu. */ @Override public boolean onNavigationItemSelected(final MenuItem menuItem) { // update highlighted item in the navigation menu menuItem.setChecked(true); mNavItemId = menuItem.getItemId(); // allow some time after closing the drawer before performing real navigation // so the user can see what is happening mDrawerLayout.closeDrawer(GravityCompat.START); mDrawerActionHandler.postDelayed(new Runnable() { @Override public void run() { navigate(menuItem.getItemId()); } }, DRAWER_CLOSE_DELAY_MS); return true; }
Example 9
Source File: PlayerActivity.java From leafpicrevived with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(com.alienpants.leafpicrevived.R.menu.menu_video_player, menu); MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo(); if (player != null && mappedTrackInfo != null) { for (int i = 0; i < mappedTrackInfo.length; i++) { TrackGroupArray trackGroups = mappedTrackInfo.getTrackGroups(i); if (trackGroups.length != 0) { switch (player.getRendererType(i)) { case C.TRACK_TYPE_AUDIO: menu.findItem(R.id.audio_stuff).setVisible(true); audio = i; break; case C.TRACK_TYPE_VIDEO: menu.findItem(R.id.video_stuff).setVisible(true); video = i; break; case C.TRACK_TYPE_TEXT: menu.findItem(R.id.text_stuff).setVisible(true); text = i; break; } } } } MenuItem loop = menu.findItem(R.id.loop_video); loop.setChecked(Prefs.getLoopVideo()); return true; }
Example 10
Source File: AppListFragment.java From island with Apache License 2.0 | 5 votes |
@Override public boolean onOptionsItemSelected(final MenuItem item) { final int id = item.getItemId(); if (id == R.id.menu_show_system) { final boolean should_include = ! item.isChecked(); mViewModel.onFilterHiddenSysAppsInclusionChanged(should_include); item.setChecked(should_include); // Toggle the checked state } else if (id == R.id.menu_settings) startActivity(new Intent(getActivity(), SettingsActivity.class)); else if (id == R.id.menu_test) TempDebug.run(getActivity()); else return super.onOptionsItemSelected(item); return true; }
Example 11
Source File: MainActivity.java From memetastic with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("ConstantConditions") private void selectTab(int pos, int mainMode) { MenuItem navItem = null; switch (mainMode) { case 0: pos = pos >= 0 ? pos : _tabLayout.getTabCount() - 1; pos = pos < _tabLayout.getTabCount() ? pos : 0; _tabLayout.getTabAt(pos).select(); break; case 1: navItem = _bottomNav.getMenu().findItem(R.id.nav_mode_favs); break; case 2: navItem = _bottomNav.getMenu().findItem(R.id.nav_mode_saved); break; case 3: navItem = _bottomNav.getMenu().findItem(R.id.nav_mode_hidden); break; case 4: navItem = _bottomNav.getMenu().findItem(R.id.nav_more); break; } if (navItem != null) { navItem.setChecked(true); onNavigationItemSelected(navItem); } }
Example 12
Source File: TaskListFragment.java From opentasks with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { // create menu inflater.inflate(R.menu.task_list_fragment_menu, menu); // restore menu state MenuItem item = menu.findItem(R.id.menu_show_completed); if (item != null) { item.setChecked(mSavedCompletedFilter); } }
Example 13
Source File: MovieDrawerFragment.java From watchlist with Apache License 2.0 | 5 votes |
private void setSelectedDrawerItem(int position) { MenuItem item = navigationView.getMenu().getItem(position); item.setChecked(true); toolbar.setTitle(item.getTitle()); // Create and setup bundle args Bundle args = new Bundle(); if (position == 0) { args.putInt(WatchlistApp.VIEW_TYPE, WatchlistApp.VIEW_TYPE_POPULAR); } else if (position == 1) { args.putInt(WatchlistApp.VIEW_TYPE, WatchlistApp.VIEW_TYPE_RATED); } else if (position == 2) { args.putInt(WatchlistApp.VIEW_TYPE, WatchlistApp.VIEW_TYPE_UPCOMING); } else if (position == 3) { args.putInt(WatchlistApp.VIEW_TYPE, WatchlistApp.VIEW_TYPE_PLAYING); } else if (position == 4) { args.putInt(WatchlistApp.VIEW_TYPE, WatchlistApp.VIEW_TYPE_WATCHED); } else if (position == 5) { args.putInt(WatchlistApp.VIEW_TYPE, WatchlistApp.VIEW_TYPE_TO_SEE); } // Initialize fragment type if (position <= 3) { fragment = new MovieListFragment(); } else { fragment = new MovieSavedFragment(); } fragment.setArguments(args); FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.content_frame, fragment, WatchlistApp.TAG_GRID_FRAGMENT); transaction.commit(); // Save selected position to preference SharedPreferences.Editor editor = preferences.edit(); editor.putInt(WatchlistApp.LAST_SELECTED, position); editor.apply(); }
Example 14
Source File: ChartActivity.java From currency with GNU General Public License v3.0 | 5 votes |
private boolean onMaxClick(MenuItem item) { range = MAX; item.setChecked(true); updateRange(); return true; }
Example 15
Source File: ContactDetailsActivity.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
@Override public boolean onOptionsItemSelected(final MenuItem menuItem) { if (MenuDoubleTabUtil.shouldIgnoreTap()) { return false; } final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setNegativeButton(getString(R.string.cancel), null); switch (menuItem.getItemId()) { case android.R.id.home: finish(); break; case R.id.action_share_http: shareLink(true); break; case R.id.action_share_uri: shareLink(false); break; case R.id.action_block: BlockContactDialog.show(this, contact); break; case R.id.action_unblock: BlockContactDialog.show(this, contact); break; case R.id.action_advanced_mode: this.mAdvancedMode = !menuItem.isChecked(); menuItem.setChecked(this.mAdvancedMode); getPreferences().edit().putBoolean("advanced_mode", mAdvancedMode).apply(); invalidateOptionsMenu(); refreshUi(); break; } return super.onOptionsItemSelected(menuItem); }
Example 16
Source File: MainActivity.java From media-samples with Apache License 2.0 | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_clear_all: mLogLines.clear(); logOnUiThread(""); break; case R.id.action_keep_screen_on: boolean checked = !item.isChecked(); setKeepScreenOn(checked); item.setChecked(checked); break; } return super.onOptionsItemSelected(item); }
Example 17
Source File: LibraryFragment.java From Music-Player with GNU General Public License v3.0 | 5 votes |
private boolean handleGridSizeMenuItem(@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, @NonNull MenuItem item) { int gridSize = 0; switch (item.getItemId()) { case R.id.action_grid_size_1: gridSize = 1; break; case R.id.action_grid_size_2: gridSize = 2; break; case R.id.action_grid_size_3: gridSize = 3; break; case R.id.action_grid_size_4: gridSize = 4; break; case R.id.action_grid_size_5: gridSize = 5; break; case R.id.action_grid_size_6: gridSize = 6; break; case R.id.action_grid_size_7: gridSize = 7; break; case R.id.action_grid_size_8: gridSize = 8; break; } if (gridSize > 0) { item.setChecked(true); fragment.setAndSaveGridSize(gridSize); toolbar.getMenu().findItem(R.id.action_colored_footers).setEnabled(fragment.canUsePalette()); return true; } return false; }
Example 18
Source File: LanguageEditor.java From xDrip with GNU General Public License v3.0 | 4 votes |
public void languageShowOnlyUntranslated(MenuItem v) { v.setChecked(!v.isChecked()); show_only_untranslated = v.isChecked(); applyFilter(last_filter); forceRefresh(); }
Example 19
Source File: DragActivity.java From PracticalRecyclerView with Apache License 2.0 | 4 votes |
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem grid = menu.findItem(R.id.action_grid); grid.setChecked(gridChecked); return true; }
Example 20
Source File: AdapterBaseImpl.java From microMathematics with GNU General Public License v3.0 | 4 votes |
@Override public void populateContextMenu(ContextMenu menu, AdapterView.AdapterContextMenuInfo acmi, int num) { try { if (readWriteAdapter) { menu.add(0, R.id.fman_action_refresh, 0, R.string.fman_refresh_title); menu.add(0, R.id.fman_action_create_folder, 0, R.string.fman_create_folder_title); if (num > 0) { menu.add(0, R.id.fman_action_rename, 0, R.string.fman_rename_title); menu.add(0, R.id.fman_action_delete, 0, R.string.fman_delete_title); } } MenuItem activeSort = null; menu.add(0, R.id.fman_action_sort_by_name, 0, R.string.fman_sort_by_name); if ((mode & MODE_SORTING) == SORT_NAME) { activeSort = menu.findItem(R.id.fman_action_sort_by_name); } menu.add(0, R.id.fman_action_sort_by_ext, 0, R.string.fman_sort_by_ext); if ((mode & MODE_SORTING) == SORT_EXT) { activeSort = menu.findItem(R.id.fman_action_sort_by_ext); } menu.add(0, R.id.fman_action_sort_by_size, 0, R.string.fman_sort_by_size); if ((mode & MODE_SORTING) == SORT_SIZE) { activeSort = menu.findItem(R.id.fman_action_sort_by_size); } menu.add(0, R.id.fman_action_sort_by_date, 0, R.string.fman_sort_by_date); if ((mode & MODE_SORTING) == SORT_DATE) { activeSort = menu.findItem(R.id.fman_action_sort_by_date); } if (activeSort != null) { activeSort.setCheckable(true); activeSort.setChecked(true); } } catch (Exception e) { e.printStackTrace(); } }