[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.StatusBarStateControllerImpl;
|
||||||
import com.android.systemui.statusbar.SysuiStatusBarStateController;
|
import com.android.systemui.statusbar.SysuiStatusBarStateController;
|
||||||
import com.android.systemui.statusbar.commandline.CommandRegistry;
|
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.NotifPipelineFlags;
|
||||||
import com.android.systemui.statusbar.notification.collection.NotifCollection;
|
import com.android.systemui.statusbar.notification.collection.NotifCollection;
|
||||||
import com.android.systemui.statusbar.notification.collection.NotifPipeline;
|
import com.android.systemui.statusbar.notification.collection.NotifPipeline;
|
||||||
@@ -230,7 +230,7 @@ public interface CentralSurfacesDependenciesModule {
|
|||||||
OngoingCallLogger logger,
|
OngoingCallLogger logger,
|
||||||
DumpManager dumpManager,
|
DumpManager dumpManager,
|
||||||
StatusBarWindowController statusBarWindowController,
|
StatusBarWindowController statusBarWindowController,
|
||||||
SwipeUpGestureHandler swipeStatusBarAwayGestureHandler,
|
SwipeStatusBarAwayGestureHandler swipeStatusBarAwayGestureHandler,
|
||||||
StatusBarStateController statusBarStateController,
|
StatusBarStateController statusBarStateController,
|
||||||
OngoingCallFlags ongoingCallFlags) {
|
OngoingCallFlags ongoingCallFlags) {
|
||||||
|
|
||||||
@@ -239,7 +239,7 @@ public interface CentralSurfacesDependenciesModule {
|
|||||||
ongoingCallInImmersiveEnabled
|
ongoingCallInImmersiveEnabled
|
||||||
? Optional.of(statusBarWindowController)
|
? Optional.of(statusBarWindowController)
|
||||||
: Optional.empty();
|
: Optional.empty();
|
||||||
Optional<SwipeUpGestureHandler> gestureHandler =
|
Optional<SwipeStatusBarAwayGestureHandler> gestureHandler =
|
||||||
ongoingCallInImmersiveEnabled
|
ongoingCallInImmersiveEnabled
|
||||||
? Optional.of(swipeStatusBarAwayGestureHandler)
|
? Optional.of(swipeStatusBarAwayGestureHandler)
|
||||||
: Optional.empty();
|
: 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_MOVE
|
||||||
import android.view.MotionEvent.ACTION_UP
|
import android.view.MotionEvent.ACTION_UP
|
||||||
import com.android.systemui.dagger.SysUISingleton
|
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
|
* A class to detect a generic "swipe up" gesture. To be notified when the swipe up gesture is
|
||||||
* gesture is detected, add a callback via [addOnGestureDetectedCallback].
|
* detected, add a callback via [addOnGestureDetectedCallback].
|
||||||
*/
|
*/
|
||||||
@SysUISingleton
|
@SysUISingleton
|
||||||
open class SwipeUpGestureHandler @Inject constructor(
|
abstract class SwipeUpGestureHandler(
|
||||||
context: Context,
|
context: Context,
|
||||||
private val statusBarWindowController: StatusBarWindowController,
|
private val logger: SwipeUpGestureLogger,
|
||||||
private val logger: SwipeUpGestureLogger
|
private val loggerTag: String,
|
||||||
) : GenericGestureDetector(SwipeUpGestureHandler::class.simpleName!!) {
|
) : GenericGestureDetector(SwipeUpGestureHandler::class.simpleName!!) {
|
||||||
|
|
||||||
private var startY: Float = 0f
|
private var startY: Float = 0f
|
||||||
@@ -54,11 +52,9 @@ open class SwipeUpGestureHandler @Inject constructor(
|
|||||||
when (ev.actionMasked) {
|
when (ev.actionMasked) {
|
||||||
ACTION_DOWN -> {
|
ACTION_DOWN -> {
|
||||||
if (
|
if (
|
||||||
// Gesture starts just below the status bar
|
startOfGestureIsWithinBounds(ev)
|
||||||
ev.y >= statusBarWindowController.statusBarHeight
|
|
||||||
&& ev.y <= 3 * statusBarWindowController.statusBarHeight
|
|
||||||
) {
|
) {
|
||||||
logger.logGestureDetectionStarted(ev.y.toInt())
|
logger.logGestureDetectionStarted(loggerTag, ev.y.toInt())
|
||||||
startY = ev.y
|
startY = ev.y
|
||||||
startTime = ev.eventTime
|
startTime = ev.eventTime
|
||||||
monitoringCurrentTouch = true
|
monitoringCurrentTouch = true
|
||||||
@@ -79,27 +75,36 @@ open class SwipeUpGestureHandler @Inject constructor(
|
|||||||
(ev.eventTime - startTime) < SWIPE_TIMEOUT_MS
|
(ev.eventTime - startTime) < SWIPE_TIMEOUT_MS
|
||||||
) {
|
) {
|
||||||
monitoringCurrentTouch = false
|
monitoringCurrentTouch = false
|
||||||
logger.logGestureDetected(ev.y.toInt())
|
logger.logGestureDetected(loggerTag, ev.y.toInt())
|
||||||
onGestureDetected(ev)
|
onGestureDetected(ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ACTION_CANCEL, ACTION_UP -> {
|
ACTION_CANCEL, ACTION_UP -> {
|
||||||
if (monitoringCurrentTouch) {
|
if (monitoringCurrentTouch) {
|
||||||
logger.logGestureDetectionEndedWithoutTriggering(ev.y.toInt())
|
logger.logGestureDetectionEndedWithoutTriggering(loggerTag, ev.y.toInt())
|
||||||
}
|
}
|
||||||
monitoringCurrentTouch = false
|
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() {
|
override fun startGestureListening() {
|
||||||
super.startGestureListening()
|
super.startGestureListening()
|
||||||
logger.logInputListeningStarted()
|
logger.logInputListeningStarted(loggerTag)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun stopGestureListening() {
|
override fun stopGestureListening() {
|
||||||
super.stopGestureListening()
|
super.stopGestureListening()
|
||||||
logger.logInputListeningStopped()
|
logger.logInputListeningStopped(loggerTag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,49 +16,49 @@
|
|||||||
|
|
||||||
package com.android.systemui.statusbar.gesture
|
package com.android.systemui.statusbar.gesture
|
||||||
|
|
||||||
|
import com.android.systemui.dagger.SysUISingleton
|
||||||
import com.android.systemui.log.dagger.SwipeUpLog
|
import com.android.systemui.log.dagger.SwipeUpLog
|
||||||
import com.android.systemui.plugins.log.LogBuffer
|
import com.android.systemui.plugins.log.LogBuffer
|
||||||
import com.android.systemui.plugins.log.LogLevel
|
import com.android.systemui.plugins.log.LogLevel
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/** Log messages for [SwipeUpGestureHandler]. */
|
/** Log messages for [SwipeUpGestureHandler]. */
|
||||||
|
@SysUISingleton
|
||||||
class SwipeUpGestureLogger @Inject constructor(
|
class SwipeUpGestureLogger @Inject constructor(
|
||||||
@SwipeUpLog private val buffer: LogBuffer,
|
@SwipeUpLog private val buffer: LogBuffer,
|
||||||
) {
|
) {
|
||||||
fun logGestureDetectionStarted(y: Int) {
|
fun logGestureDetectionStarted(tag: String, y: Int) {
|
||||||
buffer.log(
|
buffer.log(
|
||||||
TAG,
|
tag,
|
||||||
LogLevel.DEBUG,
|
LogLevel.DEBUG,
|
||||||
{ int1 = y },
|
{ int1 = y },
|
||||||
{ "Beginning gesture detection. y=$int1" }
|
{ "Beginning gesture detection. y=$int1" }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun logGestureDetectionEndedWithoutTriggering(y: Int) {
|
fun logGestureDetectionEndedWithoutTriggering(tag: String, y: Int) {
|
||||||
buffer.log(
|
buffer.log(
|
||||||
TAG,
|
tag,
|
||||||
LogLevel.DEBUG,
|
LogLevel.DEBUG,
|
||||||
{ int1 = y },
|
{ int1 = y },
|
||||||
{ "Gesture finished; no swipe up gesture detected. Final y=$int1" }
|
{ "Gesture finished; no swipe up gesture detected. Final y=$int1" }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun logGestureDetected(y: Int) {
|
fun logGestureDetected(tag: String, y: Int) {
|
||||||
buffer.log(
|
buffer.log(
|
||||||
TAG,
|
tag,
|
||||||
LogLevel.INFO,
|
LogLevel.INFO,
|
||||||
{ int1 = y },
|
{ int1 = y },
|
||||||
{ "Gesture detected; notifying callbacks. y=$int1" }
|
{ "Gesture detected; notifying callbacks. y=$int1" }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun logInputListeningStarted() {
|
fun logInputListeningStarted(tag: String) {
|
||||||
buffer.log(TAG, LogLevel.VERBOSE, {}, { "Input listening started "})
|
buffer.log(tag, LogLevel.VERBOSE, {}, { "Input listening started "})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun logInputListeningStopped() {
|
fun logInputListeningStopped(tag: String) {
|
||||||
buffer.log(TAG, LogLevel.VERBOSE, {}, { "Input listening stopped "})
|
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.dump.DumpManager
|
||||||
import com.android.systemui.plugins.ActivityStarter
|
import com.android.systemui.plugins.ActivityStarter
|
||||||
import com.android.systemui.plugins.statusbar.StatusBarStateController
|
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.NotificationEntry
|
||||||
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
|
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
|
||||||
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener
|
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener
|
||||||
@@ -62,7 +62,7 @@ class OngoingCallController @Inject constructor(
|
|||||||
private val logger: OngoingCallLogger,
|
private val logger: OngoingCallLogger,
|
||||||
private val dumpManager: DumpManager,
|
private val dumpManager: DumpManager,
|
||||||
private val statusBarWindowController: Optional<StatusBarWindowController>,
|
private val statusBarWindowController: Optional<StatusBarWindowController>,
|
||||||
private val swipeStatusBarAwayGestureHandler: Optional<SwipeUpGestureHandler>,
|
private val swipeStatusBarAwayGestureHandler: Optional<SwipeStatusBarAwayGestureHandler>,
|
||||||
private val statusBarStateController: StatusBarStateController
|
private val statusBarStateController: StatusBarStateController
|
||||||
) : CallbackController<OngoingCallListener>, Dumpable {
|
) : CallbackController<OngoingCallListener>, Dumpable {
|
||||||
private var isFullscreen: Boolean = false
|
private var isFullscreen: Boolean = false
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import com.android.systemui.SysuiTestCase
|
|||||||
import com.android.systemui.dump.DumpManager
|
import com.android.systemui.dump.DumpManager
|
||||||
import com.android.systemui.plugins.ActivityStarter
|
import com.android.systemui.plugins.ActivityStarter
|
||||||
import com.android.systemui.plugins.statusbar.StatusBarStateController
|
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.NotificationEntry
|
||||||
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder
|
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder
|
||||||
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
|
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
|
||||||
@@ -50,7 +50,9 @@ import org.junit.Before
|
|||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mockito.ArgumentCaptor
|
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.Mock
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
import org.mockito.Mockito.eq
|
import org.mockito.Mockito.eq
|
||||||
@@ -83,7 +85,8 @@ class OngoingCallControllerTest : SysuiTestCase() {
|
|||||||
private lateinit var notifCollectionListener: NotifCollectionListener
|
private lateinit var notifCollectionListener: NotifCollectionListener
|
||||||
|
|
||||||
@Mock private lateinit var mockOngoingCallFlags: OngoingCallFlags
|
@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 mockOngoingCallListener: OngoingCallListener
|
||||||
@Mock private lateinit var mockActivityStarter: ActivityStarter
|
@Mock private lateinit var mockActivityStarter: ActivityStarter
|
||||||
@Mock private lateinit var mockIActivityManager: IActivityManager
|
@Mock private lateinit var mockIActivityManager: IActivityManager
|
||||||
|
|||||||
Reference in New Issue
Block a user