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

Commit bf48aedd authored by Ats Jenk's avatar Ats Jenk
Browse files

Create a dismiss zone for bubble bar dragging

Create an area around the dismiss circle where the bubble bar can't be
dragged to the other side.
Avoids user accidentally moving the bar to the other side when getting
close to the dismiss target.

Bug: 313661121
Test: manual, drag the expanded view around the dismiss target, check
  that the bar is not moved to the other side, when moving farther, bar
  is moved to the other side
Change-Id: I43b3aa07316a9ded050d678b067c2684397eda98
parent a0d8e5fb
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -272,6 +272,10 @@
    <dimen name="bubble_bar_expanded_view_corner_radius">16dp</dimen>
    <!-- Corner radius for expanded view while it is being dragged -->
    <dimen name="bubble_bar_expanded_view_corner_radius_dragged">28dp</dimen>
    <!-- Width of the box around bottom center of the screen where drag only leads to dismiss -->
    <dimen name="bubble_bar_dismiss_zone_width">192dp</dimen>
    <!-- Height of the box around bottom center of the screen where drag only leads to dismiss -->
    <dimen name="bubble_bar_dismiss_zone_height">242dp</dimen>

    <!-- Bottom and end margin for compat buttons. -->
    <dimen name="compat_button_margin">24dp</dimen>
+26 −1
Original line number Diff line number Diff line
@@ -17,8 +17,10 @@
package com.android.wm.shell.bubbles.bar

import android.annotation.SuppressLint
import android.graphics.RectF
import android.view.MotionEvent
import android.view.View
import com.android.wm.shell.R
import com.android.wm.shell.bubbles.BubblePositioner
import com.android.wm.shell.common.bubbles.BubbleBarLocation
import com.android.wm.shell.common.bubbles.DismissView
@@ -43,6 +45,8 @@ class BubbleBarExpandedViewDragController(
    private val magnetizedExpandedView: MagnetizedObject<BubbleBarExpandedView> =
        MagnetizedObject.magnetizeView(expandedView)
    private val magnetizedDismissTarget: MagnetizedObject.MagneticTarget
    private val dismissZoneHeight: Int
    private val dismissZoneWidth: Int

    init {
        magnetizedExpandedView.magnetListener = MagnetListener()
@@ -74,6 +78,11 @@ class BubbleBarExpandedViewDragController(
            }
            return@setOnTouchListener dragMotionEventHandler.onTouch(view, event) || magnetConsumed
        }

        dismissZoneHeight =
            dismissView.resources.getDimensionPixelSize(R.dimen.bubble_bar_dismiss_zone_height)
        dismissZoneWidth =
            dismissView.resources.getDimensionPixelSize(R.dimen.bubble_bar_dismiss_zone_width)
    }

    /** Listener to receive callback about dragging events */
@@ -97,12 +106,23 @@ class BubbleBarExpandedViewDragController(
        private var isMoving = false
        private var screenCenterX: Int = -1
        private var isOnLeft = false
        private val dismissZone = RectF()

        override fun onDown(v: View, ev: MotionEvent): Boolean {
            // While animating, don't allow new touch events
            if (expandedView.isAnimating) return false
            screenCenterX = bubblePositioner.screenRect.centerX()
            isOnLeft = bubblePositioner.isBubbleBarOnLeft

            val screenRect = bubblePositioner.screenRect
            screenCenterX = screenRect.centerX()
            val screenBottom = screenRect.bottom

            dismissZone.set(
                screenCenterX - dismissZoneWidth / 2f,
                (screenBottom - dismissZoneHeight).toFloat(),
                screenCenterX + dismissZoneHeight / 2f,
                screenBottom.toFloat()
            )
            return true
        }

@@ -122,6 +142,11 @@ class BubbleBarExpandedViewDragController(
            expandedView.translationY = expandedViewInitialTranslationY + dy
            dismissView.show()

            // Check if we are in the zone around dismiss view where drag can only lead to dismiss
            if (dismissZone.contains(ev.rawX, ev.rawY)) {
                return
            }

            if (isOnLeft && ev.rawX > screenCenterX) {
                isOnLeft = false
                dragListener.onLocationChanged(BubbleBarLocation.RIGHT)