List of usage examples for android.view MenuItem setIcon
public MenuItem setIcon(@DrawableRes int iconRes);
From source file:de.vanita5.twittnuker.util.Utils.java
public static void setMenuItemIcon(final Menu menu, final int id, final int icon) { if (menu == null) return;//from www. j a v a 2s . c o m final MenuItem item = menu.findItem(id); if (item == null) return; item.setIcon(icon); }
From source file:org.de.jmg.learn.MainActivity.java
public void setMnuReverse() { if (OptionsMenu != null) { MenuItem item = OptionsMenu.findItem(R.id.mnuAskReverse); boolean isAction = false; if (ActionMenu != null) { MenuBuilder mm = (MenuBuilder) ActionMenu.getMenu(); if (mm.getActionItems().contains(item)) { isAction = true;//from www .j av a2 s . c om } } if (vok != null) { item.setChecked(vok.reverse); if (isAction) { if (vok.reverse) { item.setIcon(android.R.drawable.ic_menu_revert); } else { item.setIcon(android.R.drawable.ic_media_rew); } } } else if (isAction) { item.setIcon(android.R.drawable.ic_media_rew); } } }
From source file:com.nononsenseapps.feeder.ui.FeedFragment.java
@Override public boolean onOptionsItemSelected(MenuItem menuItem) { final long id = menuItem.getItemId(); if (id == R.id.action_sync) { // Sync all feeds when menu button pressed RssContentProvider.RequestSync(); return true; } else if (id == R.id.action_edit_feed && this.id > 0) { Intent i = new Intent(getActivity(), EditFeedActivity.class); // TODO do not animate the back movement here i.putExtra(EditFeedActivity.SHOULD_FINISH_BACK, true); i.putExtra(EditFeedActivity._ID, this.id); i.putExtra(EditFeedActivity.TITLE, customTitle); i.putExtra(EditFeedActivity.TAG, tag); i.setData(Uri.parse(url));// ww w . j a v a 2 s.com startActivity(i); return true; } else if (id == R.id.action_add_templated && this.id > 0) { Intent i = new Intent(getActivity(), EditFeedActivity.class); // TODO do not animate the back movement here i.putExtra(EditFeedActivity.SHOULD_FINISH_BACK, true); i.putExtra(EditFeedActivity.TEMPLATE, true); //i.putExtra(EditFeedActivity.TITLE, title); i.putExtra(EditFeedActivity.TAG, tag); i.setData(Uri.parse(url)); startActivity(i); return true; } else if (id == R.id.action_delete_feed && this.id > 0) { getActivity().getContentResolver().delete(FeedSQL.URI_FEEDS, Util.WHEREIDIS, Util.LongsToStringArray(this.id)); RssContentProvider.notifyAllUris(getActivity()); // Tell activity to open another fragment ((FeedActivity) getActivity()).loadFirstFeedInDB(true); return true; } // else if (id == R.id.action_mark_as_read) { // markAsRead(); // return true; // } else if (id == R.id.action_only_unread) { final boolean onlyUnread = !menuItem.isChecked(); PrefUtils.setPrefShowOnlyUnread(getActivity(), onlyUnread); menuItem.setChecked(onlyUnread); if (onlyUnread) { menuItem.setIcon(R.drawable.ic_action_visibility_off); } else { menuItem.setIcon(R.drawable.ic_action_visibility); } menuItem.setTitle(onlyUnread ? R.string.show_unread_items : R.string.show_all_items); //getActivity().invalidateOptionsMenu(); // Restart loader getLoaderManager().restartLoader(FEEDITEMS_LOADER, new Bundle(), this); return true; } else { return super.onOptionsItemSelected(menuItem); } }
From source file:net.zorgblub.typhon.fragment.ReadingFragment.java
private void onBookmarkLongClick(final Bookmark bookmark) { actionModeBuilderProvider.get().setTitle(R.string.bookmark_options) .setOnCreateAction((actionMode, menu) -> { MenuItem delete = menu.add(R.string.delete); delete.setIcon(R.drawable.trash_can); return true; }).setOnActionItemClickedAction((actionMode, menuItem) -> { boolean result = false; if (menuItem.getTitle().equals(getString(R.string.delete))) { bookmarkDatabaseHelper.deleteBookmark(bookmark); Toast.makeText(context, R.string.bookmark_deleted, Toast.LENGTH_SHORT).show(); result = true;/*from w w w . ja v a 2 s . c om*/ } if (result) { actionMode.finish(); } return result; }).build((AppCompatActivity) getActivity()); }
From source file:org.mozilla.gecko.GeckoApp.java
@Override public boolean onPrepareOptionsMenu(Menu aMenu) { Iterator<ExtraMenuItem> i = sExtraMenuItems.iterator(); while (i.hasNext()) { final ExtraMenuItem item = i.next(); if (aMenu.findItem(item.id) == null) { final MenuItem mi = aMenu.add(Menu.NONE, item.id, Menu.NONE, item.label); if (item.icon != null) { if (item.icon.startsWith("data")) { byte[] raw = GeckoAppShell.decodeBase64(item.icon.substring(22), GeckoAppShell.BASE64_DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(raw, 0, raw.length); BitmapDrawable drawable = new BitmapDrawable(bitmap); mi.setIcon(drawable); } else if (item.icon.startsWith("jar:") || item.icon.startsWith("file://")) { GeckoAppShell.getHandler().post(new Runnable() { public void run() { try { URL url = new URL(item.icon); InputStream is = (InputStream) url.getContent(); Drawable drawable = Drawable.createFromStream(is, "src"); mi.setIcon(drawable); } catch (Exception e) { Log.w(LOGTAG, "onPrepareOptionsMenu: Unable to set icon", e); }//from ww w .ja v a 2 s . co m } }); } } mi.setOnMenuItemClickListener(item); } } if (!sIsGeckoReady) aMenu.findItem(R.id.settings).setEnabled(false); Tab tab = Tabs.getInstance().getSelectedTab(); MenuItem bookmark = aMenu.findItem(R.id.bookmark); MenuItem forward = aMenu.findItem(R.id.forward); MenuItem share = aMenu.findItem(R.id.share); MenuItem saveAsPDF = aMenu.findItem(R.id.save_as_pdf); MenuItem charEncoding = aMenu.findItem(R.id.char_encoding); if (tab == null) { bookmark.setEnabled(false); forward.setEnabled(false); share.setEnabled(false); saveAsPDF.setEnabled(false); return true; } bookmark.setEnabled(true); bookmark.setCheckable(true); if (tab.isBookmark()) { bookmark.setChecked(true); bookmark.setIcon(R.drawable.ic_menu_bookmark_remove); } else { bookmark.setChecked(false); bookmark.setIcon(R.drawable.ic_menu_bookmark_add); } forward.setEnabled(tab.canDoForward()); // Disable share menuitem for about:, chrome: and file: URIs String scheme = Uri.parse(tab.getURL()).getScheme(); boolean enabled = scheme != null && !(scheme.equals("about") || scheme.equals("chrome") || scheme.equals("file")); share.setEnabled(enabled); // Disable save as PDF for about:home and xul pages saveAsPDF.setEnabled(!(tab.getURL().equals("about:home") || tab.getContentType().equals("application/vnd.mozilla.xul+xml"))); charEncoding.setVisible(GeckoPreferences.getCharEncodingState()); return true; }
From source file:com.ichi2.anki2.Reviewer.java
@Override public boolean onCreateOptionsMenu(Menu menu) { Resources res = getResources(); UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_MARK, Menu.NONE, R.string.menu_mark_card, R.drawable.ic_menu_mark);//from w w w . jav a2 s . c o m UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_UNDO, Menu.NONE, R.string.undo, R.drawable.ic_menu_revert_disabled); UIUtils.addMenuItem(menu, Menu.NONE, MENU_EDIT, Menu.NONE, R.string.menu_edit_card, R.drawable.ic_menu_edit); if (mPrefWhiteboard) { if (mShowWhiteboard) { UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE, R.string.hide_whiteboard, R.drawable.ic_menu_compose); } else { UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE, R.string.show_whiteboard, R.drawable.ic_menu_compose); } UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_CLEAR_WHITEBOARD, Menu.NONE, R.string.clear_whiteboard, R.drawable.ic_menu_clear_playlist); } if (mPrefRecord) { // TODO proper icon final MenuItem recorderItem = UIUtils.addMenuItem(menu, Menu.NONE, MENU_RECORD, Menu.NONE, Recorder.recording() ? R.string.record_stop : R.string.record_start, R.drawable.ic_circle_pressed); final MenuItem replayItem = UIUtils.addMenuItem(menu, Menu.NONE, MENU_RECORD_REPLAY, Menu.NONE, R.string.record_play, R.drawable.ic_circle_normal); // disable unless something is recorded replayItem.setEnabled(false); // set relevant listeners Recorder.setRecordingStartedListener(new Recorder.RecordingStartedListener() { @Override public void onRecordingStarted() { recorderItem.setTitle(R.string.record_stop); } }); Recorder.setRecordingFinishedListener(new Recorder.RecordingFinishedListener() { @Override public void onRecordingFinished() { recorderItem.setTitle(R.string.record_start); replayItem.setEnabled(true); } }); Recorder.setRecorderResetListener(new Recorder.RecorderResetListener() { @Override public void onRecorderReset() { replayItem.setEnabled(false); } }); } SubMenu removeDeckSubMenu = menu.addSubMenu(Menu.NONE, MENU_REMOVE, Menu.NONE, R.string.menu_dismiss_note); removeDeckSubMenu.setIcon(R.drawable.ic_menu_stop); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY, Menu.NONE, R.string.menu_bury_note); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_CARD, Menu.NONE, R.string.menu_suspend_card); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_NOTE, Menu.NONE, R.string.menu_suspend_note); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_DELETE, Menu.NONE, R.string.menu_delete_note); if (mPrefTextSelection) { MenuItem item = menu.add(Menu.NONE, MENU_SEARCH, Menu.NONE, res.getString(R.string.menu_select)); item.setIcon(R.drawable.ic_menu_search); item.setEnabled(Lookup.isAvailable()); } return true; }
From source file:com.nit.vicky.Reviewer.java
@Override public boolean onCreateOptionsMenu(Menu menu) { Resources res = getResources(); UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_MARK, Menu.NONE, R.string.menu_mark_card, R.drawable.ic_menu_mark);// w w w .j ava 2 s . co m UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_UNDO, Menu.NONE, R.string.undo, R.drawable.ic_menu_revert_disabled); UIUtils.addMenuItem(menu, Menu.NONE, MENU_EDIT, Menu.NONE, R.string.menu_edit_card, R.drawable.ic_menu_edit); if (mPrefWhiteboard) { if (mShowWhiteboard) { UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE, R.string.hide_whiteboard, R.drawable.ic_menu_compose); } else { UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE, R.string.show_whiteboard, R.drawable.ic_menu_compose); } UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_CLEAR_WHITEBOARD, Menu.NONE, R.string.clear_whiteboard, R.drawable.ic_menu_clear_playlist); } SubMenu removeDeckSubMenu = menu.addSubMenu(Menu.NONE, MENU_REMOVE, Menu.NONE, R.string.menu_dismiss_note); removeDeckSubMenu.setIcon(R.drawable.ic_menu_stop); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY_CARD, Menu.NONE, R.string.menu_bury_card); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY_NOTE, Menu.NONE, R.string.menu_bury_note); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_CARD, Menu.NONE, R.string.menu_suspend_card); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_NOTE, Menu.NONE, R.string.menu_suspend_note); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_DELETE, Menu.NONE, R.string.menu_delete_note); if (mPrefTextSelection) { MenuItem item = menu.add(Menu.NONE, MENU_SEARCH, Menu.NONE, res.getString(R.string.menu_select)); item.setIcon(R.drawable.ic_menu_search); item.setEnabled(Lookup.isAvailable()); } return true; }
From source file:de.vanita5.twittnuker.util.Utils.java
public static void addIntentToMenu(final Context context, final Menu menu, final Intent queryIntent, final int groupId) { if (context == null || menu == null || queryIntent == null) return;/*from ww w . j ava 2 s .c om*/ final PackageManager pm = context.getPackageManager(); final Resources res = context.getResources(); final float density = res.getDisplayMetrics().density; final int padding = Math.round(density * 4); final List<ResolveInfo> activities = pm.queryIntentActivities(queryIntent, 0); for (final ResolveInfo info : activities) { final Intent intent = new Intent(queryIntent); final Drawable icon = info.loadIcon(pm); intent.setClassName(info.activityInfo.packageName, info.activityInfo.name); final MenuItem item = menu.add(groupId, Menu.NONE, Menu.NONE, info.loadLabel(pm)); item.setIntent(intent); final int iw = icon.getIntrinsicWidth(), ih = icon.getIntrinsicHeight(); if (iw > 0 && ih > 0) { final Drawable iconWithPadding = new PaddingDrawable(icon, padding); iconWithPadding.setBounds(0, 0, iw, ih); item.setIcon(iconWithPadding); } else { item.setIcon(icon); } } }
From source file:com.ichi2.anki2.Reviewer.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { Resources res = getResources(); MenuItem item = menu.findItem(MENU_MARK); if (mCurrentCard != null && mCurrentCard.note().hasTag("marked")) { item.setTitle(R.string.menu_unmark_card); item.setIcon(R.drawable.ic_menu_marked); } else {/*from w w w .j a v a2s . com*/ item.setTitle(R.string.menu_mark_card); item.setIcon(R.drawable.ic_menu_mark); } item = menu.findItem(MENU_UNDO); if (AnkiDroidApp.colIsOpen() && AnkiDroidApp.getCol().undoAvailable()) { item.setEnabled(true); item.setIcon(R.drawable.ic_menu_revert); } else { item.setEnabled(false); item.setIcon(R.drawable.ic_menu_revert_disabled); } item = menu.findItem(MENU_SEARCH); if (item != null) { item.setTitle(clipboardHasText() ? Lookup.getSearchStringTitle() : res.getString(R.string.menu_select)); } return true; }
From source file:org.mozilla.gecko.GeckoApp.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Tab tab = null;//from ww w . j ava 2 s. com Intent intent = null; switch (item.getItemId()) { case R.id.quit: synchronized (sLaunchState) { if (sLaunchState == LaunchState.GeckoRunning) GeckoAppShell.notifyGeckoOfEvent(GeckoEvent.createBroadcastEvent("Browser:Quit", null)); else System.exit(0); sLaunchState = LaunchState.GeckoExiting; } return true; case R.id.bookmark: tab = Tabs.getInstance().getSelectedTab(); if (tab != null) { if (item.isChecked()) { tab.removeBookmark(); Toast.makeText(this, R.string.bookmark_removed, Toast.LENGTH_SHORT).show(); item.setIcon(R.drawable.ic_menu_bookmark_add); } else { tab.addBookmark(); Toast.makeText(this, R.string.bookmark_added, Toast.LENGTH_SHORT).show(); item.setIcon(R.drawable.ic_menu_bookmark_remove); } } return true; case R.id.share: tab = Tabs.getInstance().getSelectedTab(); if (tab != null) { GeckoAppShell.openUriExternal(tab.getURL(), "text/plain", "", "", Intent.ACTION_SEND, tab.getTitle()); } return true; case R.id.reload: doReload(); return true; case R.id.forward: doForward(); return true; case R.id.save_as_pdf: GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SaveAs:PDF", null)); return true; case R.id.settings: intent = new Intent(this, GeckoPreferences.class); startActivity(intent); return true; case R.id.site_settings: GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Permissions:Get", null)); return true; case R.id.addons: loadUrlInTab("about:addons"); return true; case R.id.downloads: intent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS); startActivity(intent); return true; case R.id.char_encoding: GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("CharEncoding:Get", null)); return true; default: return super.onOptionsItemSelected(item); } }