List of usage examples for android.view MenuItem setIcon
public MenuItem setIcon(@DrawableRes int iconRes);
From source file:de.vanita5.twittnuker.activity.support.HomeActivity.java
@Override public boolean onPrepareOptionsMenu(final Menu menu) { if (mViewPager == null || mPagerAdapter == null) return false; final boolean useBottomActionItems = FlymeUtils.hasSmartBar() && isBottomComposeButton(); setMenuItemAvailability(menu, MENU_ACTIONS, useBottomActionItems); setMenuItemAvailability(menu, MENU_PROGRESS, useBottomActionItems); if (useBottomActionItems) { final int icon, title; final int position = mViewPager.getCurrentItem(); final SupportTabSpec tab = mPagerAdapter.getTab(position); if (tab == null) { title = R.string.compose;//from w w w .ja va2s .c o m icon = R.drawable.ic_iconic_action_compose; } else { if (classEquals(DirectMessagesFragment.class, tab.cls)) { icon = R.drawable.ic_iconic_action_new_message; title = R.string.new_direct_message; } else if (classEquals(TrendsSuggectionsFragment.class, tab.cls)) { icon = R.drawable.ic_iconic_action_search; title = android.R.string.search_go; } else { icon = R.drawable.ic_iconic_action_compose; title = R.string.compose; } } final ActionBar actionBar = getActionBar(); final MenuItem actionsItem = menu.findItem(MENU_ACTIONS); if (actionBar != null) { actionsItem.setIcon(actionBar.getThemedContext().getResources().getDrawable(icon)); } actionsItem.setTitle(title); } 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 . ja v a 2 s . c om*/ 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:com.gelakinetic.selfr.CameraActivity.java
/** * If the flash is on, turn it off, and vice versa. Front facing cameras without hardware * flash will briefly display a max brightness, pure white screen * * @param item The menu item to change the icon in order to reflect the current state *//*from ww w. j a va2 s .c om*/ private void switchFlash(MenuItem item) { /* Change the flash mode & icon */ switch (mFlashMode) { case Camera.Parameters.FLASH_MODE_OFF: { mFlashMode = Camera.Parameters.FLASH_MODE_ON; item.setIcon(R.drawable.ic_flash_on_white_24dp); break; } case Camera.Parameters.FLASH_MODE_ON: { mFlashMode = Camera.Parameters.FLASH_MODE_OFF; item.setIcon(R.drawable.ic_flash_off_white_24dp); break; } } /* Then set the parameter */ setFlashParameter(); /* Hide the UI */ delayedHide(2500); }
From source file:org.ozonecity.gpslogger2.GpsMainActivity.java
private void enableDisableMenuItems() { OnWaitingForLocation(Session.isWaitingForLocation()); SetBulbStatus(Session.isStarted());/*from w w w . j a va 2 s . c o m*/ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarBottom); MenuItem mnuAnnotate = toolbar.getMenu().findItem(R.id.mnuAnnotate); MenuItem mnuOnePoint = toolbar.getMenu().findItem(R.id.mnuOnePoint); MenuItem mnuAutoSendNow = toolbar.getMenu().findItem(R.id.mnuAutoSendNow); if (mnuOnePoint != null) { mnuOnePoint.setEnabled(!Session.isStarted()); mnuOnePoint.setIcon((Session.isStarted() ? R.drawable.singlepoint_disabled : R.drawable.singlepoint)); } if (mnuAutoSendNow != null) { mnuAutoSendNow.setEnabled(Session.isStarted()); } if (mnuAnnotate != null) { if (!AppSettings.shouldLogToGpx() && !AppSettings.shouldLogToKml() && !AppSettings.shouldLogToCustomUrl()) { mnuAnnotate.setIcon(R.drawable.annotate2_disabled); mnuAnnotate.setEnabled(false); } else { if (Session.isAnnotationMarked()) { mnuAnnotate.setIcon(R.drawable.annotate2_active); } else { mnuAnnotate.setIcon(R.drawable.annotate2); } } } }
From source file:com.dwdesign.tweetings.activity.HomeActivity.java
@Override public boolean onPrepareOptionsMenu(final Menu menu) { final boolean bottom_actions = mPreferences.getBoolean(PREFERENCE_KEY_COMPOSE_BUTTON, false); final boolean leftside_compose_button = mPreferences.getBoolean(PREFERENCE_KEY_LEFTSIDE_COMPOSE_BUTTON, false);/*from w w w . j a va2s . c o m*/ int icon = R.drawable.ic_menu_tweet, title = R.string.compose; if (mViewPager != null && mAdapter != null) { final int position = mViewPager.getCurrentItem(); int messagesPosition = TAB_POSITION_MESSAGES; if (mShowHomeTab == false) { messagesPosition--; } if (mShowMentionsTab == false) { messagesPosition--; } if (position == mAdapter.getCount() - 1 && mShowAccountsTab) { icon = R.drawable.ic_menu_add; title = R.string.add_account; } else { title = R.string.compose; if (mShowMessagesTab && position == messagesPosition) { icon = R.drawable.ic_menu_compose; } else { icon = R.drawable.ic_menu_tweet; } } final MenuItem composeItem = menu.findItem(MENU_COMPOSE); if (composeItem != null) { composeItem.setIcon(icon); composeItem.setTitle(title); composeItem.setVisible(!bottom_actions && mViewPager.getVisibility() == View.VISIBLE); } if (mComposeButton != null) { mComposeButton.setImageResource(icon); mComposeButton.setVisibility( bottom_actions && mViewPager.getVisibility() == View.VISIBLE ? View.VISIBLE : View.GONE); if (bottom_actions) { final FrameLayout.LayoutParams compose_lp = (FrameLayout.LayoutParams) mComposeButton .getLayoutParams(); compose_lp.gravity = Gravity.BOTTOM | (leftside_compose_button ? Gravity.LEFT : Gravity.RIGHT); mComposeButton.setLayoutParams(compose_lp); } } } return super.onPrepareOptionsMenu(menu); }
From source file:tv.acfun.a63.ArticleActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_comment: if (mArticle != null) { CommentsActivity.start(ArticleActivity.this, mArticle.id); }/*from w w w. j a va 2 s . c om*/ return true; case R.id.menu_item_fav_action: if (isFaved) { db.deleteFav(aid); AcApp.showToast("??"); isFaved = false; item.setIcon(R.drawable.rating_favorite); } else { if (mArticle != null) { db.addFav(mArticle); isFaved = true; item.setIcon(R.drawable.rating_favorite_p); AcApp.showToast("??"); } } return true; case android.R.id.button1: if (mSizeChooser == null) { final int checked = AcApp.getConfig().getInt("text_size", 0); mSizeChooser = new AlertDialog.Builder(this).setCancelable(true).setTitle(R.string.font_size) .setSingleChoiceItems(R.array.title_sizes, checked, new DialogInterface.OnClickListener() { int lastSelected = checked; @Override public void onClick(DialogInterface dialog, int which) { if (lastSelected != which) { AcApp.putInt("text_size", which); setTextZoom(which); dialog.dismiss(); lastSelected = which; } } }).create(); } mSizeChooser.show(); return true; } return super.onOptionsItemSelected(item); }
From source file:de.grobox.liberario.DirectionsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_navigation_expand: View productsScrollView = mView.findViewById(R.id.productsScrollView); if (productsScrollView.getVisibility() == View.GONE) { productsScrollView.setVisibility(View.VISIBLE); item.setIcon(R.drawable.ic_action_navigation_collapse); Preferences.setPref(getActivity(), Preferences.SHOW_ADV_DIRECTIONS, true); } else {//from w ww . j a va 2 s .co m productsScrollView.setVisibility(View.GONE); item.setIcon(R.drawable.ic_action_navigation_expand); Preferences.setPref(getActivity(), Preferences.SHOW_ADV_DIRECTIONS, false); } return true; case R.id.action_swap_locations: // get location icons to be swapped as well final ImageView fromStatusButton = (ImageView) mView.findViewById(R.id.fromStatusButton); final Drawable icon = ((ImageView) mView.findViewById(R.id.toStatusButton)).getDrawable(); // swap location objects and drawables Location tmp = getLocation(FavLocation.LOC_TYPE.TO); if (!mGpsPressed) { setLocation(getLocation(FavLocation.LOC_TYPE.FROM), FavLocation.LOC_TYPE.TO, fromStatusButton.getDrawable()); } else { // GPS currently only supports from location, so don't swap it clearLocation(FavLocation.LOC_TYPE.TO); } setLocation(tmp, FavLocation.LOC_TYPE.FROM, icon); return true; default: return super.onOptionsItemSelected(item); } }
From source file:es.usc.citius.servando.calendula.HomePagerActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_calendar: startActivity(new Intent(this, CalendarActivity.class)); return true; case R.id.action_expand: final boolean expanded = ((DailyAgendaFragment) getViewPagerFragment(0)).isExpanded(); appBarLayout.setExpanded(expanded); boolean delay = appBarLayoutExpanded && !expanded || !appBarLayoutExpanded && expanded; new Handler().postDelayed(new Runnable() { @Override// w w w .j a v a 2 s. co m public void run() { ((DailyAgendaFragment) getViewPagerFragment(0)).toggleViewMode(); } }, delay ? 500 : 0); item.setIcon(expanded ? icAgendaMore : icAgendaLess); return true; case R.id.action_schedules_help: launchActivity(new Intent(this, SchedulesHelpActivity.class)); } return super.onOptionsItemSelected(item); }
From source file:com.wanikani.androidnotifier.WebReviewActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem mi; int i;//from w w w . j a va 2 s . com for (i = 0; i < menu.size(); i++) { mi = menu.getItem(i); if (mi.getItemId() == R.id.em_fonts) { mi.setVisible(keyboard.canOverrideFonts()); mi.setIcon(keyboard.getOverrideFonts() ? R.drawable.ic_menu_font_enabled : R.drawable.ic_menu_font); } } return true; }
From source file:com.gelakinetic.selfr.CameraActivity.java
/** * If the rear camera is being used, switch to the front camera, and vice versa * This blocks the UI thread, which is generally bad, but nothing is happening anyway, * and swapping camera resources on a separate thread is a recipe for crashes * * @param item The menu item to change the icon in order to reflect the current state *///from w w w .ja va 2 s .c om private void switchCamera(MenuItem item) { /* Switch from one camera type to the other, adjust the icon as necessary */ switch (mCameraType) { case Camera.CameraInfo.CAMERA_FACING_FRONT: { mCameraType = Camera.CameraInfo.CAMERA_FACING_BACK; item.setIcon(R.drawable.ic_camera_rear_white_24dp); break; } case Camera.CameraInfo.CAMERA_FACING_BACK: { mCameraType = Camera.CameraInfo.CAMERA_FACING_FRONT; item.setIcon(R.drawable.ic_camera_front_white_24dp); break; } } /* Remove old camera & preview */ if (mCameraPreview != null) { mContentView.removeView(mCameraPreview); } /* Release current camera resources */ if (mCamera != null) { mCamera.stopPreview(); mCamera.release(); mCamera = null; } /* Get a new camera instance */ mCamera = getCameraInstance(mCameraType); /* Set the preview with the new Camera object */ if (mCamera != null) { mCameraPreview = new CameraPreview(getApplicationContext(), mCamera); mContentView.addView(mCameraPreview); /* Make sure the flash parameter is correct */ setFlashParameter(); } /* Hide the UI */ delayedHide(2500); }