Search in sources :

Example 71 with MenuItem

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

the class LocalePickerWithRegion method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (mParentLocale == null) {
        inflater.inflate(R.menu.language_selection_list, menu);
        final MenuItem searchMenuItem = menu.findItem(R.id.locale_search_menu);
        mSearchView = (SearchView) searchMenuItem.getActionView();
        mSearchView.setQueryHint(getText(R.string.search_language_hint));
        mSearchView.setOnQueryTextListener(this);
        // Restore previous search status
        if (!TextUtils.isEmpty(mPreviousSearch)) {
            searchMenuItem.expandActionView();
            mSearchView.setIconified(false);
            mSearchView.setActivated(true);
            if (mPreviousSearchHadFocus) {
                mSearchView.requestFocus();
            }
            mSearchView.setQuery(mPreviousSearch, true);
        } else {
            mSearchView.setQuery(null, false);
        }
        // Restore previous scroll position
        getListView().setSelectionFromTop(mFirstVisiblePosition, mTopDistance);
    }
}
Also used : MenuItem(android.view.MenuItem)

Example 72 with MenuItem

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

the class Toolbar method onRestoreInstanceState.

@Override
protected void onRestoreInstanceState(Parcelable state) {
    final SavedState ss = (SavedState) state;
    super.onRestoreInstanceState(ss.getSuperState());
    final Menu menu = mMenuView != null ? mMenuView.peekMenu() : null;
    if (ss.expandedMenuItemId != 0 && mExpandedMenuPresenter != null && menu != null) {
        final MenuItem item = menu.findItem(ss.expandedMenuItemId);
        if (item != null) {
            item.expandActionView();
        }
    }
    if (ss.isOverflowOpen) {
        postShowOverflowMenu();
    }
}
Also used : MenuItem(android.view.MenuItem) Menu(android.view.Menu)

Example 73 with MenuItem

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

the class ActionMenu method addIntentOptions.

public int addIntentOptions(int groupId, int itemId, int order, ComponentName caller, Intent[] specifics, Intent intent, int flags, MenuItem[] outSpecificItems) {
    PackageManager pm = mContext.getPackageManager();
    final List<ResolveInfo> lri = pm.queryIntentActivityOptions(caller, specifics, intent, 0);
    final int N = lri != null ? lri.size() : 0;
    if ((flags & FLAG_APPEND_TO_GROUP) == 0) {
        removeGroup(groupId);
    }
    for (int i = 0; i < N; i++) {
        final ResolveInfo ri = lri.get(i);
        Intent rintent = new Intent(ri.specificIndex < 0 ? intent : specifics[ri.specificIndex]);
        rintent.setComponent(new ComponentName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name));
        final MenuItem item = add(groupId, itemId, order, ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)).setIntent(rintent);
        if (outSpecificItems != null && ri.specificIndex >= 0) {
            outSpecificItems[ri.specificIndex] = item;
        }
    }
    return N;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent) ComponentName(android.content.ComponentName) MenuItem(android.view.MenuItem)

Example 74 with MenuItem

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

the class CascadingMenuPopup method findParentViewForSubmenu.

/**
     * Attempts to find the view for the menu item that owns the specified
     * submenu.
     *
     * @param parentInfo info for the parent menu
     * @param submenu the submenu whose parent view should be obtained
     * @return the parent view, or {@code null} if one could not be found
     */
@Nullable
private View findParentViewForSubmenu(@NonNull CascadingMenuInfo parentInfo, @NonNull MenuBuilder submenu) {
    final MenuItem owner = findMenuItemForSubmenu(parentInfo.menu, submenu);
    if (owner == null) {
        // Couldn't find the submenu owner.
        return null;
    }
    // The adapter may be wrapped. Adjust the index if necessary.
    final int headersCount;
    final MenuAdapter menuAdapter;
    final ListView listView = parentInfo.getListView();
    final ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter instanceof HeaderViewListAdapter) {
        final HeaderViewListAdapter headerAdapter = (HeaderViewListAdapter) listAdapter;
        headersCount = headerAdapter.getHeadersCount();
        menuAdapter = (MenuAdapter) headerAdapter.getWrappedAdapter();
    } else {
        headersCount = 0;
        menuAdapter = (MenuAdapter) listAdapter;
    }
    // Find the index within the menu adapter's data set of the menu item.
    int ownerPosition = AbsListView.INVALID_POSITION;
    for (int i = 0, count = menuAdapter.getCount(); i < count; i++) {
        if (owner == menuAdapter.getItem(i)) {
            ownerPosition = i;
            break;
        }
    }
    if (ownerPosition == AbsListView.INVALID_POSITION) {
        // Couldn't find the owner within the menu adapter.
        return null;
    }
    // Adjust the index for the adapter used to display views.
    ownerPosition += headersCount;
    // Adjust the index for the visible views.
    final int ownerViewPosition = ownerPosition - listView.getFirstVisiblePosition();
    if (ownerViewPosition < 0 || ownerViewPosition >= listView.getChildCount()) {
        // Not visible on screen.
        return null;
    }
    return listView.getChildAt(ownerViewPosition);
}
Also used : AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) MenuItem(android.view.MenuItem) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) ListAdapter(android.widget.ListAdapter) Nullable(android.annotation.Nullable)

Example 75 with MenuItem

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

the class IconMenuPresenter method restoreHierarchyState.

public void restoreHierarchyState(Bundle inState) {
    SparseArray<Parcelable> viewStates = inState.getSparseParcelableArray(VIEWS_TAG);
    if (viewStates != null) {
        ((View) mMenuView).restoreHierarchyState(viewStates);
    }
    int subMenuId = inState.getInt(OPEN_SUBMENU_KEY, 0);
    if (subMenuId > 0 && mMenu != null) {
        MenuItem item = mMenu.findItem(subMenuId);
        if (item != null) {
            onSubMenuSelected((SubMenuBuilder) item.getSubMenu());
        }
    }
}
Also used : Parcelable(android.os.Parcelable) MenuItem(android.view.MenuItem) View(android.view.View) ItemView(com.android.internal.view.menu.MenuView.ItemView)

Aggregations

MenuItem (android.view.MenuItem)761 View (android.view.View)140 Intent (android.content.Intent)86 TextView (android.widget.TextView)78 PopupMenu (android.widget.PopupMenu)62 ImageView (android.widget.ImageView)58 Menu (android.view.Menu)52 SearchView (android.support.v7.widget.SearchView)46 SmallTest (android.test.suitebuilder.annotation.SmallTest)42 RecyclerView (android.support.v7.widget.RecyclerView)36 MenuInflater (android.view.MenuInflater)35 AdapterView (android.widget.AdapterView)33 ListView (android.widget.ListView)32 SubMenu (android.view.SubMenu)30 ComponentName (android.content.ComponentName)25 PackageManager (android.content.pm.PackageManager)25 Parcelable (android.os.Parcelable)24 Toolbar (android.support.v7.widget.Toolbar)24 Bundle (android.os.Bundle)19 PopupMenu (android.support.v7.widget.PopupMenu)19