Loading packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommon.kt +13 −1 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading @@ -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 Loading Loading @@ -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) } Loading Loading @@ -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 Loading packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt +8 −1 Original line number Diff line number Diff line Loading @@ -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 /** Loading @@ -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( Loading packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttChipControllerSender.kt +3 −1 Original line number Diff line number Diff line Loading @@ -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 /** Loading @@ -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( Loading packages/SystemUI/src/com/android/systemui/statusbar/gesture/GenericGestureDetector.kt +14 −6 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) { Loading @@ -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. */ Loading packages/SystemUI/src/com/android/systemui/statusbar/gesture/SwipeStatusBarAwayGestureHandler.kt +1 −1 Original line number Diff line number Diff line Loading @@ -80,7 +80,7 @@ open class SwipeStatusBarAwayGestureHandler @Inject constructor( ) { monitoringCurrentTouch = false logger.logGestureDetected(ev.y.toInt()) onGestureDetected() onGestureDetected(ev) } } ACTION_CANCEL, ACTION_UP -> { Loading Loading
packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommon.kt +13 −1 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading @@ -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 Loading Loading @@ -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) } Loading Loading @@ -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 Loading
packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt +8 −1 Original line number Diff line number Diff line Loading @@ -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 /** Loading @@ -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( Loading
packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttChipControllerSender.kt +3 −1 Original line number Diff line number Diff line Loading @@ -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 /** Loading @@ -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( Loading
packages/SystemUI/src/com/android/systemui/statusbar/gesture/GenericGestureDetector.kt +14 −6 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) { Loading @@ -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. */ Loading
packages/SystemUI/src/com/android/systemui/statusbar/gesture/SwipeStatusBarAwayGestureHandler.kt +1 −1 Original line number Diff line number Diff line Loading @@ -80,7 +80,7 @@ open class SwipeStatusBarAwayGestureHandler @Inject constructor( ) { monitoringCurrentTouch = false logger.logGestureDetected(ev.y.toInt()) onGestureDetected() onGestureDetected(ev) } } ACTION_CANCEL, ACTION_UP -> { Loading