List of usage examples for android.view MenuItem setEnabled
public MenuItem setEnabled(boolean enabled);
From source file:org.dmfs.tasks.ViewTaskFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { /*//from w w w.j a v a2s.com * Don't show any options if we don't have a task to show. */ if (mTaskUri != null) { inflater.inflate(R.menu.view_task_fragment_menu, menu); if (mContentSet != null) { Integer status = TaskFieldAdapters.STATUS.get(mContentSet); if (status != null) { mOldStatus = status; } if (TaskFieldAdapters.IS_CLOSED.get(mContentSet) || status != null && status == Tasks.STATUS_COMPLETED) { // we disable the edit option, because the task is completed and the action button shows the edit option. MenuItem item = menu.findItem(R.id.edit_task); item.setEnabled(false); item.setVisible(false); } // check pinned status if (TaskFieldAdapters.PINNED.get(mContentSet)) { // we disable the edit option, because the task is completed and the action button shows the edit option. MenuItem item = menu.findItem(R.id.pin_task); item.setIcon(R.drawable.ic_pin_off_white_24dp); } else { MenuItem item = menu.findItem(R.id.pin_task); item.setIcon(R.drawable.ic_pin_white_24dp); } } } }
From source file:de.vanita5.twittnuker.fragment.support.UserListDetailsFragment.java
private void setMenu(final Menu menu) { final AsyncTwitterWrapper twitter = getTwitterWrapper(); final ParcelableUserList userList = mUserList; final MenuItem followItem = menu.findItem(MENU_FOLLOW); if (followItem != null) { followItem.setEnabled(userList != null); if (userList == null) { followItem.setIcon(android.R.color.transparent); }/* w w w . j av a 2s .c o m*/ } if (twitter == null || userList == null) return; final boolean isMyList = userList.user_id == userList.account_id; setMenuItemAvailability(menu, MENU_EDIT, isMyList); setMenuItemAvailability(menu, MENU_ADD, isMyList); setMenuItemAvailability(menu, MENU_DELETE, isMyList); final boolean isFollowing = userList.is_following; if (followItem != null) { followItem.setVisible(!isMyList); if (isFollowing) { followItem.setIcon(R.drawable.ic_iconic_action_cancel); followItem.setTitle(R.string.unsubscribe); } else { followItem.setIcon(R.drawable.ic_iconic_action_add); followItem.setTitle(R.string.subscribe); } } }
From source file:com.jefftharris.passwdsafe.PasswdSafeNavDrawerFragment.java
/** * Update drawer for the fragments displayed in the activity * @param fileNameUpdate If non-null, the file name to set in the view *//* w w w .j av a 2 s.c o m*/ public void updateView(Mode mode, String fileNameUpdate, boolean fileOpen) { boolean drawerEnabled = false; boolean openDrawer = false; int upIndicator = 0; NavMenuItem selNavItem = null; switch (mode) { case INIT: { drawerEnabled = true; break; } case RECORDS_LIST: { drawerEnabled = true; // If the user hasn't 'learned' about the drawer, open it openDrawer = shouldOpenDrawer(); selNavItem = NavMenuItem.RECORDS; break; } case RECORDS_SINGLE: { selNavItem = NavMenuItem.RECORDS; break; } case RECORDS_ACTION: { upIndicator = R.drawable.ic_action_close_cancel; selNavItem = NavMenuItem.RECORDS; break; } case POLICIES: { drawerEnabled = true; selNavItem = NavMenuItem.PASSWORD_POLICIES; break; } case EXPIRATIONS: { drawerEnabled = true; selNavItem = NavMenuItem.EXPIRED_PASSWORDS; break; } case PREFERENCES: { drawerEnabled = true; selNavItem = NavMenuItem.PREFERENCES; break; } case ABOUT: { drawerEnabled = true; selNavItem = NavMenuItem.ABOUT; break; } } updateDrawerToggle(drawerEnabled, upIndicator); Menu menu = getNavView().getMenu(); for (int i = 0; i < menu.size(); ++i) { MenuItem item = menu.getItem(i); int itemId = item.getItemId(); if (selNavItem == null) { item.setChecked(false); } else if (selNavItem.itsMenuId == itemId) { item.setChecked(true); } if ((itemId == NavMenuItem.RECORDS.itsMenuId) || (itemId == NavMenuItem.PASSWORD_POLICIES.itsMenuId) || (itemId == NavMenuItem.EXPIRED_PASSWORDS.itsMenuId)) { item.setEnabled(fileOpen); } } itsSelNavItem = selNavItem; if (fileNameUpdate != null) { GuiUtils.setVisible(itsFileName, !TextUtils.isEmpty(fileNameUpdate)); itsFileName.setText(fileNameUpdate); } openDrawer(openDrawer); }
From source file:com.github.kanata3249.ffxieq.android.FoodSelectorActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem item; FoodListView flv;/* ww w . j a va2 s . com*/ item = menu.findItem(R.id.FilterByType); SubMenu submenu = item.getSubMenu(); submenu.removeGroup(R.id.FilterByType); flv = (FoodListView) findViewById(R.id.ListView); if (flv != null) { String types[] = flv.getAvailableFoodTypes(); if (types == null || types.length == 1) { item.setEnabled(false); } else { item.setEnabled(true); submenu.add(R.id.FilterByType, -1, Menu.NONE, getString(R.string.ResetFilterByType)); for (int i = 0; i < types.length; i++) { submenu.add(R.id.FilterByType, i, Menu.NONE, types[i]); } } } return super.onPrepareOptionsMenu(menu); }
From source file:de.vanita5.twittnuker.fragment.support.UserListFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { final AsyncTwitterWrapper twitter = getTwitterWrapper(); final ParcelableUserList userList = mUserList; final MenuItem followItem = menu.findItem(MENU_FOLLOW); if (followItem != null) { followItem.setEnabled(userList != null); if (userList == null) { followItem.setIcon(android.R.color.transparent); }//from ww w .j av a2 s . c o m } if (twitter == null || userList == null) return; final boolean isMyList = userList.user_id == userList.account_id; setMenuItemAvailability(menu, MENU_EDIT, isMyList); setMenuItemAvailability(menu, MENU_ADD, isMyList); setMenuItemAvailability(menu, MENU_DELETE, isMyList); final boolean isFollowing = userList.is_following; if (followItem != null) { followItem.setVisible(!isMyList); if (isFollowing) { followItem.setIcon(R.drawable.ic_action_cancel); followItem.setTitle(R.string.unsubscribe); } else { followItem.setIcon(R.drawable.ic_action_add); followItem.setTitle(R.string.subscribe); } } }
From source file:org.sufficientlysecure.keychain.ui.ViewKeyAdvActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { if (!mHasSecret) { return false; }//from w w w . j ava 2s. c o m // always add the item, switch its visibility depending on fragment getMenuInflater().inflate(R.menu.action_mode_edit, menu); final MenuItem vActionModeItem = menu.findItem(R.id.menu_action_mode_edit); boolean isCurrentActionFragment = mTabsWithActionMode[mViewPager.getCurrentItem()]; // if the state is as it should be, never mind if (isCurrentActionFragment == mActionIconShown) { return isCurrentActionFragment; } // show or hide accordingly mActionIconShown = isCurrentActionFragment; vActionModeItem.setEnabled(isCurrentActionFragment); animateMenuItem(vActionModeItem, isCurrentActionFragment); return true; }
From source file:com.dwdesign.tweetings.activity.FileSaveAsActivity.java
@Override public boolean onPrepareOptionsMenu(final Menu menu) { final MenuItem item = menu.findItem(MENU_SAVE); if (item != null) { final int filename_length = mEditFileName != null ? mEditFileName.getText().toString().trim().length() : 0;/* www . ja v a 2s .c o m*/ final int default_filename_length = mDefaultFileName != null ? mDefaultFileName.trim().length() : 0; item.setEnabled(mCurrentDirectory.canWrite() && (default_filename_length > 0 || filename_length > 0)); } return super.onPrepareOptionsMenu(menu); }
From source file:com.cachirulop.moneybox.activity.MovementDetailActivity.java
/** * Load the menu from the movement_detail.xml file. * //from w w w. j ava 2s . co m * Activates and deactivates the put and drop menu buttons depending of the * movement. * * @param menu * Menu to be inflated with the menu inflater. */ @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.movement_detail, menu); MenuItem item; item = menu.findItem(R.id.action_get_from_moneybox); item.setVisible(MovementsManager.canGetMovement(_movement)); item.setEnabled(item.isVisible()); item = menu.findItem(R.id.action_drop_to_moneybox); item.setVisible(MovementsManager.canDropMovement(_movement)); item.setEnabled(item.isVisible()); item = menu.findItem(R.id.action_delete_movement); item.setVisible(MovementsManager.canDeleteMovement(_movement)); item.setEnabled(item.isVisible()); return true; }
From source file:com.lemon.lime.MainActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem back = menu.findItem(R.id.back); MenuItem forward = menu.findItem(R.id.forward); if (mWebView.canGoBack()) { back.setEnabled(true); back.getIcon().setAlpha(255);/*from w w w . j a v a 2 s .c om*/ } else { // disabled back.setEnabled(false); back.getIcon().setAlpha(130); } if (mWebView.canGoForward()) { forward.setEnabled(true); forward.getIcon().setAlpha(255); } else { // disabled forward.setEnabled(false); forward.getIcon().setAlpha(130); } return true; }
From source file:com.github.michalbednarski.intentslab.editor.IntentEditorActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); {//from www . ja va2s . c om MenuItem runIntentOption = menu.findItem(R.id.menu_run_intent); if (mComponentType == IntentEditorConstants.RESULT) { if (getIntent().getBooleanExtra(EXTRA_FORWARD_ABLE_RESULT, false)) { runIntentOption.setVisible(true).setTitle("setResult(); finish()"); } else { runIntentOption.setVisible(false); } } else { runIntentOption.setVisible(true).setTitle( IntentGeneralFragment.getMethodNamesArray(getResources(), mComponentType)[mMethodId]); } } menu.findItem(R.id.set_editor_result).setVisible(mGenericEditorMode); menu.findItem(R.id.detach_intent_filter).setVisible(mAttachedIntentFilters != null); menu.findItem(R.id.component_info).setVisible(mEditedIntent.getComponent() != null); menu.findItem(R.id.attach_intent_filter).setVisible(mEditedIntent.getComponent() != null); // Intent tracking options { boolean intentTrackerAvailable = isIntentTrackerAvailable(); MenuItem trackIntentOption = menu.findItem(R.id.track_intent); trackIntentOption.setVisible(intentTrackerAvailable); trackIntentOption.setEnabled(intentTrackerAvailable); trackIntentOption.setChecked(getIntentTracker() != null); } // "Disable interception" option menu.findItem(R.id.disable_interception).setVisible(isInterceptedIntent()).setEnabled( isInterceptedIntent() && getPackageManager().getComponentEnabledSetting(new ComponentName(this, IntentEditorInterceptedActivity.class)) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED); return true; }