Commit bc927617 authored by Matthew Jones's avatar Matthew Jones Committed by Commit Bot

Fix bottom anchored overflow menu position in Duet

This patch re-adds some of the code that was removed during Chrome
Home cleanup to correctly position the overflow menu when anchored to
the bottom of the screen (removal patch fround here:
https://chromium-review.googlesource.com/c/chromium/src/+/934978).

Bug: 866265
Change-Id: I4e4341b138cd9315f9a7fae8cbf47487923a0086
Reviewed-on: https://chromium-review.googlesource.com/1161174Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580300}
parent 723bb5d5
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
via scrolling. --> via scrolling. -->
<dimen name="menu_vertical_fade_distance">15dp</dimen> <dimen name="menu_vertical_fade_distance">15dp</dimen>
<dimen name="menu_badge_translation_y_distance">6dp</dimen> <dimen name="menu_badge_translation_y_distance">6dp</dimen>
<dimen name="menu_negative_vertical_offset_not_top_anchored">4dp</dimen>
<!-- Menu button dragging related dimensions --> <!-- Menu button dragging related dimensions -->
<dimen name="auto_scroll_full_velocity">500dp</dimen> <dimen name="auto_scroll_full_velocity">500dp</dimen>
......
...@@ -59,6 +59,7 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -59,6 +59,7 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
private final int mItemDividerHeight; private final int mItemDividerHeight;
private final int mVerticalFadeDistance; private final int mVerticalFadeDistance;
private final int mNegativeSoftwareVerticalOffset; private final int mNegativeSoftwareVerticalOffset;
private final int mNegativeVerticalOffsetNotTopAnchored;
private final int[] mTempLocation; private final int[] mTempLocation;
private PopupWindow mPopup; private PopupWindow mPopup;
...@@ -95,6 +96,8 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -95,6 +96,8 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
mNegativeSoftwareVerticalOffset = mNegativeSoftwareVerticalOffset =
res.getDimensionPixelSize(R.dimen.menu_negative_software_vertical_offset); res.getDimensionPixelSize(R.dimen.menu_negative_software_vertical_offset);
mVerticalFadeDistance = res.getDimensionPixelSize(R.dimen.menu_vertical_fade_distance); mVerticalFadeDistance = res.getDimensionPixelSize(R.dimen.menu_vertical_fade_distance);
mNegativeVerticalOffsetNotTopAnchored =
res.getDimensionPixelSize(R.dimen.menu_negative_vertical_offset_not_top_anchored);
mTempLocation = new int[2]; mTempLocation = new int[2];
} }
...@@ -256,7 +259,7 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -256,7 +259,7 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
int popupHeight = setMenuHeight(menuItems.size(), visibleDisplayFrame, screenHeight, int popupHeight = setMenuHeight(menuItems.size(), visibleDisplayFrame, screenHeight,
sizingPadding, footerHeight, headerHeight, anchorView); sizingPadding, footerHeight, headerHeight, anchorView);
int[] popupPosition = getPopupPosition(mCurrentScreenRotation, visibleDisplayFrame, int[] popupPosition = getPopupPosition(mCurrentScreenRotation, visibleDisplayFrame,
sizingPadding, anchorView, popupWidth, popupHeight); sizingPadding, anchorView, popupWidth, popupHeight, showFromBottom);
mPopup.setContentView(contentView); mPopup.setContentView(contentView);
mPopup.showAtLocation( mPopup.showAtLocation(
...@@ -295,7 +298,7 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -295,7 +298,7 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
} }
private int[] getPopupPosition(int screenRotation, Rect appRect, Rect padding, View anchorView, private int[] getPopupPosition(int screenRotation, Rect appRect, Rect padding, View anchorView,
int popupWidth, int popupHeight) { int popupWidth, int popupHeight, boolean isAnchorAtBottom) {
anchorView.getLocationInWindow(mTempLocation); anchorView.getLocationInWindow(mTempLocation);
int anchorViewX = mTempLocation[0]; int anchorViewX = mTempLocation[0];
int anchorViewY = mTempLocation[1]; int anchorViewY = mTempLocation[1];
...@@ -326,6 +329,18 @@ public class AppMenu implements OnItemClickListener, OnKeyListener { ...@@ -326,6 +329,18 @@ public class AppMenu implements OnItemClickListener, OnKeyListener {
} else { } else {
offsets[1] = -mNegativeSoftwareVerticalOffset; offsets[1] = -mNegativeSoftwareVerticalOffset;
// If the anchor is at the bottom of the screen, align the popup with the bottom of the
// anchor. The anchor may not be fully visible, so
// (appRect.bottom - anchorViewLocationOnScreenY) is used to determine the visible
// bottom edge of the anchor view.
if (isAnchorAtBottom) {
anchorView.getLocationOnScreen(mTempLocation);
int anchorViewLocationOnScreenY = mTempLocation[1];
offsets[1] += appRect.bottom - anchorViewLocationOnScreenY - popupHeight;
offsets[1] -= mNegativeVerticalOffsetNotTopAnchored;
if (!mIsByPermanentButton) offsets[1] += padding.bottom;
}
if (!ApiCompatibilityUtils.isLayoutRtl(anchorView.getRootView())) { if (!ApiCompatibilityUtils.isLayoutRtl(anchorView.getRootView())) {
offsets[0] = anchorView.getWidth() - popupWidth; offsets[0] = anchorView.getWidth() - popupWidth;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment