List of usage examples for android.view Menu findItem
public MenuItem findItem(int id);
From source file:com.dycody.android.idealnote.ListFragment.java
private void setActionItemsVisibility(Menu menu, boolean searchViewHasFocus) { boolean drawerOpen = mainActivity.getDrawerLayout() != null && mainActivity.getDrawerLayout().isDrawerOpen(GravityCompat.START); boolean expandedView = prefs.getBoolean(Constants.PREF_EXPANDED_VIEW, true); int navigation = Navigation.getNavigation(); boolean navigationReminders = navigation == Navigation.REMINDERS; boolean navigationArchive = navigation == Navigation.ARCHIVE; boolean navigationTrash = navigation == Navigation.TRASH; boolean navigationCategory = navigation == Navigation.CATEGORY; boolean filterPastReminders = prefs.getBoolean(Constants.PREF_FILTER_PAST_REMINDERS, true); boolean filterArchivedInCategory = navigationCategory && prefs.getBoolean(Constants.PREF_FILTER_ARCHIVED_IN_CATEGORIES + Navigation.getCategory(), false); if (isFabAllowed()) { fab.setAllowed(true);/*from ww w. j a va 2s . c o m*/ fab.showFab(); } else { fab.setAllowed(false); fab.hideFab(); } menu.findItem(R.id.menu_search).setVisible(!drawerOpen); menu.findItem(R.id.menu_filter) .setVisible(!drawerOpen && !filterPastReminders && navigationReminders && !searchViewHasFocus); menu.findItem(R.id.menu_filter_remove) .setVisible(!drawerOpen && filterPastReminders && navigationReminders && !searchViewHasFocus); menu.findItem(R.id.menu_filter_category) .setVisible(!drawerOpen && !filterArchivedInCategory && navigationCategory && !searchViewHasFocus); menu.findItem(R.id.menu_filter_category_remove) .setVisible(!drawerOpen && filterArchivedInCategory && navigationCategory && !searchViewHasFocus); menu.findItem(R.id.menu_sort).setVisible(!drawerOpen && !navigationReminders && !searchViewHasFocus); menu.findItem(R.id.menu_expanded_view).setVisible(!drawerOpen && !expandedView && !searchViewHasFocus); menu.findItem(R.id.menu_contracted_view).setVisible(!drawerOpen && expandedView && !searchViewHasFocus); menu.findItem(R.id.menu_empty_trash).setVisible(!drawerOpen && navigationTrash); menu.findItem(R.id.menu_tags).setVisible(searchViewHasFocus); }
From source file:com.zen.androidhtmleditor.AHEActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); if (isFinalized) ;//from w w w .j av a2 s. c om //Button backButton = (Button)findViewById(R.id.button2); //int vis = backButton.getVisibility(); MenuItem newfile = menu.findItem(R.id.newfile); MenuItem newfolder = menu.findItem(R.id.newfolder); MenuItem uploadfile = menu.findItem(R.id.uploadfile); MenuItem terminal = menu.findItem(R.id.terminal); if (connectedTo > -1) { newfile.setEnabled(true); newfolder.setEnabled(true); uploadfile.setEnabled(true); terminal.setEnabled(true); } else { newfile.setEnabled(false); newfolder.setEnabled(false); uploadfile.setEnabled(false); terminal.setEnabled(false); } return super.onPrepareOptionsMenu(menu); }
From source file:com.amaze.filemanager.activities.MainActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem s = menu.findItem(R.id.view); MenuItem search = menu.findItem(R.id.search); MenuItem paste = menu.findItem(R.id.paste); String f = null;/* ww w . j a v a 2s. c o m*/ Fragment fragment; try { fragment = getSupportFragmentManager().findFragmentById(R.id.content_frame); f = fragment.getClass().getName(); } catch (Exception e1) { return true; } if (f.contains("TabFragment")) { setActionBarTitle("Amaze"); if (aBoolean) { s.setTitle(getResources().getString(R.string.gridview)); } else { s.setTitle(getResources().getString(R.string.listview)); } try { TabFragment tabFragment = (TabFragment) fragment; Main ma = ((Main) tabFragment.getTab()); if (ma.IS_LIST) s.setTitle(R.string.gridview); else s.setTitle(R.string.listview); updatePath(ma.CURRENT_PATH, ma.results, ma.openMode, ma.folder_count, ma.file_count); } catch (Exception e) { } initiatebbar(); if (Build.VERSION.SDK_INT >= 21) toolbar.setElevation(0); invalidatePasteButton(paste); search.setVisible(true); if (indicator_layout != null) indicator_layout.setVisibility(View.VISIBLE); menu.findItem(R.id.search).setVisible(true); menu.findItem(R.id.home).setVisible(true); menu.findItem(R.id.history).setVisible(true); menu.findItem(R.id.sethome).setVisible(true); menu.findItem(R.id.item10).setVisible(true); if (showHidden) menu.findItem(R.id.hiddenitems).setVisible(true); menu.findItem(R.id.view).setVisible(true); menu.findItem(R.id.extract).setVisible(false); invalidatePasteButton(menu.findItem(R.id.paste)); findViewById(R.id.buttonbarframe).setVisibility(View.VISIBLE); } else if (f.contains("AppsList") || f.contains("ProcessViewer")) { appBarLayout.setExpanded(true); menu.findItem(R.id.sethome).setVisible(false); if (indicator_layout != null) indicator_layout.setVisibility(View.GONE); findViewById(R.id.buttonbarframe).setVisibility(View.GONE); menu.findItem(R.id.search).setVisible(false); menu.findItem(R.id.home).setVisible(false); menu.findItem(R.id.history).setVisible(false); menu.findItem(R.id.extract).setVisible(false); if (f.contains("ProcessViewer")) menu.findItem(R.id.item10).setVisible(false); else { menu.findItem(R.id.dsort).setVisible(false); menu.findItem(R.id.sortby).setVisible(false); } menu.findItem(R.id.hiddenitems).setVisible(false); menu.findItem(R.id.view).setVisible(false); menu.findItem(R.id.paste).setVisible(false); } else if (f.contains("ZipViewer")) { menu.findItem(R.id.sethome).setVisible(false); if (indicator_layout != null) indicator_layout.setVisibility(View.GONE); TextView textView = (TextView) mainActivity.pathbar.findViewById(R.id.fullpath); pathbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { } }); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { } }); menu.findItem(R.id.search).setVisible(false); menu.findItem(R.id.home).setVisible(false); menu.findItem(R.id.history).setVisible(false); menu.findItem(R.id.item10).setVisible(false); menu.findItem(R.id.hiddenitems).setVisible(false); menu.findItem(R.id.view).setVisible(false); menu.findItem(R.id.paste).setVisible(false); menu.findItem(R.id.extract).setVisible(true); } return super.onPrepareOptionsMenu(menu); }
From source file:cgeo.geocaching.CacheListActivity.java
/** * Menu items which are not at all usable with the current list type should be hidden. * Menu items which are usable with the current list type but not in the current situation should be disabled. *///from ww w .ja va 2s . c om @Override public boolean onPrepareOptionsMenu(final Menu menu) { super.onPrepareOptionsMenu(menu); final boolean isHistory = type == CacheListType.HISTORY; final boolean isOffline = type == CacheListType.OFFLINE; final boolean isEmpty = cacheList.isEmpty(); final boolean isConcrete = isConcreteList(); final boolean isNonDefaultList = isConcrete && listId != StoredList.STANDARD_LIST_ID; final List<CacheListApp> listNavigationApps = CacheListApps.getActiveApps(); try { // toplevel menu items setEnabled(menu, R.id.menu_show_on_map, !isEmpty); setEnabled(menu, R.id.menu_filter, search != null && search.getCount() > 0); setVisibleEnabled(menu, R.id.menu_sort, !isHistory, !isEmpty); if (adapter.isSelectMode()) { menu.findItem(R.id.menu_switch_select_mode) .setTitle(res.getString(R.string.caches_select_mode_exit)) .setIcon(R.drawable.ic_menu_clear_playlist); } else { menu.findItem(R.id.menu_switch_select_mode).setTitle(res.getString(R.string.caches_select_mode)) .setIcon(R.drawable.ic_menu_agenda); } setEnabled(menu, R.id.menu_switch_select_mode, !isEmpty); setVisible(menu, R.id.menu_invert_selection, adapter.isSelectMode()); // exception to the general rule: only show in select mode setVisibleEnabled(menu, R.id.menu_cache_list_app_provider, listNavigationApps.size() > 1, !isEmpty); setVisibleEnabled(menu, R.id.menu_cache_list_app, listNavigationApps.size() == 1, !isEmpty); // Manage Caches submenu setEnabled(menu, R.id.menu_refresh_stored, !isEmpty); if (!isOffline && !isHistory) { menu.findItem(R.id.menu_refresh_stored).setTitle(R.string.caches_store_offline); } setVisibleEnabled(menu, R.id.menu_move_to_list, isHistory || isOffline, !isEmpty); setVisibleEnabled(menu, R.id.menu_copy_to_list, isHistory || isOffline, !isEmpty); setVisibleEnabled(menu, R.id.menu_drop_caches, isHistory || containsStoredCaches(), !isEmpty); setVisibleEnabled(menu, R.id.menu_delete_events, isConcrete, !isEmpty && containsPastEvents()); setVisibleEnabled(menu, R.id.menu_clear_offline_logs, isHistory || isOffline, !isEmpty && containsOfflineLogs()); setVisibleEnabled(menu, R.id.menu_remove_from_history, isHistory, !isEmpty); setMenuItemLabel(menu, R.id.menu_remove_from_history, R.string.cache_remove_from_history, R.string.cache_clear_history); if (isOffline || type == CacheListType.HISTORY) { // only offline list setMenuItemLabel(menu, R.id.menu_drop_caches, R.string.caches_remove_selected, R.string.caches_remove_all); setMenuItemLabel(menu, R.id.menu_refresh_stored, R.string.caches_refresh_selected, R.string.caches_refresh_all); setMenuItemLabel(menu, R.id.menu_move_to_list, R.string.caches_move_selected, R.string.caches_move_all); setMenuItemLabel(menu, R.id.menu_copy_to_list, R.string.caches_copy_selected, R.string.caches_copy_all); } else { // search and global list (all other than offline and history) setMenuItemLabel(menu, R.id.menu_refresh_stored, R.string.caches_store_selected, R.string.caches_store_offline); } // Manage Lists submenu setVisible(menu, R.id.menu_lists, isOffline); setVisible(menu, R.id.menu_drop_list, isNonDefaultList); setVisible(menu, R.id.menu_rename_list, isNonDefaultList); setVisibleEnabled(menu, R.id.menu_make_list_unique, listId != PseudoList.ALL_LIST.id, !isEmpty); // Import submenu setVisible(menu, R.id.menu_import, isOffline && listId != PseudoList.ALL_LIST.id); setEnabled(menu, R.id.menu_import_android, Compatibility.isStorageAccessFrameworkAvailable()); setEnabled(menu, R.id.menu_import_pq, Settings.isGCConnectorActive() && Settings.isGCPremiumMember()); // Export setVisibleEnabled(menu, R.id.menu_export, isHistory || isOffline, !isEmpty); } catch (final RuntimeException e) { Log.e("CacheListActivity.onPrepareOptionsMenu", e); } return true; }
From source file:com.kll.collect.android.activities.FormEntryActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); FormController formController = Collect.getInstance().getFormController(); boolean useability; useability = mAdminPreferences.getBoolean(AdminPreferencesActivity.KEY_SAVE_MID, true); menu.findItem(MENU_SAVE).setVisible(useability).setEnabled(useability); useability = mAdminPreferences.getBoolean(AdminPreferencesActivity.KEY_JUMP_TO, true); menu.findItem(MENU_HIERARCHY_VIEW).setVisible(useability).setEnabled(useability); useability = mAdminPreferences.getBoolean(AdminPreferencesActivity.KEY_CHANGE_LANGUAGE, true) && (formController != null) && formController.getLanguages() != null && formController.getLanguages().length > 1; menu.findItem(MENU_LANGUAGES).setVisible(useability).setEnabled(useability); useability = mAdminPreferences.getBoolean(AdminPreferencesActivity.KEY_ACCESS_SETTINGS, true); menu.findItem(MENU_PREFERENCES).setVisible(useability).setEnabled(useability); return true;// w w w . j a v a2s .c om }
From source file:com.ichi2.anki2.DeckPicker.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { boolean sdCardAvailable = AnkiDroidApp.isSdCardMounted(); if (mFragmented) { menu.findItem(MENU_SYNC).setEnabled(sdCardAvailable); menu.findItem(MENU_ADD_NOTE).setEnabled(sdCardAvailable); menu.findItem(MENU_STATISTICS).setEnabled(sdCardAvailable); menu.findItem(MENU_CARDBROWSER).setEnabled(sdCardAvailable); }/*from ww w.j av a 2s. c om*/ menu.findItem(MENU_CREATE_DECK).setEnabled(sdCardAvailable); menu.findItem(MENU_CREATE_DYNAMIC_DECK).setEnabled(sdCardAvailable); menu.findItem(CHECK_DATABASE).setEnabled(sdCardAvailable); return true; }
From source file:de.vanita5.twittnuker.util.Utils.java
public static void setMenuItemIcon(final Menu menu, final int id, final int icon) { if (menu == null) return;//from www .jav a 2 s . c o m final MenuItem item = menu.findItem(id); if (item == null) return; item.setIcon(icon); }
From source file:de.vanita5.twittnuker.util.Utils.java
public static void setMenuItemTitle(final Menu menu, final int id, final int icon) { if (menu == null) return;/*from ww w. j ava 2s. com*/ final MenuItem item = menu.findItem(id); if (item == null) return; item.setTitle(icon); }
From source file:de.vanita5.twittnuker.util.Utils.java
public static void setMenuItemAvailability(final Menu menu, final int id, final boolean available) { if (menu == null) return;/* w w w . j ava2 s . c o m*/ final MenuItem item = menu.findItem(id); if (item == null) return; item.setVisible(available); item.setEnabled(available); }