mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-13 03:28:03 +00:00
refact: android, handle right click (#10806)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import android.view.accessibility.AccessibilityEvent
|
|||||||
import android.view.ViewGroup.LayoutParams
|
import android.view.ViewGroup.LayoutParams
|
||||||
import android.view.accessibility.AccessibilityNodeInfo
|
import android.view.accessibility.AccessibilityNodeInfo
|
||||||
import android.view.KeyEvent as KeyEventAndroid
|
import android.view.KeyEvent as KeyEventAndroid
|
||||||
|
import android.view.ViewConfiguration
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.accessibilityservice.AccessibilityServiceInfo
|
import android.accessibilityservice.AccessibilityServiceInfo
|
||||||
@@ -64,13 +65,15 @@ class InputService : AccessibilityService() {
|
|||||||
|
|
||||||
private val logTag = "input service"
|
private val logTag = "input service"
|
||||||
private var leftIsDown = false
|
private var leftIsDown = false
|
||||||
private var touchPath = Path()
|
private val touchPath = Path()
|
||||||
private var stroke: GestureDescription.StrokeDescription? = null
|
private var stroke: GestureDescription.StrokeDescription? = null
|
||||||
private var lastTouchGestureStartTime = 0L
|
private var lastTouchGestureStartTime = 0L
|
||||||
private var mouseX = 0
|
private var mouseX = 0
|
||||||
private var mouseY = 0
|
private var mouseY = 0
|
||||||
private var timer = Timer()
|
private var timer = Timer()
|
||||||
private var recentActionTask: TimerTask? = null
|
private var recentActionTask: TimerTask? = null
|
||||||
|
// 100(tap timeout) + 400(long press timeout)
|
||||||
|
private val longPressDuration = ViewConfiguration.getTapTimeout().toLong() + ViewConfiguration.getLongPressTimeout().toLong()
|
||||||
|
|
||||||
private val wheelActionsQueue = LinkedList<GestureDescription>()
|
private val wheelActionsQueue = LinkedList<GestureDescription>()
|
||||||
private var isWheelActionsPolling = false
|
private var isWheelActionsPolling = false
|
||||||
@@ -102,7 +105,7 @@ class InputService : AccessibilityService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// left button down ,was up
|
// left button down, was up
|
||||||
if (mask == LEFT_DOWN) {
|
if (mask == LEFT_DOWN) {
|
||||||
isWaitingLongPress = true
|
isWaitingLongPress = true
|
||||||
timer.schedule(object : TimerTask() {
|
timer.schedule(object : TimerTask() {
|
||||||
@@ -112,19 +115,19 @@ class InputService : AccessibilityService() {
|
|||||||
continueGesture(mouseX, mouseY)
|
continueGesture(mouseX, mouseY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, LONG_TAP_DELAY * 4)
|
}, longPressDuration)
|
||||||
|
|
||||||
leftIsDown = true
|
leftIsDown = true
|
||||||
startGesture(mouseX, mouseY)
|
startGesture(mouseX, mouseY)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// left down ,was down
|
// left down, was down
|
||||||
if (leftIsDown) {
|
if (leftIsDown) {
|
||||||
continueGesture(mouseX, mouseY)
|
continueGesture(mouseX, mouseY)
|
||||||
}
|
}
|
||||||
|
|
||||||
// left up ,was down
|
// left up, was down
|
||||||
if (mask == LEFT_UP) {
|
if (mask == LEFT_UP) {
|
||||||
if (leftIsDown) {
|
if (leftIsDown) {
|
||||||
leftIsDown = false
|
leftIsDown = false
|
||||||
@@ -135,7 +138,7 @@ class InputService : AccessibilityService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mask == RIGHT_UP) {
|
if (mask == RIGHT_UP) {
|
||||||
performGlobalAction(GLOBAL_ACTION_BACK)
|
longPress(mouseX, mouseY)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,6 +247,26 @@ class InputService : AccessibilityService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.N)
|
||||||
|
private fun performClick(x: Int, y: Int, duration: Long) {
|
||||||
|
val path = Path()
|
||||||
|
path.moveTo(x.toFloat(), y.toFloat())
|
||||||
|
try {
|
||||||
|
val longPressStroke = GestureDescription.StrokeDescription(path, 0, duration)
|
||||||
|
val builder = GestureDescription.Builder()
|
||||||
|
builder.addStroke(longPressStroke)
|
||||||
|
Log.d(logTag, "performClick x:$x y:$y time:$duration")
|
||||||
|
dispatchGesture(builder.build(), null, null)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(logTag, "performClick, error:$e")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.N)
|
||||||
|
private fun longPress(x: Int, y: Int) {
|
||||||
|
performClick(x, y, longPressDuration)
|
||||||
|
}
|
||||||
|
|
||||||
private fun startGesture(x: Int, y: Int) {
|
private fun startGesture(x: Int, y: Int) {
|
||||||
touchPath.reset()
|
touchPath.reset()
|
||||||
touchPath.moveTo(x.toFloat(), y.toFloat())
|
touchPath.moveTo(x.toFloat(), y.toFloat())
|
||||||
@@ -273,7 +296,7 @@ class InputService : AccessibilityService() {
|
|||||||
stroke?.let {
|
stroke?.let {
|
||||||
val builder = GestureDescription.Builder()
|
val builder = GestureDescription.Builder()
|
||||||
builder.addStroke(it)
|
builder.addStroke(it)
|
||||||
Log.d(logTag, "end gesture x:$x y:$y time:$duration")
|
Log.d(logTag, "doDispatchGesture x:$x y:$y time:$duration")
|
||||||
dispatchGesture(builder.build(), null, null)
|
dispatchGesture(builder.build(), null, null)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
Reference in New Issue
Block a user