List of usage examples for android.view MenuItem setIcon
public MenuItem setIcon(@DrawableRes int iconRes);
From source file:com.lauszus.launchpadflightcontrollerandroid.app.LaunchPadFlightControllerActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { if (D)//from w w w . j a v a 2s . com Log.d(TAG, "onPrepareOptionsMenu"); MenuItem menuItem = menu.findItem(R.id.action_connect); // Find item if (mChatService != null && mChatService.getState() == BluetoothChatService.STATE_CONNECTED) menuItem.setIcon(R.drawable.device_access_bluetooth_connected); else menuItem.setIcon(R.drawable.device_access_bluetooth); return true; }
From source file:com.he5ed.lib.cloudprovider.picker.CloudPickerActivity.java
/** * @hide// w w w . j a v a 2 s. c om */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cp_activity_picker); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); // lock right drawer from been swiped open drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.END); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); navigationView.setItemIconTintList(null); // remove the auto grey tint to keep icon color Menu menu = navigationView.getMenu(); CloudProvider cloudProvider = CloudProvider.getInstance(this); // check whether individual account is assigned String accountId = getIntent().getStringExtra(EXTRA_PICK_ACCOUNT_ID); if (!TextUtils.isEmpty(accountId)) { mAccounts = new CloudAccount[1]; mAccounts[0] = cloudProvider.getAccountById(accountId); } else { mAccounts = cloudProvider.getCloudAccounts(); } // populate navigation menu for (int i = 0; i < mAccounts.length; i++) { CloudAccount account = mAccounts[i]; MenuItem item = menu.add(0, i, 0, account.getUser().email); // use cloud API class reflection try { Class clazz = Class.forName(account.api); Field iconResource = clazz.getField("ICON_RESOURCE"); item.setIcon(iconResource.getInt(null)); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); item.setIcon(R.drawable.ic_cloud_black_24dp); } catch (IllegalAccessException e) { e.printStackTrace(); } item.setCheckable(true); } mFragmentManager = getSupportFragmentManager(); mItemFragment = (ItemFragment) mFragmentManager.findFragmentById(R.id.right_drawer_view); if (mItemFragment == null) { mItemFragment = new ItemFragment(); mFragmentManager.beginTransaction().add(R.id.right_drawer_view, mItemFragment).commit(); } mProgressBar = (ProgressBar) findViewById(R.id.progress_bar); mErrorView = (LinearLayout) findViewById(R.id.error_view); if (savedInstanceState != null) { switch (savedInstanceState.getInt("empty_view_visibility")) { case View.VISIBLE: mErrorView.setVisibility(View.VISIBLE); ImageView icon = (ImageView) mErrorView.findViewById(R.id.empty_icon_image_view); TextView title = (TextView) mErrorView.findViewById(R.id.empty_title_text_view); TextView detail = (TextView) mErrorView.findViewById(R.id.empty_detail_text_view); Bitmap bitmap = savedInstanceState.getParcelable("icon_drawable"); icon.setImageBitmap(bitmap); title.setText(savedInstanceState.getCharSequence("title_text")); detail.setText(savedInstanceState.getCharSequence("detail_text")); break; case View.INVISIBLE: mErrorView.setVisibility(View.INVISIBLE); break; case View.GONE: mErrorView.setVisibility(View.GONE); break; } } else { // open drawer on first load drawer.openDrawer(GravityCompat.START); } }
From source file:com.flowzr.activity.BlotterFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); MenuItem item = menu.findItem(R.id.action_filter); if (item != null) { //ex templates item.setIcon(blotterFilter.isEmpty() ? R.drawable.ic_menu_filter_off : R.drawable.ic_menu_filter_on); }//www . ja v a 2 s .c om String title = blotterFilter.getTitle(); if (title != null) { getActivity().setTitle(title); } }
From source file:fr.pasteque.client.Configure.java
@Override public boolean onCreateOptionsMenu(Menu menu) { int i = 0;// w w w .j av a 2 s .c o m MenuItem imp = menu.add(Menu.NONE, MENU_IMPORT_ID, i++, this.getString(R.string.menu_cfg_import)); imp.setIcon(android.R.drawable.ic_menu_revert); MenuItem exp = menu.add(Menu.NONE, MENU_EXPORT_ID, i++, this.getString(R.string.menu_cfg_export)); exp.setIcon(android.R.drawable.ic_menu_edit); MenuItem dbg = menu.add(Menu.NONE, MENU_DEBUG_ID, i, this.getString(R.string.menu_cfg_debug)); dbg.setIcon(android.R.drawable.ic_menu_report_image); return true; }
From source file:com.dycode.jepretstory.mediachooser.activity.HomeFragmentActivity.java
private void setCurrentMode(MediaType mode) { currentMediaMode = mode;//from w w w. j av a 2s .c o m if (currentMediaMode == MediaType.IMAGE) { if (mMenu != null) { MenuItem item = mMenu.findItem(R.id.menuCamera); item.setIcon(R.drawable.selector_camera_button); item.setTitle(getString(R.string.image)); } getActionBar().setTitle(getString(R.string.image)); } else { if (mMenu != null) { MenuItem item = mMenu.findItem(R.id.menuCamera); item.setIcon(R.drawable.selector_video_button); item.setTitle(getString(R.string.video)); } getActionBar().setTitle(getString(R.string.video)); } }
From source file:org.tomasdavid.vehicleroutingproblem.fragments.VrpFragment.java
/** * {@inheritDoc}/*ww w. j a va2 s .c o m*/ */ @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_run) { // according to solver task status change play/ stop icon, start or stop solver vrpSolverTask.cancelToast(); if (vrpSolverTask.isRunning()) { vrpSolverTask.stopTask(); item.setIcon(R.drawable.ic_play_arrow_white_24dp); } else { item.setIcon(R.drawable.ic_stop_white_24dp); if (vrpSolverTask.getStatus() != Status.PENDING) { vrpSolverTask = new VrpSolverTask(this, timeLimitInSeconds, algorithm); } vrpSolverTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, vrs); if (progressBarTask.getStatus() != Status.PENDING) { progressBarTask = new ProgressBarTask(this); } progressBarTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, timeLimitInSeconds); } return true; } else if (id == R.id.action_about) { AboutAppDialog aad = new AboutAppDialog(); aad.show(getActivity().getSupportFragmentManager(), null); return true; } else if (id == R.id.action_legend) { LegendDialog aad = new LegendDialog(); aad.show(getActivity().getSupportFragmentManager(), null); return true; } return super.onOptionsItemSelected(item); }
From source file:org.mariotaku.twidere.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);/* w w w. ja v a2 s . c om*/ int icon = R.drawable.ic_menu_tweet, title = R.string.compose; if (mViewPager != null && mAdapter != null) { final int position = mViewPager.getCurrentItem(); final TabSpec tab = mAdapter.getTab(position); if (mShowAccountsTab && tab.position == Integer.MAX_VALUE) { icon = R.drawable.ic_menu_add; title = R.string.add_account; } else { title = R.string.compose; switch (tab.position) { case TAB_POSITION_MESSAGES: icon = R.drawable.ic_menu_compose; break; default: 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:org.mariotaku.twidere.fragment.support.UserListFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { final ParcelableUserList userList = mUserList; setMenuItemAvailability(menu, MENU_INFO, userList != null); menu.removeGroup(MENU_GROUP_USER_LIST_EXTENSION); if (userList != null) { final boolean isMyList = userList.user_id == userList.account_id; final boolean isFollowing = userList.is_following; setMenuItemAvailability(menu, MENU_EDIT, isMyList); setMenuItemAvailability(menu, MENU_FOLLOW, !isMyList); setMenuItemAvailability(menu, MENU_ADD, isMyList); setMenuItemAvailability(menu, MENU_DELETE, isMyList); final MenuItem followItem = menu.findItem(MENU_FOLLOW); if (isFollowing) { followItem.setIcon(R.drawable.ic_action_cancel); followItem.setTitle(R.string.unsubscribe); } else {//from ww w.j av a 2s . c o m followItem.setIcon(R.drawable.ic_action_add); followItem.setTitle(R.string.subscribe); } final Intent extensionsIntent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER_LIST); extensionsIntent.setExtrasClassLoader(getActivity().getClassLoader()); extensionsIntent.putExtra(EXTRA_USER_LIST, userList); addIntentToMenu(getActivity(), menu, extensionsIntent, MENU_GROUP_USER_LIST_EXTENSION); } else { setMenuItemAvailability(menu, MENU_EDIT, false); setMenuItemAvailability(menu, MENU_FOLLOW, false); setMenuItemAvailability(menu, MENU_ADD, false); setMenuItemAvailability(menu, MENU_DELETE, false); } }
From source file:de.tap.easy_xkcd.fragments.comics.ComicFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { //Update the favorites icon MenuItem fav = menu.findItem(R.id.action_favorite); if (databaseManager.checkFavorite(lastComicNumber)) { fav.setIcon(R.drawable.ic_action_favorite); fav.setTitle(R.string.action_favorite_remove); } else {/* w w w. j ava 2 s .co m*/ fav.setIcon(R.drawable.ic_favorite_outline); fav.setTitle(R.string.action_favorite); } //If the FAB is visible, hide the random comic menu item if (((MainActivity) getActivity()).getFab().getVisibility() == View.GONE) { menu.findItem(R.id.action_random).setVisible(true); } else { menu.findItem(R.id.action_random).setVisible(false); } menu.findItem(R.id.action_alt).setVisible(prefHelper.showAltTip()); if (Arrays.binarySearch(getResources().getIntArray(R.array.interactive_comics), lastComicNumber) >= 0) menu.findItem(R.id.action_browser).setVisible(true); }