Fix popup container alignment issues
- Arrow did not line up with the icon when right aligned
- Popup was always centered horizontally in RTL instead
of aligning with the icon
Change-Id: I90e065d0b0c1c59166e5c2e5de5e6cff9126ee6f
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 1ae7cbf..36eb34b 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -199,10 +199,6 @@
<dimen name="popup_arrow_horizontal_center_start">28dp</dimen>
<!-- popup_padding_end + deep_shortcut_drag_handle_size / 2 -->
<dimen name="popup_arrow_horizontal_center_end">24dp</dimen>
- <!-- popup_arrow_center_start - popup_arrow_width / 2-->
- <dimen name="popup_arrow_horizontal_offset_start">23dp</dimen>
- <!-- popup_arrow_center_end - popup_arrow_width / 2-->
- <dimen name="popup_arrow_horizontal_offset_end">19dp</dimen>
<dimen name="popup_arrow_corner_radius">2dp</dimen>
<!-- popup_padding_start + icon_size + 10dp -->
<dimen name="deep_shortcuts_text_padding_start">56dp</dimen>
diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java
index a166dff..6481183 100644
--- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java
+++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java
@@ -341,15 +341,17 @@
updateDividers();
// Add the arrow.
- final int arrowHorizontalOffset = getResources().getDimensionPixelSize(isAlignedWithStart()
- ? R.dimen.popup_arrow_horizontal_offset_start
- : R.dimen.popup_arrow_horizontal_offset_end);
+ final Resources res = getResources();
+ final int arrowCenterOffset = res.getDimensionPixelSize(isAlignedWithStart()
+ ? R.dimen.popup_arrow_horizontal_center_start
+ : R.dimen.popup_arrow_horizontal_center_end);
+ final int halfArrowWidth = res.getDimensionPixelSize(R.dimen.popup_arrow_width) / 2;
mLauncher.getDragLayer().addView(mArrow);
DragLayer.LayoutParams arrowLp = (DragLayer.LayoutParams) mArrow.getLayoutParams();
if (mIsLeftAligned) {
- mArrow.setX(getX() + arrowHorizontalOffset);
+ mArrow.setX(getX() + arrowCenterOffset - halfArrowWidth);
} else {
- mArrow.setX(getX() + getMeasuredWidth() - arrowHorizontalOffset);
+ mArrow.setX(getX() + getMeasuredWidth() - arrowCenterOffset - halfArrowWidth);
}
if (Gravity.isVertical(mGravity)) {
@@ -435,9 +437,6 @@
x = rightAlignedX;
}
mIsLeftAligned = x == leftAlignedX;
- if (mIsRtl) {
- x -= dragLayer.getWidth() - width;
- }
// Offset x so that the arrow and shortcut icons are center-aligned with the original icon.
int iconWidth = mOriginalIcon.getWidth()
@@ -529,8 +528,7 @@
// enforce contained is within screen
DragLayer dragLayer = mLauncher.getDragLayer();
- if (getTranslationX() + l < 0 ||
- getTranslationX() + r > dragLayer.getWidth()) {
+ if (getTranslationX() + l < 0 || getTranslationX() + r > dragLayer.getWidth()) {
// If we are still off screen, center horizontally too.
mGravity |= Gravity.CENTER_HORIZONTAL;
}