diff options
| -rw-r--r-- | libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleEducationViewController.kt | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleEducationViewController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleEducationViewController.kt index 9fd255ded0ad..7adec39c9d66 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleEducationViewController.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleEducationViewController.kt @@ -20,6 +20,7 @@ import android.content.Context import android.graphics.Point import android.graphics.Rect import android.util.Log +import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -102,14 +103,17 @@ class BubbleEducationViewController(private val context: Context, private val li hideEducation(animated = false) log { "showStackEducation at: $position" } + val rootBounds = Rect() + // Get root bounds on screen as position is in screen coordinates + root.getBoundsOnScreen(rootBounds) educationView = createEducationView(R.layout.bubble_bar_stack_education, root).apply { setArrowDirection(BubblePopupDrawable.ArrowDirection.DOWN) - setArrowPosition(BubblePopupDrawable.ArrowPosition.End) - updateEducationPosition(view = this, position, root) + updateEducationPosition(view = this, position, rootBounds) val arrowToEdgeOffset = popupDrawable?.config?.cornerRadius ?: 0f doOnLayout { - it.pivotX = it.width - arrowToEdgeOffset + it.pivotX = if (position.x < rootBounds.centerX()) + arrowToEdgeOffset else it.width - arrowToEdgeOffset it.pivotY = it.height.toFloat() } setOnClickListener { educationClickHandler() } @@ -218,12 +222,9 @@ class BubbleEducationViewController(private val context: Context, private val li * * @param view the user education view to layout * @param position the reference position in Screen coordinates - * @param root the root view to use for the layout + * @param rootBounds bounds of the parent the education view is placed in */ - private fun updateEducationPosition(view: BubblePopupView, position: Point, root: ViewGroup) { - val rootBounds = Rect() - // Get root bounds on screen as position is in screen coordinates - root.getBoundsOnScreen(rootBounds) + private fun updateEducationPosition(view: BubblePopupView, position: Point, rootBounds: Rect) { // Get the offset to the arrow from the edge of the education view val arrowToEdgeOffset = view.popupDrawable?.config?.let { it.cornerRadius + it.arrowWidth / 2f }?.roundToInt() @@ -231,7 +232,15 @@ class BubbleEducationViewController(private val context: Context, private val li // Calculate education view margins val params = view.layoutParams as FrameLayout.LayoutParams params.bottomMargin = rootBounds.bottom - position.y - params.rightMargin = rootBounds.right - position.x - arrowToEdgeOffset + if (position.x < rootBounds.centerX()) { + params.leftMargin = position.x - arrowToEdgeOffset + params.gravity = Gravity.LEFT or Gravity.BOTTOM + view.setArrowPosition(BubblePopupDrawable.ArrowPosition.Start) + } else { + params.rightMargin = rootBounds.right - position.x - arrowToEdgeOffset + params.gravity = Gravity.RIGHT or Gravity.BOTTOM + view.setArrowPosition(BubblePopupDrawable.ArrowPosition.End) + } view.layoutParams = params } |