mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
Merge upstream shortcuts and dual-screen session updates
Preserve profile bindings, shared held-input ownership and custom panels alongside upstream physical shortcuts, mouse routing and docked menus. Add integration regressions and record the full 2,918-test JVM run.
This commit is contained in:
commit
d6b4b0589b
630 files changed
+42269
-1875
No files matched your search
@@ -0,0 +1,118 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.graphics.RectF
|
||||
import android.os.Build
|
||||
import android.view.Gravity
|
||||
import android.view.HapticFeedbackConstants
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.WindowInsets
|
||||
import android.widget.FrameLayout
|
||||
import com.droiddeck.launcher.R
|
||||
|
||||
@SuppressLint("ViewConstructor")
|
||||
class DesktopKeyboardButton(context: Context, private val onTap: () -> Unit) : View(context) {
|
||||
|
||||
private val fill = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }
|
||||
private val stroke = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE; strokeWidth = dp(1.5f) }
|
||||
private val box = RectF()
|
||||
private var idleFill = 0
|
||||
private var idleStroke = 0
|
||||
private var heldStroke = 0
|
||||
private var pressed = false
|
||||
|
||||
init {
|
||||
contentDescription = context.getString(R.string.second_show_keyboard)
|
||||
isClickable = true
|
||||
visibility = GONE
|
||||
layoutParams = FrameLayout.LayoutParams(dp(SIZE).toInt(), dp(SIZE).toInt(), Gravity.BOTTOM or Gravity.START)
|
||||
place(0, 0)
|
||||
applyColors()
|
||||
}
|
||||
|
||||
private fun dp(value: Float) = value * resources.displayMetrics.density
|
||||
|
||||
fun applyColors() {
|
||||
val settings = ControllerPrefs.read(context)
|
||||
val tint = settings.tint
|
||||
val alpha = settings.opacity / 100f
|
||||
fun light(a: Int, f: Float) = Color.argb(
|
||||
(a * alpha).toInt(),
|
||||
(Color.red(tint) + (255 - Color.red(tint)) * f).toInt(),
|
||||
(Color.green(tint) + (255 - Color.green(tint)) * f).toInt(),
|
||||
(Color.blue(tint) + (255 - Color.blue(tint)) * f).toInt(),
|
||||
)
|
||||
idleFill = Color.argb(190, (Color.red(tint) * 0.12f).toInt(), (Color.green(tint) * 0.12f).toInt(), (Color.blue(tint) * 0.12f).toInt())
|
||||
idleStroke = light(150, 0.25f)
|
||||
heldStroke = light(230, 0.7f)
|
||||
invalidate()
|
||||
}
|
||||
|
||||
private fun place(left: Int, bottom: Int) {
|
||||
val params = layoutParams as FrameLayout.LayoutParams
|
||||
val marginStart = left + (dp(CENTER_X) - dp(SIZE) / 2f).toInt()
|
||||
val marginBottom = bottom + (dp(CENTER_Y) - dp(SIZE) / 2f).toInt()
|
||||
if (params.leftMargin == marginStart && params.bottomMargin == marginBottom) return
|
||||
params.leftMargin = marginStart
|
||||
params.bottomMargin = marginBottom
|
||||
layoutParams = params
|
||||
}
|
||||
|
||||
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
|
||||
val cutout = if (Build.VERSION.SDK_INT >= 28) insets.displayCutout else null
|
||||
place(cutout?.safeInsetLeft ?: 0, cutout?.safeInsetBottom ?: 0)
|
||||
return super.onApplyWindowInsets(insets)
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
val x = width / 2f
|
||||
val y = height / 2f
|
||||
fill.color = idleFill
|
||||
canvas.drawCircle(x, y, dp(18f), fill)
|
||||
stroke.color = if (pressed) heldStroke else idleStroke
|
||||
canvas.drawCircle(x, y, dp(18f), stroke)
|
||||
box.set(x - dp(10f), y - dp(7f), x + dp(10f), y + dp(7f))
|
||||
canvas.drawRoundRect(box, dp(2f), dp(2f), stroke)
|
||||
for (row in 0..1) for (col in 0..2) {
|
||||
val kx = x + dp(-6f + col * 5f)
|
||||
val ky = y + dp(-3f + row * 4f)
|
||||
canvas.drawLine(kx, ky, kx + dp(2f), ky, stroke)
|
||||
}
|
||||
canvas.drawLine(x - dp(5f), y + dp(4f), x + dp(5f), y + dp(4f), stroke)
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> { pressed = true; invalidate() }
|
||||
MotionEvent.ACTION_UP -> {
|
||||
val inside = event.x in 0f..width.toFloat() && event.y in 0f..height.toFloat()
|
||||
pressed = false
|
||||
invalidate()
|
||||
if (inside) {
|
||||
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY)
|
||||
performClick()
|
||||
}
|
||||
}
|
||||
MotionEvent.ACTION_CANCEL -> { pressed = false; invalidate() }
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun performClick(): Boolean {
|
||||
super.performClick()
|
||||
onTap()
|
||||
return true
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val SIZE = 52f
|
||||
const val CENTER_X = 90f
|
||||
const val CENTER_Y = 34f
|
||||
}
|
||||
}
|
||||
@@ -8,52 +8,125 @@ import kotlin.math.abs
|
||||
class DirectTouchHold(
|
||||
private val slopPx: Float,
|
||||
private val listener: PointerGestures.Listener,
|
||||
private val cancelTouch: () -> Unit,
|
||||
private val touch: Touch,
|
||||
) {
|
||||
interface Touch {
|
||||
fun down(pointerId: Int, x: Float, y: Float)
|
||||
fun move(pointerId: Int, x: Float, y: Float)
|
||||
fun up(pointerId: Int, x: Float, y: Float)
|
||||
fun cancel()
|
||||
}
|
||||
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private var x = 0f
|
||||
private var y = 0f
|
||||
private var consumed = false
|
||||
private var pressed = false
|
||||
private var downX = 0f
|
||||
private var downY = 0f
|
||||
private var downId = 0
|
||||
private var delayMs = 0L
|
||||
private var holdBehavior = TouchGestureConfig.MOUSE_BEHAVIOR_CLICK
|
||||
private var forwarded = false
|
||||
private var held = false
|
||||
private var pressing = false
|
||||
private var upX = 0f
|
||||
private var upY = 0f
|
||||
private var liftId = 0
|
||||
private var liftPending = false
|
||||
private val lift = Runnable {
|
||||
liftPending = false
|
||||
if (forwarded) {
|
||||
touch.up(liftId, upX, upY)
|
||||
forwarded = false
|
||||
}
|
||||
}
|
||||
private val release = Runnable {
|
||||
if (pressed) listener.onButton(PointerGestures.BTN_RIGHT, false, x, y)
|
||||
pressed = false
|
||||
if (pressing) listener.onButton(PointerGestures.BTN_RIGHT, false, downX, downY)
|
||||
pressing = false
|
||||
}
|
||||
private val hold = Runnable {
|
||||
cancelTouch()
|
||||
consumed = true
|
||||
held = true
|
||||
listener.onLongPress()
|
||||
listener.onButton(PointerGestures.BTN_RIGHT, true, x, y)
|
||||
pressed = true
|
||||
handler.postDelayed(release, 50L)
|
||||
listener.onButton(PointerGestures.BTN_RIGHT, true, downX, downY)
|
||||
pressing = true
|
||||
if (holdBehavior != TouchGestureConfig.MOUSE_BEHAVIOR_HOLD) handler.postDelayed(release, 50L)
|
||||
}
|
||||
|
||||
fun configure(config: TouchGestureConfig) {
|
||||
cancel()
|
||||
delayMs = if (config.longPressEnabled) config.longPressDelay.toLong().coerceAtLeast(1L) else 0L
|
||||
delayMs = config.longPressDelay.toLong().coerceAtLeast(1L)
|
||||
holdBehavior = config.directHoldBehavior
|
||||
}
|
||||
|
||||
fun cancel() {
|
||||
handler.removeCallbacks(hold)
|
||||
handler.removeCallbacks(release)
|
||||
handler.removeCallbacks(lift)
|
||||
liftPending = false
|
||||
release.run()
|
||||
consumed = false
|
||||
if (forwarded) touch.cancel()
|
||||
forwarded = false
|
||||
held = false
|
||||
}
|
||||
|
||||
fun onTouch(event: MotionEvent): Boolean {
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||
if (liftPending) {
|
||||
handler.removeCallbacks(lift)
|
||||
lift.run()
|
||||
}
|
||||
cancel()
|
||||
downX = event.x
|
||||
downY = event.y
|
||||
downId = event.getPointerId(0)
|
||||
if (holdBehavior == TouchGestureConfig.MOUSE_BEHAVIOR_NONE) forwardDown()
|
||||
else handler.postDelayed(hold, delayMs)
|
||||
return true
|
||||
}
|
||||
if (held) {
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_UP -> { release.run(); held = false }
|
||||
MotionEvent.ACTION_CANCEL -> cancel()
|
||||
}
|
||||
return true
|
||||
}
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
cancel()
|
||||
x = event.x; y = event.y
|
||||
if (delayMs > 0L) handler.postDelayed(hold, delayMs)
|
||||
MotionEvent.ACTION_POINTER_DOWN -> {
|
||||
handler.removeCallbacks(hold)
|
||||
if (!forwarded) forwardDown()
|
||||
val index = event.actionIndex
|
||||
touch.down(event.getPointerId(index), event.getX(index), event.getY(index))
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
if (!forwarded && (event.pointerCount > 1 ||
|
||||
abs(event.x - downX) > slopPx || abs(event.y - downY) > slopPx)) {
|
||||
handler.removeCallbacks(hold)
|
||||
forwardDown()
|
||||
}
|
||||
if (forwarded) for (index in 0 until event.pointerCount)
|
||||
touch.move(event.getPointerId(index), event.getX(index), event.getY(index))
|
||||
}
|
||||
MotionEvent.ACTION_POINTER_UP -> {
|
||||
val index = event.actionIndex
|
||||
touch.up(event.getPointerId(index), event.getX(index), event.getY(index))
|
||||
}
|
||||
MotionEvent.ACTION_UP -> {
|
||||
handler.removeCallbacks(hold)
|
||||
if (!forwarded) forwardDown()
|
||||
upX = event.x
|
||||
upY = event.y
|
||||
liftId = event.getPointerId(event.actionIndex)
|
||||
liftPending = true
|
||||
handler.postDelayed(lift, LIFT_MS)
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> if (event.pointerCount > 1 ||
|
||||
abs(event.x - x) > slopPx || abs(event.y - y) > slopPx) handler.removeCallbacks(hold)
|
||||
MotionEvent.ACTION_POINTER_DOWN, MotionEvent.ACTION_POINTER_UP,
|
||||
MotionEvent.ACTION_UP -> handler.removeCallbacks(hold)
|
||||
MotionEvent.ACTION_CANCEL -> cancel()
|
||||
}
|
||||
return consumed
|
||||
return true
|
||||
}
|
||||
|
||||
private fun forwardDown() {
|
||||
touch.down(downId, downX, downY)
|
||||
forwarded = true
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val LIFT_MS = 50L
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import android.hardware.display.DisplayManager
|
||||
import android.os.Build
|
||||
import android.view.Display
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
object DualScreen {
|
||||
const val MODE_AUTO = "auto"
|
||||
const val MODE_ON = "on"
|
||||
const val MODE_OFF = "off"
|
||||
val modes = listOf(MODE_AUTO, MODE_ON, MODE_OFF)
|
||||
private const val TYPE_INTERNAL = 1
|
||||
private val knownModels = setOf("retroid pocket duo", "ayn thor")
|
||||
|
||||
fun builtInDisplay(displayManager: DisplayManager, primaryDisplayId: Int): Display? =
|
||||
displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION).firstOrNull {
|
||||
it.isValid && it.displayId != primaryDisplayId && (it.flags and Display.FLAG_PRESENTATION) != 0 &&
|
||||
isBuiltIn(displayType(it), Build.MODEL)
|
||||
}
|
||||
|
||||
fun display(context: Context, displayManager: DisplayManager, primaryDisplayId: Int): Display? =
|
||||
when (SessionPrefs.dualScreenMode(context)) {
|
||||
MODE_OFF -> null
|
||||
MODE_ON -> builtInDisplay(displayManager, primaryDisplayId) ?: anyDisplay(displayManager, primaryDisplayId)
|
||||
else -> builtInDisplay(displayManager, primaryDisplayId)
|
||||
}
|
||||
|
||||
fun anyDisplay(displayManager: DisplayManager, primaryDisplayId: Int): Display? =
|
||||
displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION).firstOrNull {
|
||||
it.isValid && it.displayId != primaryDisplayId && (it.flags and Display.FLAG_PRESENTATION) != 0
|
||||
}
|
||||
|
||||
internal fun isBuiltIn(type: Int?, model: String): Boolean =
|
||||
if (type != null) type == TYPE_INTERNAL else model.trim().lowercase() in knownModels
|
||||
|
||||
private fun displayType(display: Display): Int? =
|
||||
runCatching { Display::class.java.getMethod("getType").invoke(display) as Int }.getOrNull()
|
||||
}
|
||||
@@ -14,6 +14,7 @@ public class FakeInputWriter {
|
||||
|
||||
public static final short EV_SYN = 0x00;
|
||||
public static final short EV_KEY = 0x01;
|
||||
public static final short EV_REL = 0x02;
|
||||
public static final short EV_ABS = 0x03;
|
||||
public static final short EV_MSC = 0x04;
|
||||
|
||||
@@ -52,7 +53,8 @@ public class FakeInputWriter {
|
||||
private static final int EVENT_SIZE = 24;
|
||||
static final int MAX_EVENTS_PER_UPDATE = 32;
|
||||
private static final int BUFFER_SIZE = EVENT_SIZE * MAX_EVENTS_PER_UPDATE;
|
||||
private static final int MAX_FAKE_INPUT_SLOTS = 4;
|
||||
private static final int MAX_FAKE_INPUT_SLOTS = 5;
|
||||
public static final int MOUSE_SLOT = 4;
|
||||
|
||||
private static final int RING_CAPACITY_EVENTS = 4096;
|
||||
private static final int RING_HEADER_SIZE = 64;
|
||||
@@ -88,6 +90,17 @@ public class FakeInputWriter {
|
||||
public static final int PAD_TYPE_XBOX = 2;
|
||||
public static final int PAD_TYPE_DS4 = 3;
|
||||
public static final int PAD_TYPE_DUALSENSE = 4;
|
||||
public static final int PAD_TYPE_MOUSE = 5;
|
||||
|
||||
public static final short REL_X = 0x00;
|
||||
public static final short REL_Y = 0x01;
|
||||
public static final short REL_HWHEEL = 0x06;
|
||||
public static final short REL_WHEEL = 0x08;
|
||||
public static final short REL_WHEEL_HI_RES = 0x0b;
|
||||
public static final short REL_HWHEEL_HI_RES = 0x0c;
|
||||
public static final short MOUSE_BTN_LEFT = 0x110;
|
||||
public static final short MOUSE_BTN_RIGHT = 0x111;
|
||||
public static final short MOUSE_BTN_MIDDLE = 0x112;
|
||||
private static volatile int padType = -1;
|
||||
private static volatile boolean tritonConnected = false;
|
||||
private static final int TRITON_OFFSET = RING_SIZE + 64;
|
||||
@@ -136,6 +149,8 @@ public class FakeInputWriter {
|
||||
private int prevThumbLX, prevThumbLY, prevThumbRX, prevThumbRY;
|
||||
private int prevTriggerL, prevTriggerR;
|
||||
private int prevHatX, prevHatY;
|
||||
private final boolean[] prevMouseButtons = new boolean[3];
|
||||
private float pendingMouseX, pendingMouseY;
|
||||
private boolean hasChanges = false;
|
||||
private boolean pendingFullResend = false;
|
||||
private boolean forceResend = false;
|
||||
@@ -201,7 +216,7 @@ public class FakeInputWriter {
|
||||
return FakeInputRingPaths.ringFile(fakeInputDir, slot);
|
||||
}
|
||||
|
||||
private static void initializeRingHeader(ByteBuffer data) {
|
||||
private static void initializeRingHeader(int slot, ByteBuffer data) {
|
||||
data.order(ByteOrder.LITTLE_ENDIAN);
|
||||
data.putInt(RING_MAGIC_OFFSET, RING_MAGIC);
|
||||
data.putInt(RING_VERSION_OFFSET, RING_VERSION);
|
||||
@@ -221,7 +236,7 @@ public class FakeInputWriter {
|
||||
data.putShort(IMU_ACCEL_OFFSET + (i * 2), (short) 0);
|
||||
}
|
||||
data.putInt(DECK_CONTROLS_OFFSET, 0);
|
||||
int type = padType;
|
||||
int type = slot == MOUSE_SLOT ? PAD_TYPE_MOUSE : padType;
|
||||
data.putInt(PAD_TYPE_OFFSET, type >= 0 ? PAD_TYPE_SET | type : 0);
|
||||
data.putInt(LATENCY_OFFSET, latency);
|
||||
data.putInt(TRITON_OFFSET, TRITON_MAGIC);
|
||||
@@ -312,7 +327,7 @@ public class FakeInputWriter {
|
||||
raf.setLength(RING_FILE_SIZE);
|
||||
channel = raf.getChannel();
|
||||
ByteBuffer data = channel.map(FileChannel.MapMode.READ_WRITE, 0, RING_FILE_SIZE);
|
||||
initializeRingHeader(data);
|
||||
initializeRingHeader(slot, data);
|
||||
|
||||
RingSlot ringSlot = new RingSlot();
|
||||
ringSlot.data = data;
|
||||
@@ -745,6 +760,14 @@ public class FakeInputWriter {
|
||||
prevHatY = 0;
|
||||
writeEvent(EV_ABS, ABS_HAT0Y, 0);
|
||||
}
|
||||
for (int i = 0; i < prevMouseButtons.length; i++) {
|
||||
if (prevMouseButtons[i]) {
|
||||
prevMouseButtons[i] = false;
|
||||
writeEvent(EV_KEY, (short) (MOUSE_BTN_LEFT + i), 0);
|
||||
}
|
||||
}
|
||||
pendingMouseX = 0;
|
||||
pendingMouseY = 0;
|
||||
|
||||
if (hasChanges) {
|
||||
writeEvent(EV_SYN, SYN_REPORT, 0);
|
||||
@@ -874,4 +897,64 @@ public class FakeInputWriter {
|
||||
public boolean isOpen() {
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
public synchronized void writeMouseDelta(float dx, float dy) {
|
||||
if (!isOpen && !open())
|
||||
return;
|
||||
pendingMouseX += dx;
|
||||
pendingMouseY += dy;
|
||||
int x = (int) Math.floor(pendingMouseX);
|
||||
int y = (int) Math.floor(pendingMouseY);
|
||||
if (x == 0 && y == 0)
|
||||
return;
|
||||
pendingMouseX -= x;
|
||||
pendingMouseY -= y;
|
||||
buffer.clear();
|
||||
hasChanges = false;
|
||||
if (x != 0) writeEvent(EV_REL, REL_X, x);
|
||||
if (y != 0) writeEvent(EV_REL, REL_Y, y);
|
||||
writeEvent(EV_SYN, SYN_REPORT, 0);
|
||||
buffer.flip();
|
||||
if (!flushBuffer())
|
||||
Log.e(TAG, "Mouse delta write error: fake input mmap ring unavailable");
|
||||
}
|
||||
|
||||
public synchronized void writeMouseButton(short code, boolean pressed) {
|
||||
if (code < MOUSE_BTN_LEFT || code > MOUSE_BTN_MIDDLE)
|
||||
return;
|
||||
int idx = code - MOUSE_BTN_LEFT;
|
||||
if (!isOpen && !open())
|
||||
return;
|
||||
if (prevMouseButtons[idx] == pressed)
|
||||
return;
|
||||
prevMouseButtons[idx] = pressed;
|
||||
buffer.clear();
|
||||
hasChanges = false;
|
||||
writeEvent(EV_KEY, code, pressed ? 1 : 0);
|
||||
writeEvent(EV_SYN, SYN_REPORT, 0);
|
||||
buffer.flip();
|
||||
if (!flushBuffer())
|
||||
Log.e(TAG, "Mouse button write error: fake input mmap ring unavailable");
|
||||
}
|
||||
|
||||
public synchronized void writeMouseWheel(int verticalClicks, int horizontalClicks, int value120) {
|
||||
if (verticalClicks == 0 && horizontalClicks == 0)
|
||||
return;
|
||||
if (!isOpen && !open())
|
||||
return;
|
||||
buffer.clear();
|
||||
hasChanges = false;
|
||||
if (verticalClicks != 0) {
|
||||
writeEvent(EV_REL, REL_WHEEL, verticalClicks);
|
||||
writeEvent(EV_REL, REL_WHEEL_HI_RES, verticalClicks * value120);
|
||||
}
|
||||
if (horizontalClicks != 0) {
|
||||
writeEvent(EV_REL, REL_HWHEEL, horizontalClicks);
|
||||
writeEvent(EV_REL, REL_HWHEEL_HI_RES, horizontalClicks * value120);
|
||||
}
|
||||
writeEvent(EV_SYN, SYN_REPORT, 0);
|
||||
buffer.flip();
|
||||
if (!flushBuffer())
|
||||
Log.e(TAG, "Mouse wheel write error: fake input mmap ring unavailable");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.os.Build
|
||||
import android.view.KeyEvent
|
||||
|
||||
class HomeGuideInput(private val setPressed: (Boolean) -> Unit, private val onCancel: () -> Unit = {}) {
|
||||
@@ -8,6 +9,10 @@ class HomeGuideInput(private val setPressed: (Boolean) -> Unit, private val onCa
|
||||
|
||||
fun onKeyEvent(event: KeyEvent, enabled: Boolean): Boolean {
|
||||
if (!isHome(event.keyCode)) return false
|
||||
if (isQuickMenuKey(event)) {
|
||||
if (event.action == KeyEvent.ACTION_DOWN) cancel()
|
||||
return false
|
||||
}
|
||||
if (!enabled) cancel()
|
||||
val device = event.deviceId
|
||||
return when (event.action) {
|
||||
@@ -43,5 +48,10 @@ class HomeGuideInput(private val setPressed: (Boolean) -> Unit, private val onCa
|
||||
companion object {
|
||||
// The Retroid Nova pad falls back to Generic.kl, which maps its Home scan code to MOVE_HOME.
|
||||
fun isHome(keyCode: Int) = keyCode == KeyEvent.KEYCODE_HOME || keyCode == KeyEvent.KEYCODE_MOVE_HOME
|
||||
|
||||
private const val DUO_QUICK_MENU_SCAN_CODE = 194
|
||||
|
||||
fun isQuickMenuKey(event: KeyEvent) =
|
||||
event.scanCode == DUO_QUICK_MENU_SCAN_CODE && "Retroid Pocket Duo".equals(Build.MODEL, ignoreCase = true)
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,9 @@ class KeyboardHost(
|
||||
private val map: KeyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD)
|
||||
var shown = false
|
||||
private set
|
||||
var imeShowing = false
|
||||
private set
|
||||
var onImeChanged: ((Boolean) -> Unit)? = null
|
||||
|
||||
init {
|
||||
isFocusable = false
|
||||
@@ -42,6 +45,28 @@ class KeyboardHost(
|
||||
return KeyConnection()
|
||||
}
|
||||
|
||||
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
val visible = insets.isVisible(WindowInsets.Type.ime())
|
||||
if (visible != imeShowing) {
|
||||
imeShowing = visible
|
||||
onImeChanged?.invoke(visible)
|
||||
}
|
||||
}
|
||||
return super.onApplyWindowInsets(insets)
|
||||
}
|
||||
|
||||
override fun onKeyPreIme(keyCode: Int, event: KeyEvent): Boolean {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R || keyCode != KeyEvent.KEYCODE_BACK || !shown) {
|
||||
return super.onKeyPreIme(keyCode, event)
|
||||
}
|
||||
if (event.action == KeyEvent.ACTION_UP && !event.isCanceled) {
|
||||
hide()
|
||||
onImeChanged?.invoke(false)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun toggle() = if (shown && imeVisible()) hide() else show()
|
||||
|
||||
private fun imeVisible() = Build.VERSION.SDK_INT < Build.VERSION_CODES.R ||
|
||||
|
||||
@@ -673,6 +673,11 @@ class OnScreenControls(
|
||||
private fun closestSnap(position: Float, targets: List<Float>): Float? =
|
||||
targets.minByOrNull { abs(position - it) }?.takeIf { abs(position - it) <= dp(SNAP_DP) }
|
||||
|
||||
/** Whether a finger going down at ([x], [y]) lands on something here, as [onTouchEvent] decides it. */
|
||||
fun takesTouchAt(x: Float, y: Float): Boolean =
|
||||
editing || keyboardContains(x, y) || (!buttonsOnly && quickContains(x, y)) ||
|
||||
(!quickHidden && (controlAt(x, y) ?: adaptiveStickAt(x, y)) != null)
|
||||
|
||||
private fun controlAt(x: Float, y: Float): Control? =
|
||||
controls.firstOrNull {
|
||||
!quickHidden && isVisible(it) && (editing || !settings.adaptiveSticks || it.stick < 0) && it.contains(x, y, it.radius)
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import android.view.InputDevice
|
||||
import android.view.KeyEvent
|
||||
import androidx.annotation.StringRes
|
||||
import com.droiddeck.launcher.R
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
|
||||
object PhysicalShortcuts {
|
||||
internal const val KEY = "physicalShortcuts"
|
||||
private const val TAG = "PhysicalShortcuts"
|
||||
|
||||
enum class Action(@StringRes val label: Int) {
|
||||
STEAM(R.string.drawer_steam_menu),
|
||||
QAM(R.string.drawer_open_qam),
|
||||
DROIDDECK(R.string.shortcuts_dd_menu),
|
||||
}
|
||||
|
||||
data class Button(
|
||||
val device: String,
|
||||
val name: String,
|
||||
val keyCode: Int,
|
||||
val scanCode: Int,
|
||||
) {
|
||||
fun matches(event: KeyEvent): Boolean =
|
||||
event.device?.let { device == identity(it) } == true &&
|
||||
keyCode == event.keyCode && scanCode == event.scanCode
|
||||
|
||||
fun sameInput(other: Button): Boolean =
|
||||
device == other.device && keyCode == other.keyCode && scanCode == other.scanCode
|
||||
|
||||
val label: String
|
||||
get() = KeyEvent.keyCodeToString(keyCode).removePrefix("KEYCODE_").removePrefix("BUTTON_")
|
||||
|
||||
}
|
||||
|
||||
data class Binding(val button: Button, val action: Action)
|
||||
|
||||
private fun identity(device: InputDevice): String =
|
||||
"${device.vendorId}:${device.productId}:${device.descriptor.ifBlank { device.name }}"
|
||||
|
||||
fun isVolumeKey(event: KeyEvent): Boolean = when (event.keyCode) {
|
||||
KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_VOLUME_MUTE -> true
|
||||
else -> false
|
||||
}
|
||||
|
||||
fun isDrawerNavigationKey(event: KeyEvent): Boolean = when (event.keyCode) {
|
||||
KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_DOWN,
|
||||
KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_RIGHT -> true
|
||||
else -> false
|
||||
}
|
||||
|
||||
fun button(event: KeyEvent): Button? {
|
||||
val device = event.device ?: return null
|
||||
if (device.isVirtual || isVolumeKey(event)) return null
|
||||
when (event.keyCode) {
|
||||
KeyEvent.KEYCODE_HOME, KeyEvent.KEYCODE_POWER, KeyEvent.KEYCODE_SLEEP,
|
||||
KeyEvent.KEYCODE_WAKEUP, KeyEvent.KEYCODE_APP_SWITCH -> return null
|
||||
}
|
||||
if (event.keyCode == KeyEvent.KEYCODE_UNKNOWN && event.scanCode <= 0) return null
|
||||
return Button(identity(device), device.name, event.keyCode, event.scanCode)
|
||||
}
|
||||
|
||||
fun read(context: Context): List<Binding> {
|
||||
val raw = ControllerPrefs.prefs(context).getString(KEY, null) ?: return emptyList()
|
||||
return try {
|
||||
val array = JSONArray(raw)
|
||||
buildList {
|
||||
for (i in 0 until array.length()) {
|
||||
try {
|
||||
val entry = array.getJSONObject(i)
|
||||
val action = Action.entries.firstOrNull { it.name == entry.getString("action") }
|
||||
val code = entry.getInt("keyCode")
|
||||
val scan = entry.getInt("scanCode")
|
||||
val device = entry.getString("device")
|
||||
if (action == null || device.isBlank() || code < 0 || scan < 0) {
|
||||
Log.w(TAG, "Ignoring invalid shortcut at index $i")
|
||||
continue
|
||||
}
|
||||
val binding = Binding(Button(device, entry.getString("name"), code, scan), action)
|
||||
if (none { it.button.sameInput(binding.button) }) add(binding)
|
||||
} catch (e: JSONException) {
|
||||
Log.w(TAG, "Ignoring malformed shortcut at index $i", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: JSONException) {
|
||||
Log.w(TAG, "Could not read physical shortcuts; reset shortcuts to restore defaults", e)
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
fun assign(context: Context, button: Button, action: Action) {
|
||||
val bindings = read(context).filterNot {
|
||||
it.button.sameInput(button) || (it.button.device == button.device && it.action == action)
|
||||
} + Binding(button, action)
|
||||
write(context, bindings)
|
||||
}
|
||||
|
||||
fun remove(context: Context, binding: Binding) {
|
||||
write(context, read(context).filterNot { it == binding })
|
||||
}
|
||||
|
||||
private fun write(context: Context, bindings: List<Binding>) {
|
||||
val array = JSONArray()
|
||||
bindings.forEach {
|
||||
array.put(JSONObject().put("device", it.button.device).put("name", it.button.name)
|
||||
.put("keyCode", it.button.keyCode).put("scanCode", it.button.scanCode).put("action", it.action.name))
|
||||
}
|
||||
ControllerPrefs.prefs(context).edit().putString(KEY, array.toString()).apply()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class PhysicalShortcutRouter {
|
||||
var bindings: List<PhysicalShortcuts.Binding> = emptyList()
|
||||
private data class Press(val device: Int, val keyCode: Int, val scanCode: Int)
|
||||
private val held = mutableSetOf<Press>()
|
||||
|
||||
fun onKey(event: KeyEvent, enabled: Boolean, steam: Boolean, perform: (PhysicalShortcuts.Action) -> Unit): Boolean {
|
||||
val press = Press(event.deviceId, event.keyCode, event.scanCode)
|
||||
if (event.action == KeyEvent.ACTION_UP) return held.remove(press)
|
||||
if (event.action != KeyEvent.ACTION_DOWN) return false
|
||||
if (press in held) return true
|
||||
if (!enabled || bindings.isEmpty()) return false
|
||||
val button = PhysicalShortcuts.button(event) ?: return false
|
||||
val binding = bindings.firstOrNull { it.button.sameInput(button) } ?: return false
|
||||
if (!steam && binding.action != PhysicalShortcuts.Action.DROIDDECK) return false
|
||||
held.add(press)
|
||||
if (event.repeatCount == 0) perform(binding.action)
|
||||
return true
|
||||
}
|
||||
|
||||
fun onDeviceRemoved(deviceId: Int) {
|
||||
held.removeAll { it.device == deviceId }
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
held.clear()
|
||||
}
|
||||
}
|
||||
@@ -1,104 +1,22 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.MotionEvent
|
||||
import android.view.ViewConfiguration
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class PointerGestures(
|
||||
private val slopPx: Float,
|
||||
private val listener: Listener,
|
||||
) {
|
||||
class PointerGestures {
|
||||
interface Listener {
|
||||
fun onMove(x: Float, y: Float)
|
||||
fun onButton(button: Int, pressed: Boolean, x: Float, y: Float)
|
||||
fun onWheel(steps: Int)
|
||||
fun onLongPress()
|
||||
}
|
||||
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private var downX = 0f
|
||||
private var downY = 0f
|
||||
private var downAt = 0L
|
||||
private var moved = false
|
||||
private var held = false
|
||||
private var dragging = false
|
||||
private var scrolling = false
|
||||
private var scrollAnchorY = 0f
|
||||
private val longPress = Runnable {
|
||||
held = true
|
||||
listener.onLongPress()
|
||||
}
|
||||
|
||||
fun onTouch(event: MotionEvent): Boolean {
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
downX = event.x; downY = event.y; downAt = event.eventTime
|
||||
moved = false; held = false; dragging = false; scrolling = false
|
||||
listener.onMove(event.x, event.y)
|
||||
handler.postDelayed(longPress, HOLD_MS)
|
||||
return true
|
||||
}
|
||||
MotionEvent.ACTION_POINTER_DOWN -> {
|
||||
handler.removeCallbacks(longPress)
|
||||
if (dragging) { listener.onButton(BTN_LEFT, false, event.x, event.y); dragging = false }
|
||||
scrolling = true
|
||||
scrollAnchorY = event.getY(0)
|
||||
return true
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
if (scrolling) {
|
||||
val dy = event.getY(0) - scrollAnchorY
|
||||
val steps = (dy / SCROLL_STEP_PX).toInt()
|
||||
if (steps != 0) {
|
||||
listener.onWheel(-steps)
|
||||
scrollAnchorY += steps * SCROLL_STEP_PX
|
||||
}
|
||||
return true
|
||||
}
|
||||
if (!moved && (abs(event.x - downX) > slopPx || abs(event.y - downY) > slopPx)) {
|
||||
moved = true
|
||||
handler.removeCallbacks(longPress)
|
||||
if (held) {
|
||||
dragging = true
|
||||
listener.onButton(BTN_LEFT, true, downX, downY)
|
||||
}
|
||||
}
|
||||
if (moved) listener.onMove(event.x, event.y)
|
||||
return true
|
||||
}
|
||||
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
||||
handler.removeCallbacks(longPress)
|
||||
val cancelled = event.actionMasked == MotionEvent.ACTION_CANCEL
|
||||
when {
|
||||
scrolling -> {}
|
||||
dragging -> listener.onButton(BTN_LEFT, false, event.x, event.y)
|
||||
held && !moved && !cancelled -> {
|
||||
listener.onButton(BTN_RIGHT, true, downX, downY)
|
||||
listener.onButton(BTN_RIGHT, false, downX, downY)
|
||||
}
|
||||
!moved && !cancelled && event.eventTime - downAt < TAP_MS -> {
|
||||
listener.onButton(BTN_LEFT, true, downX, downY)
|
||||
listener.onButton(BTN_LEFT, false, downX, downY)
|
||||
}
|
||||
}
|
||||
scrolling = false; dragging = false; held = false
|
||||
return true
|
||||
}
|
||||
MotionEvent.ACTION_POINTER_UP -> return true
|
||||
}
|
||||
return false
|
||||
fun onScroll(dx: Float, dy: Float) {}
|
||||
fun onScrollEnd() {}
|
||||
fun onZoom(steps: Int) {}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val BTN_LEFT = 0x110
|
||||
const val BTN_RIGHT = 0x111
|
||||
const val BTN_MIDDLE = 0x112
|
||||
private const val HOLD_MS = 450L
|
||||
private const val TAP_MS = 350L
|
||||
private const val SCROLL_STEP_PX = 40f
|
||||
|
||||
fun slop(context: android.content.Context) = ViewConfiguration.get(context).scaledTouchSlop.toFloat()
|
||||
}
|
||||
|
||||
@@ -609,6 +609,9 @@ class ScreenKeys(context: Context, private val sendKey: (Int, Boolean) -> Unit)
|
||||
else -> entry.halfH
|
||||
}
|
||||
|
||||
/** Whether a finger going down at ([x], [y]) lands on something here, as [onTouchEvent] decides it. */
|
||||
fun takesTouchAt(x: Float, y: Float): Boolean = editing || entryAt(x, y) != null
|
||||
|
||||
private fun entryAt(x: Float, y: Float): Entry? = entries.lastOrNull { entry ->
|
||||
x >= entry.cx - entry.halfW && x <= entry.cx + entry.halfW && y >= entry.cy - entry.halfH && y <= entry.cy + entry.halfH
|
||||
}
|
||||
|
||||
@@ -86,27 +86,14 @@ class ScrollTouchGestures(
|
||||
lastY = startY
|
||||
tracker = VelocityTracker.obtain().also { it.addMovement(event) }
|
||||
listener.onMove(startX, startY)
|
||||
handler.postDelayed(longPress, HOLD_MS)
|
||||
handler.postDelayed(longPress, TouchTiming.HOLD_MS)
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
val index = event.findPointerIndex(pointerId).takeIf { it >= 0 } ?: return true
|
||||
tracker?.addMovement(event)
|
||||
val x = event.getX(index)
|
||||
val y = event.getY(index)
|
||||
if (!scrolling && !dragging && hypot(x - startX, y - startY) > slopPx) {
|
||||
handler.removeCallbacks(longPress)
|
||||
if (held) {
|
||||
dragging = true
|
||||
listener.onButton(PointerGestures.BTN_LEFT, true)
|
||||
} else {
|
||||
scrolling = true
|
||||
vertical = abs(y - startY) >= abs(x - startX)
|
||||
lastX = startX
|
||||
lastY = startY
|
||||
}
|
||||
}
|
||||
if (dragging) listener.onMove(x, y)
|
||||
follow(event, x, y)
|
||||
for (h in 0 until event.historySize)
|
||||
sample(event.getHistoricalX(index, h), event.getHistoricalY(index, h), event.getHistoricalEventTime(h))
|
||||
sample(event.getX(index), event.getY(index), event.eventTime)
|
||||
}
|
||||
MotionEvent.ACTION_POINTER_UP -> {
|
||||
if (event.getPointerId(event.actionIndex) == pointerId) cancel()
|
||||
@@ -115,7 +102,7 @@ class ScrollTouchGestures(
|
||||
handler.removeCallbacks(longPress)
|
||||
if (pointerId == -1 || event.getPointerId(0) != pointerId) return true
|
||||
tracker?.addMovement(event)
|
||||
follow(event, event.x, event.y)
|
||||
follow(event.x, event.y, event.eventTime)
|
||||
when {
|
||||
scrolling -> tracker?.takeIf { event.eventTime - movedAt <= FLING_STILL_MS }?.let { t ->
|
||||
t.computeCurrentVelocity(1000)
|
||||
@@ -139,9 +126,26 @@ class ScrollTouchGestures(
|
||||
return true
|
||||
}
|
||||
|
||||
private fun follow(event: MotionEvent, x: Float, y: Float) {
|
||||
private fun sample(x: Float, y: Float, t: Long) {
|
||||
if (!scrolling && !dragging && hypot(x - startX, y - startY) > slopPx) {
|
||||
handler.removeCallbacks(longPress)
|
||||
if (held) {
|
||||
dragging = true
|
||||
listener.onButton(PointerGestures.BTN_LEFT, true)
|
||||
} else {
|
||||
scrolling = true
|
||||
vertical = abs(y - startY) >= abs(x - startX)
|
||||
lastX = startX
|
||||
lastY = startY
|
||||
}
|
||||
}
|
||||
if (dragging) listener.onMove(x, y)
|
||||
follow(x, y, t)
|
||||
}
|
||||
|
||||
private fun follow(x: Float, y: Float, t: Long) {
|
||||
if (!scrolling || (x == lastX && y == lastY)) return
|
||||
movedAt = event.eventTime
|
||||
movedAt = t
|
||||
if (vertical) listener.onScroll(0f, lastY - y) else listener.onScroll(lastX - x, 0f)
|
||||
lastX = x
|
||||
lastY = y
|
||||
@@ -151,7 +155,7 @@ class ScrollTouchGestures(
|
||||
releaseClick()
|
||||
listener.onButton(button, true)
|
||||
clicked = button
|
||||
handler.postDelayed(clickUp, CLICK_MS)
|
||||
handler.postDelayed(clickUp, TouchTiming.CLICK_MS)
|
||||
}
|
||||
|
||||
private fun releaseClick() {
|
||||
@@ -181,8 +185,6 @@ class ScrollTouchGestures(
|
||||
return if (pixels < 0) -units else units
|
||||
}
|
||||
|
||||
private const val HOLD_MS = 500L
|
||||
private const val CLICK_MS = 50L
|
||||
private const val FLING_TIME_S = 0.45f
|
||||
private const val FLING_STOP_PX = 40f
|
||||
private const val FLING_STILL_MS = 60L
|
||||
|
||||
@@ -10,7 +10,12 @@ enum class SecondScreenMode(val id: String, @StringRes val label: Int) {
|
||||
KEYBOARD_TRACKPAD("keyboard-trackpad", R.string.second_mode_keyboard_trackpad),
|
||||
TERMINAL("terminal", R.string.second_mode_terminal),
|
||||
DECK_CONTROLS("deck-controls", R.string.second_mode_deck_controls),
|
||||
CUSTOM_CONTROLS("custom-controls", R.string.input_custom_controls),
|
||||
CUSTOM_CONTROLS("custom-controls", R.string.input_custom_controls);
|
||||
|
||||
companion object {
|
||||
fun opening(remembered: String?, deckPad: Boolean): SecondScreenMode =
|
||||
entries.firstOrNull { it != NONE && it.id == remembered && (it != DECK_CONTROLS || deckPad) } ?: if (deckPad) DECK_CONTROLS else KEYBOARD_TRACKPAD
|
||||
}
|
||||
}
|
||||
|
||||
data class SecondScreenDisplay(val id: Int, val label: String)
|
||||
|
||||
@@ -16,13 +16,19 @@ class SessionClipboard(context: Context, private val hasFocus: () -> Boolean) {
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private val hostFile = File(context.filesDir, "session/android-clipboard")
|
||||
private var active = false
|
||||
private val androidListener = ClipboardManager.OnPrimaryClipChangedListener { refresh() }
|
||||
private var published = false
|
||||
private var shared: String? = null
|
||||
private var echo: String? = null
|
||||
private val androidListener = ClipboardManager.OnPrimaryClipChangedListener { refresh(changed = true) }
|
||||
private val guestListener = object : WaylandCompositor.ClipboardListener {
|
||||
override fun onGuestClipboardText(text: String) {
|
||||
handler.post {
|
||||
if (active && hasFocus() && WaylandCompositor.isClipboardListener(this)) {
|
||||
val current = clipboard.primaryClip?.takeIf { it.itemCount > 0 }?.getItemAt(0)?.text
|
||||
shared = text
|
||||
published = true
|
||||
if (current?.toString() != text) {
|
||||
echo = text
|
||||
clipboard.setPrimaryClip(ClipData.newPlainText("DroidDeck", text))
|
||||
}
|
||||
}
|
||||
@@ -46,17 +52,23 @@ class SessionClipboard(context: Context, private val hasFocus: () -> Boolean) {
|
||||
handler.removeCallbacksAndMessages(null)
|
||||
}
|
||||
|
||||
fun refresh() {
|
||||
fun refresh(changed: Boolean = false) {
|
||||
if (!active || !hasFocus()) return
|
||||
val clip = clipboard.primaryClip
|
||||
if (clip == null) {
|
||||
publish(null)
|
||||
} else if (clip.itemCount > 0) {
|
||||
publish(clip.getItemAt(0).text?.toString())
|
||||
if (clip != null && clip.itemCount == 0) return
|
||||
val text = clip?.getItemAt(0)?.text?.toString()
|
||||
if (echo != null && text == echo) {
|
||||
echo = null
|
||||
return
|
||||
}
|
||||
echo = null
|
||||
if (!changed && published && text == shared) return
|
||||
publish(text)
|
||||
}
|
||||
|
||||
private fun publish(text: String?) {
|
||||
published = true
|
||||
shared = text
|
||||
WaylandCompositor.setClipboardText(text)
|
||||
val pending = File(hostFile.parentFile, "android-clipboard.pending")
|
||||
try {
|
||||
|
||||
@@ -244,6 +244,9 @@ class SteamTouchControls(
|
||||
private fun hit(list: List<Element>, x: Float, y: Float): Element? =
|
||||
list.filter { reach(it, x, y) <= 1.15f }.minByOrNull { reach(it, x, y) }
|
||||
|
||||
/** Whether a finger going down at ([x], [y]) lands on something here, as [onTouchEvent] decides it. */
|
||||
fun takesTouchAt(x: Float, y: Float): Boolean = editing || menuOpen || hit(live(), x, y) != null
|
||||
|
||||
private fun live(): List<Element> =
|
||||
if (shakenAway) emptyList() else if (options.inputMode == SteamTouchConfig.INPUT_MOUSE) elements.filter { it.type == SteamTouchConfig.THUMB } else elements
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ data class TouchGestureConfig(
|
||||
val longPressAction: String = ACTION_RIGHT_CLICK,
|
||||
val longPressMouseBehavior: String = MOUSE_BEHAVIOR_HOLD,
|
||||
val longPressDelay: Int = DEFAULT_DELAY_MS,
|
||||
val directHoldBehavior: String = MOUSE_BEHAVIOR_CLICK,
|
||||
val doubleTapEnabled: Boolean = true,
|
||||
val doubleTapDelay: Int = DEFAULT_DELAY_MS,
|
||||
val twoFingerDragEnabled: Boolean = true,
|
||||
@@ -50,6 +51,7 @@ data class TouchGestureConfig(
|
||||
put(KEY_LONG_PRESS_ACTION, longPressAction)
|
||||
put(KEY_LONG_PRESS_MOUSE_BEHAVIOR, longPressMouseBehavior)
|
||||
put(KEY_LONG_PRESS_DELAY, longPressDelay)
|
||||
put(KEY_DIRECT_HOLD_BEHAVIOR, directHoldBehavior)
|
||||
put(KEY_DOUBLE_TAP_ENABLED, doubleTapEnabled)
|
||||
put(KEY_DOUBLE_TAP_DELAY, doubleTapDelay)
|
||||
put(KEY_TWO_FINGER_DRAG_ENABLED, twoFingerDragEnabled)
|
||||
@@ -85,6 +87,7 @@ data class TouchGestureConfig(
|
||||
|
||||
const val MOUSE_BEHAVIOR_HOLD = "hold"
|
||||
const val MOUSE_BEHAVIOR_CLICK = "click"
|
||||
const val MOUSE_BEHAVIOR_NONE = "none"
|
||||
|
||||
const val MOUSE_DRAG_MOVEMENT_DIRECT = "direct"
|
||||
const val MOUSE_DRAG_MOVEMENT_RELATIVE = "relative"
|
||||
@@ -110,6 +113,7 @@ data class TouchGestureConfig(
|
||||
private const val KEY_LONG_PRESS_ACTION = "longPressAction"
|
||||
private const val KEY_LONG_PRESS_MOUSE_BEHAVIOR = "longPressMouseBehavior"
|
||||
private const val KEY_LONG_PRESS_DELAY = "longPressDelay"
|
||||
private const val KEY_DIRECT_HOLD_BEHAVIOR = "directHoldBehavior"
|
||||
private const val KEY_DOUBLE_TAP_ENABLED = "doubleTapEnabled"
|
||||
private const val KEY_DOUBLE_TAP_DELAY = "doubleTapDelay"
|
||||
private const val KEY_TWO_FINGER_DRAG_ENABLED = "twoFingerDragEnabled"
|
||||
@@ -155,6 +159,9 @@ data class TouchGestureConfig(
|
||||
obj.optString(KEY_LONG_PRESS_MOUSE_BEHAVIOR, MOUSE_BEHAVIOR_HOLD)
|
||||
),
|
||||
longPressDelay = obj.optInt(KEY_LONG_PRESS_DELAY, DEFAULT_DELAY_MS),
|
||||
directHoldBehavior = normalizeDirectHoldBehavior(
|
||||
obj.optString(KEY_DIRECT_HOLD_BEHAVIOR, MOUSE_BEHAVIOR_CLICK)
|
||||
),
|
||||
doubleTapEnabled = obj.optBoolean(KEY_DOUBLE_TAP_ENABLED, true),
|
||||
doubleTapDelay = obj.optInt(KEY_DOUBLE_TAP_DELAY, DEFAULT_DELAY_MS),
|
||||
twoFingerDragEnabled = obj.optBoolean(KEY_TWO_FINGER_DRAG_ENABLED, true),
|
||||
@@ -190,6 +197,10 @@ data class TouchGestureConfig(
|
||||
}
|
||||
}
|
||||
|
||||
private fun normalizeDirectHoldBehavior(value: String): String {
|
||||
return if (value == MOUSE_BEHAVIOR_CLICK || value == MOUSE_BEHAVIOR_NONE) value else MOUSE_BEHAVIOR_HOLD
|
||||
}
|
||||
|
||||
private fun normalizeMouseBehavior(value: String): String {
|
||||
return if (value == MOUSE_BEHAVIOR_CLICK) MOUSE_BEHAVIOR_CLICK else MOUSE_BEHAVIOR_HOLD
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
object TouchRouter {
|
||||
enum class Route { BLOCKED, GESTURES, SCROLL, OFF, TOUCHPAD, DIRECT }
|
||||
|
||||
data class Snapshot(
|
||||
val uiBlocking: Boolean,
|
||||
val mode: String,
|
||||
val scrollLayer: Boolean,
|
||||
val steamSession: Boolean,
|
||||
val steamDesktopUi: Boolean,
|
||||
)
|
||||
|
||||
fun decide(s: Snapshot): Route {
|
||||
if (s.uiBlocking) return Route.BLOCKED
|
||||
if (s.mode == SessionPrefs.TOUCH_GESTURES) return Route.GESTURES
|
||||
if (s.scrollLayer) return Route.SCROLL
|
||||
if (s.mode == SessionPrefs.TOUCH_OFF) return Route.OFF
|
||||
return if (touchpad(s)) Route.TOUCHPAD else Route.DIRECT
|
||||
}
|
||||
|
||||
fun steamKeyboardZone(s: Snapshot): Boolean = s.steamSession && !s.steamDesktopUi
|
||||
|
||||
private fun touchpad(s: Snapshot): Boolean = when (s.mode) {
|
||||
SessionPrefs.TOUCH_PAD -> true
|
||||
SessionPrefs.TOUCH_DIRECT -> false
|
||||
else -> !s.steamSession || s.steamDesktopUi
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
object TouchTiming {
|
||||
const val HOLD_MS = 500L
|
||||
const val TAP_MS = 300L
|
||||
const val CLICK_MS = 30L
|
||||
const val DOUBLE_TAP_MS = 300L
|
||||
const val SCROLL_STEP_PX = 36f
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.MotionEvent
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.hypot
|
||||
|
||||
class TouchpadGestures(
|
||||
private val slopPx: Float,
|
||||
@@ -15,6 +16,7 @@ class TouchpadGestures(
|
||||
private set
|
||||
var bounds: android.graphics.RectF = android.graphics.RectF(0f, 0f, 1f, 1f)
|
||||
var sensitivity = 1.15f
|
||||
var desktop = false
|
||||
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private var lastX = 0f
|
||||
@@ -27,7 +29,11 @@ class TouchpadGestures(
|
||||
private var secondDownAt = 0L
|
||||
private var secondWasTap = false
|
||||
private var twoFingers = false
|
||||
private var scrollAnchorX = 0f
|
||||
private var scrollAnchorY = 0f
|
||||
private var fingers = 0
|
||||
private var pinching = false
|
||||
private var pinchSpan = 0f
|
||||
private var scrolled = false
|
||||
private var anchorId = -1
|
||||
private var anchorStartX = 0f
|
||||
@@ -52,7 +58,7 @@ class TouchpadGestures(
|
||||
releaseClick()
|
||||
listener.onButton(button, true, x, y)
|
||||
clicked = button
|
||||
handler.postDelayed(clickUp, CLICK_MS)
|
||||
handler.postDelayed(clickUp, TouchTiming.CLICK_MS)
|
||||
}
|
||||
|
||||
private fun releaseClick() {
|
||||
@@ -79,6 +85,20 @@ class TouchpadGestures(
|
||||
y = py.coerceIn(bounds.top, bounds.bottom)
|
||||
}
|
||||
|
||||
private fun trackMove(px: Float, py: Float) {
|
||||
val dx = px - lastX
|
||||
val dy = py - lastY
|
||||
lastX = px; lastY = py
|
||||
travelled += abs(dx) + abs(dy)
|
||||
if (travelled > slopPx) {
|
||||
handler.removeCallbacks(longPress)
|
||||
val speed = abs(dx) + abs(dy)
|
||||
val gain = sensitivity * (1f + minOf(speed / 40f, 1.5f))
|
||||
place(x + dx * gain, y + dy * gain)
|
||||
listener.onMove(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
fun onTouch(event: MotionEvent): Boolean {
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
@@ -86,18 +106,20 @@ class TouchpadGestures(
|
||||
lastX = event.x; lastY = event.y
|
||||
downAt = event.eventTime
|
||||
travelled = 0f; held = false; twoFingers = false; scrolled = false; secondWasTap = false
|
||||
fingers = 1; pinching = false
|
||||
anchorId = event.getPointerId(0); moverId = -1; holdDrag = false; scrollLocked = false
|
||||
if (event.eventTime - lastTapAt < DOUBLE_TAP_MS) {
|
||||
if (event.eventTime - lastTapAt < TouchTiming.DOUBLE_TAP_MS) {
|
||||
dragging = true
|
||||
listener.onButton(PointerGestures.BTN_LEFT, true, x, y)
|
||||
} else {
|
||||
dragging = false
|
||||
handler.postDelayed(longPress, HOLD_MS)
|
||||
handler.postDelayed(longPress, TouchTiming.HOLD_MS)
|
||||
}
|
||||
return true
|
||||
}
|
||||
MotionEvent.ACTION_POINTER_DOWN -> {
|
||||
handler.removeCallbacks(longPress)
|
||||
fingers = maxOf(fingers, event.pointerCount)
|
||||
val i = event.actionIndex
|
||||
if (moverId == -1 && event.getPointerId(i) != anchorId) {
|
||||
moverId = event.getPointerId(i)
|
||||
@@ -111,7 +133,9 @@ class TouchpadGestures(
|
||||
twoFingers = true
|
||||
secondDownAt = event.eventTime
|
||||
secondWasTap = true
|
||||
scrollAnchorX = (event.getX(0) + event.getX(1)) / 2f
|
||||
scrollAnchorY = (event.getY(0) + event.getY(1)) / 2f
|
||||
pinchSpan = span(event)
|
||||
return true
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
@@ -146,29 +170,49 @@ class TouchpadGestures(
|
||||
} else if (holdDrag) {
|
||||
return true
|
||||
}
|
||||
if (twoFingers && event.pointerCount >= 2) {
|
||||
val mid = (event.getY(0) + event.getY(1)) / 2f
|
||||
val dy = mid - scrollAnchorY
|
||||
val steps = (dy / SCROLL_STEP_PX).toInt()
|
||||
if (steps != 0) {
|
||||
listener.onWheel(-steps)
|
||||
scrollAnchorY += steps * SCROLL_STEP_PX
|
||||
if (twoFingers && event.pointerCount >= 2 && desktop) {
|
||||
if (fingers >= 3) return true
|
||||
val span = span(event)
|
||||
if (!scrolled && !pinching && abs(span - pinchSpan) > slopPx * PINCH_SLOPS) {
|
||||
pinching = true
|
||||
secondWasTap = false
|
||||
pinchSpan = span
|
||||
}
|
||||
if (pinching) {
|
||||
val steps = ((span - pinchSpan) / PINCH_STEP_PX).toInt()
|
||||
if (steps != 0) {
|
||||
listener.onZoom(-steps)
|
||||
pinchSpan += steps * PINCH_STEP_PX
|
||||
}
|
||||
return true
|
||||
}
|
||||
val midX = (event.getX(0) + event.getX(1)) / 2f
|
||||
val midY = (event.getY(0) + event.getY(1)) / 2f
|
||||
val dx = scrollAnchorX - midX
|
||||
val dy = scrollAnchorY - midY
|
||||
if (scrolled || abs(dx) + abs(dy) > slopPx) {
|
||||
listener.onScroll(dx, dy)
|
||||
scrollAnchorX = midX; scrollAnchorY = midY
|
||||
scrolled = true
|
||||
secondWasTap = false
|
||||
}
|
||||
return true
|
||||
}
|
||||
val dx = event.x - lastX
|
||||
val dy = event.y - lastY
|
||||
lastX = event.x; lastY = event.y
|
||||
travelled += abs(dx) + abs(dy)
|
||||
if (travelled > slopPx) {
|
||||
handler.removeCallbacks(longPress)
|
||||
val speed = (abs(dx) + abs(dy))
|
||||
val gain = sensitivity * (1f + minOf(speed / 40f, 1.5f))
|
||||
place(x + dx * gain, y + dy * gain)
|
||||
listener.onMove(x, y)
|
||||
if (twoFingers && event.pointerCount >= 2) {
|
||||
val mid = (event.getY(0) + event.getY(1)) / 2f
|
||||
val dy = mid - scrollAnchorY
|
||||
val steps = (dy / TouchTiming.SCROLL_STEP_PX).toInt()
|
||||
if (steps != 0) {
|
||||
listener.onWheel(-steps)
|
||||
scrollAnchorY += steps * TouchTiming.SCROLL_STEP_PX
|
||||
scrolled = true
|
||||
secondWasTap = false
|
||||
}
|
||||
return true
|
||||
}
|
||||
for (h in 0 until event.historySize)
|
||||
trackMove(event.getHistoricalX(0, h), event.getHistoricalY(0, h))
|
||||
trackMove(event.x, event.y)
|
||||
return true
|
||||
}
|
||||
MotionEvent.ACTION_POINTER_UP -> {
|
||||
@@ -194,7 +238,12 @@ class TouchpadGestures(
|
||||
event.findPointerIndex(anchorId).takeIf { it >= 0 && it != event.actionIndex }?.let {
|
||||
lastX = event.getX(it); lastY = event.getY(it)
|
||||
}
|
||||
if (twoFingers && secondWasTap && event.eventTime - secondDownAt < TAP_MS && !scrolled) {
|
||||
if (desktop && scrolled && event.pointerCount == 2) listener.onScrollEnd()
|
||||
if (fingers >= 3) {
|
||||
if (event.pointerCount == 2 && secondWasTap && !scrolled && event.eventTime - downAt < TouchTiming.TAP_MS * 2)
|
||||
click(PointerGestures.BTN_MIDDLE)
|
||||
if (event.pointerCount == 2) secondWasTap = false
|
||||
} else if (twoFingers && secondWasTap && event.eventTime - secondDownAt < TouchTiming.TAP_MS && !scrolled) {
|
||||
click(PointerGestures.BTN_RIGHT)
|
||||
secondWasTap = false
|
||||
}
|
||||
@@ -206,29 +255,30 @@ class TouchpadGestures(
|
||||
when {
|
||||
dragging -> listener.onButton(PointerGestures.BTN_LEFT, false, x, y)
|
||||
twoFingers -> {
|
||||
if (secondWasTap && !scrolled && !cancelled && event.eventTime - downAt < TAP_MS * 2) {
|
||||
if (secondWasTap && !scrolled && !cancelled && event.eventTime - downAt < TouchTiming.TAP_MS * 2) {
|
||||
click(PointerGestures.BTN_RIGHT)
|
||||
}
|
||||
}
|
||||
!cancelled && travelled <= slopPx && event.eventTime - downAt < TAP_MS -> {
|
||||
!cancelled && travelled <= slopPx && event.eventTime - downAt < TouchTiming.TAP_MS -> {
|
||||
click(PointerGestures.BTN_LEFT)
|
||||
lastTapAt = event.eventTime
|
||||
}
|
||||
}
|
||||
dragging = false; held = false; twoFingers = false
|
||||
holdDrag = false; scrollLocked = false; anchorId = -1; moverId = -1
|
||||
pinching = false; fingers = 0
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun span(event: MotionEvent): Float =
|
||||
if (event.pointerCount < 2) 0f else hypot(event.getX(0) - event.getX(1), event.getY(0) - event.getY(1))
|
||||
|
||||
companion object {
|
||||
private const val HOLD_MS = 500L
|
||||
private const val TAP_MS = 300L
|
||||
private const val CLICK_MS = 50L
|
||||
private const val DOUBLE_TAP_MS = 300L
|
||||
private const val SCROLL_STEP_PX = 36f
|
||||
private const val PINCH_SLOPS = 3f
|
||||
private const val PINCH_STEP_PX = 60f
|
||||
private const val HOLD_DRAG_MOVER_SLOPS = 2f
|
||||
private const val HOLD_DRAG_ANCHOR_SLOPS = 0.5f
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public final class TouchscreenGestures {
|
||||
private final Output output;
|
||||
private final float doubleTapSlop;
|
||||
private TouchGestureConfig gestureConfig = new TouchGestureConfig();
|
||||
private static final int CLICK_DELAYED_TIME = 50;
|
||||
private static final int CLICK_DELAYED_TIME = 30;
|
||||
private Runnable delayedPress, pendingHoldClickRelease;
|
||||
private Runnable pendingTapPress;
|
||||
private final ArrayDeque<TapClick> pendingTapClicks = new ArrayDeque<>();
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.MotionEvent
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.hypot
|
||||
|
||||
class TwoFingerGestures(private val slopPx: Float, private val listener: Listener) {
|
||||
interface Listener {
|
||||
fun cancelTouch()
|
||||
fun replay(event: MotionEvent)
|
||||
fun rightClick(x: Float, y: Float)
|
||||
fun scrollStart(x: Float, y: Float)
|
||||
fun scroll(dx: Float, dy: Float)
|
||||
fun scrollEnd()
|
||||
}
|
||||
|
||||
private enum class State { IDLE, PENDING, CANDIDATE, TAPPED, HELD, SCROLLING, PASSING }
|
||||
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private var state = State.IDLE
|
||||
private var x = 0f
|
||||
private var y = 0f
|
||||
private var twoAt = 0L
|
||||
private var startSpan = 0f
|
||||
private var lastX = 0f
|
||||
private var lastY = 0f
|
||||
private val starts = HashMap<Int, Pair<Float, Float>>()
|
||||
private val held = ArrayList<MotionEvent>()
|
||||
private val hold = Runnable {
|
||||
if (state != State.CANDIDATE) return@Runnable
|
||||
state = State.HELD
|
||||
drop()
|
||||
listener.cancelTouch()
|
||||
listener.rightClick(x, y)
|
||||
}
|
||||
private val release = Runnable {
|
||||
if (state == State.PENDING) pass(State.IDLE)
|
||||
}
|
||||
|
||||
fun cancel() {
|
||||
if (state == State.SCROLLING) listener.scrollEnd()
|
||||
handler.removeCallbacks(hold)
|
||||
handler.removeCallbacks(release)
|
||||
drop()
|
||||
state = State.IDLE
|
||||
}
|
||||
|
||||
fun onTouch(event: MotionEvent): Boolean {
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
cancel()
|
||||
starts.clear()
|
||||
x = event.x
|
||||
y = event.y
|
||||
note(event, event.actionIndex)
|
||||
state = State.PENDING
|
||||
keep(event)
|
||||
handler.postDelayed(release, LAND_MS)
|
||||
return true
|
||||
}
|
||||
MotionEvent.ACTION_POINTER_DOWN -> {
|
||||
note(event, event.actionIndex)
|
||||
when (state) {
|
||||
State.PENDING -> {
|
||||
handler.removeCallbacks(release)
|
||||
keep(event)
|
||||
if (event.pointerCount != 2) {
|
||||
pass(State.PASSING)
|
||||
return true
|
||||
}
|
||||
state = State.CANDIDATE
|
||||
twoAt = event.eventTime
|
||||
startSpan = span(event)
|
||||
lastX = midX(event)
|
||||
lastY = midY(event)
|
||||
handler.postDelayed(hold, HOLD_MS)
|
||||
return true
|
||||
}
|
||||
State.CANDIDATE -> {
|
||||
keep(event)
|
||||
pass(State.PASSING)
|
||||
return true
|
||||
}
|
||||
State.SCROLLING, State.HELD, State.TAPPED -> return true
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> when (state) {
|
||||
State.PENDING -> {
|
||||
keep(event)
|
||||
if (moved(event)) pass(State.IDLE)
|
||||
return true
|
||||
}
|
||||
State.CANDIDATE -> {
|
||||
if (event.pointerCount == 2 && moved(event)) {
|
||||
handler.removeCallbacks(hold)
|
||||
if (abs(span(event) - startSpan) > slopPx * 2) {
|
||||
keep(event)
|
||||
pass(State.PASSING)
|
||||
return true
|
||||
}
|
||||
state = State.SCROLLING
|
||||
drop()
|
||||
listener.cancelTouch()
|
||||
lastX = midX(event)
|
||||
lastY = midY(event)
|
||||
listener.scrollStart(lastX, lastY)
|
||||
return true
|
||||
}
|
||||
keep(event)
|
||||
return true
|
||||
}
|
||||
State.SCROLLING -> {
|
||||
if (event.pointerCount >= 2) {
|
||||
val mx = midX(event)
|
||||
val my = midY(event)
|
||||
listener.scroll(lastX - mx, lastY - my)
|
||||
lastX = mx
|
||||
lastY = my
|
||||
}
|
||||
return true
|
||||
}
|
||||
State.TAPPED, State.HELD -> return true
|
||||
else -> Unit
|
||||
}
|
||||
MotionEvent.ACTION_POINTER_UP -> when (state) {
|
||||
State.CANDIDATE -> {
|
||||
handler.removeCallbacks(hold)
|
||||
keep(event)
|
||||
if (event.eventTime - twoAt < TAP_MS) {
|
||||
state = State.TAPPED
|
||||
drop()
|
||||
return true
|
||||
}
|
||||
pass(State.PASSING)
|
||||
return true
|
||||
}
|
||||
State.SCROLLING, State.HELD, State.TAPPED -> return true
|
||||
else -> Unit
|
||||
}
|
||||
MotionEvent.ACTION_UP -> {
|
||||
val was = state
|
||||
if (was == State.PENDING) {
|
||||
keep(event)
|
||||
pass(State.IDLE)
|
||||
return true
|
||||
}
|
||||
cancel()
|
||||
when (was) {
|
||||
State.TAPPED -> {
|
||||
listener.cancelTouch()
|
||||
listener.rightClick(x, y)
|
||||
return true
|
||||
}
|
||||
State.SCROLLING, State.HELD -> return true
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
MotionEvent.ACTION_CANCEL -> cancel()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun keep(event: MotionEvent) {
|
||||
held += MotionEvent.obtain(event)
|
||||
}
|
||||
|
||||
private fun drop() {
|
||||
held.forEach { it.recycle() }
|
||||
held.clear()
|
||||
}
|
||||
|
||||
private fun pass(next: State) {
|
||||
handler.removeCallbacks(release)
|
||||
handler.removeCallbacks(hold)
|
||||
state = next
|
||||
val events = held.toList()
|
||||
held.clear()
|
||||
events.forEach {
|
||||
listener.replay(it)
|
||||
it.recycle()
|
||||
}
|
||||
}
|
||||
|
||||
private fun note(event: MotionEvent, index: Int) {
|
||||
starts[event.getPointerId(index)] = event.getX(index) to event.getY(index)
|
||||
}
|
||||
|
||||
private fun moved(event: MotionEvent): Boolean = (0 until event.pointerCount).any { i ->
|
||||
val start = starts[event.getPointerId(i)] ?: return@any false
|
||||
hypot(event.getX(i) - start.first, event.getY(i) - start.second) > slopPx
|
||||
}
|
||||
|
||||
private fun span(event: MotionEvent) = hypot(event.getX(1) - event.getX(0), event.getY(1) - event.getY(0))
|
||||
private fun midX(event: MotionEvent) = (event.getX(0) + event.getX(1)) / 2f
|
||||
private fun midY(event: MotionEvent) = (event.getY(0) + event.getY(1)) / 2f
|
||||
|
||||
companion object {
|
||||
const val LAND_MS = 250L
|
||||
const val TAP_MS = 350L
|
||||
const val HOLD_MS = 500L
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user