Java Code Examples for android.view.MenuItem#setEnabled()
The following examples show how to use
android.view.MenuItem#setEnabled() .
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: CreateEDSLocationFragmentBase.java From edslite with GNU General Public License v2.0 | 6 votes |
@Override public void onPrepareOptionsMenu (Menu menu) { super.onPrepareOptionsMenu(menu); MenuItem mi = menu.findItem(R.id.confirm); mi.setVisible(_state.containsKey(ARG_ADD_EXISTING_LOCATION)); mi.setTitle(_state.getBoolean(ARG_ADD_EXISTING_LOCATION) ? R.string.add_container : R.string.create_new_container); boolean enabled = checkParams(); mi.setEnabled(enabled); @SuppressWarnings("deprecation") StateListDrawable sld = (StateListDrawable) getActivity().getResources().getDrawable(R.drawable.ic_menu_done); if(sld!=null) { sld.setState(enabled ? new int[]{android.R.attr.state_enabled} : new int[0]); mi.setIcon(sld.getCurrent()); } }
Example 2
Source File: ViewUserActivity.java From BotLibre with Eclipse Public License 1.0 | 6 votes |
@Override public boolean onPrepareOptionsMenu(Menu menu) { for (int index = 0; index < menu.size(); index++) { menu.getItem(index).setEnabled(true); } if (MainActivity.user == null || MainActivity.user == MainActivity.viewUser) { MenuItem item = menu.findItem(R.id.menuFlag); if (item != null) { item.setEnabled(false); } } if (MainActivity.user != MainActivity.viewUser) { menu.findItem(R.id.menuChangeIcon).setEnabled(false); menu.findItem(R.id.menuEditUser).setEnabled(false); } return true; }
Example 3
Source File: PacketListActivity.java From sniffer154 with GNU General Public License v3.0 | 6 votes |
@Override public boolean onPrepareOptionsMenu(Menu menu) { AppSniffer154 app = (AppSniffer154) getApplication(); MenuItem item = menu.findItem(R.id.itemToggleTestMode); if (app.isTestModeEnblad()) { item.setTitle(R.string.titleTestModeDisable); } else { item.setTitle(R.string.titleTestModeEnable); } item = menu.findItem(R.id.itemExport); if (!app.isSniffingInProgress() && !app.getSessionUri().equals(Uri.EMPTY)) item.setEnabled(true); else item.setEnabled(false); item = menu.findItem(R.id.itemManageSessions); item.setEnabled(!app.isSniffingInProgress()); return true; }
Example 4
Source File: EditRuleActivity.java From FwdPortForwardingApp with GNU General Public License v3.0 | 6 votes |
@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(); switch (id) { case R.id.action_save_rule: Log.i(TAG, "Save Menu Button Clicked"); // Set the item to disabled while saving item.setEnabled(false); saveEditedRule(); item.setEnabled(true); break; case R.id.action_delete_rule: deleteRule(); break; } return super.onOptionsItemSelected(item); }
Example 5
Source File: AppMenuPropertiesDelegate.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Updates the bookmark item's visibility. * * @param bookmarkMenuItem {@link MenuItem} for adding/editing the bookmark. * @param currentTab Current tab being displayed. */ protected void updateBookmarkMenuItem(MenuItem bookmarkMenuItem, Tab currentTab) { bookmarkMenuItem.setEnabled(mBookmarkBridge.isEditBookmarksEnabled()); if (currentTab.getBookmarkId() != Tab.INVALID_BOOKMARK_ID) { bookmarkMenuItem.setIcon(R.drawable.btn_star_filled); bookmarkMenuItem.setChecked(true); bookmarkMenuItem.setTitleCondensed(mActivity.getString(R.string.edit_bookmark)); } else { bookmarkMenuItem.setIcon(R.drawable.btn_star); bookmarkMenuItem.setChecked(false); bookmarkMenuItem.setTitleCondensed(null); } }
Example 6
Source File: SearchActivity.java From BotLibre with Eclipse Public License 1.0 | 5 votes |
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem item = menu.findItem(R.id.menuMyBots); if (MainActivity.user == null) { item.setEnabled(false); } item.setTitle("My " + getType() + "s"); return true; }
Example 7
Source File: ShareExternalLinkFragment.java From kaif-android with Apache License 2.0 | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.action_share) { item.setEnabled(false); createArticle(); return true; } return super.onOptionsItemSelected(item); }
Example 8
Source File: AppMenuPropertiesDelegate.java From delion with Apache License 2.0 | 5 votes |
/** * Updates the bookmark item's visibility. * * @param bookmarkMenuItem {@link MenuItem} for adding/editing the bookmark. * @param currentTab Current tab being displayed. */ protected void updateBookmarkMenuItem(MenuItem bookmarkMenuItem, Tab currentTab) { bookmarkMenuItem.setEnabled(mBookmarkBridge.isEditBookmarksEnabled()); if (currentTab.getBookmarkId() != Tab.INVALID_BOOKMARK_ID) { bookmarkMenuItem.setIcon(R.drawable.btn_star_filled); bookmarkMenuItem.setChecked(true); bookmarkMenuItem.setTitleCondensed(mActivity.getString(R.string.edit_bookmark)); } else { bookmarkMenuItem.setIcon(R.drawable.btn_star); bookmarkMenuItem.setChecked(false); bookmarkMenuItem.setTitleCondensed(null); } }
Example 9
Source File: BrowsePostActivity.java From BotLibre with Eclipse Public License 1.0 | 5 votes |
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem item = menu.findItem(R.id.menuMyPosts); if (MainActivity.user == null) { item.setEnabled(false); } return true; }
Example 10
Source File: ForumSearchActivity.java From BotLibre with Eclipse Public License 1.0 | 5 votes |
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem item = menu.findItem(R.id.menuMyPosts); if (MainActivity.user == null) { item.setEnabled(false); } return super.onPrepareOptionsMenu(menu); }
Example 11
Source File: AbstractFragment.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
@CallSuper public void showNewLayoutInfo(final MenuItem item) { item.setEnabled(false); mRecyclerView.postDelayed(new Runnable() { @Override public void run() { item.setEnabled(true); } }, 1000L); }
Example 12
Source File: LocatrFragment.java From AndroidProgramming3e with Apache License 2.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.fragment_locatr, menu); MenuItem searchItem = menu.findItem(R.id.action_locate); searchItem.setEnabled(mClient.isConnected()); }
Example 13
Source File: ProcessManagerActivity.java From MobileGuard with MIT License | 5 votes |
/** * Will be call before shown * Use it to enable or disable item * * @param menu * @return */ @Override public boolean onPrepareOptionsMenu(Menu menu) { // find items MenuItem killProcess = menu.findItem(R.id.m_kill_process); MenuItem selectAllItem = menu.findItem(R.id.m_select_all); MenuItem cancelAllItem = menu.findItem(R.id.m_cancel_all); // get checked item count int checkedCount = getCheckedItemCount(); if (0 == checkedCount) { // no checked item, disable it killProcess.setEnabled(false); cancelAllItem.setEnabled(false); } else { // enable it killProcess.setEnabled(true); cancelAllItem.setEnabled(true); } // if all item are checked, no need enable select all if (checkedCount == checkeds.size()) { selectAllItem.setEnabled(false); } else { selectAllItem.setEnabled(true); } return true; }
Example 14
Source File: BaseFragment.java From microMathematics with GNU General Public License v3.0 | 4 votes |
public void setInOperation(boolean inOperation, OnClickListener stopHandler) { this.inOperation = inOperation; this.stopHandler = stopHandler; if (mainMenu == null) { return; } // update menu items for (int i = 0; i < mainMenu.size(); i++) { MenuItem m = mainMenu.getItem(i); if (m.getItemId() == R.id.action_exit) { continue; } m.setEnabled(!inOperation); // update undo button if (m.getItemId() == R.id.action_undo && !inOperation) { formulas.getUndoState().updateMenuItemState(m); } // update save button for work-sheet fragment if (fragmentNumber == WORKSHEET_FRAGMENT_ID && m.getItemId() == R.id.action_save) { final String str = preferences.getString(OPENED_URI, OPENED_FILE_EMPTY); final Uri uri = str.equals(OPENED_FILE_EMPTY) ? null : Uri.parse(str); m.setVisible(!FileUtils.isAssetUri(uri)); } // update buttons background ViewUtils.updateMenuIconColor(activity, m); } // update floating buttons if (!inOperation) { primaryButtonsSet.activate(R.id.main_flb_action_play, this); } else if (inOperation) { if (stopHandler != null) { primaryButtonsSet.activate(R.id.main_flb_action_stop, stopHandler); } else { primaryButtonsSet.activate(-1, null); } } // update progress bar final ProgressBar progressBar = activity.findViewById(R.id.main_progress_bar); if (progressBar != null) { progressBar.setVisibility(inOperation ? View.VISIBLE : View.GONE); } }
Example 15
Source File: PreviewImageFragment.java From Cirrus_depricated with GNU General Public License v2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); if (mContainerActivity != null && mContainerActivity.getStorageManager() != null) { // Update the file setFile(mContainerActivity.getStorageManager().getFileById(getFile().getFileId())); FileMenuFilter mf = new FileMenuFilter( getFile(), mContainerActivity.getStorageManager().getAccount(), mContainerActivity, getActivity() ); mf.filter(menu); } // additional restriction for this fragment // TODO allow renaming in PreviewImageFragment MenuItem item = menu.findItem(R.id.action_rename_file); if (item != null) { item.setVisible(false); item.setEnabled(false); } // additional restriction for this fragment // TODO allow refresh file in PreviewImageFragment item = menu.findItem(R.id.action_sync_file); if (item != null) { if (getFile().isDown()) { item.setVisible(false); item.setEnabled(false); } else { item.setVisible(true); item.setEnabled(true); } } // additional restriction for this fragment // TODO allow refresh file in PreviewImageFragment item = menu.findItem(R.id.action_download_file); if (item != null) { item.setVisible(false); item.setEnabled(false); } // additional restriction for this fragment // TODO allow refresh file in PreviewImageFragment item = menu.findItem(R.id.action_send_file); if (item != null && !getFile().isDown()) { item.setVisible(false); item.setEnabled(false); } // additional restriction for this fragment item = menu.findItem(R.id.action_move); if (item != null) { item.setVisible(false); item.setEnabled(false); } // additional restriction for this fragment item = menu.findItem(R.id.action_copy); if (item != null) { item.setVisible(false); item.setEnabled(false); } }
Example 16
Source File: LogcatActivity.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
@Override public boolean onPrepareOptionsMenu(Menu menu) { invalidateDarkOrLightMenuItems(this, menu); boolean showingMainLog = (mTask != null); MenuItem item = menu.findItem(R.id.menu_expand_all); if (mCollapsedMode) { item.setIcon(R.drawable.ic_expand_more_white_24dp); item.setTitle(R.string.expand_all); } else { item.setIcon(R.drawable.ic_expand_less_white_24dp); item.setTitle(R.string.collapse_all); } MenuItem clear = menu.findItem(R.id.menu_clear); MenuItem pause = menu.findItem(R.id.menu_play_pause); clear.setVisible(mCurrentlyOpenLog == null); pause.setVisible(mCurrentlyOpenLog == null); MenuItem saveLogMenuItem = menu.findItem(R.id.menu_save_log); MenuItem saveAsLogMenuItem = menu.findItem(R.id.menu_save_as_log); saveLogMenuItem.setEnabled(showingMainLog); saveLogMenuItem.setVisible(showingMainLog); saveAsLogMenuItem.setEnabled(!showingMainLog); saveAsLogMenuItem.setVisible(!showingMainLog); boolean recordingInProgress = ServiceHelper.checkIfServiceIsRunning(getApplicationContext(), LogcatRecordingService.class); MenuItem recordMenuItem = menu.findItem(R.id.menu_record_log); recordMenuItem.setEnabled(!recordingInProgress); recordMenuItem.setVisible(!recordingInProgress); MenuItem crazyLoggerMenuItem = menu.findItem(R.id.menu_crazy_logger_service); crazyLoggerMenuItem.setEnabled(UtilLogger.DEBUG_MODE); crazyLoggerMenuItem.setVisible(UtilLogger.DEBUG_MODE); MenuItem partialSelectMenuItem = menu.findItem(R.id.menu_partial_select); partialSelectMenuItem.setEnabled(!partialSelectMode); partialSelectMenuItem.setVisible(!partialSelectMode); return super.onPrepareOptionsMenu(menu); }
Example 17
Source File: MainActivity.java From onpc with GNU General Public License v3.0 | 4 votes |
private void updateToolbar(State state) { // Logo if (state == null) { toolbar.setSubtitle(R.string.state_not_connected); } else { final StringBuilder subTitle = new StringBuilder(); subTitle.append(state.getDeviceName(configuration.isFriendlyNames())); if (state.isExtendedZone()) { if (!subTitle.toString().isEmpty()) { subTitle.append("/"); } subTitle.append(state.getActiveZoneInfo().getName()); } if (!state.isOn()) { subTitle.append(" (").append(getResources().getString(R.string.state_standby)).append(")"); } toolbar.setSubtitle(subTitle.toString()); } // Main menu if (mainMenu != null) { for (int i = 0; i < mainMenu.size(); i++) { final MenuItem m = mainMenu.getItem(i); if (m.getItemId() == R.id.menu_power_standby) { m.setEnabled(state != null); Utils.updateMenuIconColor(this, m); if (m.isEnabled() && state != null) { Utils.setDrawableColorAttr(this, m.getIcon(), state.isOn() ? android.R.attr.textColorTertiary : R.attr.colorAccent); } } } } }
Example 18
Source File: CustomTabAppMenuPropertiesDelegate.java From 365browser with Apache License 2.0 | 4 votes |
@Override public void prepareMenu(Menu menu) { Tab currentTab = mActivity.getActivityTab(); if (currentTab != null) { MenuItem forwardMenuItem = menu.findItem(R.id.forward_menu_id); forwardMenuItem.setEnabled(currentTab.canGoForward()); mReloadMenuItem = menu.findItem(R.id.reload_menu_id); mReloadMenuItem.setIcon(R.drawable.btn_reload_stop); loadingStateChanged(currentTab.isLoading()); MenuItem shareItem = menu.findItem(R.id.share_row_menu_id); shareItem.setVisible(mShowShare); shareItem.setEnabled(mShowShare); if (mShowShare) { ShareHelper.configureDirectShareMenuItem( mActivity, menu.findItem(R.id.direct_share_menu_id)); } MenuItem iconRow = menu.findItem(R.id.icon_row_menu_id); MenuItem openInChromeItem = menu.findItem(R.id.open_in_browser_id); MenuItem bookmarkItem = menu.findItem(R.id.bookmark_this_page_id); MenuItem downloadItem = menu.findItem(R.id.offline_page_id); boolean addToHomeScreenVisible = true; // Hide request desktop site on all chrome:// pages except for the NTP. Check request // desktop site if it's activated on this page. MenuItem requestItem = menu.findItem(R.id.request_desktop_site_id); updateRequestDesktopSiteMenuItem(requestItem, currentTab); if (mIsMediaViewer) { // Most of the menu items don't make sense when viewing media. iconRow.setVisible(false); openInChromeItem.setVisible(false); menu.findItem(R.id.find_in_page_id).setVisible(false); menu.findItem(R.id.request_desktop_site_id).setVisible(false); addToHomeScreenVisible = false; } else { openInChromeItem.setTitle( DefaultBrowserInfo.getTitleOpenInDefaultBrowser(mIsOpenedByChrome)); updateBookmarkMenuItem(bookmarkItem, currentTab); } bookmarkItem.setVisible(mShowStar); downloadItem.setVisible(mShowDownload); if (!FirstRunStatus.getFirstRunFlowComplete()) { openInChromeItem.setVisible(false); bookmarkItem.setVisible(false); downloadItem.setVisible(false); addToHomeScreenVisible = false; } downloadItem.setEnabled(DownloadUtils.isAllowedToDownloadPage(currentTab)); String url = currentTab.getUrl(); boolean isChromeScheme = url.startsWith(UrlConstants.CHROME_URL_PREFIX) || url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX); if (isChromeScheme) { addToHomeScreenVisible = false; } // Add custom menu items. Make sure they are only added once. if (!mIsCustomEntryAdded) { mIsCustomEntryAdded = true; for (int i = 0; i < mMenuEntries.size(); i++) { MenuItem item = menu.add(0, 0, 1, mMenuEntries.get(i)); mItemToIndexMap.put(item, i); } } prepareAddToHomescreenMenuItem(menu, currentTab, addToHomeScreenVisible); } }
Example 19
Source File: PostTextActivity.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 4 votes |
@Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (isPosting) { promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_submit_post_detail); return true; } else { if (!titleEditText.getText().toString().equals("") || !contentEditText.getText().toString().equals("")) { promptAlertDialog(R.string.discard, R.string.discard_detail); return true; } } finish(); return true; case R.id.action_send_post_text_activity: if (!subredditSelected) { Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show(); return true; } if (titleEditText.getText() == null || titleEditText.getText().toString().equals("")) { Snackbar.make(coordinatorLayout, R.string.title_required, Snackbar.LENGTH_SHORT).show(); return true; } isPosting = true; item.setEnabled(false); item.getIcon().setAlpha(130); mPostingSnackbar.show(); String subredditName; if (subredditIsUser) { subredditName = "u_" + subredditNameTextView.getText().toString(); } else { subredditName = subredditNameTextView.getText().toString(); } Intent intent = new Intent(this, SubmitPostService.class); intent.putExtra(SubmitPostService.EXTRA_ACCESS_TOKEN, mAccessToken); intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName); intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString()); intent.putExtra(SubmitPostService.EXTRA_CONTENT, contentEditText.getText().toString()); intent.putExtra(SubmitPostService.EXTRA_KIND, APIUtils.KIND_SELF); intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair); intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler); intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW); intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK); startService(intent); return true; } return false; }
Example 20
Source File: MucDetailsContextMenuHelper.java From Conversations with GNU General Public License v3.0 | 4 votes |
public static void configureMucDetailsContextMenu(Activity activity, Menu menu, Conversation conversation, User user) { final MucOptions mucOptions = conversation.getMucOptions(); final boolean advancedMode = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("advanced_muc_mode", false); final boolean isGroupChat = mucOptions.isPrivateAndNonAnonymous(); MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message); if (user != null && user.getRealJid() != null) { MenuItem showContactDetails = menu.findItem(R.id.action_contact_details); MenuItem startConversation = menu.findItem(R.id.start_conversation); MenuItem giveMembership = menu.findItem(R.id.give_membership); MenuItem removeMembership = menu.findItem(R.id.remove_membership); MenuItem giveAdminPrivileges = menu.findItem(R.id.give_admin_privileges); MenuItem giveOwnerPrivileges = menu.findItem(R.id.give_owner_privileges); MenuItem removeOwnerPrivileges = menu.findItem(R.id.revoke_owner_privileges); MenuItem removeAdminPrivileges = menu.findItem(R.id.remove_admin_privileges); MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room); MenuItem managePermissions = menu.findItem(R.id.manage_permissions); removeFromRoom.setTitle(isGroupChat ? R.string.remove_from_room : R.string.remove_from_channel); MenuItem banFromConference = menu.findItem(R.id.ban_from_conference); banFromConference.setTitle(isGroupChat ? R.string.ban_from_conference : R.string.ban_from_channel); MenuItem invite = menu.findItem(R.id.invite); startConversation.setVisible(true); final Contact contact = user.getContact(); final User self = conversation.getMucOptions().getSelf(); if ((contact != null && contact.showInRoster()) || mucOptions.isPrivateAndNonAnonymous()) { showContactDetails.setVisible(contact == null || !contact.isSelf()); } if ((activity instanceof ConferenceDetailsActivity || activity instanceof MucUsersActivity) && user.getRole() == MucOptions.Role.NONE) { invite.setVisible(true); } boolean managePermissionsVisible = false; if ((self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) && self.getAffiliation().outranks(user.getAffiliation())) || self.getAffiliation() == MucOptions.Affiliation.OWNER) { if (advancedMode) { if (!user.getAffiliation().ranks(MucOptions.Affiliation.MEMBER)) { managePermissionsVisible = true; giveMembership.setVisible(true); } else if (user.getAffiliation() == MucOptions.Affiliation.MEMBER) { managePermissionsVisible = true; removeMembership.setVisible(true); } if (!Config.DISABLE_BAN) { managePermissionsVisible = true; banFromConference.setVisible(true); } } else { if (!Config.DISABLE_BAN || conversation.getMucOptions().membersOnly()) { removeFromRoom.setVisible(true); } } } if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) { if (isGroupChat || advancedMode || user.getAffiliation() == MucOptions.Affiliation.OWNER) { if (!user.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) { managePermissionsVisible = true; giveOwnerPrivileges.setVisible(true); } else if (user.getAffiliation() == MucOptions.Affiliation.OWNER){ managePermissionsVisible = true; removeOwnerPrivileges.setVisible(true); } } if (!isGroupChat || advancedMode || user.getAffiliation() == MucOptions.Affiliation.ADMIN) { if (!user.getAffiliation().ranks(MucOptions.Affiliation.ADMIN)) { managePermissionsVisible = true; giveAdminPrivileges.setVisible(true); } else if (user.getAffiliation() == MucOptions.Affiliation.ADMIN) { managePermissionsVisible = true; removeAdminPrivileges.setVisible(true); } } } managePermissions.setVisible(managePermissionsVisible); sendPrivateMessage.setVisible(!isGroupChat && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR)); } else { sendPrivateMessage.setVisible(true); sendPrivateMessage.setEnabled(user != null && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR)); } }