List of usage examples for android.view MenuItem setIcon
public MenuItem setIcon(@DrawableRes int iconRes);
From source file:com.gmail.charleszq.picorner.ui.ImageDetailFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { MenuItem likeItem = menu.findItem(R.id.menu_item_like); MenuItem ownerPhotoItem = menu.findItem(R.id.menu_item_see_owner_photos); MenuItem commentItem = menu.findItem(R.id.menu_item_comment); MenuItem mapItem = menu.findItem(R.id.menu_item_view_on_map); MenuItem exifItem = menu.findItem(R.id.menu_item_view_exif); MenuItem detailItem = menu.findItem(R.id.menu_item_detail); PicornerApplication app = (PicornerApplication) getActivity().getApplication(); boolean ismyphoto = app.isMyOwnPhoto(mPhoto); ownerPhotoItem.setVisible(!ismyphoto); switch (mPhoto.getMediaSource()) { case FLICKR:/* ww w . jav a2 s .c om*/ menu.setGroupVisible(R.id.group_my_flickr_photo, ismyphoto); likeItem.setVisible(!ismyphoto); break; case PX500: menu.setGroupVisible(R.id.group_my_flickr_photo, false); likeItem.setVisible(!ismyphoto); break; case INSTAGRAM: commentItem.setVisible(false); exifItem.setVisible(false); menu.setGroupVisible(R.id.group_my_flickr_photo, false); break; case RSS: menu.setGroupVisible(R.id.group_my_flickr_photo, false); likeItem.setVisible(false); exifItem.setVisible(false); commentItem.setVisible(false); ownerPhotoItem.setVisible(false); detailItem.setVisible(false); break; } mapItem.setVisible(mPhoto.getLocation() != null); if (mUserLikeThePhoto) { likeItem.setIcon(R.drawable.star_big_on); } else { likeItem.setIcon(R.drawable.ic_menu_star); } // 500px menu group MenuItem voteItem = menu.findItem(R.id.menu_item_vote); if (mPhoto.getMediaSource() != MediaSourceType.PX500) { voteItem.setVisible(false); } else { voteItem.setVisible(SPUtil.getPx500OauthToken(getActivity()) != null && !app.isMyOwnPhoto(mPhoto) && !mPhoto.isUserVoted()); } }
From source file:org.path.episample.android.activities.MainMenuActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); int showOption = MenuItem.SHOW_AS_ACTION_IF_ROOM; MenuItem item; if (currentFragment != ScreenList.WEBKIT) { ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE); actionBar.show();// w ww . ja v a 2 s .c o m item = menu.add(Menu.NONE, MENU_MAIN_MENU, Menu.NONE, getString(R.string.main_menu)); item.setIcon(R.drawable.ic_action_home).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); //item = menu.add(Menu.NONE, MENU_FILL_FORM, Menu.NONE, getString(R.string.enter_data_button)); //item.setIcon(R.drawable.ic_action_collections_collection).setShowAsAction(showOption); // Using a file for this work now String get = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_GET_BLANK); if (get.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_PULL_FORMS, Menu.NONE, getString(R.string.get_forms)); item.setIcon(R.drawable.ic_action_av_download).setShowAsAction(showOption); //item = menu.add(Menu.NONE, MENU_CLOUD_FORMS, Menu.NONE, getString(R.string.get_forms)); //item.setIcon(R.drawable.ic_action_cloud).setShowAsAction(showOption); } String send = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_SEND_FINALIZED); if (send.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_PUSH_FORMS, Menu.NONE, getString(R.string.send_data)); item.setIcon(R.drawable.ic_action_av_upload).setShowAsAction(showOption); } String manage = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_MANAGE_FORMS); if (manage.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_MANAGE_FORMS, Menu.NONE, getString(R.string.manage_files)); item.setIcon(R.drawable.trash).setShowAsAction(showOption); } String settings = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_ACCESS_SETTINGS); if (settings.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_PREFERENCES, Menu.NONE, getString(R.string.general_preferences)); item.setIcon(R.drawable.ic_menu_preferences).setShowAsAction(showOption); } item = menu.add(Menu.NONE, MENU_ADMIN_PREFERENCES, Menu.NONE, getString(R.string.admin_preferences)); item.setIcon(R.drawable.ic_action_device_access_accounts).setShowAsAction(showOption); String backup = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_BACKUP_CENSUS); if (backup != null && backup.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_BACKUP_CENSUS, Menu.NONE, getString(R.string.backup_census)); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } String restore = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_RESTORE_CENSUS); if (restore != null && restore.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_RESTORE_CENSUS, Menu.NONE, getString(R.string.restore_census)); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } String invalidateCensus = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_INVALIDATE_CENSUS); if (invalidateCensus != null && invalidateCensus.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_MARK_CENSUS_AS_INVALID, Menu.NONE, getString(R.string.invalidate_census)); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } String edit = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_EDIT_CENSUS); if (edit != null && edit.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_EDIT_CENSUS, Menu.NONE, getString(R.string.edit_census)); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } String removeCensus = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_REMOVE_CENSUS); if (removeCensus != null && removeCensus.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_REMOVE_CENSUS, Menu.NONE, getString(R.string.remove_census)); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } /*String send_receive_bt = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_SEND_RECEIVE_BLUETOOTH); if (send_receive_bt != null && send_receive_bt.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_SEND_REVEIVE_BLUETOOTH, Menu.NONE, getString(R.string.send_receive_bluetooth)); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); }*/ item = menu.add(Menu.NONE, MENU_ABOUT, Menu.NONE, getString(R.string.about)); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } else { ActionBar actionBar = getActionBar(); actionBar.hide(); } return true; }
From source file:biz.bokhorst.xprivacy.ActivityMain.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { int userId = Util.getUserId(Process.myUid()); boolean mounted = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); boolean updates = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingUpdates, false); menu.findItem(R.id.menu_export).setEnabled(mounted); menu.findItem(R.id.menu_import).setEnabled(mounted); menu.findItem(R.id.menu_submit).setEnabled(Util.hasValidFingerPrint(this)); menu.findItem(R.id.menu_pro).setVisible(!Util.isProEnabled() && Util.hasProLicense(this) == null); menu.findItem(R.id.menu_dump).setVisible(Util.isDebuggable(this)); menu.findItem(R.id.menu_update).setVisible(updates); menu.findItem(R.id.menu_update).setEnabled(mounted); // Update filter count // Get settings boolean fUsed = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUsed, false); boolean fInternet = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFInternet, false); boolean fRestriction = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFRestriction, false); boolean fPermission = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFPermission, true); boolean fOnDemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFOnDemand, false); boolean fUser = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUser, true); boolean fSystem = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFSystem, false); // Count number of active filters int numberOfFilters = 0; if (fUsed)/*from w w w. j av a2 s .c o m*/ numberOfFilters++; if (fInternet) numberOfFilters++; if (fRestriction) numberOfFilters++; if (fPermission) numberOfFilters++; if (fOnDemand) numberOfFilters++; if (fUser) numberOfFilters++; if (fSystem) numberOfFilters++; if (numberOfFilters > 0) { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_filter) .copy(Bitmap.Config.ARGB_8888, true); Paint paint = new Paint(); paint.setStyle(Style.FILL); paint.setColor(Color.GRAY); paint.setTextSize(bitmap.getWidth() / 3); paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); String text = Integer.toString(numberOfFilters); Canvas canvas = new Canvas(bitmap); canvas.drawText(text, bitmap.getWidth() - paint.measureText(text), bitmap.getHeight(), paint); MenuItem fMenu = menu.findItem(R.id.menu_filter); fMenu.setIcon(new BitmapDrawable(getResources(), bitmap)); } return super.onPrepareOptionsMenu(menu); }
From source file:com.haibison.android.anhuu.FragmentFiles.java
@Override public void onPrepareOptionsMenu(Menu menu) { if (BuildConfig.DEBUG) Log.d(CLASSNAME, "onPrepareOptionsMenu()"); /*//from w w w. ja va 2 s . co m * Some bugs? This method seems to be called even after `onDestroy()`... */ if (getActivity() == null) return; /* * Sorting. */ final boolean sortAscending = Display.isSortAscending(getActivity()); MenuItem miSort = menu.findItem(R.id.anhuu_f5be488d_menuitem_sort); switch (Display.getSortType(getActivity())) { case BaseFile.SORT_BY_NAME: miSort.setIcon(UI.resolveAttribute(getActivity(), sortAscending ? R.attr.anhuu_f5be488d_ic_menu_sort_by_name_asc : R.attr.anhuu_f5be488d_ic_menu_sort_by_name_desc)); break; case BaseFile.SORT_BY_SIZE: miSort.setIcon(UI.resolveAttribute(getActivity(), sortAscending ? R.attr.anhuu_f5be488d_ic_menu_sort_by_size_asc : R.attr.anhuu_f5be488d_ic_menu_sort_by_size_desc)); break; case BaseFile.SORT_BY_MODIFICATION_TIME: miSort.setIcon(UI.resolveAttribute(getActivity(), sortAscending ? R.attr.anhuu_f5be488d_ic_menu_sort_by_date_asc : R.attr.anhuu_f5be488d_ic_menu_sort_by_date_desc)); break; } /* * View type. */ MenuItem menuItem = menu.findItem(R.id.anhuu_f5be488d_menuitem_switch_viewmode); switch (Display.getViewType(getActivity())) { case GRID: menuItem.setIcon(UI.resolveAttribute(getActivity(), R.attr.anhuu_f5be488d_ic_menu_listview)); menuItem.setTitle(R.string.anhuu_f5be488d_cmd_list_view); break; case LIST: menuItem.setIcon(UI.resolveAttribute(getActivity(), R.attr.anhuu_f5be488d_ic_menu_gridview)); menuItem.setTitle(R.string.anhuu_f5be488d_cmd_grid_view); break; } /* * New folder. */ menu.findItem(R.id.anhuu_f5be488d_menuitem_new_folder).setEnabled(!mLoading); }
From source file:com.aimfire.gallery.GalleryActivity.java
/** * Override Activity lifecycle method./*from w w w. j a va 2 s. co 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:au.org.intersect.faims.android.ui.activity.ShowModuleActivity.java
public boolean onPrepareOptionsMenu(Menu menu) { // gps status menu.findItem(R.id.action_gps_inactive).setVisible(false); menu.findItem(R.id.action_gps_active_has_signal).setVisible(false); menu.findItem(R.id.action_gps_active_no_signal).setVisible(false); if (gpsDataManager.isExternalGPSStarted() || gpsDataManager.isInternalGPSStarted()) { if (gpsDataManager.hasValidExternalGPSSignal() || gpsDataManager.hasValidInternalGPSSignal()) { menu.findItem(R.id.action_gps_active_has_signal).setVisible(true); } else {/* w ww . ja va 2s.c o m*/ menu.findItem(R.id.action_gps_active_no_signal).setVisible(true); } } else { menu.findItem(R.id.action_gps_inactive).setVisible(true); } // tracker status menu.findItem(R.id.action_tracker_active_no_gps).setVisible(false); menu.findItem(R.id.action_tracker_active_has_gps).setVisible(false); menu.findItem(R.id.action_tracker_inactive).setVisible(false); if (gpsDataManager.isTrackingStarted()) { if (gpsDataManager.hasValidExternalGPSSignal() || gpsDataManager.hasValidInternalGPSSignal()) { menu.findItem(R.id.action_tracker_active_has_gps).setVisible(true); } else { menu.findItem(R.id.action_tracker_active_no_gps).setVisible(true); } } else { menu.findItem(R.id.action_tracker_inactive).setVisible(true); } // sync status menu.findItem(R.id.action_sync).setVisible(false); menu.findItem(R.id.action_sync_active).setVisible(false); menu.findItem(R.id.action_sync_error).setVisible(false); menu.findItem(R.id.action_sync_has_changes).setVisible(false); menu.findItem(R.id.action_sync_inactive).setVisible(false); syncAnimImage.clearAnimation(); switch (syncStatus) { case ACTIVE_SYNCING: MenuItem syncItem = menu.findItem(R.id.action_sync_active).setVisible(true); syncAnimImage.startAnimation(rotation); syncItem.setActionView(syncAnimImage); break; case ERROR: menu.findItem(R.id.action_sync_error).setVisible(true); break; case ACTIVE_NO_CHANGES: menu.findItem(R.id.action_sync).setVisible(true); break; case ACTIVE_HAS_CHANGES: menu.findItem(R.id.action_sync_has_changes).setVisible(true); break; default: menu.findItem(R.id.action_sync_inactive).setVisible(true); break; } // follow status MenuItem distance_text = menu.findItem(R.id.distance_text); distance_text.setVisible(pathIndicatorVisible); String distanceInfo = pathIndex < 0 ? "" : " to point (" + pathIndex + "/" + pathLength + ")"; if (pathDistance > 1000) { distance_text.setTitle( MeasurementUtil.displayAsKiloMeters(pathDistance / 1000, "###,###,###,###.0") + distanceInfo); } else { distance_text.setTitle(MeasurementUtil.displayAsMeters(pathDistance, "###,###,###,###") + distanceInfo); } MenuItem direction_text = menu.findItem(R.id.direction_text); direction_text.setVisible(pathIndicatorVisible); direction_text.setTitle(MeasurementUtil.displayAsDegrees(pathBearing, "###")); MenuItem direction_indicator = menu.findItem(R.id.direction_indicator); direction_indicator.setVisible(pathIndicatorVisible); if (pathHeading != null) { if (tempBitmap != null) { tempBitmap.recycle(); } if (whiteArrow == null) { whiteArrow = new BitmapDrawable(getResources(), UnscaledBitmapLoader.decodeResource(getResources(), au.org.intersect.faims.android.R.drawable.white_arrow)); } if (greyArrow == null) { greyArrow = new BitmapDrawable(getResources(), UnscaledBitmapLoader.decodeResource(getResources(), au.org.intersect.faims.android.R.drawable.grey_arrow)); } this.tempBitmap = BitmapUtil.rotateBitmap(pathValid ? whiteArrow.getBitmap() : greyArrow.getBitmap(), pathBearing - pathHeading); direction_indicator.setIcon(new BitmapDrawable(getResources(), tempBitmap)); } else { direction_indicator.setVisible(false); } return true; }
From source file:org.videolan.vlc.gui.MyFragment.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); if (menu == null) return false; Fragment current = getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder); MenuItem item; // Disable the sort option if we can't use it on the current fragment. if (current == null || !(current instanceof ISortable)) { item = menu.findItem(R.id.ml_menu_sortby); if (item == null) return false; item.setEnabled(false);/*w w w .j a v a 2 s .co m*/ item.setVisible(false); } else { ISortable sortable = (ISortable) current; item = menu.findItem(R.id.ml_menu_sortby); if (item == null) return false; item.setEnabled(true); item.setVisible(true); item = menu.findItem(R.id.ml_menu_sortby_name); if (sortable.sortDirection(VideoListAdapter.SORT_BY_TITLE) == 1) item.setTitle(R.string.sortby_name_desc); //item.setTitle(R.string.sortby_name_desc); else item.setTitle(R.string.sortby_name); item = menu.findItem(R.id.ml_menu_sortby_length); if (sortable.sortDirection(VideoListAdapter.SORT_BY_LENGTH) == 1) item.setTitle(R.string.sortby_length_desc); else item.setTitle(R.string.sortby_length); item = menu.findItem(R.id.ml_menu_sortby_date); if (sortable.sortDirection(VideoListAdapter.SORT_BY_DATE) == 1) item.setTitle(R.string.sortby_date_desc); else item.setTitle(R.string.sortby_date); } boolean networkSave = current instanceof NetworkBrowserFragment && !((NetworkBrowserFragment) current).isRootDirectory(); if (networkSave) { item = menu.findItem(R.id.ml_menu_save); item.setVisible(true); String mrl = ((BaseBrowserFragment) current).mMrl; item.setIcon( MediaDatabase.getInstance().networkFavExists(Uri.parse(mrl)) ? R.drawable.ic_menu_bookmark_w : R.drawable.ic_menu_bookmark_outline_w); } else menu.findItem(R.id.ml_menu_save).setVisible(false); if (current instanceof MRLPanelFragment) menu.findItem(R.id.ml_menu_clean).setVisible(!((MRLPanelFragment) current).isEmpty()); boolean showLast = current instanceof AudioBrowserFragment || (current instanceof VideoGridFragment && mSettings.getString(PreferencesActivity.VIDEO_LAST, null) != null); menu.findItem(R.id.ml_menu_last_playlist).setVisible(showLast); return true; }
From source file:com.android.contacts.quickcontact.QuickContactActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { if (mContactData != null) { final MenuItem starredMenuItem = menu.findItem(R.id.menu_star); ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, mContactData.isDirectoryEntry(), mContactData.isUserProfile(), mContactData.getStarred()); // Configure edit MenuItem final MenuItem editMenuItem = menu.findItem(R.id.menu_edit); editMenuItem.setVisible(true);/*www .j ava 2 s . c om*/ if (DirectoryContactUtil.isDirectoryContact(mContactData) || InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) { editMenuItem.setIcon(R.drawable.ic_person_add_tinted_24dp); editMenuItem.setTitle(R.string.menu_add_contact); } else if (isContactEditable()) { editMenuItem.setIcon(R.drawable.ic_create_24dp); editMenuItem.setTitle(R.string.menu_editContact); } else { editMenuItem.setVisible(false); } final MenuItem deleteMenuItem = menu.findItem(R.id.menu_delete); deleteMenuItem.setVisible(isContactEditable() && !mContactData.isUserProfile()); final MenuItem shareMenuItem = menu.findItem(R.id.menu_share); shareMenuItem.setVisible(isContactShareable()); final MenuItem shortcutMenuItem = menu.findItem(R.id.menu_create_contact_shortcut); shortcutMenuItem.setVisible(isShortcutCreatable()); final MenuItem helpMenu = menu.findItem(R.id.menu_help); helpMenu.setVisible(HelpUtils.isHelpAndFeedbackAvailable()); return true; } return false; }
From source file:org.uguess.android.sysinfo.SiragonManager.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { MenuItem mi = menu.add(Menu.NONE, MI_REFRESH, Menu.NONE, R.string.refresh); mi.setIcon(android.R.drawable.ic_menu_rotate); Util.setShowAsAction(mi, MenuItem.SHOW_AS_ACTION_IF_ROOM); /*mi = menu.add( Menu.NONE, MI_ABOUT, Menu.NONE, R.string.about ); mi.setIcon( android.R.drawable.ic_menu_info_details ); Util.setShowAsAction( mi, MenuItem.SHOW_AS_ACTION_NEVER ); /*from w w w. ja va 2 s . c o m*/ mi = menu.add( Menu.NONE, MI_HELP, Menu.NONE, R.string.help ); mi.setIcon( android.R.drawable.ic_menu_help ); Util.setShowAsAction( mi, MenuItem.SHOW_AS_ACTION_NEVER );*/ mi = menu.add(Menu.NONE, MI_PREFERENCE, Menu.NONE, R.string.preference); mi.setIcon(android.R.drawable.ic_menu_preferences); Util.setShowAsAction(mi, MenuItem.SHOW_AS_ACTION_NEVER); mi = menu.add(Menu.NONE, MI_EXIT, Menu.NONE, R.string.exit); mi.setIcon(android.R.drawable.ic_menu_close_clear_cancel); Util.setShowAsAction(mi, MenuItem.SHOW_AS_ACTION_NEVER); }