Search in sources :

Example 1 with ActionMenuPresenter

use of android.widget.ActionMenuPresenter in project android_frameworks_base by DirtyUnicorns.

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 2 with ActionMenuPresenter

use of android.widget.ActionMenuPresenter in project android_frameworks_base by AOSPA.

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

use of android.widget.ActionMenuPresenter in project android_frameworks_base by AOSPA.

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

use of android.widget.ActionMenuPresenter in project android_frameworks_base by AOSPA.

the class ToolbarWidgetWrapper method setMenu.

@Override
public void setMenu(Menu menu, MenuPresenter.Callback cb) {
    if (mActionMenuPresenter == null) {
        mActionMenuPresenter = new ActionMenuPresenter(mToolbar.getContext());
        mActionMenuPresenter.setId(com.android.internal.R.id.action_menu_presenter);
    }
    mActionMenuPresenter.setCallback(cb);
    mToolbar.setMenu((MenuBuilder) menu, mActionMenuPresenter);
}
Also used : ActionMenuPresenter(android.widget.ActionMenuPresenter)

Example 5 with ActionMenuPresenter

use of android.widget.ActionMenuPresenter in project android_frameworks_base by AOSPA.

the class FrameworkActionBar method isOverflowPopupNeeded.

private boolean isOverflowPopupNeeded() {
    boolean needed = mActionBar.isOverflowPopupNeeded();
    if (!needed) {
        return false;
    }
    // Copied from android.widget.ActionMenuPresenter.updateMenuView()
    ArrayList<MenuItemImpl> menus = mActionBar.getMenuBuilder().getNonActionItems();
    ActionMenuPresenter presenter = mActionBar.getActionMenuPresenter();
    if (presenter == null) {
        throw new RuntimeException("Failed to create a Presenter for Action Bar Menus.");
    }
    if (presenter.isOverflowReserved() && menus != null) {
        final int count = menus.size();
        if (count == 1) {
            needed = !menus.get(0).isActionViewExpanded();
        } else {
            needed = count > 0;
        }
    }
    return needed;
}
Also used : MenuItemImpl(com.android.internal.view.menu.MenuItemImpl) ActionMenuPresenter(android.widget.ActionMenuPresenter)

Aggregations

ActionMenuPresenter (android.widget.ActionMenuPresenter)20 ActionMenuView (android.widget.ActionMenuView)10 MenuBuilder (com.android.internal.view.menu.MenuBuilder)10 LayoutInflater (android.view.LayoutInflater)5 View (android.view.View)5 ViewGroup (android.view.ViewGroup)5 TextView (android.widget.TextView)5 MenuItemImpl (com.android.internal.view.menu.MenuItemImpl)5 SubMenuBuilder (com.android.internal.view.menu.SubMenuBuilder)5