Example usage for android.view SubMenu setIcon

List of usage examples for android.view SubMenu setIcon

Introduction

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

Prototype

public SubMenu setIcon(Drawable icon);

Source Link

Document

Change the icon associated with this submenu's item in its parent menu.

Usage

From source file:og.android.tether.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    boolean supRetVal = super.onCreateOptionsMenu(menu);
    SubMenu setup = menu.addSubMenu(0, MENU_SETUP, 0, getString(R.string.main_activity_settings));
    setup.setIcon(drawable.ic_menu_preferences);
    if (this.application.accessControlSupported) {
        SubMenu accessctr = menu.addSubMenu(0, MENU_ACCESS, 0, getString(R.string.main_activity_accesscontrol));
        accessctr.setIcon(drawable.ic_menu_manage);
    }//  w ww .  j  av a2 s. co m
    SubMenu connect = menu.addSubMenu(0, MENU_CONNECT, 0, getString(R.string.main_activity_connect));
    connect.setIcon(drawable.ic_menu_add);
    SubMenu log = menu.addSubMenu(0, MENU_LOG, 0, getString(R.string.main_activity_showlog));
    log.setIcon(drawable.ic_menu_agenda);
    SubMenu community = menu.addSubMenu(0, MENU_COMMUNITY, 0, getString(R.string.main_activity_community));
    community.setIcon(drawable.ic_menu_myplaces);
    SubMenu about = menu.addSubMenu(0, MENU_ABOUT, 0, getString(R.string.main_activity_about));
    about.setIcon(drawable.ic_menu_info_details);

    SubMenu twitter = menu.addSubMenu(0, MENU_TWITTER, 0, getString(R.string.main_activity_twitter));
    SubMenu facebook = menu.addSubMenu(0, MENU_FACEBOOK, 0, getString(R.string.main_activity_facebook));
    return supRetVal;
}

From source file:org.alfresco.mobile.android.application.fragments.actions.NodeActions.java

