Search in sources :

Example 51 with SubMenu

use of android.view.SubMenu in project GestureViews by alexvasilkov.

the class GestureSettingsMenu method addSubMenu.

private <T> void addSubMenu(Menu menu, T[] items, T selected, @StringRes int titleId) {
    SubMenu sub = menu.addSubMenu(titleId);
    sub.setGroupCheckable(Menu.NONE, true, true);
    for (int i = 0; i < items.length; i++) {
        MenuItem item = sub.add(Menu.NONE, titleId, i, items[i].toString());
        item.setCheckable(true);
        item.setChecked(items[i] == selected);
    }
}
Also used : SubMenu(android.view.SubMenu) MenuItem(android.view.MenuItem)

Example 52 with SubMenu

use of android.view.SubMenu in project platform_frameworks_base by android.

the class Editor method onCreateContextMenu.

void onCreateContextMenu(ContextMenu menu) {
    if (mIsBeingLongClicked || Float.isNaN(mContextMenuAnchorX) || Float.isNaN(mContextMenuAnchorY)) {
        return;
    }
    final int offset = mTextView.getOffsetForPosition(mContextMenuAnchorX, mContextMenuAnchorY);
    if (offset == -1) {
        return;
    }
    stopTextActionModeWithPreservingSelection();
    final boolean isOnSelection = mTextView.hasSelection() && offset >= mTextView.getSelectionStart() && offset <= mTextView.getSelectionEnd();
    if (!isOnSelection) {
        // Right clicked position is not on the selection. Remove the selection and move the
        // cursor to the right clicked position.
        Selection.setSelection((Spannable) mTextView.getText(), offset);
        stopTextActionMode();
    }
    if (shouldOfferToShowSuggestions()) {
        final SuggestionInfo[] suggestionInfoArray = new SuggestionInfo[SuggestionSpan.SUGGESTIONS_MAX_SIZE];
        for (int i = 0; i < suggestionInfoArray.length; i++) {
            suggestionInfoArray[i] = new SuggestionInfo();
        }
        final SubMenu subMenu = menu.addSubMenu(Menu.NONE, Menu.NONE, MENU_ITEM_ORDER_REPLACE, com.android.internal.R.string.replace);
        final int numItems = mSuggestionHelper.getSuggestionInfo(suggestionInfoArray, null);
        for (int i = 0; i < numItems; i++) {
            final SuggestionInfo info = suggestionInfoArray[i];
            subMenu.add(Menu.NONE, Menu.NONE, i, info.mText).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    replaceWithSuggestion(info);
                    return true;
                }
            });
        }
    }
    menu.add(Menu.NONE, TextView.ID_UNDO, MENU_ITEM_ORDER_UNDO, com.android.internal.R.string.undo).setAlphabeticShortcut('z').setOnMenuItemClickListener(mOnContextMenuItemClickListener).setEnabled(mTextView.canUndo());
    menu.add(Menu.NONE, TextView.ID_REDO, MENU_ITEM_ORDER_REDO, com.android.internal.R.string.redo).setOnMenuItemClickListener(mOnContextMenuItemClickListener).setEnabled(mTextView.canRedo());
    menu.add(Menu.NONE, TextView.ID_CUT, MENU_ITEM_ORDER_CUT, com.android.internal.R.string.cut).setAlphabeticShortcut('x').setOnMenuItemClickListener(mOnContextMenuItemClickListener).setEnabled(mTextView.canCut());
    menu.add(Menu.NONE, TextView.ID_COPY, MENU_ITEM_ORDER_COPY, com.android.internal.R.string.copy).setAlphabeticShortcut('c').setOnMenuItemClickListener(mOnContextMenuItemClickListener).setEnabled(mTextView.canCopy());
    menu.add(Menu.NONE, TextView.ID_PASTE, MENU_ITEM_ORDER_PASTE, com.android.internal.R.string.paste).setAlphabeticShortcut('v').setEnabled(mTextView.canPaste()).setOnMenuItemClickListener(mOnContextMenuItemClickListener);
    menu.add(Menu.NONE, TextView.ID_PASTE, MENU_ITEM_ORDER_PASTE_AS_PLAIN_TEXT, com.android.internal.R.string.paste_as_plain_text).setEnabled(mTextView.canPaste()).setOnMenuItemClickListener(mOnContextMenuItemClickListener);
    menu.add(Menu.NONE, TextView.ID_SHARE, MENU_ITEM_ORDER_SHARE, com.android.internal.R.string.share).setEnabled(mTextView.canShare()).setOnMenuItemClickListener(mOnContextMenuItemClickListener);
    menu.add(Menu.NONE, TextView.ID_SELECT_ALL, MENU_ITEM_ORDER_SELECT_ALL, com.android.internal.R.string.selectAll).setAlphabeticShortcut('a').setEnabled(mTextView.canSelectAllText()).setOnMenuItemClickListener(mOnContextMenuItemClickListener);
    mPreserveSelection = true;
}
Also used : SubMenu(android.view.SubMenu) MenuItem(android.view.MenuItem) Paint(android.graphics.Paint)

Example 53 with SubMenu

use of android.view.SubMenu in project platform_frameworks_base by android.

the class ShareActionProvider method onPrepareSubMenu.

