Search in sources :

Example 21 with MenuItem

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

the class ActionBarView method onRestoreInstanceState.

@Override
public void onRestoreInstanceState(Parcelable p) {
    SavedState state = (SavedState) p;
    super.onRestoreInstanceState(state.getSuperState());
    if (state.expandedMenuItemId != 0 && mExpandedMenuPresenter != null && mOptionsMenu != null) {
        final MenuItem item = mOptionsMenu.findItem(state.expandedMenuItemId);
        if (item != null) {
            item.expandActionView();
        }
    }
    if (state.isOverflowOpen) {
        postShowOverflowMenu();
    }
}
Also used : ActionMenuItem(com.android.internal.view.menu.ActionMenuItem) MenuItem(android.view.MenuItem)

Example 22 with MenuItem

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

the class MenuBuilder method restoreActionViewStates.

public void restoreActionViewStates(Bundle states) {
    if (states == null) {
        return;
    }
    SparseArray<Parcelable> viewStates = states.getSparseParcelableArray(getActionViewStatesKey());
    final int itemCount = size();
    for (int i = 0; i < itemCount; i++) {
        final MenuItem item = getItem(i);
        final View v = item.getActionView();
        if (v != null && v.getId() != View.NO_ID) {
            v.restoreHierarchyState(viewStates);
        }
        if (item.hasSubMenu()) {
            final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
            subMenu.restoreActionViewStates(states);
        }
    }
    final int expandedId = states.getInt(EXPANDED_ACTION_VIEW_ID);
    if (expandedId > 0) {
        MenuItem itemToExpand = findItem(expandedId);
        if (itemToExpand != null) {
            itemToExpand.expandActionView();
        }
    }
}
Also used : Parcelable(android.os.Parcelable) MenuItem(android.view.MenuItem) View(android.view.View)

Example 23 with MenuItem

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

the class MenuBuilder method saveActionViewStates.

public void saveActionViewStates(Bundle outStates) {
    SparseArray<Parcelable> viewStates = null;
    final int itemCount = size();
    for (int i = 0; i < itemCount; i++) {
        final MenuItem item = getItem(i);
        final View v = item.getActionView();
        if (v != null && v.getId() != View.NO_ID) {
            if (viewStates == null) {
                viewStates = new SparseArray<Parcelable>();
            }
            v.saveHierarchyState(viewStates);
            if (item.isActionViewExpanded()) {
                outStates.putInt(EXPANDED_ACTION_VIEW_ID, item.getItemId());
            }
        }
        if (item.hasSubMenu()) {
            final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
            subMenu.saveActionViewStates(outStates);
        }
    }
    if (viewStates != null) {
        outStates.putSparseParcelableArray(getActionViewStatesKey(), viewStates);
    }
}
Also used : Parcelable(android.os.Parcelable) MenuItem(android.view.MenuItem) View(android.view.View)

Example 24 with MenuItem

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

the class MenuPopupHelper method onSubMenuSelected.

@Override
public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
    if (subMenu.hasVisibleItems()) {
        MenuPopupHelper subPopup = new MenuPopupHelper(mContext, subMenu, mAnchorView, false);
        subPopup.setCallback(mPresenterCallback);
        boolean preserveIconSpacing = false;
        final int count = subMenu.size();
        for (int i = 0; i < count; i++) {
            MenuItem childItem = subMenu.getItem(i);
            if (childItem.isVisible() && childItem.getIcon() != null) {
                preserveIconSpacing = true;
                break;
            }
        }
        subPopup.setForceShowIcon(preserveIconSpacing);
        if (subPopup.tryShow()) {
            if (mPresenterCallback != null) {
                mPresenterCallback.onOpenSubMenu(subMenu);
            }
            return true;
        }
    }
    return false;
}
Also used : MenuItem(android.view.MenuItem)

Example 25 with MenuItem

use of android.view.MenuItem 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)

Aggregations

MenuItem (android.view.MenuItem)713 View (android.view.View)125 Intent (android.content.Intent)75 TextView (android.widget.TextView)66 ImageView (android.widget.ImageView)55 PopupMenu (android.widget.PopupMenu)54 Menu (android.view.Menu)47 SmallTest (android.test.suitebuilder.annotation.SmallTest)42 SearchView (android.support.v7.widget.SearchView)41 RecyclerView (android.support.v7.widget.RecyclerView)32 MenuInflater (android.view.MenuInflater)29 AdapterView (android.widget.AdapterView)27 ListView (android.widget.ListView)27 SubMenu (android.view.SubMenu)26 ComponentName (android.content.ComponentName)25 PackageManager (android.content.pm.PackageManager)24 Parcelable (android.os.Parcelable)23 Toolbar (android.support.v7.widget.Toolbar)19 ResolveInfo (android.content.pm.ResolveInfo)18 Bundle (android.os.Bundle)18