Search in sources :

Example 36 with MenuBuilder

use of com.android.internal.view.menu.MenuBuilder in project platform_frameworks_base by android.

the class PhoneWindow method initializePanelMenu.

/**
     * Initializes the menu associated with the given panel feature state. You
     * must at the very least set PanelFeatureState.menu to the Menu to be
     * associated with the given panel state. The default implementation creates
     * a new menu for the panel state.
     *
     * @param st The panel whose menu is being initialized.
     * @return Whether the initialization was successful.
     */
protected boolean initializePanelMenu(final PanelFeatureState st) {
    Context context = getContext();
    // If we have an action bar, initialize the menu with the right theme.
    if ((st.featureId == FEATURE_OPTIONS_PANEL || st.featureId == FEATURE_ACTION_BAR) && mDecorContentParent != null) {
        final TypedValue outValue = new TypedValue();
        final Theme baseTheme = context.getTheme();
        baseTheme.resolveAttribute(R.attr.actionBarTheme, outValue, true);
        Theme widgetTheme = null;
        if (outValue.resourceId != 0) {
            widgetTheme = context.getResources().newTheme();
            widgetTheme.setTo(baseTheme);
            widgetTheme.applyStyle(outValue.resourceId, true);
            widgetTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
        } else {
            baseTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
        }
        if (outValue.resourceId != 0) {
            if (widgetTheme == null) {
                widgetTheme = context.getResources().newTheme();
                widgetTheme.setTo(baseTheme);
            }
            widgetTheme.applyStyle(outValue.resourceId, true);
        }
        if (widgetTheme != null) {
            context = new ContextThemeWrapper(context, 0);
            context.getTheme().setTo(widgetTheme);
        }
    }
    final MenuBuilder menu = new MenuBuilder(context);
    menu.setCallback(this);
    st.setMenu(menu);
    return true;
}
Also used : Context(android.content.Context) ContextThemeWrapper(android.view.ContextThemeWrapper) Theme(android.content.res.Resources.Theme) ContextMenuBuilder(com.android.internal.view.menu.ContextMenuBuilder) MenuBuilder(com.android.internal.view.menu.MenuBuilder) TypedValue(android.util.TypedValue)

Example 37 with MenuBuilder

use of com.android.internal.view.menu.MenuBuilder in project platform_frameworks_base by android.

the class ActionBarContextView method initForMode.

public void initForMode(final ActionMode mode) {
    if (mClose == null) {
        LayoutInflater inflater = LayoutInflater.from(mContext);
        mClose = inflater.inflate(mCloseItemLayout, this, false);
        addView(mClose);
    } else if (mClose.getParent() == null) {
        addView(mClose);
    }
    View closeButton = mClose.findViewById(R.id.action_mode_close_button);
    closeButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            mode.finish();
        }
    });
    final MenuBuilder menu = (MenuBuilder) mode.getMenu();
    if (mActionMenuPresenter != null) {
        mActionMenuPresenter.dismissPopupMenus();
    }
    mActionMenuPresenter = new ActionMenuPresenter(mContext);
    mActionMenuPresenter.setReserveOverflow(true);
    final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    if (!mSplitActionBar) {
        menu.addMenuPresenter(mActionMenuPresenter, mPopupContext);
        mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
        mMenuView.setBackground(null);
        addView(mMenuView, layoutParams);
    } else {
        // Allow full screen width in split mode.
        mActionMenuPresenter.setWidthLimit(getContext().getResources().getDisplayMetrics().widthPixels, true);
        // No limit to the item count; use whatever will fit.
        mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
        // Span the whole width
        layoutParams.width = LayoutParams.MATCH_PARENT;
        layoutParams.height = mContentHeight;
        menu.addMenuPresenter(mActionMenuPresenter, mPopupContext);
        mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
        mMenuView.setBackgroundDrawable(mSplitBackground);
        mSplitView.addView(mMenuView, layoutParams);
    }
}
Also used : LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ActionMenuView(android.widget.ActionMenuView) View(android.view.View) MenuBuilder(com.android.internal.view.menu.MenuBuilder) ActionMenuPresenter(android.widget.ActionMenuPresenter)

Example 38 with MenuBuilder

use of com.android.internal.view.menu.MenuBuilder in project platform_frameworks_base by android.

the class ActionBarView method setMenu.

