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.geometerplus.android.fbreader.FBReader.java

private void addMenuItem(Menu menu, String actionId, Integer iconId, String name) {
    if (name == null) {
        name = ZLResource.resource("menu").getResource(actionId).getValue();
    }/*from  w  ww.  j  av a  2s  .  com*/
    final MenuItem menuItem = menu.add(name);
    if (iconId != null) {
        menuItem.setIcon(iconId);
    }
    menuItem.setOnMenuItemClickListener(myMenuListener);
    myMenuItemMap.put(menuItem, actionId);
}

From source file:com.ibuildapp.romanblack.WebPlugin.WebPlugin.java

/**
 * This menu contains back, forward and refresh buttons.
 *
 * @param menu//from  www.j  a v a 2s .c om
 * @return true if there are no an exception while preparing, false otherwise
 */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    try {
        menu.clear();
        MenuItem itemBack = menu.add("");
        itemBack.setIcon(R.drawable.romanblack_html_menu_back);
        itemBack.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem mi) {
                webView.goBack();
                return true;
            }
        });
        if (!webView.canGoBack()) {
            itemBack.setEnabled(false);
        }

        MenuItem itemRefresh = menu.add("");
        itemRefresh.setIcon(R.drawable.romanblack_html_menu_refresh);
        itemRefresh.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem mi) {
                webView.reload();
                return true;
            }
        });
        if ("".equals(currentUrl) || "about:blank".equals(currentUrl)) {
            itemRefresh.setEnabled(false);
        }

        MenuItem itemForward = menu.add("");
        itemForward.setIcon(R.drawable.romanblack_html_menu_forward);
        itemForward.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem mi) {
                webView.goForward();
                return true;
            }
        });
        if (!webView.canGoForward()) {
            itemForward.setEnabled(false);
        }

        return true;

    } catch (Exception ex) {
        return false;
    }
}

From source file:com.zion.htf.ui.fragment.ArtistDetailsFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    MenuItem addAlarmItem = menu.findItem(R.id.action_addAlarm);
    MenuItem editAlarmItem = menu.findItem(R.id.action_editAlarm);
    MenuItem toggleFavorite = menu.findItem(R.id.action_toggle_favorite);

    boolean areAlarmsEnabled = 0 != this.setId;
    boolean hasAlarm = null != this.alarm;

    // Add / edit alarm button
    if (null != addAlarmItem) {
        addAlarmItem.setVisible(areAlarmsEnabled && !hasAlarm);
        addAlarmItem.setEnabled(areAlarmsEnabled && !hasAlarm);
    }//ww w. j  av a2  s. c om
    if (null != editAlarmItem) {
        editAlarmItem.setVisible(areAlarmsEnabled && hasAlarm);
        editAlarmItem.setEnabled(areAlarmsEnabled && hasAlarm);
    }

    // Favorite button
    if (this.artist.isFavorite()) {
        toggleFavorite.setTitle(R.string.action_unset_favorite);
        toggleFavorite.setIcon(R.drawable.ic_menu_favorite);
    } else {
        toggleFavorite.setTitle(R.string.action_set_favorite);
        toggleFavorite.setIcon(R.drawable.ic_menu_not_favorite);
    }
}

From source file:org.alfresco.mobile.android.application.fragments.person.PersonProfileFragment.java

private void getMenu(Menu menu, int mode) {
    MenuItem mi = null;
    switch (mode) {
    case MODE_CALL:
        if (person.getTelephoneNumber() != null && !person.getTelephoneNumber().isEmpty()) {
            mi = menu.add(Menu.NONE, MenuActionItem.MENU_TEL, Menu.FIRST + MenuActionItem.MENU_TEL,
                    person.getTelephoneNumber());
            mi.setIcon(R.drawable.ic_call);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }//from w w  w.  ja  v  a 2s  . co m

        if (person.getMobileNumber() != null && !person.getMobileNumber().isEmpty()) {
            mi = menu.add(Menu.NONE, MenuActionItem.MENU_MOBILE, Menu.FIRST + MenuActionItem.MENU_MOBILE,
                    person.getMobileNumber());
            mi.setIcon(R.drawable.ic_call);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }

        if (person.getCompany() != null && person.getCompany().getTelephoneNumber() != null
                && !person.getCompany().getTelephoneNumber().isEmpty()) {
            mi = menu.add(Menu.NONE, MenuActionItem.MENU_COMPANY_TEL,
                    Menu.FIRST + MenuActionItem.MENU_COMPANY_TEL, person.getCompany().getTelephoneNumber());
            mi.setIcon(R.drawable.ic_call);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }
        break;
    case MODE_SKYPE:
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_CHAT, Menu.FIRST + MenuActionItem.MENU_CHAT,
                R.string.start_chat);
        mi.setIcon(R.drawable.ic_im);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

        mi = menu.add(Menu.NONE, MenuActionItem.MENU_CALL, Menu.FIRST + MenuActionItem.MENU_CALL,
                R.string.start_call);
        mi.setIcon(R.drawable.ic_call);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

        mi = menu.add(Menu.NONE, MenuActionItem.MENU_VIDEOCALL, Menu.FIRST + MenuActionItem.MENU_VIDEOCALL,
                R.string.start_video_call);
        mi.setIcon(R.drawable.ic_videocall);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        break;
    case MODE_EMAIL:
        if (person.getEmail() != null && !person.getEmail().isEmpty()) {
            mi = menu.add(Menu.NONE, MenuActionItem.MENU_EMAIL, Menu.FIRST + MenuActionItem.MENU_EMAIL,
                    person.getEmail());
            mi.setIcon(R.drawable.ic_send_mail);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }

        if (person.getCompany() != null && person.getCompany().getEmail() != null
                && !person.getCompany().getEmail().isEmpty()) {
            mi = menu.add(Menu.NONE, MenuActionItem.MENU_COMPANY_EMAIL,
                    Menu.FIRST + MenuActionItem.MENU_COMPANY_EMAIL, person.getCompany().getEmail());
            mi.setIcon(R.drawable.ic_send_mail);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }
        break;

    default:
        break;
    }

}

