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:com.yahala.ui.LaunchActivity.java

public void updatePresenceMenuIcon() {

    try {/*from   ww w. j av a2  s . c  o  m*/
        MenuItem menuTypeAvailability = menu.findItem(R.id.menu_type_availability);
        if (menuTypeAvailability != null) {
            //FileLog.e("Test updatePresenceMenuIcon","!Null");
            if (XMPPManager.getInstance().currentPresence == XMPPManager.Available) {
                menuTypeAvailability.setIcon(R.drawable.ic_type_available);
            } else if (XMPPManager.getInstance().currentPresence == XMPPManager.Away) {
                menuTypeAvailability.setIcon(R.drawable.ic_type_away);
            } else if (XMPPManager.getInstance().currentPresence == 5) {
                menuTypeAvailability.setIcon(R.drawable.ic_type_unavailable);
            } else if (XMPPManager.getInstance().currentPresence == XMPPManager.DoNotDisturb) {
                menuTypeAvailability.setIcon(R.drawable.ic_type_dns);
            } else if (XMPPManager.getInstance().currentPresence == XMPPManager.FreeToChat) {
                menuTypeAvailability.setIcon(R.drawable.ic_type_available);
            }
            menuTypeAvailability.setVisible(true);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.nextgis.maplibui.overlay.EditLayerOverlay.java

public void setMode(int mode) {
    if (mode != MODE_NONE && mLayer == null)
        return;// ww w . j a v a  2 s  .  co  m

    mMode = mode;
    switch (mMode) {
    case MODE_NONE:
        clearAll();
        break;
    case MODE_HIGHLIGHT:
        if (mFeature != null)
            mLayer.showFeature(mFeature.getId());
        break;
    case MODE_EDIT:
        if (mFeature == null)
            break;

        mBottomToolbar.setTitle(null);
        mBottomToolbar.getMenu().clear();
        switch (mLayer.getGeometryType()) {
        case GeoConstants.GTPoint:
            mBottomToolbar.inflateMenu(R.menu.edit_point);
            break;
        case GeoConstants.GTMultiPoint:
            mBottomToolbar.inflateMenu(R.menu.edit_multipoint);
            break;
        case GeoConstants.GTLineString:
            mBottomToolbar.inflateMenu(R.menu.edit_line);
            break;
        case GeoConstants.GTMultiLineString:
            mBottomToolbar.inflateMenu(R.menu.edit_multiline);
            break;
        case GeoConstants.GTPolygon:
            mBottomToolbar.inflateMenu(R.menu.edit_polygon);
            break;
        case GeoConstants.GTMultiPolygon:
            mBottomToolbar.inflateMenu(R.menu.edit_multipolygon);
            break;
        case GeoConstants.GTGeometryCollection:
        default:
            break;
        }

        hideNavigationButton();

        for (EditEventListener listener : mListeners)
            listener.onStartEditSession();

        mLayer.hideFeature(mFeature.getId());
        break;
    case MODE_EDIT_BY_WALK:
        hideNavigationButton();

        for (EditEventListener listener : mListeners)
            listener.onStartEditSession();

        mBottomToolbar.setTitle(R.string.title_edit_by_walk);
        mBottomToolbar.getMenu().clear();
        mBottomToolbar.inflateMenu(R.menu.edit_by_walk);
        mBottomToolbar.setOnMenuItemClickListener(new BottomToolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                if (menuItem.getItemId() == R.id.menu_settings) {
                    IGISApplication app = (IGISApplication) ((Activity) mContext).getApplication();
                    app.showSettings(SettingsConstantsUI.ACTION_PREFS_LOCATION);
                }

                return true;
            }
        });

        startGeometryByWalk();
        break;
    case MODE_EDIT_BY_TOUCH:
        hideNavigationButton();
        mBottomToolbar.setTitle(R.string.title_edit_by_touch);
        mBottomToolbar.getMenu().clear();
        MenuItem apply = mBottomToolbar.getMenu().add(0, 0, 0, R.string.ok);
        apply.setIcon(R.drawable.ic_action_apply_dark);
        MenuItemCompat.setShowAsAction(apply, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
        mMapViewOverlays.setLockMap(true);
        break;
    }

    hideOverlayPoint();
    updateMap();
}

From source file:pro.dbro.bart.TheActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    //Use setting-button context menu OR Action bar
    if (Build.VERSION.SDK_INT < 11) {
        MenuItem mi = menu.add(0, 0, 0, "About");
        mi.setIcon(R.drawable.about);
    } else {//from   w  w  w  . j a v a2s .  c o m
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.layout.actionitem, menu);
        //return true;
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:com.murati.oszk.audiobook.ui.ActionBarCastActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (mDrawerToggle != null && mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }/*w  w  w .  ja v  a2 s  .  c  om*/

    //Try to get mediaId
    String mediaId = null;
    try {
        if (this.getClass() == MusicPlayerActivity.class) {
            MusicPlayerActivity musicPlayerActivity = (MusicPlayerActivity) this;
            mediaId = musicPlayerActivity.getMediaId();
        } else if (this.getClass() == FullScreenPlayerActivity.class) {
            FullScreenPlayerActivity fullPlayer = (FullScreenPlayerActivity) this;
            mediaId = fullPlayer.getMediaId();
        }
    } catch (Exception ex) {
        Log.d(TAG, "Unable to fetch mediaId");
    }

    //Favorites Toggle
    if (item != null && mediaId != null && item.getItemId() == R.id.option_favorite) {
        item.setIcon(FavoritesHelper.toggleFavoriteWithText(mediaId, ActionBarCastActivity.this));
        return true;
    }

    //Download button
    //TODO: if not downloaded yet
    if (item != null && mediaId != null && item.getItemId() == R.id.option_download) {
        return OfflineBookService.downloadWithActivity(mediaId, ActionBarCastActivity.this);
    }

    //Delete button
    if (item != null && mediaId != null && item.getItemId() == R.id.option_delete) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.confirm_delete_question).setTitle(R.string.action_delete)
                .setCancelable(false)
                .setPositiveButton(R.string.confirm_delete, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        ActionBarCastActivity.this.deleteEbook();
                    }
                }).setNegativeButton(R.string.confirm_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
        return true;
    }

    // If not handled by drawerToggle, home needs to be handled by returning to previous
    if (item != null && item.getItemId() == android.R.id.home) {
        onBackPressed();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:de.dreier.mytargets.features.training.input.InputActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    final MenuItem eye = menu.findItem(R.id.action_show);
    final MenuItem keyboard = menu.findItem(R.id.action_keyboard);
    final MenuItem grouping = menu.findItem(R.id.action_grouping);
    final MenuItem timer = menu.findItem(R.id.action_timer);
    final MenuItem newRound = menu.findItem(R.id.action_new_round);
    if (targetView == null || data.getEnds().size() == 0) {
        eye.setVisible(false);// w w  w .java  2  s. com
        keyboard.setVisible(false);
        grouping.setVisible(false);
        timer.setVisible(false);
        newRound.setVisible(false);
    } else {
        final boolean plotting = targetView.getInputMode() == EInputMethod.PLOTTING;
        eye.setVisible(plotting);
        grouping.setVisible(plotting);
        keyboard.setIcon(plotting ? R.drawable.ic_keyboard_white_24dp : R.drawable.ic_keyboard_white_off_24dp);
        keyboard.setChecked(!plotting);
        keyboard.setVisible(data.getCurrentEnd().getId() == null);
        timer.setIcon(SettingsManager.getTimerEnabled() ? R.drawable.ic_timer_off_white_24dp
                : R.drawable.ic_timer_white_24dp);
        timer.setVisible(true);
        timer.setChecked(SettingsManager.getTimerEnabled());
        newRound.setVisible(data.training.standardRoundId == null);
    }

    switch (SettingsManager.getShowMode()) {
    case END:
        menu.findItem(R.id.action_show_end).setChecked(true);
        break;
    case ROUND:
        menu.findItem(R.id.action_show_round).setChecked(true);
        break;
    case TRAINING:
        menu.findItem(R.id.action_show_training).setChecked(true);
        break;
    default:
        // Never called: All enum values are checked
        break;
    }
    switch (SettingsManager.getAggregationStrategy()) {
    case NONE:
        menu.findItem(R.id.action_grouping_none).setChecked(true);
        break;
    case AVERAGE:
        menu.findItem(R.id.action_grouping_average).setChecked(true);
        break;
    case CLUSTER:
        menu.findItem(R.id.action_grouping_cluster).setChecked(true);
        break;
    default:
        // Never called: All enum values are checked
        break;
    }
    return true;
}

