[Media TTT] Make the SwipeUpGestureHandler generic.
The media swipe gesture will re-use SwipeUpGestureHandler, so this CL removes the status-bar-specific items from the handler. Bug: 262584940 Test: verify swiping the status bar away when there's an ongoing call still works Test: Verify SwipeUpLog logs still appear Test: atest OngoingCallControllerTest Change-Id: I18707ac9bb5f6f92531ac660f29bfc6a59437314
This commit is contained in:
@@ -48,7 +48,7 @@ import com.android.systemui.statusbar.SmartReplyController;
|
||||
import com.android.systemui.statusbar.StatusBarStateControllerImpl;
|
||||
import com.android.systemui.statusbar.SysuiStatusBarStateController;
|
||||
import com.android.systemui.statusbar.commandline.CommandRegistry;
|
||||
import com.android.systemui.statusbar.gesture.SwipeUpGestureHandler;
|
||||
import com.android.systemui.statusbar.gesture.SwipeStatusBarAwayGestureHandler;
|
||||
import com.android.systemui.statusbar.notification.NotifPipelineFlags;
|
||||
import com.android.systemui.statusbar.notification.collection.NotifCollection;
|
||||
import com.android.systemui.statusbar.notification.collection.NotifPipeline;
|
||||
@@ -230,7 +230,7 @@ public interface CentralSurfacesDependenciesModule {
|
||||
OngoingCallLogger logger,
|
||||
DumpManager dumpManager,
|
||||
StatusBarWindowController statusBarWindowController,
|
||||
SwipeUpGestureHandler swipeStatusBarAwayGestureHandler,
|
||||
SwipeStatusBarAwayGestureHandler swipeStatusBarAwayGestureHandler,
|
||||
StatusBarStateController statusBarStateController,
|
||||
OngoingCallFlags ongoingCallFlags) {
|
||||
|
||||
@@ -239,7 +239,7 @@ public interface CentralSurfacesDependenciesModule {
|
||||
ongoingCallInImmersiveEnabled
|
||||
? Optional.of(statusBarWindowController)
|
||||
: Optional.empty();
|
||||
Optional<SwipeUpGestureHandler> gestureHandler =
|
||||
Optional<SwipeStatusBarAwayGestureHandler> gestureHandler =
|
||||
ongoingCallInImmersiveEnabled
|
||||
? Optional.of(swipeStatusBarAwayGestureHandler)
|
||||
: Optional.empty();
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.statusbar.gesture
|
||||
|
||||
import android.content.Context
|
||||
import android.view.MotionEvent
|
||||
import com.android.systemui.dagger.SysUISingleton
|
||||
import com.android.systemui.statusbar.window.StatusBarWindowController
|
||||
import javax.inject.Inject
|
||||
|
||||
/** A class to detect when a user swipes away the status bar. */
|
||||
@SysUISingleton
|
||||
class SwipeStatusBarAwayGestureHandler
|
||||
@Inject
|
||||
constructor(
|
||||
context: Context,
|
||||
logger: SwipeUpGestureLogger,
|
||||
private val statusBarWindowController: StatusBarWindowController,
|
||||
) : SwipeUpGestureHandler(context, logger, loggerTag = LOGGER_TAG) {
|
||||
override fun startOfGestureIsWithinBounds(ev: MotionEvent): Boolean {
|
||||
// Gesture starts just below the status bar
|
||||
return ev.y >= statusBarWindowController.statusBarHeight &&
|
||||
ev.y <= 3 * statusBarWindowController.statusBarHeight
|
||||
}
|
||||
}
|
||||
|
||||
private const val LOGGER_TAG = "SwipeStatusBarAway"
|
||||
@@ -24,18 +24,16 @@ import android.view.MotionEvent.ACTION_DOWN
|
||||
import android.view.MotionEvent.ACTION_MOVE
|
||||
import android.view.MotionEvent.ACTION_UP
|
||||
import com.android.systemui.dagger.SysUISingleton
|
||||
import com.android.systemui.statusbar.window.StatusBarWindowController
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* A class to detect when a user swipes away the status bar. To be notified when the swipe away
|
||||
* gesture is detected, add a callback via [addOnGestureDetectedCallback].
|
||||
* A class to detect a generic "swipe up" gesture. To be notified when the swipe up gesture is
|
||||
* detected, add a callback via [addOnGestureDetectedCallback].
|
||||
*/
|
||||
@SysUISingleton
|
||||
open class SwipeUpGestureHandler @Inject constructor(
|
||||
abstract class SwipeUpGestureHandler(
|
||||
context: Context,
|
||||
private val statusBarWindowController: StatusBarWindowController,
|
||||
private val logger: SwipeUpGestureLogger
|
||||
private val logger: SwipeUpGestureLogger,
|
||||
private val loggerTag: String,
|
||||
) : GenericGestureDetector(SwipeUpGestureHandler::class.simpleName!!) {
|
||||
|
||||
private var startY: Float = 0f
|
||||
@@ -54,11 +52,9 @@ open class SwipeUpGestureHandler @Inject constructor(
|
||||
when (ev.actionMasked) {
|
||||
ACTION_DOWN -> {
|
||||
if (
|
||||
// Gesture starts just below the status bar
|
||||
ev.y >= statusBarWindowController.statusBarHeight
|
||||
&& ev.y <= 3 * statusBarWindowController.statusBarHeight
|
||||
startOfGestureIsWithinBounds(ev)
|
||||
) {
|
||||
logger.logGestureDetectionStarted(ev.y.toInt())
|
||||
logger.logGestureDetectionStarted(loggerTag, ev.y.toInt())
|
||||
startY = ev.y
|
||||
startTime = ev.eventTime
|
||||
monitoringCurrentTouch = true
|
||||
@@ -79,27 +75,36 @@ open class SwipeUpGestureHandler @Inject constructor(
|
||||
(ev.eventTime - startTime) < SWIPE_TIMEOUT_MS
|
||||
) {
|
||||
monitoringCurrentTouch = false
|
||||
logger.logGestureDetected(ev.y.toInt())
|
||||
logger.logGestureDetected(loggerTag, ev.y.toInt())
|
||||
onGestureDetected(ev)
|
||||
}
|
||||
}
|
||||
ACTION_CANCEL, ACTION_UP -> {
|
||||
if (monitoringCurrentTouch) {
|
||||
logger.logGestureDetectionEndedWithoutTriggering(ev.y.toInt())
|
||||
logger.logGestureDetectionEndedWithoutTriggering(loggerTag, ev.y.toInt())
|
||||
}
|
||||
monitoringCurrentTouch = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the [ACTION_DOWN] event falls within bounds for this specific swipe-up
|
||||
* gesture.
|
||||
*
|
||||
* Implementations must override this method to specify what part(s) of the screen are valid
|
||||
* locations for the swipe up gesture to start at.
|
||||
*/
|
||||
abstract fun startOfGestureIsWithinBounds(ev: MotionEvent): Boolean
|
||||
|
||||
override fun startGestureListening() {
|
||||
super.startGestureListening()
|
||||
logger.logInputListeningStarted()
|
||||
logger.logInputListeningStarted(loggerTag)
|
||||
}
|
||||
|
||||
override fun stopGestureListening() {
|
||||
super.stopGestureListening()
|
||||
logger.logInputListeningStopped()
|
||||
logger.logInputListeningStopped(loggerTag)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,49 +16,49 @@
|
||||
|
||||
package com.android.systemui.statusbar.gesture
|
||||
|
||||
import com.android.systemui.dagger.SysUISingleton
|
||||
import com.android.systemui.log.dagger.SwipeUpLog
|
||||
import com.android.systemui.plugins.log.LogBuffer
|
||||
import com.android.systemui.plugins.log.LogLevel
|
||||
import javax.inject.Inject
|
||||
|
||||
/** Log messages for [SwipeUpGestureHandler]. */
|
||||
@SysUISingleton
|
||||
class SwipeUpGestureLogger @Inject constructor(
|
||||
@SwipeUpLog private val buffer: LogBuffer,
|
||||
) {
|
||||
fun logGestureDetectionStarted(y: Int) {
|
||||
fun logGestureDetectionStarted(tag: String, y: Int) {
|
||||
buffer.log(
|
||||
TAG,
|
||||
tag,
|
||||
LogLevel.DEBUG,
|
||||
{ int1 = y },
|
||||
{ "Beginning gesture detection. y=$int1" }
|
||||
)
|
||||
}
|
||||
|
||||
fun logGestureDetectionEndedWithoutTriggering(y: Int) {
|
||||
fun logGestureDetectionEndedWithoutTriggering(tag: String, y: Int) {
|
||||
buffer.log(
|
||||
TAG,
|
||||
tag,
|
||||
LogLevel.DEBUG,
|
||||
{ int1 = y },
|
||||
{ "Gesture finished; no swipe up gesture detected. Final y=$int1" }
|
||||
)
|
||||
}
|
||||
|
||||
fun logGestureDetected(y: Int) {
|
||||
fun logGestureDetected(tag: String, y: Int) {
|
||||
buffer.log(
|
||||
TAG,
|
||||
tag,
|
||||
LogLevel.INFO,
|
||||
{ int1 = y },
|
||||
{ "Gesture detected; notifying callbacks. y=$int1" }
|
||||
)
|
||||
}
|
||||
|
||||
fun logInputListeningStarted() {
|
||||
buffer.log(TAG, LogLevel.VERBOSE, {}, { "Input listening started "})
|
||||
fun logInputListeningStarted(tag: String) {
|
||||
buffer.log(tag, LogLevel.VERBOSE, {}, { "Input listening started "})
|
||||
}
|
||||
|
||||
fun logInputListeningStopped() {
|
||||
buffer.log(TAG, LogLevel.VERBOSE, {}, { "Input listening stopped "})
|
||||
fun logInputListeningStopped(tag: String) {
|
||||
buffer.log(tag, LogLevel.VERBOSE, {}, { "Input listening stopped "})
|
||||
}
|
||||
}
|
||||
|
||||
private const val TAG = "SwipeUpGestureHandler"
|
||||
|
||||
@@ -35,7 +35,7 @@ import com.android.systemui.dagger.qualifiers.Main
|
||||
import com.android.systemui.dump.DumpManager
|
||||
import com.android.systemui.plugins.ActivityStarter
|
||||
import com.android.systemui.plugins.statusbar.StatusBarStateController
|
||||
import com.android.systemui.statusbar.gesture.SwipeUpGestureHandler
|
||||
import com.android.systemui.statusbar.gesture.SwipeStatusBarAwayGestureHandler
|
||||
import com.android.systemui.statusbar.notification.collection.NotificationEntry
|
||||
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
|
||||
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener
|
||||
@@ -62,7 +62,7 @@ class OngoingCallController @Inject constructor(
|
||||
private val logger: OngoingCallLogger,
|
||||
private val dumpManager: DumpManager,
|
||||
private val statusBarWindowController: Optional<StatusBarWindowController>,
|
||||
private val swipeStatusBarAwayGestureHandler: Optional<SwipeUpGestureHandler>,
|
||||
private val swipeStatusBarAwayGestureHandler: Optional<SwipeStatusBarAwayGestureHandler>,
|
||||
private val statusBarStateController: StatusBarStateController
|
||||
) : CallbackController<OngoingCallListener>, Dumpable {
|
||||
private var isFullscreen: Boolean = false
|
||||
|
||||
@@ -35,7 +35,7 @@ import com.android.systemui.SysuiTestCase
|
||||
import com.android.systemui.dump.DumpManager
|
||||
import com.android.systemui.plugins.ActivityStarter
|
||||
import com.android.systemui.plugins.statusbar.StatusBarStateController
|
||||
import com.android.systemui.statusbar.gesture.SwipeUpGestureHandler
|
||||
import com.android.systemui.statusbar.gesture.SwipeStatusBarAwayGestureHandler
|
||||
import com.android.systemui.statusbar.notification.collection.NotificationEntry
|
||||
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder
|
||||
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
|
||||
@@ -50,7 +50,9 @@ import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentCaptor
|
||||
import org.mockito.ArgumentMatchers.*
|
||||
import org.mockito.ArgumentMatchers.anyBoolean
|
||||
import org.mockito.ArgumentMatchers.anyString
|
||||
import org.mockito.ArgumentMatchers.nullable
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.Mockito.eq
|
||||
@@ -83,7 +85,8 @@ class OngoingCallControllerTest : SysuiTestCase() {
|
||||
private lateinit var notifCollectionListener: NotifCollectionListener
|
||||
|
||||
@Mock private lateinit var mockOngoingCallFlags: OngoingCallFlags
|
||||
@Mock private lateinit var mockSwipeStatusBarAwayGestureHandler: SwipeUpGestureHandler
|
||||
@Mock private lateinit var mockSwipeStatusBarAwayGestureHandler:
|
||||
SwipeStatusBarAwayGestureHandler
|
||||
@Mock private lateinit var mockOngoingCallListener: OngoingCallListener
|
||||
@Mock private lateinit var mockActivityStarter: ActivityStarter
|
||||
@Mock private lateinit var mockIActivityManager: IActivityManager
|
||||
|
||||
Reference in New Issue
Block a user