List of usage examples for android.view MenuItem setEnabled
public MenuItem setEnabled(boolean enabled);
From source file:com.dwdesign.tweetings.activity.ComposeActivity.java
@Override public boolean onPrepareOptionsMenu(final Menu menu) { if (menu == null || mEditText == null || mTextCount == null) return false; final String text_orig = parseString(mEditText.getText()); final String text = mIsPhotoAttached || mIsImageAttached ? mUploadUseExtension ? getImageUploadStatus(this, FAKE_IMAGE_LINK, text_orig) : text_orig + " " + FAKE_IMAGE_LINK : text_orig;//from www . j av a 2 s .c o m final int count = mValidator.getTweetLength(text); final float hue = count < 140 ? count >= 130 ? 5 * (140 - count) : 50 : 0; final float[] hsv = new float[] { hue, 1.0f, 1.0f }; mTextCount.setTextColor(count >= 130 ? Color.HSVToColor(0x80, hsv) : 0x80808080); mTextCount.setText(parseString(140 - count)); final MenuItem sendItem = menu.findItem(MENU_SEND); if (sendItem != null) { sendItem.setEnabled(text_orig.length() > 0); } return super.onPrepareOptionsMenu(menu); }
From source file:com.iiordanov.bVNC.RemoteCanvasActivity.java
/** * Change the scaling mode sub-menu to reflect available scaling modes. */// w ww . j a va 2 s . c o m void updateScalingMenu() { try { for (MenuItem item : scalingModeMenuItems) { // If the entire framebuffer is NOT contained in the bitmap, fit-to-screen is meaningless. if (item.getItemId() == R.id.itemFitToScreen) { if (canvas != null && canvas.bitmapData != null && (canvas.bitmapData.bitmapheight != canvas.bitmapData.framebufferheight || canvas.bitmapData.bitmapwidth != canvas.bitmapData.framebufferwidth)) item.setEnabled(false); else item.setEnabled(true); } else item.setEnabled(true); } } catch (NullPointerException e) { } }
From source file:org.cobaltians.cobalt.activities.CobaltActivity.java
protected void addMenuItem(Menu menu, int order, JSONObject action, final int id, String position, String barsColor) {/*w w w.j av a2 s. c om*/ try { final String name = action.getString(Cobalt.kActionName); String title = action.getString(Cobalt.kActionTitle); boolean visible = action.optBoolean(Cobalt.kActionVisible, true); boolean enabled = action.optBoolean(Cobalt.kActionEnabled, true); final MenuItem menuItem = menu.add(Menu.NONE, id, order, title); int showAsAction = MenuItemCompat.SHOW_AS_ACTION_IF_ROOM; switch (position) { case Cobalt.kPositionBottom: showAsAction = MenuItemCompat.SHOW_AS_ACTION_ALWAYS; break; case Cobalt.kPositionOverflow: showAsAction = MenuItemCompat.SHOW_AS_ACTION_NEVER; break; } MenuItemCompat.setShowAsAction(menuItem, showAsAction); ActionViewMenuItem actionView = new ActionViewMenuItem(this, action, barsColor); actionView.setActionViewMenuItemListener(new WeakReference<>(this)); MenuItemCompat.setActionView(menuItem, actionView); menuItem.setVisible(visible); menuItem.setEnabled(enabled); mMenuItemsHashMap.put(name, actionView); //need this next hashmap to send onPressed when item is on overflow mMenuItemsIdMap.put(id, name); //need this next hashmap to set menuItem mMenuItemByNameMap.put(name, menuItem); } catch (JSONException exception) { if (Cobalt.DEBUG) { Log.w(Cobalt.TAG, TAG + "addMenuItem: action " + action.toString() + " format not supported, use at least {\n" + "\tname: \"name\",\n" + "\ttitle: \"title\",\n" + "}"); } exception.printStackTrace(); } }
From source file:biz.bokhorst.xprivacy.ActivityApp.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); // Check if running boolean running = false; ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); for (RunningAppProcessInfo info : activityManager.getRunningAppProcesses()) if (info.uid == mAppInfo.getUid()) running = true;/*from w ww . j a v a 2 s . c om*/ PackageManager pm = getPackageManager(); List<String> listPackageNames = mAppInfo.getPackageName(); List<String> listApplicationName = mAppInfo.getApplicationName(); for (int i = 0; i < listPackageNames.size(); i++) { Menu appMenu = (listPackageNames.size() == 1) ? menu : menu.addSubMenu(i, Menu.NONE, Menu.NONE, listApplicationName.get(i)); // Launch MenuItem launch = appMenu.add(i, MENU_LAUNCH, Menu.NONE, getString(R.string.menu_app_launch)); if (pm.getLaunchIntentForPackage(listPackageNames.get(i)) == null) launch.setEnabled(false); // Settings appMenu.add(i, MENU_SETTINGS, Menu.NONE, getString(R.string.menu_app_settings)); // Kill MenuItem kill = appMenu.add(i, MENU_KILL, Menu.NONE, getString(R.string.menu_app_kill)); kill.setEnabled(running && PrivacyManager.isApplication(mAppInfo.getUid())); // Play store MenuItem store = appMenu.add(i, MENU_STORE, Menu.NONE, getString(R.string.menu_app_store)); if (!Util.hasMarketLink(this, listPackageNames.get(i))) store.setEnabled(false); } }
From source file:net.czlee.debatekeeper.DebatingActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem resetDebateItem = menu.findItem(R.id.mainScreen_menuItem_resetDebate); resetDebateItem.setEnabled(mDebateManager != null); return super.onPrepareOptionsMenu(menu); }
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);/*from w w w . j a v a 2 s . c o m*/ 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); }
From source file:com.vuze.android.remote.fragment.TorrentListFragment.java
protected void prepareContextMenu(Menu menu) { boolean isLocalHost = sessionInfo != null && sessionInfo.getRemoteProfile().isLocalHost(); boolean isOnlineOrLocal = VuzeRemoteApp.getNetworkState().isOnline() || isLocalHost; MenuItem menuMove = menu.findItem(R.id.action_sel_move); if (menuMove != null) { boolean enabled = isOnlineOrLocal && (torrentListAdapter.getCheckedItemCount() > 0 || torrentListAdapter.getSelectedPosition() >= 0); menuMove.setEnabled(enabled); }/*from w w w. j a v a 2s . c o m*/ Map<?, ?>[] checkedTorrentMaps = getCheckedTorrentMaps(torrentListAdapter); boolean canStart = false; boolean canStop = false; if (isOnlineOrLocal) { for (Map<?, ?> mapTorrent : checkedTorrentMaps) { int status = MapUtils.getMapInt(mapTorrent, TransmissionVars.FIELD_TORRENT_STATUS, TransmissionVars.TR_STATUS_STOPPED); canStart |= status == TransmissionVars.TR_STATUS_STOPPED; canStop |= status != TransmissionVars.TR_STATUS_STOPPED; if (AndroidUtils.DEBUG_MENU) { Log.d(TAG, "prepareContextMenu: " + canStart + "/" + canStop + "/" + status); } } } if (AndroidUtils.DEBUG_MENU) { Log.d(TAG, "prepareContextMenu: " + canStart + "/" + canStop); } MenuItem menuStart = menu.findItem(R.id.action_sel_start); if (menuStart != null) { menuStart.setVisible(canStart); menuStart.setEnabled(canStart); } else { Log.d(TAG, "prepareContextMenu: No Start Menu!"); } MenuItem menuStop = menu.findItem(R.id.action_sel_stop); if (menuStop != null) { menuStop.setVisible(canStop); menuStop.setEnabled(canStop); } AndroidUtilsUI.setManyMenuItemsEnabled(isOnlineOrLocal, menu, new int[] { R.id.action_sel_remove, R.id.action_sel_forcestart, R.id.action_sel_move, R.id.action_sel_relocate }); }
From source file:com.aimfire.gallery.GalleryActivity.java
/** * Override Activity lifecycle method.// w ww. j a v a 2 s. c o m */ @Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem sbs = menu.findItem(R.id.action_sbs); MenuItem tv = menu.findItem(R.id.action_3dtv); MenuItem ag = menu.findItem(R.id.action_anaglyph); MenuItem sw = menu.findItem(R.id.action_swap); MenuItem gs = menu.findItem(R.id.action_grayscale); switch (mDisplayMode) { case SbsFull: sbs.setChecked(true); sw.setEnabled(true); if (mDisplaySwap) { sbs.setIcon(R.drawable.ic_crossed_eye); sbs.setTitle(R.string.action_sbs_cross); } else { sbs.setIcon(R.drawable.ic_parallel_eye_white); sbs.setTitle(R.string.action_sbs_parallel); } break; case SbsHalf: tv.setChecked(true); sw.setEnabled(false); break; case Anaglyph: ag.setChecked(true); sw.setEnabled(true); if (mDisplaySwap) { ag.setIcon(R.drawable.ic_cyan_red); ag.setTitle(R.string.action_anaglyph_cyanred); } else { ag.setIcon(R.drawable.ic_red_cyan); ag.setTitle(R.string.action_anaglyph_redcyan); } break; default: break; } if (mDisplaySwap) { sw.setChecked(true); } else { sw.setChecked(false); } if (mDisplayColor) { gs.setChecked(false); } else { gs.setChecked(true); } return super.onPrepareOptionsMenu(menu); }
From source file:de.badaix.snapcast.MainActivity.java
@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(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { ServerDialogFragment serverDialogFragment = new ServerDialogFragment(); serverDialogFragment.setHost(Settings.getInstance(this).getHost(), Settings.getInstance(this).getStreamPort(), Settings.getInstance(this).getControlPort()); serverDialogFragment.setAutoStart(Settings.getInstance(this).isAutostart()); serverDialogFragment.setListener(new ServerDialogFragment.ServerDialogListener() { @Override/*from www .j a v a2 s . c o m*/ public void onHostChanged(String host, int streamPort, int controlPort) { setHost(host, streamPort, controlPort); startRemoteControl(); } @Override public void onAutoStartChanged(boolean autoStart) { Settings.getInstance(MainActivity.this).setAutostart(autoStart); } }); serverDialogFragment.show(getSupportFragmentManager(), "serverDialogFragment"); // NsdHelper.getInstance(this).startListening("_snapcast._tcp.", SERVICE_NAME, this); return true; } else if (id == R.id.action_play_stop) { if (bound && snapclientService.isRunning()) { stopSnapclient(); } else { item.setEnabled(false); startSnapclient(); } return true; } else if (id == R.id.action_hide_offline) { item.setChecked(!item.isChecked()); Settings.getInstance(this).put("hide_offline", item.isChecked()); sectionsPagerAdapter.setHideOffline(item.isChecked()); return true; } else if (id == R.id.action_refresh) { startRemoteControl(); remoteControl.getServerStatus(); } else if (id == R.id.action_about) { Intent intent = new Intent(this, AboutActivity.class); startActivity(intent); } return super.onOptionsItemSelected(item); }
From source file:com.android.calendar.EventInfoFragment.java
/** * */// www . j a v a 2 s. co m private void updateMenu() { if (mMenu == null) { return; } MenuItem delete = mMenu.findItem(R.id.info_action_delete); MenuItem edit = mMenu.findItem(R.id.info_action_edit); MenuItem changeColor = mMenu.findItem(R.id.info_action_change_color); if (delete != null) { delete.setVisible(mCanModifyCalendar); delete.setEnabled(mCanModifyCalendar); } if (edit != null) { edit.setVisible(mCanModifyEvent); edit.setEnabled(mCanModifyEvent); } if (changeColor != null && mColors != null && mColors.length > 0) { changeColor.setVisible(mCanModifyCalendar); changeColor.setEnabled(mCanModifyCalendar); } }