Search in sources :

Example 6 with MenuPopupWindow

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

the class CascadingMenuPopup method showMenu.

/**
     * Prepares and shows the specified menu immediately.
     *
     * @param menu the menu to show
     */
private void showMenu(@NonNull MenuBuilder menu) {
    final LayoutInflater inflater = LayoutInflater.from(mContext);
    final MenuAdapter adapter = new MenuAdapter(menu, inflater, mOverflowOnly);
    // (3) This is the top level menu and icon spacing isn't forced. Do not add spacing.
    if (!isShowing() && mForceShowIcon) {
        // Case 1
        adapter.setForceShowIcon(true);
    } else if (isShowing()) {
        // Case 2
        adapter.setForceShowIcon(MenuPopup.shouldPreserveIconSpacing(menu));
    }
    // Case 3: Else, don't allow spacing for icons (default behavior; do nothing).
    final int menuWidth = measureIndividualMenuWidth(adapter, null, mContext, mMenuMaxWidth);
    final MenuPopupWindow popupWindow = createPopupWindow();
    popupWindow.setAdapter(adapter);
    popupWindow.setContentWidth(menuWidth);
    popupWindow.setDropDownGravity(mDropDownGravity);
    final CascadingMenuInfo parentInfo;
    final View parentView;
    if (mShowingMenus.size() > 0) {
        parentInfo = mShowingMenus.get(mShowingMenus.size() - 1);
        parentView = findParentViewForSubmenu(parentInfo, menu);
    } else {
        parentInfo = null;
        parentView = null;
    }
    if (parentView != null) {
        // This menu is a cascading submenu anchored to a parent view.
        popupWindow.setTouchModal(false);
        popupWindow.setEnterTransition(null);
        @HorizPosition final int nextMenuPosition = getNextMenuPosition(menuWidth);
        final boolean showOnRight = nextMenuPosition == HORIZ_POSITION_RIGHT;
        mLastPosition = nextMenuPosition;
        final int[] tempLocation = new int[2];
        // This popup menu will be positioned relative to the top-left edge
        // of the view representing its parent menu.
        parentView.getLocationInWindow(tempLocation);
        final int parentOffsetLeft = parentInfo.window.getHorizontalOffset() + tempLocation[0];
        final int parentOffsetTop = parentInfo.window.getVerticalOffset() + tempLocation[1];
        // By now, mDropDownGravity is the resolved absolute gravity, so
        // this should work in both LTR and RTL.
        final int x;
        if ((mDropDownGravity & Gravity.RIGHT) == Gravity.RIGHT) {
            if (showOnRight) {
                x = parentOffsetLeft + menuWidth;
            } else {
                x = parentOffsetLeft - parentView.getWidth();
            }
        } else {
            if (showOnRight) {
                x = parentOffsetLeft + parentView.getWidth();
            } else {
                x = parentOffsetLeft - menuWidth;
            }
        }
        popupWindow.setHorizontalOffset(x);
        final int y = parentOffsetTop;
        popupWindow.setVerticalOffset(y);
    } else {
        if (mHasXOffset) {
            popupWindow.setHorizontalOffset(mXOffset);
        }
        if (mHasYOffset) {
            popupWindow.setVerticalOffset(mYOffset);
        }
        final Rect epicenterBounds = getEpicenterBounds();
        popupWindow.setEpicenterBounds(epicenterBounds);
    }
    final CascadingMenuInfo menuInfo = new CascadingMenuInfo(popupWindow, menu, mLastPosition);
    mShowingMenus.add(menuInfo);
    popupWindow.show();
    // If this is the root menu, show the title if requested.
    if (parentInfo == null && mShowTitle && menu.getHeaderTitle() != null) {
        final ListView listView = popupWindow.getListView();
        final FrameLayout titleItemView = (FrameLayout) inflater.inflate(R.layout.popup_menu_header_item_layout, listView, false);
        final TextView titleView = (TextView) titleItemView.findViewById(R.id.title);
        titleItemView.setEnabled(false);
        titleView.setText(menu.getHeaderTitle());
        listView.addHeaderView(titleItemView, null, false);
        // Show again to update the title.
        popupWindow.show();
    }
}
Also used : Rect(android.graphics.Rect) MenuPopupWindow(android.widget.MenuPopupWindow) View(android.view.View) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) LayoutInflater(android.view.LayoutInflater) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView)

