Java Code Examples for android.view.MenuItem#isEnabled()
The following examples show how to use
android.view.MenuItem#isEnabled() .
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: AppMenuAdapter.java From delion with Apache License 2.0 | 6 votes |
private void setupStandardMenuItemViewHolder(StandardMenuItemViewHolder holder, View convertView, final MenuItem item) { // Set up the icon. Drawable icon = item.getIcon(); holder.image.setImageDrawable(icon); holder.image.setVisibility(icon == null ? View.GONE : View.VISIBLE); holder.image.setChecked(item.isChecked()); holder.text.setText(item.getTitle()); holder.text.setContentDescription(item.getTitleCondensed()); boolean isEnabled = item.isEnabled(); // Set the text color (using a color state list). holder.text.setEnabled(isEnabled); // This will ensure that the item is not highlighted when selected. convertView.setEnabled(isEnabled); convertView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mAppMenu.onItemClick(item); } }); }
Example 2
Source File: AppMenuAdapter.java From AndroidChromium with Apache License 2.0 | 6 votes |
private void setupStandardMenuItemViewHolder(StandardMenuItemViewHolder holder, View convertView, final MenuItem item) { // Set up the icon. Drawable icon = item.getIcon(); holder.image.setImageDrawable(icon); holder.image.setVisibility(icon == null ? View.GONE : View.VISIBLE); holder.image.setChecked(item.isChecked()); holder.text.setText(item.getTitle()); holder.text.setContentDescription(item.getTitleCondensed()); boolean isEnabled = item.isEnabled(); // Set the text color (using a color state list). holder.text.setEnabled(isEnabled); // This will ensure that the item is not highlighted when selected. convertView.setEnabled(isEnabled); convertView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mAppMenu.onItemClick(item); } }); }
Example 3
Source File: MainActivity.java From 920-text-editor-v2 with Apache License 2.0 | 6 votes |
/** * * @param menuResId * @param status {@link com.jecelyin.editor.v2.view.menu.MenuDef#STATUS_NORMAL}, {@link com.jecelyin.editor.v2.view.menu.MenuDef#STATUS_DISABLED} */ public void setMenuStatus(@IdRes int menuResId, int status) { MenuItem menuItem = mToolbar.getMenu().findItem(menuResId); if (menuItem == null) { throw new RuntimeException("Can't find a menu item"); } boolean enable = status != MenuDef.STATUS_DISABLED; if (menuItem.isEnabled() == enable) { return; } Drawable icon = menuItem.getIcon(); if (!enable) { menuItem.setEnabled(false); menuItem.setIcon(MenuManager.makeToolbarDisabledIcon(icon)); } else { menuItem.setEnabled(true); if (menuItem.getGroupId() == MenuDef.GROUP_TOOLBAR) { menuItem.setIcon(MenuManager.makeToolbarNormalIcon(icon)); } else { menuItem.setIcon(MenuManager.makeMenuNormalIcon(icon)); } } }
Example 4
Source File: AppMenuAdapter.java From 365browser with Apache License 2.0 | 6 votes |
private void setupStandardMenuItemViewHolder(StandardMenuItemViewHolder holder, View convertView, final MenuItem item) { // Set up the icon. Drawable icon = item.getIcon(); holder.image.setImageDrawable(icon); holder.image.setVisibility(icon == null ? View.GONE : View.VISIBLE); holder.image.setChecked(item.isChecked()); holder.text.setText(item.getTitle()); holder.text.setContentDescription(item.getTitleCondensed()); boolean isEnabled = item.isEnabled(); // Set the text color (using a color state list). holder.text.setEnabled(isEnabled); // This will ensure that the item is not highlighted when selected. convertView.setEnabled(isEnabled); convertView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mAppMenu.onItemClick(item); } }); }
Example 5
Source File: AppMenu.java From 365browser with Apache License 2.0 | 6 votes |
/** * Handles long clicks on image buttons on the AppMenu popup. * @param menuItem The menu item in the popup that was long clicked. * @param view The anchor view of the menu item. */ boolean onItemLongClick(MenuItem menuItem, View view) { if (!menuItem.isEnabled()) return false; String description = null; Context context = ContextUtils.getApplicationContext(); Resources resources = context.getResources(); final int itemId = menuItem.getItemId(); if (itemId == R.id.forward_menu_id) { description = resources.getString(R.string.menu_forward); } else if (itemId == R.id.bookmark_this_page_id) { description = resources.getString(R.string.menu_bookmark); } else if (itemId == R.id.offline_page_id) { description = resources.getString(R.string.menu_download); } else if (itemId == R.id.info_menu_id) { description = resources.getString(R.string.menu_page_info); } else if (itemId == R.id.reload_menu_id) { description = resources.getString(R.string.menu_refresh); } return AccessibilityUtil.showAccessibilityToast(context, view, description); }
Example 6
Source File: AppMenu.java From delion with Apache License 2.0 | 5 votes |
/** * Handles clicks on the AppMenu popup. * @param menuItem The menu item in the popup that was clicked. */ void onItemClick(MenuItem menuItem) { if (menuItem.isEnabled()) { if (menuItem.getItemId() == R.id.update_menu_id) { UpdateMenuItemHelper.getInstance().setMenuItemClicked(); } dismiss(); mHandler.onOptionsItemSelected(menuItem); } }
Example 7
Source File: AppMenu.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Handles clicks on the AppMenu popup. * @param menuItem The menu item in the popup that was clicked. */ void onItemClick(MenuItem menuItem) { if (menuItem.isEnabled()) { if (menuItem.getItemId() == R.id.update_menu_id) { UpdateMenuItemHelper.getInstance().setMenuItemClicked(); } dismiss(); mHandler.onOptionsItemSelected(menuItem); } }
Example 8
Source File: AppMenu.java From 365browser with Apache License 2.0 | 5 votes |
/** * Handles clicks on the AppMenu popup. * @param menuItem The menu item in the popup that was clicked. */ void onItemClick(MenuItem menuItem) { if (menuItem.isEnabled()) { if (menuItem.getItemId() == R.id.update_menu_id) { UpdateMenuItemHelper.getInstance().setMenuItemClicked(); } dismiss(); mHandler.onOptionsItemSelected(menuItem); } }
Example 9
Source File: FloatingToolbar.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private List<MenuItem> getVisibleAndEnabledMenuItems(Menu menu) { List<MenuItem> menuItems = new ArrayList<>(); for (int i = 0; (menu != null) && (i < menu.size()); i++) { MenuItem menuItem = menu.getItem(i); if (menuItem.isVisible() && menuItem.isEnabled()) { Menu subMenu = menuItem.getSubMenu(); if (subMenu != null) { menuItems.addAll(getVisibleAndEnabledMenuItems(subMenu)); } else { menuItems.add(menuItem); } } } return menuItems; }
Example 10
Source File: FloatingToolbar.java From Telegram with GNU General Public License v2.0 | 5 votes |
private List<MenuItem> getVisibleAndEnabledMenuItems(Menu menu) { List<MenuItem> menuItems = new ArrayList<>(); for (int i = 0; (menu != null) && (i < menu.size()); i++) { MenuItem menuItem = menu.getItem(i); if (menuItem.isVisible() && menuItem.isEnabled()) { Menu subMenu = menuItem.getSubMenu(); if (subMenu != null) { menuItems.addAll(getVisibleAndEnabledMenuItems(subMenu)); } else { menuItems.add(menuItem); } } } return menuItems; }
Example 11
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 12
Source File: FloatingActionMenu.java From Carbon with Apache License 2.0 | 4 votes |
public Item(MenuItem item) { icon = item.getIcon(); tint = MenuItemCompat.getIconTintList(item); enabled = item.isEnabled(); title = item.getTitle(); }
Example 13
Source File: NewPostActivity.java From BlackLight with GNU General Public License v3.0 | 4 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.isCheckable() && item.isEnabled()) { item.setChecked(!item.isChecked()); } int id = item.getItemId(); if (id == android.R.id.home) { finish(); return true; } else if (id == R.id.post_send) { try { if (Utility.lengthOfString(mText.getText().toString()) <= 140) { if (!TextUtils.isEmpty(mText.getText().toString())) { new Uploader().execute(); } else { Toast.makeText(this, R.string.empty_weibo, Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { } return true; } else if (id == R.id.post_pic) { if (mBitmap == null){ showPicturePicker(); } else { // Delete picture setPicture(null); } return true; } else if (id == R.id.post_emoticon) { if (mDrawer.isDrawerOpen(Gravity.END)) { mDrawer.closeDrawer(Gravity.END); } else { mDrawer.openDrawer(Gravity.END); } return true; } else if (id == R.id.post_at) { AtUserSuggestDialog diag = new AtUserSuggestDialog(this); diag.setListener(new AtUserSuggestDialog.AtUserListener() { @Override public void onChooseUser(String name) { mText.getText().insert(mText.getSelectionStart(), " @" + name +" "); } }); diag.show(); return true; } else { return super.onOptionsItemSelected(item); } }