Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5c32317a authored by Mady Mellor's avatar Mady Mellor
Browse files

Fix an exception in bubble bar user education when bar is on left side

In some cases the bubble bar might originate on the left side. The
position of the view was not being updated for this -- this would
be visually incorrect & could result in an exception when trying
to position the arrow.

This CL updates the logic to support placing the education view on
the left side & animated correctly.

Flag: com.android.wm.shell.enable_bubble_bar
Test: manual - flash wipe, set device to LTR, get a bubble, observe
               that the user education appears correctly above the
               bubble
Bug: 372261208
Change-Id: I1b9687815eee12112cea2cb230f067624dfe1de3
parent 8ed2bf07
Loading
Loading
Loading
Loading
+18 −9
Original line number Diff line number Diff line
@@ -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
        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
    }