From source file:org.dmfs.tasks.ViewTaskFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    /*/* www .ja  v a 2  s.c  o m*/
     * Don't show any options if we don't have a task to show.
     */
    if (mTaskUri != null) {
        inflater.inflate(R.menu.view_task_fragment_menu, menu);

        if (mContentSet != null) {
            Integer status = TaskFieldAdapters.STATUS.get(mContentSet);
            if (status != null) {
                mOldStatus = status;
            }
            if (TaskFieldAdapters.IS_CLOSED.get(mContentSet)
                    || status != null && status == Tasks.STATUS_COMPLETED) {
                // we disable the edit option, because the task is completed and the action button shows the edit option.
                MenuItem item = menu.findItem(R.id.edit_task);
                item.setEnabled(false);
                item.setVisible(false);
            }

            // check pinned status
            if (TaskFieldAdapters.PINNED.get(mContentSet)) {
                // we disable the edit option, because the task is completed and the action button shows the edit option.
                MenuItem item = menu.findItem(R.id.pin_task);
                item.setIcon(R.drawable.ic_pin_off_white_24dp);
            } else {
                MenuItem item = menu.findItem(R.id.pin_task);
                item.setIcon(R.drawable.ic_pin_white_24dp);
            }
        }
    }
}

From source file:net.homelinux.penecoptero.android.citybikes.app.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_ITEM_SYNC:
        try {//from  w ww .  j  a  v a  2 s  . co  m
            this.fillData(view_all);
        } catch (Exception e) {

        }
        ;
        return true;
    case MENU_ITEM_LOCATION:
        updateHome();
        return true;
    case MENU_ITEM_WHATEVER:
        if (!view_all) {
            item.setIcon(android.R.drawable.checkbox_on_background);
            view_all();
        } else {
            item.setIcon(android.R.drawable.checkbox_off_background);
            view_near();
        }
        view_all = !view_all;
        return true;
    case MENU_ITEM_SETTINGS:
        this.startActivityForResult(new Intent(this, SettingsActivity.class), SETTINGS_ACTIVITY);
        return true;
    case MENU_ITEM_MY_ACCOUNT:
        this.startActivity(new Intent(this, AccountActivity.class));
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.ruesga.rview.MainActivity.java

private void updateAccountCustomFilters() {
    // Remove all custom filters and re-add them
    final DrawerNavigationMenu menu = (DrawerNavigationMenu) mBinding.drawerNavigationView.getMenu();
    int myFiltersGroupIndex = menu.findGroupIndex(R.id.category_my_filters);
    MenuItem group = menu.getItem(myFiltersGroupIndex);
    SubMenu myFiltersSubMenu = group.getSubMenu();
    int count = myFiltersSubMenu.size() - 1;
    for (int i = count; i >= 0; i--) {
        ((DrawerNavigationSubMenu) myFiltersSubMenu).removeItemAt(i);
    }//www. jav a 2s  . c  o  m

    mCustomFilters = Preferences.getAccountCustomFilters(this, mAccount);
    if (mCustomFilters != null) {
        int i = 0;
        for (CustomFilter filter : mCustomFilters) {
            int id = MY_FILTERS_GROUP_BASE_ID + i;
            String title = filter.mName + DrawerNavigationView.SEPARATOR + filter.mQuery.toString()
                    + DrawerNavigationView.SEPARATOR + "ic_close";
            MenuItem item = myFiltersSubMenu.add(group.getGroupId(), id, Menu.NONE, title);
            item.setIcon(R.drawable.ic_filter);
            item.setCheckable(true);
            i++;
        }
    }

    menu.setGroupVisible(R.id.category_my_filters,
            !mModel.isAccountExpanded && mCustomFilters != null && !mCustomFilters.isEmpty());
    mBinding.drawerNavigationView.setCheckedItem(mModel.currentNavigationItemId);
}

