[android] InputService mouse long press mode

This commit is contained in:
csf 2022-07-14 18:36:54 +08:00
parent 55427bad2f
commit fdca9acbb7

View File

@ -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<GestureDescription>()
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,10 +95,13 @@ class InputService : AccessibilityService() {
// left up ,was down
if (mask == LIFT_UP) {
if (leftIsDown) {
leftIsDown = false
isWaitingLongPress = false
endGesture(mouseX, mouseY)
return
}
}
if (mask == RIGHT_UP) {
performGlobalAction(GLOBAL_ACTION_BACK)