use of android.widget.MenuPopupWindow in project platform_frameworks_base by android.
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();
}
}
use of android.widget.MenuPopupWindow in project android_frameworks_base by ResurrectionRemix.
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();
}
}
use of android.widget.MenuPopupWindow in project android_frameworks_base by DirtyUnicorns.
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();
}
}
use of android.widget.MenuPopupWindow in project android_frameworks_base by crdroidandroid.
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();
}
}
use of android.widget.MenuPopupWindow in project platform_frameworks_base by android.
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;
}
Aggregations