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.alfresco.mobile.android.application.fragments.actions.NodeActions.java

protected void getMenu(FragmentActivity activity, Menu menu) {
    MenuItem mi;
    SubMenu createMenu;/*from w w  w  .  j a  v a2s . com*/

    if (selectedFolder.isEmpty()) {
        mi = menu.add(Menu.NONE, R.id.menu_action_download_all, Menu.FIRST, R.string.download);
        mi.setIcon(R.drawable.ic_download_light);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        removeActionIfNecessary(menu, mi.getItemId(), ConfigurableActionHelper.ACTION_NODE_DOWNLOAD);

        if (!(SessionUtils.getSession(activity) instanceof CloudSession)) {
            mi = menu.add(Menu.NONE, R.id.menu_workflow_review_attachments, Menu.FIRST + 500,
                    R.string.process_start_review);
            mi.setIcon(R.drawable.ic_start_review);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            removeActionIfNecessary(menu, mi.getItemId(), ConfigurableActionHelper.ACTION_NODE_REVIEW);
        }
    }

    // SYNC
    if (SyncContentManager.getInstance(getActivity()).hasActivateSync(getAccount())
            && !SyncContentManager.getInstance(getActivity()).isSynced(getAccount(), parentFolder)) {
        createMenu = menu.addSubMenu(Menu.NONE, R.id.menu_action_sync_group, Menu.FIRST, R.string.sync);
        createMenu.setIcon(R.drawable.ic_sync_light);
        createMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        removeActionIfNecessary(menu, createMenu.getItem().getItemId(),
                ConfigurableActionHelper.ACTION_NODE_SYNC);

        createMenu.add(Menu.NONE, R.id.menu_action_sync_group_sync, Menu.FIRST + 1, R.string.sync);
        createMenu.add(Menu.NONE, R.id.menu_action_sync_group_unsync, Menu.FIRST + 2, R.string.unsync);
    }

    // FAVORITES
    createMenu = menu.addSubMenu(Menu.NONE, R.id.menu_action_favorite_group, Menu.FIRST + 135,
            R.string.favorite);
    createMenu.setIcon(R.drawable.ic_favorite_light);
    createMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    removeActionIfNecessary(menu, createMenu.getItem().getItemId(),
            ConfigurableActionHelper.ACTION_NODE_FAVORITE);

    createMenu.add(Menu.NONE, R.id.menu_action_favorite_group_favorite, Menu.FIRST + 1, R.string.favorite);
    createMenu.add(Menu.NONE, R.id.menu_action_favorite_group_unfavorite, Menu.FIRST + 2, R.string.unfavorite);

    // LIKE
    AlfrescoSession alfSession = SessionUtils.getSession(activity);
    if (alfSession != null && alfSession.getRepositoryInfo() != null
            && alfSession.getRepositoryInfo().getCapabilities() != null
            && alfSession.getRepositoryInfo().getCapabilities().doesSupportLikingNodes()) {
        createMenu = menu.addSubMenu(Menu.NONE, R.id.menu_action_like_group, Menu.FIRST + 150, R.string.like);
        createMenu.setIcon(R.drawable.ic_like);
        createMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        removeActionIfNecessary(menu, createMenu.getItem().getItemId(),
                ConfigurableActionHelper.ACTION_NODE_LIKE);

        createMenu.add(Menu.NONE, R.id.menu_action_like_group_like, Menu.FIRST + 1, R.string.like);
        createMenu.add(Menu.NONE, R.id.menu_action_like_group_unlike, Menu.FIRST + 2, R.string.unlike);
    }

    if (parentFolder != null && ConfigurableActionHelper.isVisible(getActivity(), getAccount(), getSession(),
            parentFolder, ConfigurableActionHelper.ACTION_NODE_DELETE)) {
        mi = menu.add(Menu.NONE, R.id.menu_action_delete, Menu.FIRST + 1000, R.string.delete);
        mi.setIcon(R.drawable.ic_delete);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        removeActionIfNecessary(menu, mi.getItemId(), ConfigurableActionHelper.ACTION_NODE_DELETE);
    }
}

From source file:de.tap.easy_xkcd.fragments.comics.ComicBrowserFragment.java

/*************************
 * Favorite Modification/*from  w w  w. j  ava  2 s  .c om*/
 ************************/

