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

Commit 5012d490 authored by Caitlin Cassidy's avatar Caitlin Cassidy Committed by Android (Google) Code Review
Browse files

Merge "[Media TTT] Don't hide the chip if the user taps the chip." into tm-dev

parents ae7ce1a0 708c94fb
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.Context
import android.graphics.PixelFormat
import android.view.Gravity
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
@@ -31,6 +32,7 @@ import com.android.systemui.R
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.statusbar.gesture.TapGestureDetector
import com.android.systemui.util.concurrency.DelayableExecutor
import com.android.systemui.util.view.ViewUtil

/**
 * A superclass controller that provides common functionality for showing chips on the sender device
@@ -42,6 +44,7 @@ import com.android.systemui.util.concurrency.DelayableExecutor
abstract class MediaTttChipControllerCommon<T : MediaTttChipState>(
    internal val context: Context,
    private val windowManager: WindowManager,
    private val viewUtil: ViewUtil,
    @Main private val mainExecutor: DelayableExecutor,
    private val tapGestureDetector: TapGestureDetector,
    @LayoutRes private val chipLayoutRes: Int
@@ -84,7 +87,7 @@ abstract class MediaTttChipControllerCommon<T : MediaTttChipState>(

        // Add view if necessary
        if (oldChipView == null) {
            tapGestureDetector.addOnGestureDetectedCallback(TAG, this::removeChip)
            tapGestureDetector.addOnGestureDetectedCallback(TAG, this::onScreenTapped)
            windowManager.addView(chipView, windowLayoutParams)
        }

@@ -127,6 +130,15 @@ abstract class MediaTttChipControllerCommon<T : MediaTttChipState>(
        appIconView.setImageDrawable(appIcon)
        appIconView.visibility = visibility
    }

    private fun onScreenTapped(e: MotionEvent) {
        val view = chipView ?: return
        // If the tap is within the chip bounds, we shouldn't hide the chip (in case users think the
        // chip is tappable).
        if (!viewUtil.touchIsWithinView(view, e.x, e.y)) {
            removeChip()
        }
    }
}

// Used in CTS tests UpdateMediaTapToTransferSenderDisplayTest and
+8 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.systemui.media.taptotransfer.common.MediaTttChipControllerCom
import com.android.systemui.statusbar.CommandQueue
import com.android.systemui.statusbar.gesture.TapGestureDetector
import com.android.systemui.util.concurrency.DelayableExecutor
import com.android.systemui.util.view.ViewUtil
import javax.inject.Inject

/**
@@ -43,11 +44,17 @@ class MediaTttChipControllerReceiver @Inject constructor(
    commandQueue: CommandQueue,
    context: Context,
    windowManager: WindowManager,
    viewUtil: ViewUtil,
    mainExecutor: DelayableExecutor,
    tapGestureDetector: TapGestureDetector,
    @Main private val mainHandler: Handler,
) : MediaTttChipControllerCommon<ChipStateReceiver>(
    context, windowManager, mainExecutor, tapGestureDetector, R.layout.media_ttt_chip_receiver
    context,
    windowManager,
    viewUtil,
    mainExecutor,
    tapGestureDetector,
    R.layout.media_ttt_chip_receiver
) {
    private val commandQueueCallbacks = object : CommandQueue.Callbacks {
        override fun updateMediaTapToTransferReceiverDisplay(
+3 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import com.android.systemui.media.taptotransfer.common.MediaTttChipControllerCom
import com.android.systemui.statusbar.CommandQueue
import com.android.systemui.statusbar.gesture.TapGestureDetector
import com.android.systemui.util.concurrency.DelayableExecutor
import com.android.systemui.util.view.ViewUtil
import javax.inject.Inject

/**
@@ -43,10 +44,11 @@ class MediaTttChipControllerSender @Inject constructor(
    commandQueue: CommandQueue,
    context: Context,
    windowManager: WindowManager,
    viewUtil: ViewUtil,
    @Main mainExecutor: DelayableExecutor,
    tapGestureDetector: TapGestureDetector,
) : MediaTttChipControllerCommon<ChipStateSender>(
    context, windowManager, mainExecutor,  tapGestureDetector, R.layout.media_ttt_chip
    context, windowManager, viewUtil, mainExecutor,  tapGestureDetector, R.layout.media_ttt_chip
) {
    private val commandQueueCallbacks = object : CommandQueue.Callbacks {
        override fun updateMediaTapToTransferSenderDisplay(
+14 −6
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.Looper
import android.view.Choreographer
import android.view.Display
import android.view.InputEvent
import android.view.MotionEvent
import com.android.systemui.shared.system.InputChannelCompat
import com.android.systemui.shared.system.InputMonitorCompat

@@ -43,13 +44,17 @@ abstract class GenericGestureDetector(
     * Active callbacks, each associated with a tag. Gestures will only be monitored if
     * [callbacks.size] > 0.
     */
    private val callbacks: MutableMap<String, () -> Unit> = mutableMapOf()
    private val callbacks: MutableMap<String, (MotionEvent) -> Unit> = mutableMapOf()

    private var inputMonitor: InputMonitorCompat? = null
    private var inputReceiver: InputChannelCompat.InputEventReceiver? = null

    /** Adds a callback that will be triggered when the tap gesture is detected. */
    fun addOnGestureDetectedCallback(tag: String, callback: () -> Unit) {
    /**
     * Adds a callback that will be triggered when the tap gesture is detected.
     *
     * The callback receive the last motion event in the gesture.
     */
    fun addOnGestureDetectedCallback(tag: String, callback: (MotionEvent) -> Unit) {
        val callbacksWasEmpty = callbacks.isEmpty()
        callbacks[tag] = callback
        if (callbacksWasEmpty) {
@@ -68,9 +73,12 @@ abstract class GenericGestureDetector(
    /** Triggered each time a touch event occurs (and at least one callback is registered). */
    abstract fun onInputEvent(ev: InputEvent)

    /** Should be called by subclasses when their specific gesture is detected. */
    internal fun onGestureDetected() {
        callbacks.values.forEach { it.invoke() }
    /**
     * Should be called by subclasses when their specific gesture is detected with the last motion
     * event in the gesture.
     */
    internal fun onGestureDetected(e: MotionEvent) {
        callbacks.values.forEach { it.invoke(e) }
    }

    /** Start listening to touch events. */
+1 −1
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ open class SwipeStatusBarAwayGestureHandler @Inject constructor(
                ) {
                    monitoringCurrentTouch = false
                    logger.logGestureDetected(ev.y.toInt())
                    onGestureDetected()
                    onGestureDetected(ev)
                }
            }
            ACTION_CANCEL, ACTION_UP -> {
Loading