From source file:de.grobox.liberario.activities.MapActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.map_actions, menu);
    this.menu = menu;

    MenuItem gpsItem = this.menu.findItem(R.id.action_use_gps);

    if (gpsController != null) {
        if (gpsController.isActive()) {
            gpsItem.setIcon(TransportrUtils.getToolbarDrawable(this, R.drawable.ic_gps_off));
        } else {// w w  w . ja  va2 s .c om
            gpsItem.setIcon(TransportrUtils.getToolbarDrawable(this, R.drawable.ic_gps));
        }
    } else {
        TransportrUtils.fixToolbarIcon(this, gpsItem);
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:it.polimi.deib.p2pchat.discovery.chatmessages.waitingtosend.discovery.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.discovery:
        ServiceList.getInstance().clear();

        if (discoveryStatus) {
            discoveryStatus = false;/*from   ww w .j a  v a  2 s .  c o  m*/

            item.setIcon(R.drawable.ic_action_search_stopped);

            internalStopDiscovery();

        } else {
            discoveryStatus = true;

            item.setIcon(R.drawable.ic_action_search_searching);

            startRegistration();
            discoverService();
        }

        updateServiceAdapter();

        this.setTabFragmentToPage(0);

        return true;
    case R.id.disconenct:

        this.setTabFragmentToPage(0);

        this.forceDisconnectAndStartDiscovery();
        return true;
    case R.id.cancelConnection:

        this.setTabFragmentToPage(0);

        this.forcedCancelConnect();

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

From source file:org.alfresco.mobile.android.application.extension.samsung.pen.SNoteEditorActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    toolsSubMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TOOLS, Menu.FIRST,
            R.string.editor_tools);// www  .  j  av a 2s .c  o  m
    toolsSubMenu.setIcon(R.drawable.ic_edit);
    toolsSubMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    // TOOLS MENU
    MenuItem mi = toolsSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_PEN,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_PEN, R.string.editor_pen);
    mi.setIcon(R.drawable.ic_edit);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    mi = toolsSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TEXT,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_TEXT, R.string.editor_text);
    mi.setIcon(R.drawable.ic_text);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    mi = toolsSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SELECTION,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SELECTION, R.string.editor_selection);
    mi.setIcon(R.drawable.ic_selection);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    mi = toolsSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_ERASER,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_ERASER, R.string.editor_eraser);
    mi.setIcon(R.drawable.ic_eraser);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    // TOOL SETTINGS MENU
    SubMenu toolsSettingSubMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SETTINGS,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS, R.string.editor_tools_settings);
    toolsSettingSubMenu.setIcon(R.drawable.ic_action_settings);
    toolsSettingSubMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    mi = toolsSettingSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SETTINGS_PEN,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS_PEN, R.string.editor_pen);
    mi.setIcon(R.drawable.ic_edit);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    mi = toolsSettingSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SETTINGS_TEXT,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS_TEXT, R.string.editor_text);
    mi.setIcon(R.drawable.ic_text);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    mi = toolsSettingSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SETTINGS_SELECTION,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS_SELECTION, R.string.editor_selection);
    mi.setIcon(R.drawable.ic_selection);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    mi = toolsSettingSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SETTINGS_ERASER,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS_ERASER, R.string.editor_eraser);
    mi.setIcon(R.drawable.ic_eraser);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    // ADD MENU
    SubMenu addSubMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_ADD,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_ADD, R.string.editor_add_menu);
    addSubMenu.setIcon(R.drawable.ic_add);
    addSubMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    // IMAGE
    mi = addSubMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_ADD_IMAGE,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_ADD_IMAGE, R.string.editor_add_image);
    mi.setIcon(R.drawable.ic_add_image);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    // PAGES
    SubMenu pagesMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_PAGE,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_PAGE, R.string.editor_pages);
    pagesMenu.setIcon(R.drawable.ic_pages);
    pagesMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    mi = pagesMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_PAGE_MOVE,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_PAGE_MOVE, R.string.editor_pages_move);
    mi.setIcon(R.drawable.ic_pages);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    mi = pagesMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_PAGE_ADD,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_PAGE_ADD, R.string.editor_pages_add);
    mi.setIcon(R.drawable.ic_add_page);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    mi = pagesMenu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_PAGE_DELETE,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_PAGE_DELETE, R.string.editor_pages_remove);
    mi.setIcon(R.drawable.ic_delete);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    // EXTRA SETTINGS
    // SAVE
    mi = menu.add(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_SAVE,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SAVE, R.string.editor_save);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

    super.onCreateOptionsMenu(menu);

    return true;
}