Search in sources :

Example 31 with SubMenu

use of android.view.SubMenu in project android_frameworks_base by DirtyUnicorns.

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 32 with SubMenu

use of android.view.SubMenu in project android_frameworks_base by DirtyUnicorns.

the class ListContextMenu method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem item = menu.add(0, 0, 0, "Really long menu item name");
    item.setTitleCondensed("Long name");
    item.setIcon(R.drawable.black_square);
    SubMenu sm = menu.addSubMenu(0, 0, 0, "The 2nd item, a sub menu").setIcon(R.drawable.black_square_stretchable);
    item = sm.getItem();
    item.setTitleCondensed("Sub menu");
    sm.add(1, 0, 0, "Subitem 1");
    sm.add(1, 0, 0, "Subitem 2");
    sm.add(1, 0, 0, "Subitem 3");
    sm.setGroupCheckable(1, true, true);
    menu.add(0, 0, 0, "Item 3");
    menu.add(0, 0, 0, "Item 4");
    menu.add(0, 0, 0, "Item 5");
    menu.add(0, 0, 0, "Item 6");
    menu.add(0, 0, 0, "Item 7");
    menu.add(0, 0, 0, "Item 8");
    menu.add(0, 0, 0, "Item 9");
    sm = menu.addSubMenu(0, 0, 0, "Item 10 SM");
    sm.add(0, 0, 0, "Subitem 1");
    sm.add(0, 0, 0, "Subitem 2");
    sm.add(0, 0, 0, "Subitem 3");
    sm.add(0, 0, 0, "Subitem 4");
    sm.add(0, 0, 0, "Subitem 5");
    sm.add(0, 0, 0, "Subitem 6");
    sm.add(0, 0, 0, "Subitem 7");
    sm.add(0, 0, 0, "Subitem 8");
    return true;
}
Also used : MenuItem(android.view.MenuItem) SubMenu(android.view.SubMenu)

Example 33 with SubMenu

use of android.view.SubMenu in project android_frameworks_base by DirtyUnicorns.

the class ListContextMenu method onCreateContextMenu.

public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    String text = ((TextView) info.targetView).getText().toString();
    if (text.contains("[0]")) {
        menu.setHeaderTitle("This is a test of the title and the icon").setHeaderIcon(android.R.drawable.sym_def_app_icon);
    } else if (text.contains("[1]")) {
        menu.setHeaderTitle("This is a test of just the title");
    } else {
        TextView textView = new TextView(this);
        textView.setText("This is a test of a custom View");
        menu.setHeaderView(textView);
    }
    menu.add(0, 0, 0, "Test 1");
    SubMenu sm = menu.addSubMenu(0, 0, 0, "Test 1.5 SM");
    sm.add(0, 0, 0, "CM Subitem 1");
    sm.add(0, 0, 0, "CM Subitem 2");
    sm.add(0, 0, 0, "CM Subitem 3");
    menu.add(0, 0, 0, "Test 2");
    menu.add(0, 0, 0, "Test 3");
    menu.add(0, 0, 0, "Test 4");
    menu.add(0, 0, 0, "Test 5");
    menu.add(0, 0, 0, "Test 6");
    menu.add(0, 0, 0, "Test 7");
    menu.add(0, 0, 0, "Test 8");
    menu.add(0, 0, 0, "Test 9");
    menu.add(0, 0, 0, "Test 10");
    menu.add(0, 0, 0, "Test 11");
    menu.add(0, 0, 0, "Test 12");
    menu.add(0, 0, 0, "Test 13");
    menu.add(0, 0, 0, "Test 14");
    menu.add(0, 0, 0, "Test 15");
    menu.add(0, 0, 0, "Test 16");
    menu.add(0, 0, 0, "Test 17");
    menu.add(0, 0, 0, "Test 18");
    menu.add(0, 0, 0, "Test 19");
    menu.add(0, 0, 0, "Test 20");
    menu.add(0, 0, 0, "Test 21");
    menu.add(0, 0, 0, "Test 22");
    menu.add(0, 0, 0, "Test 23");
    menu.add(0, 0, 0, "Test 24");
}
Also used : AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) SubMenu(android.view.SubMenu)

Example 34 with SubMenu

use of android.view.SubMenu in project android_frameworks_base by DirtyUnicorns.

the class MenuTest method testSubMenu.

@SmallTest
public void testSubMenu() {
    final SubMenu subMenu = mMenu.addSubMenu(0, 0, 0, "submenu");
    final MenuItem subMenuItem = subMenu.getItem();
    final MenuItem item1 = subMenu.add(0, 1, 0, "item1");
    final MenuItem item2 = subMenu.add(0, 2, 0, "item2");
    // findItem should recurse into submenus
    Assert.assertEquals(item1, mMenu.findItem(1));
    Assert.assertEquals(item2, mMenu.findItem(2));
}
Also used : SubMenu(android.view.SubMenu) MenuItem(android.view.MenuItem) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 35 with SubMenu

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

the class AlbumArtistFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu_sort_artists, menu);
    inflater.inflate(R.menu.menu_view_as, menu);
    menu.addSubMenu(0, MENU_GRID_SIZE, 0, R.string.menu_grid_size);
    SubMenu subMenu = menu.findItem(MENU_GRID_SIZE).getSubMenu();
    int[] spanCountArray = getResources().getIntArray(R.array.span_count);
    for (int i = 0; i < spanCountArray.length; i++) {
        subMenu.add(MENU_GROUP_GRID, spanCountArray[i], i, String.valueOf(spanCountArray[i]));
    }
    subMenu.setGroupCheckable(MENU_GROUP_GRID, true, true);
}
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