protected void getMenu(FragmentActivity activity, Menu menu) {
    MenuItem mi;/*from   ww w.j  a  va 2 s . c  om*/
    SubMenu createMenu;

    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:com.vuze.android.remote.fragment.TorrentListFragment.java

private void setupActionModeCallback() {
    mActionModeCallbackV7 = new Callback() {

        // Called when the action mode is created; startActionMode() was called
        @Override//from  ww  w  .  java2s.co m
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {

            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "onCreateActionMode");
            }

            if (mode == null && torrentListAdapter.getCheckedItemCount() == 0
                    && torrentListAdapter.getSelectedPosition() < 0) {
                return false;
            }

            Menu origMenu = menu;
            if (tb != null) {
                menu = tb.getMenu();
            }
            if (mode != null) {
                mActionMode = (mode instanceof ActionModeWrapperV7) ? mode
                        : new ActionModeWrapperV7(mode, tb, getActivity());

                mActionMode.setTitle(R.string.context_torrent_title);
            }
            ActionBarToolbarSplitter.buildActionBar(getActivity(), this, R.menu.menu_context_torrent_details,
                    menu, tb);

            TorrentDetailsFragment frag = (TorrentDetailsFragment) getActivity().getSupportFragmentManager()
                    .findFragmentById(R.id.frag_torrent_details);
            if (frag != null) {
                frag.onCreateActionMode(mode, menu);
            }

            if (sideListArea == null) {
                SubMenu subMenu = origMenu.addSubMenu(R.string.menu_global_actions);
                subMenu.setIcon(R.drawable.ic_menu_white_24dp);
                MenuItemCompat.setShowAsAction(subMenu.getItem(), MenuItemCompat.SHOW_AS_ACTION_NEVER);

                try {
                    // Place "Global" actions on top bar in collapsed menu
                    MenuInflater mi = mode == null ? getActivity().getMenuInflater() : mode.getMenuInflater();
                    mi.inflate(R.menu.menu_torrent_list, subMenu);
                    onPrepareOptionsMenu(subMenu);
                } catch (UnsupportedOperationException e) {
                    Log.e(TAG, e.getMessage());
                    menu.removeItem(subMenu.getItem().getItemId());
                }
            }

            if (AndroidUtils.usesNavigationControl()) {
                MenuItem add = origMenu.add(R.string.select_multiple_items);
                add.setCheckable(true);
                add.setChecked(torrentListAdapter.isMultiCheckMode());
                add.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        boolean turnOn = !torrentListAdapter.isMultiCheckModeAllowed();

                        torrentListAdapter.setMultiCheckModeAllowed(turnOn);
                        if (turnOn) {
                            torrentListAdapter.setMultiCheckMode(turnOn);
                            torrentListAdapter.setItemChecked(torrentListAdapter.getSelectedPosition(), true);
                        }
                        return true;
                    }
                });
            }

            return true;
        }

        // Called each time the action mode is shown. Always called after
        // onCreateActionMode, but
        // may be called multiple times if the mode is invalidated.
        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {

            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "MULTI:onPrepareActionMode " + mode);
            }
            if (tb != null) {
                menu = tb.getMenu();
            }

            // Must be called first, because our drawer sets all menu items
            // visible.. :(
            getActivity().onPrepareOptionsMenu(menu);

            prepareContextMenu(menu);

            TorrentDetailsFragment frag = (TorrentDetailsFragment) getActivity().getSupportFragmentManager()
                    .findFragmentById(R.id.frag_torrent_details);
            if (frag != null) {
                frag.onPrepareActionMode(mode, menu);
            }

            AndroidUtils.fixupMenuAlpha(menu);

            return true;
        }

        // Called when the user selects a contextual menu item
        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "onActionItemClicked " + item.getTitle());
            }

            if (TorrentListFragment.this.handleFragmentMenuItems(item.getItemId())) {
                return true;
            }
            if (getActivity().onOptionsItemSelected(item)) {
                return true;
            }
            TorrentDetailsFragment frag = (TorrentDetailsFragment) getActivity().getSupportFragmentManager()
                    .findFragmentById(R.id.frag_torrent_details);
            if (frag != null) {
                if (frag.onActionItemClicked(mode, item)) {
                    return true;
                }
            }
            return false;
        }

        // Called when the user exits the action mode
        @Override
        public void onDestroyActionMode(ActionMode mode) {
            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "onDestroyActionMode. BeingReplaced?" + actionModeBeingReplaced);
            }

            mActionMode = null;

            if (!actionModeBeingReplaced) {
                listview.post(new Runnable() {
                    @Override
                    public void run() {
                        torrentListAdapter.setMultiCheckMode(false);
                        torrentListAdapter.clearChecked();
                        updateCheckedIDs();
                    }
                });

                listview.post(new Runnable() {
                    @Override
                    public void run() {
                        if (mCallback != null) {
                            mCallback.actionModeBeingReplacedDone();
                        }
                    }
                });

                listview.setLongClickable(true);
                listview.requestLayout();
                AndroidUtils.invalidateOptionsMenuHC(getActivity(), mActionMode);
            }
        }
    };
}

