Example usage for android.view MenuItem setIcon

List of usage examples for android.view MenuItem setIcon

Introduction

In this page you can find the example usage for android.view MenuItem setIcon.

Prototype

public MenuItem setIcon(@DrawableRes int iconRes);

Source Link

Document

Change the icon associated with this item.

Usage

From source file:org.proninyaroslav.libretorrent.fragments.DetailTorrentFragment.java

private void prepareOptionsMenu(Menu menu) {
    MenuItem pauseResume = menu.findItem(R.id.pause_resume_torrent_menu);

    if (torrent == null || !torrent.isPaused()) {
        pauseResume.setTitle(R.string.pause_torrent);
        if (!Utils.isTwoPane(activity.getApplicationContext())) {
            pauseResume.setIcon(R.drawable.ic_pause_white_24dp);
        }/*from w  w w  . java2 s  .  co  m*/

    } else {
        pauseResume.setTitle(R.string.resume_torrent);
        if (!Utils.isTwoPane(activity.getApplicationContext())) {
            pauseResume.setIcon(R.drawable.ic_play_arrow_white_24dp);
        }
    }
}

From source file:com.androzic.MapFragment.java

@Override
public void onPrepareOptionsMenu(final Menu menu) {
    boolean fixed = map != null && map.isFixed();

    MenuItem follow = menu.findItem(R.id.action_follow);
    if (!fixed || following && map != null && !map.getStrictUnfollow()) {
        follow.setVisible(false);//from   ww w  .j a va 2 s  . c  om
    } else if (following) {
        follow.setIcon(R.drawable.ic_lock_outline_white_24dp);
        follow.setTitle(R.string.action_unfollow);
    } else {
        follow.setVisible(true);
        follow.setIcon(R.drawable.ic_lock_open_white_24dp);
        follow.setTitle(R.string.action_follow);
    }

    menu.findItem(R.id.action_locate).setVisible(!fixed);

    menu.findItem(R.id.action_locating).setChecked(application.isLocating());
    menu.findItem(R.id.action_tracking).setChecked(application.isTracking());

    boolean navigating = application.isNavigating();
    boolean viaRoute = application.isNavigatingViaRoute();

    menu.findItem(R.id.action_stop_navigation).setVisible(navigating);
    menu.findItem(R.id.action_next_nav_point).setVisible(viaRoute);
    menu.findItem(R.id.action_prev_nav_point).setVisible(viaRoute);
    if (viaRoute) {
        menu.findItem(R.id.action_next_nav_point)
                .setEnabled(application.navigationService.hasNextRouteWaypoint());
        menu.findItem(R.id.action_prev_nav_point)
                .setEnabled(application.navigationService.hasPrevRouteWaypoint());
    }
}

From source file:com.peppe130.fireinstaller.activities.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuItem mSettings, mChangelog, mDefaultOptions;

    getMenuInflater().inflate(R.menu.activity_main_menu, menu);

    IconicsDrawable mSettingsIcon = new IconicsDrawable(MainActivity.this).icon(ControlCenter.SETTINGS_ICON)
            .actionBar().color(Color.WHITE).sizeDp(30);

    IconicsDrawable mChangelogIcon = new IconicsDrawable(MainActivity.this).icon(ControlCenter.CHANGELOG_ICON)
            .actionBar().color(Color.WHITE).sizeDp(30);

    IconicsDrawable mDefaultValuesIcon = new IconicsDrawable(MainActivity.this)
            .icon(ControlCenter.DEFAULT_VALUES_ICON).actionBar().color(Color.WHITE).sizeDp(35);

    mSettings = menu.findItem(R.id.settings);
    mSettings.setIcon(mSettingsIcon);

    mChangelog = menu.findItem(R.id.changelog);
    mChangelog.setIcon(mChangelogIcon);/*  w  w w. j  av  a2 s  .  co  m*/

    mDefaultOptions = menu.findItem(R.id.default_values);
    mDefaultOptions.setIcon(mDefaultValuesIcon);

    return true;

}

