List of usage examples for android.view MenuItem setEnabled
public MenuItem setEnabled(boolean enabled);
From source file:com.example.linhdq.test.documents.viewing.grid.DocumentGridActivity.java
@Override public void onCheckedChanged(Set<Integer> checkedIds) { if (mActionMode == null && checkedIds.size() > 0) { mActionMode = startSupportActionMode(new DocumentActionCallback()); } else if (mActionMode != null && checkedIds.size() == 0) { mActionMode.finish();/*from w w w . j a va 2 s .co m*/ mActionMode = null; } if (mActionMode != null) { // change state of action mode depending on the selection final MenuItem editItem = mActionMode.getMenu().findItem(R.id.item_edit_title); final MenuItem joinItem = mActionMode.getMenu().findItem(R.id.item_join); if (checkedIds.size() == 1) { editItem.setVisible(true); editItem.setEnabled(true); joinItem.setVisible(false); joinItem.setEnabled(false); } else { editItem.setVisible(false); editItem.setEnabled(false); joinItem.setVisible(true); joinItem.setEnabled(true); } } }
From source file:org.taulabs.androidgcs.ObjectManagerActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { // Query the telemetry service for the current state boolean channelOpen = getConnectionState() != ConnectionState.DISCONNECTED; // Show the connect button based on the status reported by the telemetry // service//from w w w . j a va 2 s .co m MenuItem connectionButton = menu.findItem(R.id.menu_connect); if (connectionButton != null) { connectionButton.setEnabled(!channelOpen).setVisible(!channelOpen); } MenuItem disconnectionButton = menu.findItem(R.id.menu_disconnect); if (disconnectionButton != null) { disconnectionButton.setEnabled(channelOpen).setVisible(channelOpen); } return super.onPrepareOptionsMenu(menu); }
From source file:com.stoutner.privacybrowser.MainWebViewActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { // Only enable Third-Party Cookies if SDK >= 21 and First-Party Cookies are enabled. MenuItem toggleThirdPartyCookies = menu.findItem(R.id.toggleThirdPartyCookies); if ((Build.VERSION.SDK_INT >= 21) && firstPartyCookiesEnabled) { toggleThirdPartyCookies.setEnabled(true); } else {/* ww w.ja v a2 s.c om*/ toggleThirdPartyCookies.setEnabled(false); } // Enable Clear Cookies if there are any. MenuItem clearCookies = menu.findItem(R.id.clearCookies); clearCookies.setEnabled(cookieManager.hasCookies()); // Run all the other default commands. super.onPrepareOptionsMenu(menu); // return true displays the menu. return true; }
From source file:com.vadimfrolov.duorem.MainActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem miAdd = (MenuItem) menu.findItem(R.id.action_add_host); MenuItem miEdit = (MenuItem) menu.findItem(R.id.action_edit_host); MenuItem miDelete = (MenuItem) menu.findItem(R.id.action_delete_host); boolean targetIsValid = mTarget != null && ((mTarget.ipAddress != null && !mTarget.ipAddress.equals(NetInfo.NOIP)) || (mTarget.hardwareAddress != null && !mTarget.hardwareAddress.equals(NetInfo.NOMAC))); if (targetIsValid) { miAdd.setTitle(getResources().getString(R.string.replace_host)); } else {/*from w ww .j ava 2 s . c om*/ miAdd.setTitle(getResources().getString(R.string.add_host)); } miEdit.setEnabled(targetIsValid); miDelete.setEnabled(targetIsValid); miEdit.setShowAsAction(targetIsValid ? MenuItem.SHOW_AS_ACTION_ALWAYS : MenuItem.SHOW_AS_ACTION_NEVER); miDelete.setShowAsAction(targetIsValid ? MenuItem.SHOW_AS_ACTION_ALWAYS : MenuItem.SHOW_AS_ACTION_NEVER); // hide replace menu item under the unfoldable menu miAdd.setShowAsAction(targetIsValid ? MenuItem.SHOW_AS_ACTION_NEVER : MenuItem.SHOW_AS_ACTION_ALWAYS); return super.onPrepareOptionsMenu(menu); }
From source file:com.workingagenda.democracydroid.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) { Intent intent = new Intent(this, SettingsActivity.class); startActivity(intent);/*w w w . j a v a 2 s .c o m*/ return true; } if (id == R.id.action_refresh) { // Don't let user click before async tasks are done item.setEnabled(false); // Call Fragment refresh methods getSupportFragmentManager().getFragments(); for (Fragment x : getSupportFragmentManager().getFragments()) { if (x instanceof PodcastFragment) ((PodcastFragment) x).refresh(); if (x instanceof StoryFragment) ((StoryFragment) x).refresh(); if (x instanceof DownloadFragment) ((DownloadFragment) x).refresh(); } // FIXME: Somehow enable this after async call... item.setEnabled(true); return true; } if (id == R.id.action_donate) { String url = "https://www.democracynow.org/donate"; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); return true; } if (id == R.id.action_exclusives) { String url = "https://www.democracynow.org/categories/web_exclusive"; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); return true; } if (id == R.id.action_site) { String url = "http://www.democracynow.org/"; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); return true; } if (id == R.id.action_about) { Intent intent = new Intent(this, AboutActivity.class); startActivityForResult(intent, 0); } return super.onOptionsItemSelected(item); }
From source file:com.owncloud.android.ui.fragment.OCFileListFragment.java
/** * {@inheritDoc}/*from w w w .j a v a2s.c om*/ */ @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { Bundle args = getArguments(); boolean allowContextualActions = (args == null) ? true : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true); if (allowContextualActions) { MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.file_actions_menu, menu); AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; OCFile targetFile = (OCFile) mAdapter.getItem(info.position); if (mContainerActivity.getStorageManager() != null) { FileMenuFilter mf = new FileMenuFilter(targetFile, mContainerActivity.getStorageManager().getAccount(), mContainerActivity, getActivity()); mf.filter(menu); } /// TODO break this direct dependency on FileDisplayActivity... if possible MenuItem item = menu.findItem(R.id.action_open_file_with); FileFragment frag = ((FileDisplayActivity) getActivity()).getSecondFragment(); if (frag != null && frag instanceof FileDetailFragment && frag.getFile().getFileId() == targetFile.getFileId()) { item = menu.findItem(R.id.action_see_details); if (item != null) { item.setVisible(false); item.setEnabled(false); } } } }
From source file:com.cw.litenote.note.Note.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); // System.out.println("Note / _onCreateOptionsMenu"); // inflate menu getMenuInflater().inflate(R.menu.pager_menu, menu); mMenu = menu;//from www .j a v a 2 s .c o m // menu item: checked status // get checked or not int isChecked = mDb_page.getNoteMarking(NoteUi.getFocus_notePos(), true); if (isChecked == 0) menu.findItem(R.id.VIEW_NOTE_CHECK).setIcon(R.drawable.btn_check_off_holo_dark); else menu.findItem(R.id.VIEW_NOTE_CHECK).setIcon(R.drawable.btn_check_on_holo_dark); // menu item: view mode markCurrentSelected(menu.findItem(R.id.VIEW_ALL), "ALL"); markCurrentSelected(menu.findItem(R.id.VIEW_PICTURE), "PICTURE_ONLY"); markCurrentSelected(menu.findItem(R.id.VIEW_TEXT), "TEXT_ONLY"); // menu item: previous MenuItem itemPrev = menu.findItem(R.id.ACTION_PREVIOUS); itemPrev.setEnabled(viewPager.getCurrentItem() > 0); itemPrev.getIcon().setAlpha(viewPager.getCurrentItem() > 0 ? 255 : 30); // menu item: Next or Finish MenuItem itemNext = menu.findItem(R.id.ACTION_NEXT); itemNext.setTitle((viewPager.getCurrentItem() == mPagerAdapter.getCount() - 1) ? R.string.view_note_slide_action_finish : R.string.view_note_slide_action_next); // set Disable and Gray for Last item boolean isLastOne = (viewPager.getCurrentItem() == (mPagerAdapter.getCount() - 1)); if (isLastOne) itemNext.setEnabled(false); itemNext.getIcon().setAlpha(isLastOne ? 30 : 255); return true; }
From source file:org.getlantern.firetweet.fragment.CustomTabsFragment.java
@Override public void onPrepareOptionsMenu(final Menu menu) { final Resources res = getResources(); final boolean hasOfficialKeyAccounts = Utils.hasAccountSignedWithOfficialKeys(getActivity()); final boolean forcePrivateAPI = mPreferences.getBoolean(KEY_FORCE_USING_PRIVATE_APIS, false); final long[] accountIds = getAccountIds(getActivity()); final MenuItem itemAdd = menu.findItem(R.id.add_submenu); if (itemAdd != null && itemAdd.hasSubMenu()) { final SubMenu subMenu = itemAdd.getSubMenu(); subMenu.clear();/*from ww w .j a v a 2s. c o m*/ final HashMap<String, CustomTabConfiguration> map = getConfiguraionMap(); final List<Entry<String, CustomTabConfiguration>> tabs = new ArrayList<>(map.entrySet()); Collections.sort(tabs, CustomTabConfigurationComparator.SINGLETON); for (final Entry<String, CustomTabConfiguration> entry : tabs) { final String type = entry.getKey(); final CustomTabConfiguration conf = entry.getValue(); final boolean isOfficiakKeyAccountRequired = TAB_TYPE_ACTIVITIES_ABOUT_ME.equals(type) || TAB_TYPE_ACTIVITIES_BY_FRIENDS.equals(type); final boolean accountIdRequired = conf .getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED; final Intent intent = new Intent(INTENT_ACTION_ADD_TAB); intent.setClass(getActivity(), CustomTabEditorActivity.class); intent.putExtra(EXTRA_TYPE, type); intent.putExtra(EXTRA_OFFICIAL_KEY_ONLY, isOfficiakKeyAccountRequired); final MenuItem subItem = subMenu.add(conf.getDefaultTitle()); final boolean disabledByNoAccount = accountIdRequired && accountIds.length == 0; final boolean disabledByNoOfficialKey = !forcePrivateAPI && isOfficiakKeyAccountRequired && !hasOfficialKeyAccounts; final boolean disabledByDuplicateTab = conf.isSingleTab() && isTabAdded(getActivity(), type); final boolean shouldDisable = disabledByDuplicateTab || disabledByNoOfficialKey || disabledByNoAccount; subItem.setVisible(!shouldDisable); subItem.setEnabled(!shouldDisable); final Drawable icon = ResourcesCompat.getDrawable(res, conf.getDefaultIcon(), null); subItem.setIcon(icon); subItem.setIntent(intent); } } ThemeUtils.applyColorFilterToMenuIcon(getActivity(), menu); }
From source file:org.mariotaku.twidere.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 w w w . j a va 2 s .co m*/ final int count = mValidator.getTweetLength(text); final float hue = count < Validator.MAX_TWEET_LENGTH ? count >= Validator.MAX_TWEET_LENGTH - 10 ? 5 * (Validator.MAX_TWEET_LENGTH - count) : 50 : 0; final float[] hsv = new float[] { hue, 1.0f, 1.0f }; mTextCount .setTextColor(count >= Validator.MAX_TWEET_LENGTH - 10 ? Color.HSVToColor(0x80, hsv) : 0x80808080); mTextCount.setText(parseString(Validator.MAX_TWEET_LENGTH - count)); final MenuItem sendItem = menu.findItem(MENU_SEND); if (sendItem != null) { sendItem.setEnabled(text_orig.length() > 0); } return super.onPrepareOptionsMenu(menu); }
From source file:org.mariotaku.twidere.activity.support.SignInActivity.java
@Override public boolean onPrepareOptionsMenu(final Menu menu) { final MenuItem itemBrowser = menu.findItem(MENU_OPEN_IN_BROWSER); if (itemBrowser != null) { final boolean is_oauth = mAuthType == ParcelableCredentials.AUTH_TYPE_OAUTH; itemBrowser.setVisible(is_oauth); itemBrowser.setEnabled(is_oauth); }/*from w w w .jav a 2s. c o m*/ final boolean result = super.onPrepareOptionsMenu(menu); if (!shouldSetActionItemColor()) return result; final Toolbar toolbar = peekActionBarToolbar(); if (toolbar != null) { final int themeColor = getCurrentThemeColor(); final int themeId = getCurrentThemeResourceId(); final int itemColor = ThemeUtils.getContrastForegroundColor(this, themeId, themeColor); ThemeUtils.wrapToolbarMenuIcon(ViewSupport.findViewByType(toolbar, ActionMenuView.class), itemColor, itemColor); } return result; }