From fdca9acbb78a031a071eca380057138af629db25 Mon Sep 17 00:00:00 2001 From: csf Date: Thu, 14 Jul 2022 18:36:54 +0800 Subject: [PATCH] [android] InputService mouse long press mode --- .../com/carriez/flutter_hbb/InputService.kt | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/InputService.kt b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/InputService.kt index 76068eee5..905a2734d 100644 --- a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/InputService.kt +++ b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/InputService.kt @@ -8,14 +8,14 @@ package com.carriez.flutter_hbb import android.accessibilityservice.AccessibilityService import android.accessibilityservice.GestureDescription -import android.content.Context import android.graphics.Path import android.os.Build import android.util.Log import android.view.accessibility.AccessibilityEvent -import androidx.annotation.Keep import androidx.annotation.RequiresApi import java.util.* +import kotlin.math.abs +import kotlin.math.max const val LIFT_DOWN = 9 const val LIFT_MOVE = 8 @@ -49,28 +49,40 @@ class InputService : AccessibilityService() { private val wheelActionsQueue = LinkedList() private var isWheelActionsPolling = false + private var isWaitingLongPress = false @RequiresApi(Build.VERSION_CODES.N) fun onMouseInput(mask: Int, _x: Int, _y: Int) { - val x = if (_x < 0) { - 0 - } else { - _x - } - - val y = if (_y < 0) { - 0 - } else { - _y - } + val x = max(0, _x) + val y = max(0, _y) if (mask == 0 || mask == LIFT_MOVE) { + val oldX = mouseX + val oldY = mouseY mouseX = x * SCREEN_INFO.scale mouseY = y * SCREEN_INFO.scale + if (isWaitingLongPress) { + val delta = abs(oldX - mouseX) + abs(oldY - mouseY) + Log.d(logTag,"delta:$delta") + if (delta > 8) { + isWaitingLongPress = false + } + } } // left button down ,was up if (mask == LIFT_DOWN) { + isWaitingLongPress = true + timer.schedule(object : TimerTask() { + override fun run() { + if (isWaitingLongPress) { + isWaitingLongPress = false + leftIsDown = false + endGesture(mouseX, mouseY) + } + } + }, LONG_TAP_DELAY * 4) + leftIsDown = true startGesture(mouseX, mouseY) return @@ -83,9 +95,12 @@ class InputService : AccessibilityService() { // left up ,was down if (mask == LIFT_UP) { - leftIsDown = false - endGesture(mouseX, mouseY) - return + if (leftIsDown) { + leftIsDown = false + isWaitingLongPress = false + endGesture(mouseX, mouseY) + return + } } if (mask == RIGHT_UP) {