From source file:com.timekeeping.app.activities.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mDrawerToggle != null && mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }//  w  w  w . j  a va  2s . c o m
    int id = item.getItemId();
    switch (id) {
    case R.id.action_about:
        showDialogFragment(AboutDialogFragment.newInstance(this), null);
        break;
    case R.id.action_view_types:
        Prefs prefs = Prefs.getInstance(getApplication());
        int screenWidth = DeviceUtils.getScreenSize(this, 0).Width;
        if (!prefs.isLastAListView()) {
            //Current is grid, then switch to list.
            mGv.setColumnWidth(screenWidth / 2);
            item.setIcon(R.drawable.ic_grid);
            prefs.setLastAListView(true);
        } else {
            mGv.setColumnWidth(screenWidth / 3);
            item.setIcon(R.drawable.ic_list);
            prefs.setLastAListView(false);
        }
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.hichinaschool.flashcards.anki.CardBrowser.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem item;
    // TODO(flerda@gmail.com): Fix card browser's undo.
    // https://code.google.com/p/ankidroid/issues/detail?id=1561
    /*/*  w ww.  j  ava  2 s .  c om*/
    item = menu.add(Menu.NONE, MENU_UNDO, Menu.NONE, R.string.undo);
    item.setIcon(R.drawable.ic_menu_revert);
    */
    item = menu.add(Menu.NONE, MENU_ADD_NOTE, Menu.NONE, R.string.card_editor_add_card);
    item.setIcon(R.drawable.ic_menu_add);
    // TODO(flerda@gmail.com): Fix card browser fields.
    // https://code.google.com/p/ankidroid/issues/detail?id=1310
    // Currently this is disabled because it is obvious what to do when cards with different models are present in
    // the deck.
    /*
    if (mWholeCollection == false) {
    item = menu.add(Menu.NONE, MENU_FIELD, Menu.NONE, R.string.card_browser_field);
    item.setIcon(R.drawable.ic_menu_add);
    }
    */
    item = menu.add(Menu.NONE, MENU_CHANGE_ORDER, Menu.NONE, R.string.card_browser_change_display_order);
    item.setIcon(R.drawable.ic_menu_sort_by_size);
    item = menu.add(Menu.NONE, MENU_SHOW_MARKED, Menu.NONE, R.string.card_browser_show_marked);
    item.setIcon(R.drawable.ic_menu_star_on);
    item = menu.add(Menu.NONE, MENU_SELECT_SUSPENDED, Menu.NONE, R.string.card_browser_show_suspended);
    item.setIcon(R.drawable.ic_menu_close_clear_cancel);
    item = menu.add(Menu.NONE, MENU_SELECT_TAG, Menu.NONE, R.string.card_browser_search_by_tag);
    item.setIcon(R.drawable.ic_menu_search);
    return true;
}

From source file:org.mariotaku.twidere.fragment.support.UserProfileFragment.java

