Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b8086ac5 authored by Beverly Tai's avatar Beverly Tai Committed by Android (Google) Code Review
Browse files

Merge "Add optional longPressDuration to LongPressHandlingView" into main

parents dede136a 4916fb62
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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,
        )
    }

+4 −2
Original line number Diff line number Diff line
@@ -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(),
            )
    }

+1 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ class LongPressHandlingViewInteractionHandlerTest : SysuiTestCase() {
                isAttachedToWindow = { isAttachedToWindow },
                onLongPressDetected = onLongPressDetected,
                onSingleTapDetected = onSingleTapDetected,
                longPressDuration = { ViewConfiguration.getLongPressTimeout().toLong() }
            )
        underTest.isLongPressHandlingEnabled = true
    }