From source file:com.bt.download.android.gui.activities.AudioPlayerActivity.java

private void setShareText(Menu menu) {
    MenuItem item = menu.findItem(R.id.menu_audio_player_share);
    try {/*  w ww  .  j av a2s. c  o  m*/
        FileDescriptor fd = Librarian.instance().getFileDescriptor(Constants.FILE_TYPE_AUDIO,
                (int) MusicUtils.getCurrentAudioId());
        if (fd != null) {
            item.setTitle(fd.shared ? R.string.unshare : R.string.share);
            item.setIcon(fd.shared ? R.drawable.contextmenu_icon_unshare : R.drawable.contextmenu_icon_share);
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}

From source file:com.musenkishi.wally.activities.ImageDetailsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.image_details, menu);

    MenuItem shareMenuItem = menu.findItem(R.id.action_share);

    if (shareMenuItem != null) {
        shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareMenuItem);
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(Intent.EXTRA_TEXT, pageUri.toString());
        shareActionProvider.setShareIntent(shareIntent);
        shareMenuItem.setIcon(R.drawable.ic_action_share);
    }/*from   w ww  .  j  a  v a2 s .  c  o  m*/

    return super.onCreateOptionsMenu(menu);
}

From source file:com.nononsenseapps.feeder.ui.FeedFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.feed_fragment, menu);

    if (id < 1) {
        menu.findItem(R.id.action_edit_feed).setVisible(false);
        menu.findItem(R.id.action_delete_feed).setVisible(false);
        menu.findItem(R.id.action_add_templated).setVisible(false);
    }//  w  w w .  ja v  a  2 s . c om

    // Set toggleable state
    MenuItem menuItem = menu.findItem(R.id.action_only_unread);
    final boolean onlyUnread = PrefUtils.isShowOnlyUnread(getActivity());
    menuItem.setChecked(onlyUnread);
    menuItem.setTitle(onlyUnread ? R.string.show_unread_items : R.string.show_all_items);
    if (onlyUnread) {
        menuItem.setIcon(R.drawable.ic_action_visibility_off);
    } else {
        menuItem.setIcon(R.drawable.ic_action_visibility);
    }

    // Don't forget super call here
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:org.libreoffice.ui.LibreOfficeUIActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Will close the drawer if the home button is pressed
    if (drawerToggle.onOptionsItemSelected(item)) {
        return true;
    }//from  ww  w.j a va  2s.c  o  m

    switch (item.getItemId()) {
    case android.R.id.home:
        if (!currentDirectory.equals(homeDirectory)) {
            openParentDirectory();
        }
        break;
    case R.id.menu_view_toggle:
        if (viewMode == GRID_VIEW) {
            viewMode = LIST_VIEW;
            item.setTitle(R.string.grid_view); // Button points to next view.
            item.setIcon(R.drawable.light_view_as_grid);
        } else {
            viewMode = GRID_VIEW;
            item.setTitle(R.string.list_view); // Button points to next view.
            item.setIcon(R.drawable.light_view_as_list);
        }
        createUI();
        break;
    case R.id.menu_sort_size:
    case R.id.menu_sort_az:
    case R.id.menu_sort_modified:
        sortFiles(item);
        break;
    case R.id.action_about:
        mAbout.showAbout();
        return true;
    case R.id.action_settings:
        startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
        return true;
    case R.id.menu_storage_preferences:
        startActivity(new Intent(this, DocumentProviderSettingsActivity.class));
        break;

    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}