diff options
3 files changed, 14 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/common/ui/view/LongPressHandlingView.kt b/packages/SystemUI/src/com/android/systemui/common/ui/view/LongPressHandlingView.kt index 323070a84863..07814512b4b8 100644 --- a/packages/SystemUI/src/com/android/systemui/common/ui/view/LongPressHandlingView.kt +++ b/packages/SystemUI/src/com/android/systemui/common/ui/view/LongPressHandlingView.kt @@ -22,6 +22,7 @@ import android.content.Context import android.util.AttributeSet import android.view.MotionEvent import android.view.View +import android.view.ViewConfiguration import com.android.systemui.shade.TouchLogger import kotlin.math.pow import kotlin.math.sqrt @@ -36,11 +37,18 @@ import kotlinx.coroutines.DisposableHandle class LongPressHandlingView( context: Context, attrs: AttributeSet?, + private val longPressDuration: () -> Long, ) : View( context, attrs, ) { + + constructor( + context: Context, + attrs: AttributeSet?, + ) : this(context, attrs, { ViewConfiguration.getLongPressTimeout().toLong() }) + interface Listener { /** Notifies that a long-press has been detected by the given view. */ fun onLongPressDetected( @@ -77,6 +85,7 @@ class LongPressHandlingView( ) }, onSingleTapDetected = { listener?.onSingleTapDetected(this@LongPressHandlingView) }, + longPressDuration = longPressDuration, ) } diff --git a/packages/SystemUI/src/com/android/systemui/common/ui/view/LongPressHandlingViewInteractionHandler.kt b/packages/SystemUI/src/com/android/systemui/common/ui/view/LongPressHandlingViewInteractionHandler.kt index c2d4d12d03c3..a742e8d614b1 100644 --- a/packages/SystemUI/src/com/android/systemui/common/ui/view/LongPressHandlingViewInteractionHandler.kt +++ b/packages/SystemUI/src/com/android/systemui/common/ui/view/LongPressHandlingViewInteractionHandler.kt @@ -33,6 +33,8 @@ class LongPressHandlingViewInteractionHandler( private val onLongPressDetected: (x: Int, y: Int) -> Unit, /** Callback reporting the a single tap gesture was detected at the given coordinates. */ private val onSingleTapDetected: () -> Unit, + /** Time for the touch to be considered a long-press in ms */ + private val longPressDuration: () -> Long, ) { sealed class MotionEventModel { object Other : MotionEventModel() @@ -77,7 +79,7 @@ class LongPressHandlingViewInteractionHandler( cancelScheduledLongPress() if ( event.distanceMoved <= ViewConfiguration.getTouchSlop() && - event.gestureDuration < ViewConfiguration.getLongPressTimeout() + event.gestureDuration < longPressDuration() ) { dispatchSingleTap() } @@ -103,7 +105,7 @@ class LongPressHandlingViewInteractionHandler( y = y, ) }, - ViewConfiguration.getLongPressTimeout().toLong(), + longPressDuration(), ) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/common/ui/view/LongPressHandlingViewInteractionHandlerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/common/ui/view/LongPressHandlingViewInteractionHandlerTest.kt index 1b2fc93ddb3f..2f4fc96ebf6c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/common/ui/view/LongPressHandlingViewInteractionHandlerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/common/ui/view/LongPressHandlingViewInteractionHandlerTest.kt @@ -67,6 +67,7 @@ class LongPressHandlingViewInteractionHandlerTest : SysuiTestCase() { isAttachedToWindow = { isAttachedToWindow }, onLongPressDetected = onLongPressDetected, onSingleTapDetected = onSingleTapDetected, + longPressDuration = { ViewConfiguration.getLongPressTimeout().toLong() } ) underTest.isLongPressHandlingEnabled = true } |