From ade96d0199c4cec4d259afe120a84e05c701d228 Mon Sep 17 00:00:00 2001 From: Artsiom Mitrokhin Date: Mon, 21 Oct 2024 10:56:41 -0400 Subject: [PATCH] Update popup and arrow positioning logic 1) By default, it's centered relative to the event position https://screenshot.googleplex.com/5Wri2CX3vASCxWt 2) It becomes left or right aligned near edges of the screen https://screenshot.googleplex.com/9AEQxWcmYX63jTv https://screenshot.googleplex.com/39KMeG2eWKr2QC6 3) And never goes beyond the minimum padding https://screenshot.googleplex.com/5LiPHiXiJSyGdx5 https://screenshot.googleplex.com/86KQnKXa38NoYpM Bug: 297325541 Flag: com.android.launcher3.show_taskbar_pinning_popup_from_anywhere Test: manual, flip the flag, open popup from different positions Change-Id: I06cf0c0352da946da7a62413144c304623557216 --- .../taskbar/TaskbarDividerPopupView.kt | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt index 69bc6bdb3d..3f6ebe21e6 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt @@ -134,10 +134,31 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 super.orientAboutObject() x = if (Flags.showTaskbarPinningPopupFromAnywhere()) { - min( - max(minPaddingFromScreenEdge, horizontalPosition - measuredWidth / 2f), - popupContainer.getWidth() - measuredWidth - minPaddingFromScreenEdge, - ) + val xForCenterAlignment = horizontalPosition - measuredWidth / 2f + val maxX = popupContainer.getWidth() - measuredWidth - minPaddingFromScreenEdge + when { + // Left-aligned popup and its arrow pointing to the event position if there is + // not enough space to center it. + xForCenterAlignment < minPaddingFromScreenEdge -> + max( + minPaddingFromScreenEdge, + horizontalPosition - mArrowOffsetHorizontal - mArrowWidth / 2, + ) + + // Right-aligned popup and its arrow pointing to the event position if there + // is not enough space to center it. + xForCenterAlignment > maxX -> + min( + horizontalPosition - measuredWidth + + mArrowOffsetHorizontal + + mArrowWidth / 2, + popupContainer.getWidth() - measuredWidth - minPaddingFromScreenEdge, + ) + + // Default alignment where the popup and its arrow are centered relative to the + // event position. + else -> xForCenterAlignment + } } else { mTempRect.centerX() - measuredWidth / 2f } @@ -183,7 +204,17 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 override fun addArrow() { super.addArrow() if (Flags.showTaskbarPinningPopupFromAnywhere()) { - mArrow.x = horizontalPosition - mArrowWidth / 2 + mArrow.x = + min( + max( + minPaddingFromScreenEdge + mArrowOffsetHorizontal, + horizontalPosition - mArrowWidth / 2, + ), + popupContainer.getWidth() - + minPaddingFromScreenEdge - + mArrowOffsetHorizontal - + mArrowWidth, + ) } else { val location = IntArray(2) popupContainer.getLocationInDragLayer(dividerView, location) @@ -232,7 +263,7 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 /** Aligning the view pivot to center for animation. */ override fun setPivotForOpenCloseAnimation() { - pivotX = measuredWidth / 2f + pivotX = mArrow.x + mArrowWidth / 2 - x pivotY = measuredHeight.toFloat() }