protected boolean ModifyFavorites(MenuItem item) {
    if (!prefHelper.isOnline(getActivity())) {
        Toast.makeText(getActivity(), R.string.no_connection, Toast.LENGTH_SHORT).show();
        return true;
    }
    if (databaseManager.checkFavorite(lastComicNumber)) {
        new DeleteComicImageTask().execute(true);
        item.setIcon(R.drawable.ic_favorite_outline);
    } else {
        if (!(ContextCompat.checkSelfPermission(getActivity(),
                Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) {
            ActivityCompat.requestPermissions(getActivity(),
                    new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 2);
            return true;
        }
        new SaveComicImageTask().execute(true);
        item.setIcon(R.drawable.ic_action_favorite);
    }
    return true;
}

From source file:com.itude.mobile.mobbl.core.view.components.tabbar.MBDefaultActionBarBuilder.java

@Override
public void fillActionBar(ActionBar actionBar, Menu menu) {
    _actionBar = actionBar;/*from w  w w  .  j  av  a2s  . c o m*/
    _menu = menu;

    List<MBToolDefinition> tools = MBMetadataService.getInstance().getTools();

    for (MBToolDefinition def : tools) {
        if (def.isPreConditionValid()) {
            String localizedTitle = MBLocalizationService.getInstance().getTextForKey(def.getTitle());
            MenuItem menuItem = menu.add(Menu.NONE, def.getName().hashCode(), tools.indexOf(def),
                    localizedTitle);

            Drawable image = null;
            if (def.getIcon() != null) {
                image = MBResourceService.getInstance().getImageByID(def.getIcon());
                menuItem.setIcon(image);
            }

            MenuItemCompat.setShowAsAction(menuItem, getMenuItemActionFlags(def));

            if ("REFRESH".equals(def.getType())) {
                _refreshToolDef = def;
            } else if ("SEARCH".equals(def.getType())) {
                final SearchView searchView = new SearchView(_context);
                searchView.setTag(def);
                searchView.setOnQueryTextFocusChangeListener(new OnFocusChangeListener() {
                    @Override
                    public void onFocusChange(View v, boolean hasFocus) {
                        if (hasFocus) {
                            Object tag = v.getTag();
                            if (tag instanceof MBToolDefinition) {
                                MBToolDefinition toolDef = (MBToolDefinition) tag;
                                if (toolDef.getOutcomeName() != null) {
                                    handleOutcome(toolDef);
                                }
                            }
                        } else {
                            searchView.setIconified(true);
                        }
                    }
                });

                changeSearchImage(image, searchView);

                SearchManager searchManager = (SearchManager) _context.getSystemService(Context.SEARCH_SERVICE);

                searchView.setSearchableInfo(
                        searchManager.getSearchableInfo(MBViewManager.getInstance().getComponentName()));

                MenuItemCompat.setActionView(menuItem, searchView);
            }
        }
    }
    if (actionBar != null) {
        populateActionBar(actionBar);
    }
}

From source file:com.ez.gallery.ucrop.UCropActivity.java

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

    // Change the next menu icon color to match the rest of the UI colors
    MenuItem next = menu.findItem(R.id.menu_crop);

    Drawable defaultIcon = next.getIcon();
    if (defaultIcon != null) {
        defaultIcon.mutate();/*from   ww w. j a  v  a 2 s .c o m*/
        defaultIcon.setColorFilter(mToolbarTextColor, PorterDuff.Mode.SRC_ATOP);
        next.setIcon(defaultIcon);
    }

    return true;
}

From source file:com.googlecode.android_scripting.facade.ui.UiFacade.java

public boolean onPrepareOptionsMenu(Menu menu) {
    if (mMenuUpdated.getAndSet(false)) {
        menu.removeGroup(MENU_GROUP_ID);
        for (UiMenuItem item : mOptionsMenuItems) {
            MenuItem menuItem = menu.add(MENU_GROUP_ID, Menu.NONE, Menu.NONE, item.mmTitle);
            if (item.mmIcon != null) {
                menuItem.setIcon(mService.getResources().getIdentifier(item.mmIcon, "drawable", "android"));
            }/*from   w  w w .j a v a2s.com*/
            menuItem.setOnMenuItemClickListener(item.mmListener);
        }
        return true;
    }
    return true;
}

From source file:com.dycode.jepretstory.mediachooser.activity.BucketHomeFragmentActivity.java

private void setCurrentMode(MediaType mode) {
    currentMediaMode = mode;//w  w  w  .j a  va  2 s  .  c o  m
    if (currentMediaMode == MediaType.IMAGE) {

        if (mMenu != null) {
            MenuItem item = mMenu.findItem(R.id.menuCamera);
            item.setTitle(getString(R.string.image));
            item.setIcon(R.drawable.selector_camera_button);
        }
        getActionBar().setTitle(getString(R.string.image));

    } else {

        if (mMenu != null) {
            MenuItem item = mMenu.findItem(R.id.menuCamera);
            item.setTitle(getString(R.string.video));
            item.setIcon(R.drawable.selector_video_button);
        }
        getActionBar().setTitle(getString(R.string.video));

    }
}

From source file:com.money.manager.ex.search.SearchParametersFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    UIHelper ui = new UIHelper(getActivity());

    // 'Reset' toolbar item
    inflater.inflate(R.menu.menu_clear, menu);
    MenuItem item = menu.findItem(R.id.clearMenuItem);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    item.setIcon(ui.getIcon(GoogleMaterial.Icon.gmd_clear));

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.nttec.everychan.ui.BoardsListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem itemUpdate = menu.add(Menu.NONE, R.id.menu_update, 101, resources.getString(R.string.menu_update));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        itemUpdate.setIcon(ThemeUtils.getActionbarIcon(activity.getTheme(), resources, R.attr.actionRefresh));
        CompatibilityImpl.setShowAsActionIfRoom(itemUpdate);
    } else {/*from   www . j a v  a  2  s  . c o  m*/
        itemUpdate.setIcon(R.drawable.ic_menu_refresh);
    }

    if (quickAccessList == null)
        return;
    for (QuickAccess.Entry entry : quickAccessList)
        if (entry.boardName == null && entry.chan != null
                && entry.chan.getChanName().equals(chan.getChanName()))
            return;
    menu.add(Menu.NONE, R.id.menu_quickaccess_add, 102, resources.getString(R.string.menu_quickaccess_add))
            .setIcon(R.drawable.ic_menu_add_bookmark);
}

