From e690a19a9a2ee750857c42010513300c1add82ec Mon Sep 17 00:00:00 2001 From: Juan Sebastian Martinez Date: Mon, 22 Apr 2024 08:50:58 -0700 Subject: Removing manual tap timeout wait The tap timeout wait has been delegated to the View logic by posting a runnable instead of delaying a coroutine. This removes the need for a coroutine that collected the tap timeout flow and the manual wait that apparently increased app launch times Test: SystemUiRobotTests:QSLongPressEffectTest Bug: 330473364 Flag: ACONFIG quick_settings_visual_haptics_longpress TEAMFOOD Change-Id: I4188c4e088424985caa04bdb8c75bf092d88fe19 --- .../systemui/haptics/qs/QSLongPressEffect.kt | 13 ----------- .../haptics/qs/QSLongPressEffectViewBinder.kt | 26 +++++++--------------- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffect.kt b/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffect.kt index bccc3c5dc284..f1a8faf87417 100644 --- a/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffect.kt +++ b/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffect.kt @@ -19,7 +19,6 @@ package com.android.systemui.haptics.qs import android.animation.ValueAnimator import android.os.VibrationEffect import android.view.View -import android.view.ViewConfiguration import android.view.animation.AccelerateDecelerateInterpolator import androidx.annotation.VisibleForTesting import androidx.core.animation.doOnCancel @@ -32,7 +31,6 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.combine -import kotlinx.coroutines.flow.map /** * A class that handles the long press visuo-haptic effect for a QS tile. @@ -76,9 +74,6 @@ constructor( } } - // Should a tap timeout countdown begin - val shouldWaitForTapTimeout: Flow = state.map { it == State.TIMEOUT_WAIT } - /** Haptic effects */ private val durations = vibratorHelper?.getPrimitiveDurations( @@ -247,12 +242,4 @@ constructor( LONG_PRESS, RESET_AND_LONG_PRESS, } - - companion object { - /** - * A timeout to let the tile resolve if it is being swiped/scrolled. Since QS tiles are - * inside a scrollable container, they will be considered pressed only after a tap timeout. - */ - val PRESSED_TIMEOUT = ViewConfiguration.getTapTimeout().toLong() + 20L - } } diff --git a/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffectViewBinder.kt b/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffectViewBinder.kt index 2ef901d34dd1..dd7a285eeaae 100644 --- a/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffectViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffectViewBinder.kt @@ -18,15 +18,13 @@ package com.android.systemui.haptics.qs import android.annotation.SuppressLint import android.view.MotionEvent +import android.view.ViewConfiguration import androidx.lifecycle.Lifecycle import androidx.lifecycle.repeatOnLifecycle import com.android.app.tracing.coroutines.launch import com.android.systemui.lifecycle.repeatWhenAttached import com.android.systemui.qs.tileimpl.QSTileViewImpl -import kotlinx.coroutines.CancellationException import kotlinx.coroutines.DisposableHandle -import kotlinx.coroutines.delay -import kotlinx.coroutines.flow.filter object QSLongPressEffectViewBinder { @@ -71,20 +69,6 @@ object QSLongPressEffectViewBinder { } } } - - // Tap timeout wait - launch({ "${tileSpec ?: "unknownTileSpec"}#LongPressEffect#timeout" }) { - qsLongPressEffect.shouldWaitForTapTimeout - .filter { it } - .collect { - try { - delay(QSLongPressEffect.PRESSED_TIMEOUT) - qsLongPressEffect.handleTimeoutComplete() - } catch (_: CancellationException) { - qsLongPressEffect.resetEffect() - } - } - } } } } @@ -93,7 +77,13 @@ object QSLongPressEffectViewBinder { private fun setTouchListener(tile: QSTileViewImpl, longPressEffect: QSLongPressEffect?) { tile.setOnTouchListener { _, event -> when (event.actionMasked) { - MotionEvent.ACTION_DOWN -> longPressEffect?.handleActionDown() + MotionEvent.ACTION_DOWN -> { + tile.postDelayed( + { longPressEffect?.handleTimeoutComplete() }, + ViewConfiguration.getTapTimeout().toLong(), + ) + longPressEffect?.handleActionDown() + } MotionEvent.ACTION_UP -> longPressEffect?.handleActionUp() MotionEvent.ACTION_CANCEL -> longPressEffect?.handleActionCancel() } -- cgit v1.2.3-59-g8ed1b