List of usage examples for android.view MenuItem setEnabled
public MenuItem setEnabled(boolean enabled);
From source file:com.iiordanov.bVNC.RemoteCanvasActivity.java
/** * Change the input mode sub-menu to reflect change in scaling *//* w w w . j a v a 2 s. c o m*/ void updateInputMenu() { try { for (MenuItem item : inputModeMenuItems) { item.setEnabled(canvas.scaling.isValidInputMode(item.getItemId())); if (getInputHandlerById(item.getItemId()) == inputHandler) item.setChecked(true); } } catch (NullPointerException e) { } }
From source file:org.mariotaku.twidere.fragment.support.UserProfileFragment.java
private void setMenu(final Menu menu) { final AsyncTwitterWrapper twitter = getTwitterWrapper(); final ParcelableUser user = mUser; final Relationship relationship = mFriendship; if (twitter == null || user == null) return;/*from www .jav a 2s .c o m*/ final boolean isMyself = user.account_id == user.id; final boolean isFollowing = relationship != null && relationship.isSourceFollowingTarget(); final boolean isProtected = user.is_protected; final boolean creatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id); final boolean destroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id); setMenuItemAvailability(menu, MENU_EDIT, isMyself); final MenuItem followItem = menu.findItem(MENU_FOLLOW); followItem.setVisible(!isMyself); final boolean shouldShowFollowItem = !creatingFriendship && !destroyingFriendship && !isMyself && relationship != null; followItem.setEnabled(shouldShowFollowItem); if (shouldShowFollowItem) { followItem.setTitle( isFollowing ? R.string.unfollow : isProtected ? R.string.send_follow_request : R.string.follow); followItem.setIcon(isFollowing ? R.drawable.ic_iconic_action_cancel : R.drawable.ic_iconic_action_add); } else { followItem.setTitle(null); followItem.setIcon(null); } if (user.id != user.account_id) { setMenuItemAvailability(menu, MENU_BLOCK, mFriendship != null); final MenuItem blockItem = menu.findItem(MENU_BLOCK); if (mFriendship != null && blockItem != null) { final Drawable blockIcon = blockItem.getIcon(); if (mFriendship.isSourceBlockingTarget()) { blockItem.setTitle(R.string.unblock); blockIcon.mutate().setColorFilter(ThemeUtils.getUserThemeColor(getActivity()), PorterDuff.Mode.MULTIPLY); } else { blockItem.setTitle(R.string.block); blockIcon.clearColorFilter(); } } final boolean is_following_me = mFriendship != null && mFriendship.isTargetFollowingSource(); setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, is_following_me); } else { setMenuItemAvailability(menu, MENU_MENTION, false); setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, false); setMenuItemAvailability(menu, MENU_BLOCK, false); setMenuItemAvailability(menu, MENU_REPORT_SPAM, false); } final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER); final Bundle extras = new Bundle(); extras.putParcelable(EXTRA_USER, user); intent.putExtras(extras); menu.removeGroup(MENU_GROUP_USER_EXTENSION); addIntentToMenu(getActivity(), menu, intent, MENU_GROUP_USER_EXTENSION); }
From source file:org.andstatus.app.TimelineActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { mOptionsMenu = menu;//from w w w .ja va2 s . c o m MyAccount ma = MyContextHolder.get().persistentAccounts().getCurrentAccount(); boolean enableReload = isTimelineCombined() || ma.isValidAndVerified(); MenuItem item = menu.findItem(R.id.reload_menu_item); item.setEnabled(enableReload); item.setVisible(enableReload); prepareDrawer(); if (mContextMenu != null) { mContextMenu.setAccountUserIdToActAs(0); } if (mMessageEditor != null) { mMessageEditor.onPrepareOptionsMenu(menu); } boolean enableGlobalSearch = MyContextHolder.get().persistentAccounts().isGlobalSearchSupported(ma, isTimelineCombined()); item = menu.findItem(R.id.global_search_menu_id); item.setEnabled(enableGlobalSearch); item.setVisible(enableGlobalSearch); return super.onPrepareOptionsMenu(menu); }
From source file:de.vanita5.twittnuker.fragment.support.UserProfileFragment.java
private void setMenu(final Menu menu) { final AsyncTwitterWrapper twitter = getTwitterWrapper(); final ParcelableUser user = mUser; final Relationship relationship = mRelationship; if (twitter == null || user == null) return;/*w ww .jav a2s . c o m*/ final int activatedColor = ThemeUtils.getUserThemeColor(getActivity()); final boolean isMyself = user.account_id == user.id; final boolean isFollowing = relationship != null && relationship.isSourceFollowingTarget(); final boolean isProtected = user.is_protected; final boolean creatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id); final boolean destroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id); setMenuItemAvailability(menu, MENU_EDIT, isMyself); final MenuItem followItem = menu.findItem(MENU_FOLLOW); followItem.setVisible(!isMyself); final boolean shouldShowFollowItem = !creatingFriendship && !destroyingFriendship && !isMyself && relationship != null; followItem.setEnabled(shouldShowFollowItem); if (shouldShowFollowItem) { followItem.setTitle( isFollowing ? R.string.unfollow : isProtected ? R.string.send_follow_request : R.string.follow); followItem.setIcon(isFollowing ? R.drawable.ic_iconic_action_cancel : R.drawable.ic_iconic_action_add); } else { followItem.setTitle(null); followItem.setIcon(null); } if (user.id != user.account_id && relationship != null) { setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, relationship.canSourceDMTarget()); setMenuItemAvailability(menu, MENU_BLOCK, true); final MenuItem blockItem = menu.findItem(MENU_BLOCK); if (blockItem != null) { final Drawable blockIcon = blockItem.getIcon(); if (relationship.isSourceBlockingTarget()) { blockItem.setTitle(R.string.unblock); blockIcon.mutate(); blockIcon.setColorFilter(activatedColor, PorterDuff.Mode.SRC_ATOP); } else { blockItem.setTitle(R.string.block); blockIcon.clearColorFilter(); } } } else { setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, false); setMenuItemAvailability(menu, MENU_BLOCK, false); setMenuItemAvailability(menu, MENU_REPORT_SPAM, false); } }
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.DisplayStopDataFragment.java
/** * {@inheritDoc}/* w w w . j ava 2 s . c o m*/ */ @Override public void onPrepareOptionsMenu(final Menu menu) { super.onPrepareOptionsMenu(menu); // Get the menu items. final MenuItem sortItem = menu.findItem(R.id.displaystopdata_option_menu_sort); final MenuItem autoRefreshItem = menu.findItem(R.id.displaystopdata_option_menu_autorefresh); final MenuItem proxItem = menu.findItem(R.id.displaystopdata_option_menu_prox); final MenuItem timeItem = menu.findItem(R.id.displaystopdata_option_menu_time); final MenuItem refreshItem = menu.findItem(R.id.displaystopdata_option_menu_refresh); // If progress is being shown, disable the refresh button. if (progressBig.getVisibility() == View.VISIBLE || progressSmall.getVisibility() == View.VISIBLE) { refreshItem.setEnabled(false); } else { refreshItem.setEnabled(true); } // If there's no bus times, disable all other menu items. if (listView.getVisibility() == View.VISIBLE) { sortItem.setEnabled(true); proxItem.setEnabled(true); timeItem.setEnabled(true); } else { sortItem.setEnabled(false); proxItem.setEnabled(false); timeItem.setEnabled(false); } // Sort by time or service? if (sp.getBoolean(PreferencesActivity.PREF_SERVICE_SORTING, false)) { sortItem.setTitle(R.string.displaystopdata_menu_sort_service); } else { sortItem.setTitle(R.string.displaystopdata_menu_sort_times); } // Auto-refresh on or off? if (autoRefresh) { autoRefreshItem.setTitle(R.string.displaystopdata_menu_turnautorefreshoff); } else { autoRefreshItem.setTitle(R.string.displaystopdata_menu_turnautorefreshon); } // Proximity alert active or not? if (sd.isActiveProximityAlert(stopCode)) { proxItem.setTitle(R.string.displaystopdata_menu_prox_rem).setIcon(R.drawable.ic_menu_proximityremove); } else { proxItem.setTitle(R.string.displaystopdata_menu_prox_add).setIcon(R.drawable.ic_menu_proximityadd); } // Time alert active or not? if (sd.isActiveTimeAlert(stopCode)) { timeItem.setTitle(R.string.displaystopdata_menu_time_rem).setIcon(R.drawable.ic_menu_arrivalremove); } else { timeItem.setTitle(R.string.displaystopdata_menu_time_add).setIcon(R.drawable.ic_menu_arrivaladd); } }
From source file:com.ibuildapp.romanblack.WebPlugin.WebPlugin.java
/** * This menu contains back, forward and refresh buttons. * * @param menu/* ww w . j a v a2 s . c o m*/ * @return true if there are no an exception while preparing, false otherwise */ @Override public boolean onPrepareOptionsMenu(Menu menu) { try { menu.clear(); MenuItem itemBack = menu.add(""); itemBack.setIcon(R.drawable.romanblack_html_menu_back); itemBack.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem mi) { webView.goBack(); return true; } }); if (!webView.canGoBack()) { itemBack.setEnabled(false); } MenuItem itemRefresh = menu.add(""); itemRefresh.setIcon(R.drawable.romanblack_html_menu_refresh); itemRefresh.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem mi) { webView.reload(); return true; } }); if ("".equals(currentUrl) || "about:blank".equals(currentUrl)) { itemRefresh.setEnabled(false); } MenuItem itemForward = menu.add(""); itemForward.setIcon(R.drawable.romanblack_html_menu_forward); itemForward.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem mi) { webView.goForward(); return true; } }); if (!webView.canGoForward()) { itemForward.setEnabled(false); } return true; } catch (Exception ex) { return false; } }
From source file:com.crearo.gpslogger.GpsMainActivity.java
private void enableDisableMenuItems() { onWaitingForLocation(Session.isWaitingForLocation()); setBulbStatus(Session.isStarted());/*from w w w.ja va 2 s .c om*/ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarBottom); MenuItem mnuAnnotate = toolbar.getMenu().findItem(R.id.mnuAnnotate); MenuItem mnuOnePoint = toolbar.getMenu().findItem(R.id.mnuOnePoint); MenuItem mnuAutoSendNow = toolbar.getMenu().findItem(R.id.mnuAutoSendNow); if (mnuOnePoint != null) { mnuOnePoint.setEnabled(!Session.isStarted()); mnuOnePoint.setIcon((Session.isStarted() ? R.drawable.singlepoint_disabled : R.drawable.singlepoint)); } if (mnuAutoSendNow != null) { mnuAutoSendNow.setEnabled(Session.isStarted()); } if (mnuAnnotate != null) { if (!preferenceHelper.shouldLogToGpx() && !preferenceHelper.shouldLogToKml() && !preferenceHelper.shouldLogToCustomUrl()) { mnuAnnotate.setIcon(R.drawable.annotate2_disabled); mnuAnnotate.setEnabled(false); } else { if (Session.isAnnotationMarked()) { mnuAnnotate.setIcon(R.drawable.annotate2_active); } else { mnuAnnotate.setIcon(R.drawable.annotate2); } } } }
From source file:com.android.contacts.activities.ContactDetailActivity.java
public void setAssociationMenu(Menu menu, boolean fromOptionsMenu) { if (fromOptionsMenu) { MenuItem associationMenuItem = menu.findItem(R.id.menu_association_sim); if (associationMenuItem != null) { /*// w w w. j av a 2s . c om * Bug Fix by Mediatek Begin. * Original Android's code: * if (isHasPhoneItem()) { * CR ID: ALPS00116397 */ if (SlotUtils.isGeminiEnabled() && isHasPhoneItem() && !isMe()) { /* * Bug Fix by Mediatek End. */ int simInfoSize = SIMInfoWrapper.getDefault().getInsertedSimCount(); associationMenuItem.setVisible(!this.mContactData.isDirectoryEntry()); associationMenuItem.setEnabled(simInfoSize > 0); } else { associationMenuItem.setVisible(false); } } } }
From source file:com.android.contacts.activities.PeopleActivity.java
private void makeMenuItemEnabled(Menu menu, int itemId, boolean visible) { final MenuItem item = menu.findItem(itemId); if (item != null) { item.setEnabled(visible); }// ww w.j a va2s. c o m }
From source file:org.woltage.irssiconnectbot.ConsoleActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); View view = findCurrentView(R.id.console_flip); final TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip); final boolean activeTerminal = (view instanceof TerminalView); boolean sessionOpen = false; boolean disconnected = false; boolean canForwardPorts = false; if (activeTerminal) { TerminalBridge bridge = ((TerminalView) view).bridge; sessionOpen = bridge.isSessionOpen(); disconnected = bridge.isDisconnected(); canForwardPorts = bridge.canFowardPorts(); }//from w w w. j a v a 2s .c om menu.setQwertyMode(true); disconnect = menu.add(R.string.list_host_disconnect); if (hardKeyboard) disconnect.setAlphabeticShortcut('w'); if (!sessionOpen && disconnected) disconnect.setTitle(R.string.console_menu_close); disconnect.setEnabled(activeTerminal); disconnect.setIcon(android.R.drawable.ic_menu_close_clear_cancel); disconnect.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { // disconnect or close the currently visible session TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip); TerminalBridge bridge = terminalView.bridge; bridge.dispatchDisconnect(true); if (bound != null && prefs.getBoolean("unloadKeysOnDisconnect", true)) { bound.lockUnusedKeys(); } return true; } }); copy = menu.add(R.string.console_menu_copy); if (hardKeyboard) copy.setAlphabeticShortcut('c'); copy.setIcon(android.R.drawable.ic_menu_set_as); copy.setEnabled(activeTerminal); copy.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { // mark as copying and reset any previous bounds TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip); copySource = terminalView.bridge; SelectionArea area = copySource.getSelectionArea(); area.reset(); area.setBounds(copySource.buffer.getColumns(), copySource.buffer.getRows()); area.setRow(copySource.buffer.getCursorRow()); area.setColumn(copySource.buffer.getCursorColumn()); copySource.setSelectingForCopy(true); // Make sure we show the initial selection copySource.redraw(); Toast.makeText(ConsoleActivity.this, getString(R.string.console_copy_start), Toast.LENGTH_LONG) .show(); return true; } }); paste = menu.add(R.string.console_menu_paste); if (hardKeyboard) paste.setAlphabeticShortcut('v'); paste.setIcon(android.R.drawable.ic_menu_edit); paste.setEnabled(clipboard.hasText() && sessionOpen); paste.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { // force insert of clipboard text into current console TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip); TerminalBridge bridge = terminalView.bridge; // pull string from clipboard and generate all events to force // down String clip = clipboard.getText().toString(); bridge.injectString(clip); return true; } }); portForward = menu.add(R.string.console_menu_portforwards); if (hardKeyboard) portForward.setAlphabeticShortcut('f'); portForward.setIcon(android.R.drawable.ic_menu_manage); portForward.setEnabled(sessionOpen && canForwardPorts); portForward.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip); TerminalBridge bridge = terminalView.bridge; Intent intent = new Intent(ConsoleActivity.this, PortForwardListActivity.class); intent.putExtra(Intent.EXTRA_TITLE, bridge.host.getId()); ConsoleActivity.this.startActivityForResult(intent, REQUEST_EDIT); return true; } }); urlscan = menu.add(R.string.console_menu_urlscan); if (hardKeyboard) urlscan.setAlphabeticShortcut('u'); urlscan.setIcon(android.R.drawable.ic_menu_search); urlscan.setEnabled(activeTerminal); urlscan.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { final TerminalView terminal = (TerminalView) findCurrentView(R.id.console_flip); TerminalKeyListener handler = terminal.bridge.getKeyHandler(); handler.urlScan(terminal); return true; } }); resize = menu.add(R.string.console_menu_resize); if (hardKeyboard) resize.setAlphabeticShortcut('s'); resize.setIcon(android.R.drawable.ic_menu_crop); resize.setEnabled(sessionOpen); resize.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { final TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip); final View resizeView = inflater.inflate(R.layout.dia_resize, null, false); ((EditText) resizeView.findViewById(R.id.width)) .setText(prefs.getString("default_fsize_width", "80")); ((EditText) resizeView.findViewById(R.id.height)) .setText(prefs.getString("default_fsize_height", "25")); new AlertDialog.Builder(ConsoleActivity.this).setView(resizeView) .setPositiveButton(R.string.button_resize, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { int width, height; try { width = Integer.parseInt( ((EditText) resizeView.findViewById(R.id.width)).getText().toString()); height = Integer.parseInt( ((EditText) resizeView.findViewById(R.id.height)).getText().toString()); } catch (NumberFormatException nfe) { // TODO change this to a real dialog where we can // make the input boxes turn red to indicate an error. return; } if (width > 0 && height > 0) { terminalView.forceSize(width, height); terminalView.bridge.parentChanged(terminalView); } else { new AlertDialog.Builder(ConsoleActivity.this) .setMessage("Width and height must be higher than zero.") .setTitle("Error").show(); } } }).setNegativeButton(android.R.string.cancel, null).create().show(); return true; } }); MenuItem ctrlKey = menu.add("Ctrl"); ctrlKey.setEnabled(activeTerminal); ctrlKey.setIcon(R.drawable.button_ctrl); MenuItemCompat.setShowAsAction(ctrlKey, MenuItem.SHOW_AS_ACTION_IF_ROOM); ctrlKey.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return false; TerminalView terminal = (TerminalView) flip; TerminalKeyListener handler = terminal.bridge.getKeyHandler(); handler.metaPress(TerminalKeyListener.META_CTRL_ON); terminal.bridge.tryKeyVibrate(); return true; } }); MenuItem escKey = menu.add("Esc"); escKey.setEnabled(activeTerminal); escKey.setIcon(R.drawable.button_esc); MenuItemCompat.setShowAsAction(escKey, MenuItem.SHOW_AS_ACTION_IF_ROOM); escKey.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return false; TerminalView terminal = (TerminalView) flip; TerminalKeyListener handler = terminal.bridge.getKeyHandler(); handler.sendEscape(); terminal.bridge.tryKeyVibrate(); return true; } }); MenuItem symKey = menu.add("SYM"); symKey.setEnabled(activeTerminal); symKey.setIcon(R.drawable.button_sym); MenuItemCompat.setShowAsAction(symKey, MenuItem.SHOW_AS_ACTION_IF_ROOM); symKey.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return false; TerminalView terminal = (TerminalView) flip; TerminalKeyListener handler = terminal.bridge.getKeyHandler(); handler.showCharPickerDialog(terminal); return true; } }); MenuItem inputButton = menu.add("Input"); inputButton.setEnabled(activeTerminal); inputButton.setIcon(R.drawable.button_input); MenuItemCompat.setShowAsAction(inputButton, MenuItem.SHOW_AS_ACTION_IF_ROOM); inputButton.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return false; final TerminalView terminal = (TerminalView) flip; Thread promptThread = new Thread(new Runnable() { public void run() { String inj = getCurrentPromptHelper().requestStringPrompt(null, ""); terminal.bridge.injectString(inj); } }); promptThread.setName("Prompt"); promptThread.setDaemon(true); promptThread.start(); return true; } }); MenuItem keyboard = menu.add("Show Keyboard"); keyboard.setEnabled(activeTerminal); keyboard.setIcon(R.drawable.button_keyboard); MenuItemCompat.setShowAsAction(keyboard, MenuItem.SHOW_AS_ACTION_IF_ROOM); keyboard.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return false; inputManager.showSoftInput(flip, InputMethodManager.SHOW_FORCED); return true; } }); MenuItem keys = menu.add(R.string.console_menu_pubkeys); keys.setIcon(android.R.drawable.ic_lock_lock); keys.setIntent(new Intent(this, PubkeyListActivity.class)); keys.setEnabled(activeTerminal); keys.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { Intent intent = new Intent(ConsoleActivity.this, PubkeyListActivity.class); intent.putExtra(PubkeyListActivity.PICK_MODE, true); ConsoleActivity.this.startActivityForResult(intent, REQUEST_SELECT); return true; } }); return true; }