From source file:com.ichi2.anki2.Reviewer.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    Resources res = getResources();

    UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_MARK, Menu.NONE, R.string.menu_mark_card,
            R.drawable.ic_menu_mark);/*from   w  w  w  .  j  a  v a2  s . c  om*/
    UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_UNDO, Menu.NONE, R.string.undo,
            R.drawable.ic_menu_revert_disabled);
    UIUtils.addMenuItem(menu, Menu.NONE, MENU_EDIT, Menu.NONE, R.string.menu_edit_card,
            R.drawable.ic_menu_edit);
    if (mPrefWhiteboard) {
        if (mShowWhiteboard) {
            UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE,
                    R.string.hide_whiteboard, R.drawable.ic_menu_compose);
        } else {
            UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE,
                    R.string.show_whiteboard, R.drawable.ic_menu_compose);
        }
        UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_CLEAR_WHITEBOARD, Menu.NONE,
                R.string.clear_whiteboard, R.drawable.ic_menu_clear_playlist);
    }

    if (mPrefRecord) {
        // TODO proper icon
        final MenuItem recorderItem = UIUtils.addMenuItem(menu, Menu.NONE, MENU_RECORD, Menu.NONE,
                Recorder.recording() ? R.string.record_stop : R.string.record_start,
                R.drawable.ic_circle_pressed);
        final MenuItem replayItem = UIUtils.addMenuItem(menu, Menu.NONE, MENU_RECORD_REPLAY, Menu.NONE,
                R.string.record_play, R.drawable.ic_circle_normal);
        // disable unless something is recorded
        replayItem.setEnabled(false);
        // set relevant listeners
        Recorder.setRecordingStartedListener(new Recorder.RecordingStartedListener() {

            @Override
            public void onRecordingStarted() {
                recorderItem.setTitle(R.string.record_stop);
            }
        });
        Recorder.setRecordingFinishedListener(new Recorder.RecordingFinishedListener() {

            @Override
            public void onRecordingFinished() {
                recorderItem.setTitle(R.string.record_start);
                replayItem.setEnabled(true);
            }
        });
        Recorder.setRecorderResetListener(new Recorder.RecorderResetListener() {

            @Override
            public void onRecorderReset() {
                replayItem.setEnabled(false);
            }
        });
    }

    SubMenu removeDeckSubMenu = menu.addSubMenu(Menu.NONE, MENU_REMOVE, Menu.NONE, R.string.menu_dismiss_note);
    removeDeckSubMenu.setIcon(R.drawable.ic_menu_stop);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY, Menu.NONE, R.string.menu_bury_note);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_CARD, Menu.NONE, R.string.menu_suspend_card);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_NOTE, Menu.NONE, R.string.menu_suspend_note);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_DELETE, Menu.NONE, R.string.menu_delete_note);
    if (mPrefTextSelection) {
        MenuItem item = menu.add(Menu.NONE, MENU_SEARCH, Menu.NONE, res.getString(R.string.menu_select));
        item.setIcon(R.drawable.ic_menu_search);
        item.setEnabled(Lookup.isAvailable());
    }
    return true;
}

From source file:com.nit.vicky.Reviewer.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    Resources res = getResources();

    UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_MARK, Menu.NONE, R.string.menu_mark_card,
            R.drawable.ic_menu_mark);//from www  .java  2s  .  c  o  m
    UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_UNDO, Menu.NONE, R.string.undo,
            R.drawable.ic_menu_revert_disabled);
    UIUtils.addMenuItem(menu, Menu.NONE, MENU_EDIT, Menu.NONE, R.string.menu_edit_card,
            R.drawable.ic_menu_edit);

    if (mPrefWhiteboard) {
        if (mShowWhiteboard) {
            UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE,
                    R.string.hide_whiteboard, R.drawable.ic_menu_compose);
        } else {
            UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_WHITEBOARD, Menu.NONE,
                    R.string.show_whiteboard, R.drawable.ic_menu_compose);
        }
        UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_CLEAR_WHITEBOARD, Menu.NONE,
                R.string.clear_whiteboard, R.drawable.ic_menu_clear_playlist);
    }

    SubMenu removeDeckSubMenu = menu.addSubMenu(Menu.NONE, MENU_REMOVE, Menu.NONE, R.string.menu_dismiss_note);
    removeDeckSubMenu.setIcon(R.drawable.ic_menu_stop);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY_CARD, Menu.NONE, R.string.menu_bury_card);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY_NOTE, Menu.NONE, R.string.menu_bury_note);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_CARD, Menu.NONE, R.string.menu_suspend_card);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_NOTE, Menu.NONE, R.string.menu_suspend_note);
    removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_DELETE, Menu.NONE, R.string.menu_delete_note);
    if (mPrefTextSelection) {
        MenuItem item = menu.add(Menu.NONE, MENU_SEARCH, Menu.NONE, res.getString(R.string.menu_select));
        item.setIcon(R.drawable.ic_menu_search);
        item.setEnabled(Lookup.isAvailable());
    }
    return true;
}