From source file:org.alfresco.mobile.android.application.fragments.node.details.NodeDetailsActionMode.java

protected void getMenu(FragmentActivity activity, Menu menu) {
    if (selectedItems.isEmpty() || selectedItems.size() > 1) {
        return;/*  www .j  a  v a2s. co m*/
    }

    MenuItem mi;
    Node node = getCurrentItem();
    if (node == null) {
        return;
    }
    if (node instanceof NodeSyncPlaceHolder) {
        return;
    }

    boolean isRestrict = node.hasAspect(ContentModel.ASPECT_RESTRICTABLE);

    if (node.isDocument()) {
        if (((Document) node).getContentStreamLength() > 0 && !isRestrict && ConfigurableActionHelper
                .isVisible(getActivity(), getAccount(), ConfigurableActionHelper.ACTION_NODE_DOWNLOAD)) {
            mi = menu.add(Menu.NONE, R.id.menu_action_download, Menu.FIRST, R.string.download);
            mi.setIcon(R.drawable.ic_download_light);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }

        if (((Document) node).isLatestVersion() && ConfigurableActionHelper.isVisible(getActivity(),
                getAccount(), getSession(), node, ConfigurableActionHelper.ACTION_NODE_UPDATE)) {
            mi = menu.add(Menu.NONE, R.id.menu_action_update, Menu.FIRST + 130, R.string.update);
            mi.setIcon(R.drawable.ic_upload);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }

        if (!(SessionUtils.getSession(activity) instanceof CloudSession) && ConfigurableActionHelper
                .isVisible(getActivity(), getAccount(), ConfigurableActionHelper.ACTION_NODE_REVIEW)) {
            mi = menu.add(Menu.NONE, R.id.menu_workflow_add, Menu.FIRST + 500, R.string.process_start_review);
            mi.setIcon(R.drawable.ic_start_review);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }
    }

    if (ConfigurableActionHelper.isVisible(getActivity(), getAccount(), getSession(), node,
            ConfigurableActionHelper.ACTION_NODE_EDIT)) {
        mi = menu.add(Menu.NONE, R.id.menu_action_edit, Menu.FIRST + 50, R.string.edit);
        mi.setIcon(R.drawable.ic_properties);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (ConfigurableActionHelper.isVisible(getActivity(), getAccount(), getSession(), node,
            ConfigurableActionHelper.ACTION_NODE_DELETE)) {
        mi = menu.add(Menu.NONE, R.id.menu_action_delete, Menu.FIRST + 1000, R.string.delete);
        mi.setIcon(R.drawable.ic_delete);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
}

From source file:com.concentricsky.android.khanacademy.app.VideoListActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    mainMenu = menu;/* w w w  .ja v  a2 s  . c o  m*/
    mainMenuDelegate.onCreateOptionsMenu(menu);

    MenuItem downloadItem = mainMenu.add(0, DOWNLOAD_ITEM_ID, mainMenu.size(), R.string.menu_item_download_all);
    downloadItem.setIcon(R.drawable.av_download);
    downloadItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    return true;
}