List of usage examples for android.view MenuItem setVisible
public MenuItem setVisible(boolean visible);
From source file:com.example.contactslist.ui.ContactsListFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override/* w w w . j av a 2 s. c om*/ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { // Inflate the menu items inflater.inflate(R.menu.contact_list_menu, menu); // Locate the search item MenuItem searchItem = menu.findItem(R.id.menu_search); // In versions prior to Android 3.0, hides the search item to prevent additional // searches. In Android 3.0 and later, searching is done via a SearchView in the ActionBar. // Since the search doesn't create a new Activity to do the searching, the menu item // doesn't need to be turned off. if (mIsSearchResultView) { searchItem.setVisible(false); } // In version 3.0 and later, sets up and configures the ActionBar SearchView if (Utils.hasHoneycomb()) { // Retrieves the system search manager service final SearchManager searchManager = (SearchManager) getActivity() .getSystemService(Context.SEARCH_SERVICE); // Retrieves the SearchView from the search menu item final SearchView searchView = (SearchView) searchItem.getActionView(); // Assign searchable info to SearchView searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); // Set listeners for SearchView searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String queryText) { // Nothing needs to happen when the user submits the search string return true; } @Override public boolean onQueryTextChange(String newText) { // Called when the action bar search text has changed. Updates // the search filter, and restarts the loader to do a new query // using the new search string. String newFilter = !TextUtils.isEmpty(newText) ? newText : null; // Don't do anything if the filter is empty if (mSearchTerm == null && newFilter == null) { return true; } // Don't do anything if the new filter is the same as the current filter if (mSearchTerm != null && mSearchTerm.equals(newFilter)) { return true; } // Updates current filter to new filter mSearchTerm = newFilter; // Restarts the loader. This triggers onCreateLoader(), which builds the // necessary content Uri from mSearchTerm. mSearchQueryChanged = true; /*Uri uri; Cursor[] atomic = new Cursor[phoneNumbers.length]; for(int i=0; i<phoneNumbers.length; i++){ uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumbers[i])); atomic[i] = getActivity().getContentResolver().query(uri, ContactsQuery.PROJECTION, null, null, ContactsQuery.SORT_ORDER); } Cursor extendedCursor = new MergeCursor(atomic);*/ /* Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; String[] projection = new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER}; String SELECTION = ContactsContract.CommonDataKinds.Phone.NUMBER + " LIKE '%9986395899' OR " + ContactsContract.CommonDataKinds.Phone.NUMBER + " LIKE '%997%'"; Cursor people = getActivity().getContentResolver().query(uri, ContactsQuery.PROJECTION, SELECTION, null, null); mAdapter.swapCursor(people);*/ getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this); return true; } }); if (Utils.hasICS()) { // This listener added in ICS searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem menuItem) { // Nothing to do when the action item is expanded return true; } @Override public boolean onMenuItemActionCollapse(MenuItem menuItem) { // When the user collapses the SearchView the current search string is // cleared and the loader restarted. if (!TextUtils.isEmpty(mSearchTerm)) { onSelectionCleared(); } mSearchTerm = null; getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this); return true; } }); } if (mSearchTerm != null) { // If search term is already set here then this fragment is // being restored from a saved state and the search menu item // needs to be expanded and populated again. // Stores the search term (as it will be wiped out by // onQueryTextChange() when the menu item is expanded). final String savedSearchTerm = mSearchTerm; // Expands the search menu item if (Utils.hasICS()) { searchItem.expandActionView(); } // Sets the SearchView to the previous search string searchView.setQuery(savedSearchTerm, false); } } }
From source file:com.google.samples.apps.sergio.ui.BaseActivity.java
protected void configureStandardMenuItems(Menu menu) { MenuItem wifiItem = menu.findItem(R.id.menu_wifi); if (wifiItem != null && !WiFiUtils.shouldOfferToSetupWifi(this, false)) { wifiItem.setVisible(false); }/*from w w w . j a va 2 s .c o m*/ MenuItem debugItem = menu.findItem(R.id.menu_debug); if (debugItem != null) { debugItem.setVisible(BuildConfig.DEBUG); } MenuItem ioExtendedItem = menu.findItem(R.id.menu_io_extended); if (ioExtendedItem != null) { ioExtendedItem.setVisible(PrefUtils.shouldOfferIOExtended(this, false)); } // if attendee is remote, show map on the overflow instead of on the nav bar final boolean isRemote = !PrefUtils.isAttendeeAtVenue(this); final MenuItem mapItem = menu.findItem(R.id.menu_map); if (mapItem != null) { mapItem.setVisible(isRemote); } MenuItem ioHuntItem = menu.findItem(R.id.menu_i_o_hunt); if (ioHuntItem != null) { ioHuntItem.setVisible(!isRemote && !TextUtils.isEmpty(Config.IO_HUNT_PACKAGE_NAME)); } }
From source file:com.saarang.samples.apps.iosched.ui.BaseActivity.java
protected void configureStandardMenuItems(Menu menu) { // if attendee is remote, show map on the overflow instead of on the nav bar final boolean isRemote = !PrefUtils.isAttendeeAtVenue(this); final MenuItem mapItem = menu.findItem(com.saarang.samples.apps.iosched.R.id.menu_map); if (mapItem != null) { mapItem.setVisible(isRemote); }//from w w w . ja v a 2 s . c o m }
From source file:com.android.contacts.activities.DialtactsActivity.java
private void prepareOptionsMenuInSearchMode(Menu menu) { // get references to menu items final MenuItem searchMenuItem = menu.findItem(R.id.search_on_action_bar); final MenuItem filterOptionMenuItem = menu.findItem(R.id.filter_option); final MenuItem addContactOptionMenuItem = menu.findItem(R.id.add_contact); final MenuItem callSettingsMenuItem = menu.findItem(R.id.menu_call_settings); final MenuItem emptyRightMenuItem = menu.findItem(R.id.empty_right_menu_item); // prepare the menu items searchMenuItem.setVisible(false); filterOptionMenuItem.setVisible(ViewConfiguration.get(this).hasPermanentMenuKey()); addContactOptionMenuItem.setVisible(false); callSettingsMenuItem.setVisible(false); emptyRightMenuItem.setVisible(false); }
From source file:com.android.contacts.activities.DialtactsActivity.java
private void prepareOptionsMenuForCallLogTab(Menu menu) { // get references to menu items final MenuItem searchMenuItem = menu.findItem(R.id.search_on_action_bar); final MenuItem filterOptionMenuItem = menu.findItem(R.id.filter_option); final MenuItem addContactOptionMenuItem = menu.findItem(R.id.add_contact); final MenuItem callSettingsMenuItem = menu.findItem(R.id.menu_call_settings); final MenuItem emptyRightMenuItem = menu.findItem(R.id.empty_right_menu_item); // prepare the menu items searchMenuItem.setVisible(true); filterOptionMenuItem.setVisible(false); addContactOptionMenuItem.setVisible(false); callSettingsMenuItem.setVisible(true); emptyRightMenuItem.setVisible(ViewConfiguration.get(this).hasPermanentMenuKey()); }
From source file:com.android.contacts.activities.DialtactsActivity.java
private void prepareOptionsMenuForFavoritesTab(Menu menu) { // get references to menu items final MenuItem searchMenuItem = menu.findItem(R.id.search_on_action_bar); final MenuItem filterOptionMenuItem = menu.findItem(R.id.filter_option); final MenuItem addContactOptionMenuItem = menu.findItem(R.id.add_contact); final MenuItem callSettingsMenuItem = menu.findItem(R.id.menu_call_settings); final MenuItem emptyRightMenuItem = menu.findItem(R.id.empty_right_menu_item); // prepare the menu items searchMenuItem.setVisible(true); filterOptionMenuItem.setVisible(true); addContactOptionMenuItem.setVisible(true); callSettingsMenuItem.setVisible(true); emptyRightMenuItem.setVisible(false); }
From source file:com.vuze.android.remote.fragment.FilesFragment.java
protected boolean prepareContextMenu(Menu menu) { if (sessionInfo == null || torrentID < 0) { return false; }/*from w ww . j a va 2 s .co m*/ boolean isComplete = false; Map<?, ?> mapFile = getFocusedFile(); boolean enable = mapFile != null && mapFile.size() > 0; if (mapFile != null) { long bytesCompleted = MapUtils.getMapLong(mapFile, "bytesCompleted", 0); long length = MapUtils.getMapLong(mapFile, "length", -1); //System.out.println("mapFIle=" + mapFile); isComplete = bytesCompleted == length; } boolean isLocalHost = sessionInfo != null && sessionInfo.getRemoteProfile().isLocalHost(); boolean isOnlineOrLocal = VuzeRemoteApp.getNetworkState().isOnline() || isLocalHost; MenuItem menuLaunch = menu.findItem(R.id.action_sel_launch); if (menuLaunch != null) { if (enable && sessionInfo.getRemoteProfile().isLocalHost()) { boolean canLaunch = isComplete; canLaunch &= isOnlineOrLocal; menuLaunch.setEnabled(canLaunch); menuLaunch.setVisible(true); } else { menuLaunch.setVisible(false); } } MenuItem menuLaunchStream = menu.findItem(R.id.action_sel_launch_stream); if (menuLaunchStream != null) { boolean canStream = enable && isComplete && mapFile.containsKey(TransmissionVars.FIELD_FILES_CONTENT_URL); canStream &= isOnlineOrLocal; menuLaunchStream.setEnabled(canStream); } MenuItem menuSave = menu.findItem(R.id.action_sel_save); if (menuSave != null) { boolean visible = !isLocalHost; menuSave.setVisible(visible); if (visible) { boolean canSave = enable && isOnlineOrLocal && isComplete && mapFile.containsKey(TransmissionVars.FIELD_FILES_CONTENT_URL); menuSave.setEnabled(canSave); } } int priority = MapUtils.getMapInt(mapFile, TransmissionVars.FIELD_TORRENT_FILES_PRIORITY, TransmissionVars.TR_PRI_NORMAL); MenuItem menuPriorityUp = menu.findItem(R.id.action_sel_priority_up); if (menuPriorityUp != null) { menuPriorityUp.setEnabled( enable && isOnlineOrLocal && !isComplete && priority < TransmissionVars.TR_PRI_HIGH); } MenuItem menuPriorityDown = menu.findItem(R.id.action_sel_priority_down); if (menuPriorityDown != null) { menuPriorityDown .setEnabled(enable && isOnlineOrLocal && !isComplete && priority > TransmissionVars.TR_PRI_LOW); } boolean wanted = MapUtils.getMapBoolean(mapFile, "wanted", true); MenuItem menuUnwant = menu.findItem(R.id.action_sel_unwanted); if (menuUnwant != null) { menuUnwant.setVisible(wanted); menuUnwant.setEnabled(enable && isOnlineOrLocal); } MenuItem menuWant = menu.findItem(R.id.action_sel_wanted); if (menuWant != null) { menuWant.setVisible(!wanted); menuWant.setEnabled(enable && isOnlineOrLocal); } AndroidUtils.fixupMenuAlpha(menu); return true; }
From source file:com.android.gallery3d.v5.filtershow.FilterShowActivity.java
private void setupMenu() { if (mMenu == null || mMasterImage == null) { return;//ww w . j a v a2 s.c o m } MenuItem undoItem = mMenu.findItem(R.id.undoButton); MenuItem redoItem = mMenu.findItem(R.id.redoButton); MenuItem resetItem = mMenu.findItem(R.id.resetHistoryButton); MenuItem printItem = mMenu.findItem(R.id.printButton); if (false) { printItem.setVisible(false); } mMasterImage.getHistory().setMenuItems(undoItem, redoItem, resetItem); }
From source file:nz.ac.auckland.lablet.ExperimentRunViewManager.java
@Override public boolean onCreateOptionsMenu(Menu menu) { menu.clear();//from w ww. j a va2 s. co m getMenuInflater().inflate(R.menu.perform_experiment_activity_actions, menu); // back item MenuItem backItem = menu.findItem(R.id.action_done); assert backItem != null; backItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { onBackPressed(); return false; } }); // analyse item MenuItem analyseItem = menu.findItem(R.id.action_analyse); assert analyseItem != null; analyseMenuItem.setMenuItem(analyseItem); if (!experiment.getCurrentExperimentRun().dataTaken()) analyseMenuItem.setEnabled(false); analyseItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { finishExperiment(true); return true; } }); // settings item MenuItem settingsMenu = menu.findItem(R.id.action_settings); assert settingsMenu != null; settingsMenuItem.setMenuItem(settingsMenu); // sensor view item MenuItem viewMenu = menu.findItem(R.id.action_view); assert viewMenu != null; viewMenu.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { showViewMenu(); return true; } }); // activate sensorDataList item MenuItem sensorMenu = menu.findItem(R.id.action_sensors); assert sensorMenu != null; sensorMenuItem.setMenuItem(sensorMenu); sensorMenu.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { showSensorMenu(); return true; } }); // config the menu Bundle options = ExperimentHelper.unpackStartExperimentOptions(getIntent()); if (options != null) { boolean showAnalyseMenu = options.getBoolean("show_analyse_menu", true); analyseMenuItem.setVisible(showAnalyseMenu); boolean sensorsEditable = options.getBoolean("sensors_editable", true); sensorMenu.setVisible(sensorsEditable); if (!sensorsEditable) { if (experiment.getCurrentExperimentRun().getExperimentSensors().size() == 1) viewMenu.setVisible(false); } } return true; }
From source file:com.jefftharris.passwdsafe.PasswdSafe.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { final BitSet options = new BitSet(); options.set(MENU_BIT_HAS_CLOSE);//w w w. j av a 2 s. c om itsFileDataFrag.useFileData(new PasswdFileDataUser() { @Override public void useFileData(@NonNull PasswdFileData fileData) { boolean fileEditable = fileData.canEdit(); switch (itsCurrViewMode) { case VIEW_LIST: { options.set(MENU_BIT_CAN_ADD, fileEditable); options.set(MENU_BIT_HAS_SEARCH, true); if (fileEditable) { options.set(MENU_BIT_HAS_FILE_OPS, true); options.set(MENU_BIT_HAS_FILE_CHANGE_PASSWORD, fileData.isNotYubikey()); options.set(MENU_BIT_HAS_FILE_PROTECT, true); options.set(MENU_BIT_PROTECT_ALL, itsLocation.getGroups().isEmpty()); } if (fileData.canDelete()) { options.set(MENU_BIT_HAS_FILE_OPS, true); options.set(MENU_BIT_HAS_FILE_DELETE, true); } break; } case VIEW_RECORD: { options.set(MENU_BIT_CAN_ADD, fileEditable); break; } case INIT: case FILE_OPEN: case FILE_NEW: case VIEW_ABOUT: case VIEW_EXPIRATION: case VIEW_POLICY_LIST: case VIEW_PREFERENCES: { break; } case EDIT_RECORD: case CHANGING_PASSWORD: { options.set(MENU_BIT_HAS_CLOSE, false); break; } } } }); MenuItem item = menu.findItem(R.id.menu_add); if (item != null) { item.setVisible(options.get(MENU_BIT_CAN_ADD)); } item = menu.findItem(R.id.menu_close); if (item != null) { item.setVisible(options.get(MENU_BIT_HAS_CLOSE)); } item = menu.findItem(R.id.menu_file_ops); if (item != null) { item.setVisible(options.get(MENU_BIT_HAS_FILE_OPS)); } item = menu.findItem(R.id.menu_file_change_password); if (item != null) { item.setEnabled(options.get(MENU_BIT_HAS_FILE_CHANGE_PASSWORD)); } if (options.get(MENU_BIT_HAS_FILE_OPS)) { boolean hasProtect = options.get(MENU_BIT_HAS_FILE_PROTECT); boolean viewProtectAll = options.get(MENU_BIT_PROTECT_ALL); item = menu.findItem(R.id.menu_file_protect_records); if (item != null) { item.setEnabled(hasProtect); item.setTitle(viewProtectAll ? R.string.protect_all : R.string.protect_group); } item = menu.findItem(R.id.menu_file_unprotect_records); if (item != null) { item.setEnabled(hasProtect); item.setTitle(viewProtectAll ? R.string.unprotect_all : R.string.unprotect_group); } item = menu.findItem(R.id.menu_file_delete); if (item != null) { item.setEnabled(options.get(MENU_BIT_HAS_FILE_DELETE)); } } item = menu.findItem(R.id.menu_search); if (item != null) { item.setVisible(options.get(MENU_BIT_HAS_SEARCH)); } return super.onPrepareOptionsMenu(menu); }