private void setMenu(final Menu menu) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUser user = mUser;
    final Relationship relationship = mFriendship;
    if (twitter == null || user == null)
        return;//from   w ww. j a  v a 2s.co  m
    final boolean isMyself = user.account_id == user.id;
    final boolean isFollowing = relationship != null && relationship.isSourceFollowingTarget();
    final boolean isProtected = user.is_protected;
    final boolean creatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id);
    final boolean destroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id);
    setMenuItemAvailability(menu, MENU_EDIT, isMyself);
    final MenuItem followItem = menu.findItem(MENU_FOLLOW);
    followItem.setVisible(!isMyself);
    final boolean shouldShowFollowItem = !creatingFriendship && !destroyingFriendship && !isMyself
            && relationship != null;
    followItem.setEnabled(shouldShowFollowItem);
    if (shouldShowFollowItem) {
        followItem.setTitle(
                isFollowing ? R.string.unfollow : isProtected ? R.string.send_follow_request : R.string.follow);
        followItem.setIcon(isFollowing ? R.drawable.ic_iconic_action_cancel : R.drawable.ic_iconic_action_add);
    } else {
        followItem.setTitle(null);
        followItem.setIcon(null);
    }
    if (user.id != user.account_id) {
        setMenuItemAvailability(menu, MENU_BLOCK, mFriendship != null);
        final MenuItem blockItem = menu.findItem(MENU_BLOCK);
        if (mFriendship != null && blockItem != null) {
            final Drawable blockIcon = blockItem.getIcon();
            if (mFriendship.isSourceBlockingTarget()) {
                blockItem.setTitle(R.string.unblock);
                blockIcon.mutate().setColorFilter(ThemeUtils.getUserThemeColor(getActivity()),
                        PorterDuff.Mode.MULTIPLY);
            } else {
                blockItem.setTitle(R.string.block);
                blockIcon.clearColorFilter();
            }
        }
        final boolean is_following_me = mFriendship != null && mFriendship.isTargetFollowingSource();
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, is_following_me);
    } else {
        setMenuItemAvailability(menu, MENU_MENTION, false);
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, false);
        setMenuItemAvailability(menu, MENU_BLOCK, false);
        setMenuItemAvailability(menu, MENU_REPORT_SPAM, false);
    }
    final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER);
    final Bundle extras = new Bundle();
    extras.putParcelable(EXTRA_USER, user);
    intent.putExtras(extras);
    menu.removeGroup(MENU_GROUP_USER_EXTENSION);
    addIntentToMenu(getActivity(), menu, intent, MENU_GROUP_USER_EXTENSION);
}

From source file:com.nttec.everychan.ui.gallery.GalleryActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    this.menu = menu;
    MenuItem itemUpdate = menu.add(Menu.NONE, R.id.menu_update, 1, R.string.menu_update);
    MenuItem itemSave = menu.add(Menu.NONE, R.id.menu_save_attachment, 2, R.string.menu_save_attachment);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        itemUpdate.setIcon(ThemeUtils.getActionbarIcon(getTheme(), getResources(), R.attr.actionRefresh));
        itemSave.setIcon(ThemeUtils.getActionbarIcon(getTheme(), getResources(), R.attr.actionSave));
        CompatibilityImpl.setShowAsActionIfRoom(itemUpdate);
        CompatibilityImpl.setShowAsActionIfRoom(itemSave);
    } else {//from   w w  w.ja  v  a 2s  .c  o  m
        itemUpdate.setIcon(R.drawable.ic_menu_refresh);
        itemSave.setIcon(android.R.drawable.ic_menu_save);
    }
    menu.add(Menu.NONE, R.id.menu_open_external, 3, R.string.menu_open).setIcon(R.drawable.ic_menu_set_as);
    menu.add(Menu.NONE, R.id.menu_share, 4, R.string.menu_share).setIcon(android.R.drawable.ic_menu_share);
    menu.add(Menu.NONE, R.id.menu_share_link, 5, R.string.menu_share_link)
            .setIcon(android.R.drawable.ic_menu_share);
    menu.add(Menu.NONE, R.id.menu_reverse_search, 6, R.string.menu_reverse_search)
            .setIcon(android.R.drawable.ic_menu_search);
    menu.add(Menu.NONE, R.id.menu_open_browser, 7, R.string.menu_open_browser)
            .setIcon(R.drawable.ic_menu_browser);
    updateMenu();

    return true;
}

From source file:de.vanita5.twittnuker.fragment.support.UserProfileFragment.java