Example 7 with MenuPopupWindow

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

the class CascadingMenuPopup method createPopupWindow.

private MenuPopupWindow createPopupWindow() {
    MenuPopupWindow popupWindow = new MenuPopupWindow(mContext, null, mPopupStyleAttr, mPopupStyleRes);
    popupWindow.setHoverListener(mMenuItemHoverListener);
    popupWindow.setOnItemClickListener(this);
    popupWindow.setOnDismissListener(this);
    popupWindow.setAnchorView(mAnchorView);
    popupWindow.setDropDownGravity(mDropDownGravity);
    popupWindow.setModal(true);
    popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
    return popupWindow;
}
Also used : MenuPopupWindow(android.widget.MenuPopupWindow)

Example 8 with MenuPopupWindow

use of android.widget.MenuPopupWindow in project android_frameworks_base by ResurrectionRemix.

the class CascadingMenuPopup method createPopupWindow.

private MenuPopupWindow createPopupWindow() {
    MenuPopupWindow popupWindow = new MenuPopupWindow(mContext, null, mPopupStyleAttr, mPopupStyleRes);
    popupWindow.setHoverListener(mMenuItemHoverListener);
    popupWindow.setOnItemClickListener(this);
    popupWindow.setOnDismissListener(this);
    popupWindow.setAnchorView(mAnchorView);
    popupWindow.setDropDownGravity(mDropDownGravity);
    popupWindow.setModal(true);
    popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
    return popupWindow;
}
Also used : MenuPopupWindow(android.widget.MenuPopupWindow)

Example 9 with MenuPopupWindow

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

the class CascadingMenuPopup method createPopupWindow.

private MenuPopupWindow createPopupWindow() {
    MenuPopupWindow popupWindow = new MenuPopupWindow(mContext, null, mPopupStyleAttr, mPopupStyleRes);
    popupWindow.setHoverListener(mMenuItemHoverListener);
    popupWindow.setOnItemClickListener(this);
    popupWindow.setOnDismissListener(this);
    popupWindow.setAnchorView(mAnchorView);
    popupWindow.setDropDownGravity(mDropDownGravity);
    popupWindow.setModal(true);
    popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
    return popupWindow;
}
Also used : MenuPopupWindow(android.widget.MenuPopupWindow)

Example 10 with MenuPopupWindow

use of android.widget.MenuPopupWindow in project android_frameworks_base by crdroidandroid.

the class CascadingMenuPopup method createPopupWindow.

private MenuPopupWindow createPopupWindow() {
    MenuPopupWindow popupWindow = new MenuPopupWindow(mContext, null, mPopupStyleAttr, mPopupStyleRes);
    popupWindow.setHoverListener(mMenuItemHoverListener);
    popupWindow.setOnItemClickListener(this);
    popupWindow.setOnDismissListener(this);
    popupWindow.setAnchorView(mAnchorView);
    popupWindow.setDropDownGravity(mDropDownGravity);
    popupWindow.setModal(true);
    popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
    return popupWindow;
}
Also used : MenuPopupWindow(android.widget.MenuPopupWindow)

Aggregations

MenuPopupWindow (android.widget.MenuPopupWindow)10 Rect (android.graphics.Rect)5 LayoutInflater (android.view.LayoutInflater)5 View (android.view.View)5 AbsListView (android.widget.AbsListView)5 FrameLayout (android.widget.FrameLayout)5 ListView (android.widget.ListView)5 TextView (android.widget.TextView)5