List of usage examples for android.view MenuItem setIcon
public MenuItem setIcon(@DrawableRes int iconRes);
From source file:de.Maxr1998.xposed.maxlock.ui.settings.appslist.AppListFragment.java
private void filterIcon(MenuItem item) { if (prefs == null) { return;// ww w. ja v a 2 s . c o m } String filter = prefs.getString("app_list_filter", ""); Drawable icon = getResources().getDrawable(R.drawable.ic_apps_white_24dp); if (filter == null) { return; } switch (filter) { case "@*activated*": icon = getResources().getDrawable(R.drawable.ic_check_white_24dp); break; case "@*deactivated*": icon = getResources().getDrawable(R.drawable.ic_close_white_24dp); break; } item.setIcon(icon); }
From source file:com.antew.redditinpictures.library.ui.RedditFragmentActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main, menu); MenuItem item;/*from w ww .j a va2 s. co m*/ // Put a checkmark by the currently selected Category + Age combination switch (mCategory) { case CONTROVERSIAL: switch (mAge) { case ALL_TIME: item = menu.findItem(R.id.category_controversial_all_time); item.setChecked(true); break; case THIS_HOUR: item = menu.findItem(R.id.category_controversial_hour); item.setChecked(true); break; case THIS_MONTH: item = menu.findItem(R.id.category_controversial_month); item.setChecked(true); break; case THIS_WEEK: item = menu.findItem(R.id.category_controversial_week); item.setChecked(true); break; case THIS_YEAR: item = menu.findItem(R.id.category_controversial_year); item.setChecked(true); break; case TODAY: item = menu.findItem(R.id.category_controversial_today); item.setChecked(true); break; } break; case HOT: menu.findItem(R.id.category_hot).setChecked(true); break; case NEW: menu.findItem(R.id.category_new).setChecked(true); break; case RISING: menu.findItem(R.id.category_rising).setChecked(true); break; case TOP: switch (mAge) { case ALL_TIME: item = menu.findItem(R.id.category_top_all_time); item.setChecked(true); break; case THIS_HOUR: item = menu.findItem(R.id.category_top_hour); item.setChecked(true); break; case THIS_MONTH: item = menu.findItem(R.id.category_top_month); item.setChecked(true); break; case THIS_WEEK: item = menu.findItem(R.id.category_top_week); item.setChecked(true); break; case THIS_YEAR: item = menu.findItem(R.id.category_top_year); item.setChecked(true); break; case TODAY: item = menu.findItem(R.id.category_top_today); item.setChecked(true); break; } break; default: mCategory = Category.HOT; mAge = Age.TODAY; menu.findItem(R.id.category_hot).setChecked(true); break; } MenuItem loginMenuItem = menu.findItem(R.id.login); // If the user is logged in, update the Logout menu item to "Log out <username>" if (RedditLoginInformation.isLoggedIn()) { loginMenuItem.setTitle(getString(R.string.log_out_) + RedditLoginInformation.getUsername()); loginMenuItem.setIcon(R.drawable.ic_action_exit_dark); } else { loginMenuItem.setTitle(R.string.log_on); loginMenuItem.setIcon(R.drawable.ic_action_key_dark); } MenuItem activeViewMenuItem = menu.findItem(R.id.change_view); switch (mActiveViewType) { case LIST: activeViewMenuItem.setIcon(R.drawable.ic_action_tiles_small_dark); activeViewMenuItem.setTitle(R.string.view_as_grid); break; case GRID: activeViewMenuItem.setIcon(R.drawable.ic_action_list_2_dark); activeViewMenuItem.setTitle(R.string.view_as_list); break; default: break; } return true; }
From source file:org.dharmaseed.android.PlayTalkActivity.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(); switch (id) { case R.id.play_talk_action_toggle_starred: if (dbManager.isStarred(DBManager.C.TalkStars.TABLE_NAME, talkID)) { dbManager.removeStar(DBManager.C.TalkStars.TABLE_NAME, talkID); item.setIcon(getResources().getIdentifier("btn_star_big_off", "drawable", "android")); } else {//from w w w . ja v a 2 s. c o m dbManager.addStar(DBManager.C.TalkStars.TABLE_NAME, talkID); item.setIcon(getResources().getIdentifier("btn_star_big_on", "drawable", "android")); } // Notify main activity to update its data LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("updateDisplayedData")); return true; } return super.onOptionsItemSelected(item); }
From source file:com.velli.passwordmanager.FragmentPasswordDetails.java
@Override public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); final MenuItem starred = menu.findItem(R.id.menu_starred); final MenuItem passwordVisibility = menu.findItem(R.id.menu_view_hide_password); if (starred != null) { if (mEntry == null) { starred.setIcon(R.drawable.ic_action_starred_off); } else {/* w w w .j a v a 2 s . co m*/ final int res = mEntry.isStarred() ? R.drawable.ic_action_starred_on : R.drawable.ic_action_starred_off; starred.setIcon(res); } } if (passwordVisibility != null) { passwordVisibility.setIcon(mShowingPassword ? R.drawable.ic_action_view : R.drawable.ic_action_hide); passwordVisibility.setTitle( mShowingPassword ? R.string.menu_action_view_password : R.string.menu_action_hide_password); } }
From source file:com.sj.android.appusage.activities.UsageListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub switch (item.getItemId()) { case R.id.filter_menu: if (UsageSharedPrefernceHelper.isFilterMode(mActivity)) { UsageSharedPrefernceHelper.setFilterMode(mActivity, false); item.setIcon(R.drawable.ic_filter_list_white_24dp); item.setTitle(R.string.string_filter); mIsFilteredMap = false;//from w ww .j a v a2s . c o m setmUsageAppData(mUsageAppData); } else { if (UsageSharedPrefernceHelper.getSelectedApplicationForFiltering(mActivity) == null || UsageSharedPrefernceHelper.getSelectedApplicationForFiltering(mActivity).size() == 0) { Toast.makeText(mActivity, R.string.string_filter_menu_enable_message, Toast.LENGTH_LONG).show(); } else { UsageSharedPrefernceHelper.setFilterMode(mActivity, true); item.setIcon(R.drawable.ic_select_all_white_24dp); item.setTitle(R.string.string_all); mIsFilteredMap = true; setmUsageAppData(mUsageAppData); } } break; } return super.onOptionsItemSelected(item); }
From source file:com.timekeeping.app.activities.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); MenuItem menuShare = menu.findItem(R.id.action_share_app); //Getting the actionprovider associated with the menu item whose id is share. android.support.v7.widget.ShareActionProvider provider = (android.support.v7.widget.ShareActionProvider) MenuItemCompat .getActionProvider(menuShare); //Setting a share intent. String subject = getString(R.string.lbl_share_app_title, getString(R.string.application_name)); String text = getString(R.string.lbl_share_app_content, getString(R.string.tray_info)); provider.setShareIntent(Utils.getDefaultShareIntent(provider, subject, text)); MenuItem viewMi = menu.findItem(R.id.action_view_types); viewMi.setIcon( Prefs.getInstance(getApplication()).isLastAListView() ? R.drawable.ic_grid : R.drawable.ic_list); return true;/*from ww w.j a va2 s. c o m*/ }
From source file:net.reichholf.dreamdroid.fragment.ServiceListFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { if (getMultiPaneHandler().isDrawerOpen()) return;/*from w ww. j a v a 2 s . co m*/ MenuItem setDefault = menu.findItem(R.id.menu_default); String defaultReference = DreamDroid.getCurrentProfile().getDefaultRef(); setDefault.setVisible(true); if (defaultReference != null) { if (defaultReference.equals(mDetailReference)) { setDefault.setIcon(R.drawable.ic_action_fav); setDefault.setTitle(R.string.reset_default); } else { setDefault.setIcon(R.drawable.ic_action_nofav); setDefault.setTitle(R.string.set_default); } } }
From source file:com.google.android.cameraview.demo.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.aspect_ratio: if (mCameraView != null) { final Set<AspectRatio> ratios = mCameraView.getSupportedAspectRatios(); final AspectRatio currentRatio = mCameraView.getAspectRatio(); AspectRatioFragment.newInstance(ratios, currentRatio).show(getSupportFragmentManager(), FRAGMENT_DIALOG);//w ww . j a v a 2 s.c o m } break; case R.id.switch_flash: if (mCameraView != null) { mCurrentFlash = (mCurrentFlash + 1) % FLASH_OPTIONS.length; item.setTitle(FLASH_TITLES[mCurrentFlash]); item.setIcon(FLASH_ICONS[mCurrentFlash]); mCameraView.setFlash(FLASH_OPTIONS[mCurrentFlash]); } break; case R.id.switch_camera: if (mCameraView != null) { int facing = mCameraView.getFacing(); mCameraView.setFacing( facing == CameraView.FACING_FRONT ? CameraView.FACING_BACK : CameraView.FACING_FRONT); } break; } return false; }
From source file:de.enlightened.peris.PostsFragment.java
@SuppressLint("NewApi") @Override/* w w w .j av a2 s. c o m*/ public final void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { inflater.inflate(R.menu.post_n_page, menu); final MenuItem itemRefresh = menu.findItem(R.id.menu_refresh); final MenuItem itemNew = menu.findItem(R.id.menu_newpost); if (ThemeSetter.getForegroundDark(this.background)) { itemRefresh.setIcon(R.drawable.ic_action_refresh_dark); itemNew.setIcon(R.drawable.ic_action_new_dark); } if (this.totalPages == null) { this.totalPages = 0; } final MenuItem browserItem = menu.findItem(R.id.posts_menu_browser); final MenuItem shareItem = menu.findItem(R.id.posts_menu_share); if (this.shareURL != null) { browserItem.setVisible(false); shareItem.setVisible(false); } else { browserItem.setVisible(true); shareItem.setVisible(true); } super.onCreateOptionsMenu(menu, inflater); }
From source file:de.kaidev.vertretungsplanapp.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuItem info = menu.add(0, 99, 0, "Info").setIcon(R.drawable.ic_info_outline_white_48dp); info.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); int i = mPager != null ? mPager.getCurrentItem() : 0; String s = i == 0 ? heute.getInfo() : morgen.getInfo(); if (!s.isEmpty()) { for (String t : s.split("\n")) { if (!t.startsWith("Abwesende") && !t.startsWith("Blockierte")) { info.setIcon(R.drawable.ic_info_white_48dp); break; }// w ww. j a va 2 s.co m } } return super.onCreateOptionsMenu(menu); }