private void setMenu(final Menu menu) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUser user = mUser;
    final Relationship relationship = mRelationship;
    if (twitter == null || user == null)
        return;//from www  .  j  av  a2 s .c om
    final int activatedColor = ThemeUtils.getUserThemeColor(getActivity());
    final boolean isMyself = user.account_id == user.id;
    final boolean isFollowing = relationship != null && relationship.isSourceFollowingTarget();
    final boolean isProtected = user.is_protected;
    final boolean creatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id);
    final boolean destroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id);
    setMenuItemAvailability(menu, MENU_EDIT, isMyself);
    final MenuItem followItem = menu.findItem(MENU_FOLLOW);
    followItem.setVisible(!isMyself);
    final boolean shouldShowFollowItem = !creatingFriendship && !destroyingFriendship && !isMyself
            && relationship != null;
    followItem.setEnabled(shouldShowFollowItem);
    if (shouldShowFollowItem) {
        followItem.setTitle(
                isFollowing ? R.string.unfollow : isProtected ? R.string.send_follow_request : R.string.follow);
        followItem.setIcon(isFollowing ? R.drawable.ic_iconic_action_cancel : R.drawable.ic_iconic_action_add);
    } else {
        followItem.setTitle(null);
        followItem.setIcon(null);
    }
    if (user.id != user.account_id && relationship != null) {
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, relationship.canSourceDMTarget());
        setMenuItemAvailability(menu, MENU_BLOCK, true);
        final MenuItem blockItem = menu.findItem(MENU_BLOCK);
        if (blockItem != null) {
            final Drawable blockIcon = blockItem.getIcon();
            if (relationship.isSourceBlockingTarget()) {
                blockItem.setTitle(R.string.unblock);
                blockIcon.mutate();
                blockIcon.setColorFilter(activatedColor, PorterDuff.Mode.SRC_ATOP);
            } else {
                blockItem.setTitle(R.string.block);
                blockIcon.clearColorFilter();
            }
        }
    } else {
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, false);
        setMenuItemAvailability(menu, MENU_BLOCK, false);
        setMenuItemAvailability(menu, MENU_REPORT_SPAM, false);
    }
}

From source file:com.coincide.alphafitness.ui.Fragment_Main.java

@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    inflater.inflate(R.menu.main, menu);
    MenuItem pause = menu.getItem(0);
    Drawable d;//from   w ww  .  j av  a  2  s  .c o m
    if (getActivity().getSharedPreferences("pedometer", Context.MODE_PRIVATE).contains("pauseCount")) { // currently paused
        pause.setTitle(R.string.resume);
        d = getResources().getDrawable(R.drawable.ic_resume);
    } else {
        pause.setTitle(R.string.pause);
        d = getResources().getDrawable(R.drawable.ic_pause);
    }
    d.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
    pause.setIcon(d);
}

From source file:gov.wa.wsdot.android.wsdot.ui.ferries.departures.FerriesRouteSchedulesDayDeparturesActivity.java

private void toggleStar(MenuItem item) {
    Snackbar added_snackbar = Snackbar.make(findViewById(R.id.activity_ferry_sailings), R.string.add_favorite,
            Snackbar.LENGTH_SHORT);/*from  www .  j a va  2  s  . com*/

    Snackbar removed_snackbar = Snackbar.make(findViewById(R.id.activity_ferry_sailings),
            R.string.remove_favorite, Snackbar.LENGTH_SHORT);

    added_snackbar.addCallback(new Snackbar.Callback() {
        @Override
        public void onShown(Snackbar snackbar) {
            super.onShown(snackbar);
            snackbar.getView().setContentDescription("added to favorites");
            snackbar.getView().sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT);
        }
    });

    removed_snackbar.addCallback(new Snackbar.Callback() {
        @Override
        public void onShown(Snackbar snackbar) {
            super.onShown(snackbar);
            snackbar.getView().setContentDescription("removed from favorites");
            snackbar.getView().sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT);
        }
    });

    if (mIsStarred) {
        item.setIcon(R.drawable.ic_menu_star);
        item.setTitle("Favorite checkbox, not checked");
        scheduleViewModel.setIsStarredFor(mScheduleId, 0);
        removed_snackbar.show();
        mIsStarred = false;
    } else {
        item.setIcon(R.drawable.ic_menu_star_on);
        item.setTitle("Favorite checkbox, checked");
        scheduleViewModel.setIsStarredFor(mScheduleId, 1);
        added_snackbar.show();
        mIsStarred = true;
    }
}