Search in sources :

Example 1 with SubMenu

use of android.view.SubMenu in project Android-ShareEverywhere by dgmltn.

the class ShareActionProvider method onPrepareSubMenu.

@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    super.onPrepareSubMenu(subMenu);
    // Clear since the order of items may change.
    subMenu.clear();
    ActivityChooserModel dataModel = mShareView.getActivityChooserModel();
    final int expandedActivityCount = dataModel.getActivityCount();
    final int collapsedActivityCount = Math.min(expandedActivityCount, ShareView.DEFAULT_INITIAL_ACTIVITY_COUNT);
    // Populate the sub-menu with a sub set of the activities.
    for (int i = 0; i < collapsedActivityCount; i++) {
        ActivityResolveInfo activity = dataModel.getActivity(i);
        subMenu.add(0, i, i, activity.label).setIcon(activity.icon).setOnMenuItemClickListener(mShareView.mCallbacks);
    }
    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.See_all___));
        for (int i = 0; i < expandedActivityCount; i++) {
            ActivityResolveInfo activity = dataModel.getActivity(i);
            expandedSubMenu.add(0, i, i, activity.label).setIcon(activity.icon).setOnMenuItemClickListener(mShareView.mCallbacks);
        }
    }
}
Also used : SubMenu(android.view.SubMenu) ActivityResolveInfo(com.dgmltn.shareeverywhere.ActivityChooserModel.ActivityResolveInfo)

Example 2 with SubMenu

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

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

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

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

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

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

use of android.view.SubMenu in project HoloEverywhere by Prototik.

the class SupportMenuInflater method parseMenu.

/**
     * Called internally to fill the given menu. If a sub menu is seen, it will
     * call this recursively.
     */
private void parseMenu(XmlPullParser parser, AttributeSet attrs, Menu menu) throws XmlPullParserException, IOException {
    MenuState menuState = new MenuState(menu);
    int eventType = parser.getEventType();
    String tagName;
    boolean lookingForEndOfUnknownTag = false;
    String unknownTagName = null;
    // This loop will skip to the menu start tag
    do {
        if (eventType == XmlPullParser.START_TAG) {
            tagName = parser.getName();
            if (tagName.equals(XML_MENU)) {
                // Go to next tag
                eventType = parser.next();
                break;
            }
            throw new RuntimeException("Expecting menu, got " + tagName);
        }
        eventType = parser.next();
    } while (eventType != XmlPullParser.END_DOCUMENT);
    boolean reachedEndOfMenu = false;
    while (!reachedEndOfMenu) {
        switch(eventType) {
            case XmlPullParser.START_TAG:
                if (lookingForEndOfUnknownTag) {
                    break;
                }
                tagName = parser.getName();
                if (tagName.equals(XML_GROUP)) {
                    menuState.readGroup(attrs);
                } else if (tagName.equals(XML_ITEM)) {
                    menuState.readItem(attrs);
                } else if (tagName.equals(XML_MENU)) {
                    // A menu start tag denotes a submenu for an item
                    SubMenu subMenu = menuState.addSubMenuItem();
                    // Parse the submenu into returned SubMenu
                    parseMenu(parser, attrs, subMenu);
                } else {
                    lookingForEndOfUnknownTag = true;
                    unknownTagName = tagName;
                }
                break;
            case XmlPullParser.END_TAG:
                tagName = parser.getName();
                if (lookingForEndOfUnknownTag && tagName.equals(unknownTagName)) {
                    lookingForEndOfUnknownTag = false;
                    unknownTagName = null;
                } else if (tagName.equals(XML_GROUP)) {
                    menuState.resetGroup();
                } else if (tagName.equals(XML_ITEM)) {
                    // a submenu, it would have been added already)
                    if (!menuState.hasAddedItem()) {
                        if (menuState.itemActionProvider != null && menuState.itemActionProvider.hasSubMenu()) {
                            menuState.addSubMenuItem();
                        } else {
                            menuState.addItem();
                        }
                    }
                } else if (tagName.equals(XML_MENU)) {
                    reachedEndOfMenu = true;
                }
                break;
            case XmlPullParser.END_DOCUMENT:
                throw new RuntimeException("Unexpected end of document");
        }
        eventType = parser.next();
    }
}
Also used : SubMenu(android.view.SubMenu)

Aggregations

SubMenu (android.view.SubMenu)64 MenuItem (android.view.MenuItem)25 PackageManager (android.content.pm.PackageManager)9 ResolveInfo (android.content.pm.ResolveInfo)8 TextView (android.widget.TextView)8 AdapterView (android.widget.AdapterView)7 SmallTest (android.test.suitebuilder.annotation.SmallTest)6 Paint (android.graphics.Paint)5 ArrayList (java.util.ArrayList)5 Cursor (android.database.Cursor)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2 Drawable (android.graphics.drawable.Drawable)2 PopupMenu (android.support.v7.widget.PopupMenu)2 RecyclerView (android.support.v7.widget.RecyclerView)2 MenuInflater (android.view.MenuInflater)2 View (android.view.View)2 Playlist (com.simplecity.amp_library.model.Playlist)2 TargetApi (android.annotation.TargetApi)1 ProgressDialog (android.app.ProgressDialog)1