/**
     * {@inheritDoc}
     */
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    // Clear since the order of items may change.
    subMenu.clear();
    ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName);
    PackageManager packageManager = mContext.getPackageManager();
    final int expandedActivityCount = dataModel.getActivityCount();
    final int collapsedActivityCount = Math.min(expandedActivityCount, mMaxShownActivityCount);
    // Populate the sub-menu with a sub set of the activities.
    for (int i = 0; i < collapsedActivityCount; i++) {
        ResolveInfo activity = dataModel.getActivity(i);
        subMenu.add(0, i, i, activity.loadLabel(packageManager)).setIcon(activity.loadIcon(packageManager)).setOnMenuItemClickListener(mOnMenuItemClickListener);
    }
    if (collapsedActivityCount < expandedActivityCount) {
        // Add a sub-menu for showing all activities as a list item.
        SubMenu expandedSubMenu = subMenu.addSubMenu(Menu.NONE, collapsedActivityCount, collapsedActivityCount, mContext.getString(R.string.activity_chooser_view_see_all));
        for (int i = 0; i < expandedActivityCount; i++) {
            ResolveInfo activity = dataModel.getActivity(i);
            expandedSubMenu.add(0, i, i, activity.loadLabel(packageManager)).setIcon(activity.loadIcon(packageManager)).setOnMenuItemClickListener(mOnMenuItemClickListener);
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) SubMenu(android.view.SubMenu)

Example 54 with SubMenu

use of android.view.SubMenu in project Shuttle by timusus.

the class MenuUtils method addAlbumArtistMenuOptions.

public static void addAlbumArtistMenuOptions(Context context, PopupMenu menu) {
    menu.getMenu().add(ARTIST_FRAGMENT_GROUP_ID, PLAY_SELECTION, 0, R.string.play_selection);
    SubMenu sub = menu.getMenu().addSubMenu(ARTIST_FRAGMENT_GROUP_ID, ADD_TO_PLAYLIST, 1, R.string.add_to_playlist);
    PlaylistUtils.makePlaylistMenu(context, sub, ARTIST_FRAGMENT_GROUP_ID);
    menu.getMenu().add(ARTIST_FRAGMENT_GROUP_ID, QUEUE, 2, R.string.add_to_queue);
    if (ShuttleUtils.isUpgraded()) {
        menu.getMenu().add(ARTIST_FRAGMENT_GROUP_ID, TAGGER, 3, R.string.edit_tags);
        menu.getMenu().add(ARTIST_FRAGMENT_GROUP_ID, EDIT_ARTWORK, 4, R.string.artwork_edit);
    }
    menu.getMenu().add(QUEUE_FRAGMENT_GROUP_ID, BLACKLIST, 5, R.string.blacklist_title);
    menu.getMenu().add(ARTIST_FRAGMENT_GROUP_ID, DELETE_ITEM, 6, R.string.delete_item);
}
Also used : SubMenu(android.view.SubMenu)

Example 55 with SubMenu

use of android.view.SubMenu in project Shuttle by timusus.

the class MenuUtils method addSongMenuOptions.

public static void addSongMenuOptions(final Context context, final PopupMenu menu) {
    menu.getMenu().add(SONG_FRAGMENT_GROUP_ID, PLAY_NEXT, 0, R.string.play_next);
    SubMenu sub = menu.getMenu().addSubMenu(SONG_FRAGMENT_GROUP_ID, ADD_TO_PLAYLIST, 1, R.string.add_to_playlist);
    PlaylistUtils.makePlaylistMenu(context, sub, SONG_FRAGMENT_GROUP_ID);
    menu.getMenu().add(SONG_FRAGMENT_GROUP_ID, QUEUE, 2, R.string.add_to_queue);
    if (ShuttleUtils.isUpgraded()) {
        menu.getMenu().add(SONG_FRAGMENT_GROUP_ID, TAGGER, 3, R.string.edit_tags);
    }
    menu.getMenu().add(SONG_FRAGMENT_GROUP_ID, USE_AS_RINGTONE, 5, R.string.ringtone_menu);
    menu.getMenu().add(SONG_FRAGMENT_GROUP_ID, VIEW_INFO, 6, R.string.song_info);
    menu.getMenu().add(SONG_FRAGMENT_GROUP_ID, SHARE, 7, R.string.share);
    menu.getMenu().add(SONG_FRAGMENT_GROUP_ID, BLACKLIST, 8, R.string.blacklist_title);
    menu.getMenu().add(SONG_FRAGMENT_GROUP_ID, DELETE_ITEM, 9, R.string.delete_item);
}
Also used : SubMenu(android.view.SubMenu)

Aggregations

SubMenu (android.view.SubMenu)80 MenuItem (android.view.MenuItem)38 View (android.view.View)11 LayoutInflater (android.view.LayoutInflater)10 PackageManager (android.content.pm.PackageManager)9 Bundle (android.os.Bundle)9 Nullable (android.support.annotation.Nullable)9 ViewGroup (android.view.ViewGroup)9 R (com.simplecity.amp_library.R)9 UpgradeDialog (com.simplecity.amp_library.ui.dialog.UpgradeDialog)9 SelectableViewModel (com.simplecity.amp_library.ui.modelviews.SelectableViewModel)9 ContextualToolbar (com.simplecity.amp_library.ui.views.ContextualToolbar)9 ContextualToolbarHelper (com.simplecity.amp_library.utils.ContextualToolbarHelper)9 MenuUtils (com.simplecity.amp_library.utils.MenuUtils)9 PlaylistUtils (com.simplecity.amp_library.utils.PlaylistUtils)9 ViewModel (com.simplecityapps.recycler_adapter.model.ViewModel)9 Disposable (io.reactivex.disposables.Disposable)9 ResolveInfo (android.content.pm.ResolveInfo)8 MusicUtils (com.simplecity.amp_library.utils.MusicUtils)8 RecyclerListener (com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener)8