public void setMenu(Menu menu, MenuPresenter.Callback cb) {
    if (menu == mOptionsMenu)
        return;
    if (mOptionsMenu != null) {
        mOptionsMenu.removeMenuPresenter(mActionMenuPresenter);
        mOptionsMenu.removeMenuPresenter(mExpandedMenuPresenter);
    }
    MenuBuilder builder = (MenuBuilder) menu;
    mOptionsMenu = builder;
    if (mMenuView != null) {
        final ViewGroup oldParent = (ViewGroup) mMenuView.getParent();
        if (oldParent != null) {
            oldParent.removeView(mMenuView);
        }
    }
    if (mActionMenuPresenter == null) {
        mActionMenuPresenter = new ActionMenuPresenter(mContext);
        mActionMenuPresenter.setCallback(cb);
        mActionMenuPresenter.setId(com.android.internal.R.id.action_menu_presenter);
        mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter();
    }
    ActionMenuView menuView;
    final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    if (!mSplitActionBar) {
        mActionMenuPresenter.setExpandedActionViewsExclusive(getResources().getBoolean(com.android.internal.R.bool.action_bar_expanded_action_views_exclusive));
        configPresenters(builder);
        menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
        final ViewGroup oldParent = (ViewGroup) menuView.getParent();
        if (oldParent != null && oldParent != this) {
            oldParent.removeView(menuView);
        }
        addView(menuView, layoutParams);
    } else {
        mActionMenuPresenter.setExpandedActionViewsExclusive(false);
        // Allow full screen width in split mode.
        mActionMenuPresenter.setWidthLimit(getContext().getResources().getDisplayMetrics().widthPixels, true);
        // No limit to the item count; use whatever will fit.
        mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
        // Span the whole width
        layoutParams.width = LayoutParams.MATCH_PARENT;
        layoutParams.height = LayoutParams.WRAP_CONTENT;
        configPresenters(builder);
        menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
        if (mSplitView != null) {
            final ViewGroup oldParent = (ViewGroup) menuView.getParent();
            if (oldParent != null && oldParent != mSplitView) {
                oldParent.removeView(menuView);
            }
            menuView.setVisibility(getAnimatedVisibility());
            mSplitView.addView(menuView, layoutParams);
        } else {
            // We'll add this later if we missed it this time.
            menuView.setLayoutParams(layoutParams);
        }
    }
    mMenuView = menuView;
}
Also used : ViewGroup(android.view.ViewGroup) ActionMenuView(android.widget.ActionMenuView) SubMenuBuilder(com.android.internal.view.menu.SubMenuBuilder) MenuBuilder(com.android.internal.view.menu.MenuBuilder) ActionMenuPresenter(android.widget.ActionMenuPresenter)

Example 39 with MenuBuilder

use of com.android.internal.view.menu.MenuBuilder in project android_frameworks_base by ParanoidAndroid.

the class View method createContextMenu.

/**
     * Show the context menu for this view. It is not safe to hold on to the
     * menu after returning from this method.
     *
     * You should normally not overload this method. Overload
     * {@link #onCreateContextMenu(ContextMenu)} or define an
     * {@link OnCreateContextMenuListener} to add items to the context menu.
     *
     * @param menu The context menu to populate
     */
public void createContextMenu(ContextMenu menu) {
    ContextMenuInfo menuInfo = getContextMenuInfo();
    // Sets the current menu info so all items added to menu will have
    // my extra info set.
    ((MenuBuilder) menu).setCurrentMenuInfo(menuInfo);
    onCreateContextMenu(menu);
    ListenerInfo li = mListenerInfo;
    if (li != null && li.mOnCreateContextMenuListener != null) {
        li.mOnCreateContextMenuListener.onCreateContextMenu(menu, this, menuInfo);
    }
    // Clear the extra information so subsequent items that aren't mine don't
    // have my extra info.
    ((MenuBuilder) menu).setCurrentMenuInfo(null);
    if (mParent != null) {
        mParent.createContextMenu(menu);
    }
}
Also used : ContextMenuInfo(android.view.ContextMenu.ContextMenuInfo) MenuBuilder(com.android.internal.view.menu.MenuBuilder)

Example 40 with MenuBuilder

use of com.android.internal.view.menu.MenuBuilder in project android_frameworks_base by ParanoidAndroid.

the class MenuTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    mMenu = new MenuBuilder(super.getContext());
}
Also used : MenuBuilder(com.android.internal.view.menu.MenuBuilder)

Aggregations

MenuBuilder (com.android.internal.view.menu.MenuBuilder)67 SubMenuBuilder (com.android.internal.view.menu.SubMenuBuilder)22 Context (android.content.Context)11 ActionMenuPresenter (android.widget.ActionMenuPresenter)10 ActionMenuView (android.widget.ActionMenuView)10 LayoutInflater (android.view.LayoutInflater)7 View (android.view.View)7 ViewGroup (android.view.ViewGroup)7 TextView (android.widget.TextView)7 TypedValue (android.util.TypedValue)6 ContextMenuInfo (android.view.ContextMenu.ContextMenuInfo)6 ContextThemeWrapper (android.view.ContextThemeWrapper)6 ContextMenuBuilder (com.android.internal.view.menu.ContextMenuBuilder)6 Theme (android.content.res.Resources.Theme)5 TypedArray (android.content.res.TypedArray)5 DisplayMetrics (android.util.DisplayMetrics)5 Menu (android.view.Menu)5 MenuInflater (android.view.MenuInflater)5 LayoutParams (android.view.ViewGroup.LayoutParams)5 ListView (android.widget.ListView)5