Skip to content

Commit 3b045ae

Browse files
committed
feat(assists-web): 添加手势操作相关方法
- 新增 web支持执行线型手势 performLinearGesture 方法 - 优化原有 gestureClick->clickByGesture 和 nodeGestureClick->clickNodeByGesture 方法的命名,提高可读性
1 parent 872f668 commit 3b045ae

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-16
lines changed

assists-web/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
android {
8-
namespace 'com.ven.assists_web'
8+
namespace 'com.ven.assists.web'
99
compileSdk rootProject.ext.compileSdk
1010

1111
defaultConfig {

assists-web/src/main/java/com/ven/assists/web/ASJavascriptInterface.kt

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.ven.assists.web
22

33
import android.graphics.Bitmap
4+
import android.graphics.Path
45
import android.graphics.Rect
56
import android.os.Build
67
import android.util.Base64
@@ -40,10 +41,11 @@ import com.ven.assists.mp.MPManager.getBitmap
4041
import com.ven.assists.service.AssistsService
4142
import com.ven.assists.utils.CoroutineWrapper
4243
import com.ven.assists.utils.runIO
44+
import com.ven.assists.utils.runMain
45+
import com.ven.assists.web.databinding.WebFloatingWindowBinding
4346
import com.ven.assists.window.AssistsWindowManager
4447
import com.ven.assists.window.AssistsWindowManager.overlayToast
4548
import com.ven.assists.window.AssistsWindowWrapper
46-
import com.ven.assists_web.databinding.WebFloatingWindowBinding
4749
import kotlinx.coroutines.CoroutineScope
4850
import kotlinx.coroutines.Dispatchers
4951
import kotlinx.coroutines.delay
@@ -191,11 +193,30 @@ class ASJavascriptInterface(val webView: WebView) {
191193
}))
192194
}
193195

194-
CallMethod.dispatchGesture -> {
195-
ScreenUtils.getScreenHeight()
196-
// AssistsCore.dispatchGesture()
197-
//
198-
// result = GsonUtils.toJson(CallResponse<List<Node>>(code = 0, data = nodes))
196+
CallMethod.performLinearGesture -> {
197+
CoroutineWrapper.launch {
198+
val startPoint = request.arguments?.get("startPoint")?.asJsonObject ?: JsonObject()
199+
val endPoint = request.arguments?.get("endPoint")?.asJsonObject ?: JsonObject()
200+
val path = Path()
201+
path.moveTo(startPoint.get("x").asFloat, startPoint.get("y").asFloat)
202+
path.lineTo(endPoint.get("x").asFloat, endPoint.get("y").asFloat)
203+
val switchWindowIntervalDelay = request.arguments?.get("switchWindowIntervalDelay")?.asLong ?: 250
204+
CoroutineWrapper.launch {
205+
AssistsWindowManager.nonTouchableByAll()
206+
delay(switchWindowIntervalDelay)
207+
val result =
208+
AssistsCore.gesture(path = path, startTime = 0, duration = request.arguments?.get("duration")?.asLong ?: 1000)
209+
AssistsWindowManager.touchableByAll()
210+
if (result) {
211+
callback(CallResponse<Boolean>(code = 0, data = true, callbackId = request.callbackId))
212+
} else {
213+
callback(CallResponse<Boolean>(code = -1, data = false, callbackId = request.callbackId))
214+
}
215+
}
216+
}
217+
result = GsonUtils.toJson(CallResponse<JsonObject>(code = 0, data = JsonObject().apply {
218+
addProperty("resultType", "callback")
219+
}))
199220
}
200221

201222
CallMethod.getAppScreenSize -> {
@@ -210,14 +231,14 @@ class ASJavascriptInterface(val webView: WebView) {
210231
}))
211232
}
212233

213-
CallMethod.gestureClick -> {
234+
CallMethod.clickByGesture -> {
214235
CoroutineWrapper.launch {
215236
AssistsCore.gestureClick(x = request.arguments?.get("x")?.asFloat ?: 0f, y = request.arguments?.get("y")?.asFloat ?: 0f)
216237
}
217238
result = GsonUtils.toJson(CallResponse<Boolean>(code = 0, data = true))
218239
}
219240

220-
CallMethod.nodeGestureClick -> {
241+
CallMethod.clickNodeByGesture -> {
221242
CoroutineWrapper.launch {
222243
val offsetX = request.arguments?.get("offsetX")?.asFloat ?: (ScreenUtils.getScreenWidth() * 0.01953f)
223244
val offsetY = request.arguments?.get("offsetY")?.asFloat ?: (ScreenUtils.getScreenWidth() * 0.01953f)
@@ -236,7 +257,7 @@ class ASJavascriptInterface(val webView: WebView) {
236257
}))
237258
}
238259

239-
CallMethod.nodeGestureClickByDouble -> {
260+
CallMethod.doubleClickNodeByGesture -> {
240261
CoroutineWrapper.launch {
241262
val offsetX = request.arguments?.get("offsetX")?.asFloat ?: (ScreenUtils.getScreenWidth() * 0.01953f)
242263
val offsetY = request.arguments?.get("offsetY")?.asFloat ?: (ScreenUtils.getScreenWidth() * 0.01953f)

assists-web/src/main/java/com/ven/assists/web/CallMethod.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ object CallMethod {
1313
const val getNodes = "getNodes"
1414
const val findFirstParentClickable = "findFirstParentClickable"
1515
const val getChildren = "getChildren"
16-
const val dispatchGesture = "dispatchGesture"
1716
const val getBoundsInScreen = "getBoundsInScreen"
1817
const val getBoundsInParent = "getBoundsInParent"
1918
const val isVisible = "isVisible"
2019
const val click = "click"
2120
const val longClick = "longClick"
22-
const val gestureClick = "gestureClick"
2321
const val back = "back"
2422
const val home = "home"
2523
const val notifications = "notifications"
@@ -33,11 +31,18 @@ object CallMethod {
3331
const val overlayToast = "overlayToast"
3432
const val getScreenSize = "getScreenSize"
3533
const val getAppScreenSize = "getAppScreenSize"
36-
const val nodeGestureClick = "nodeGestureClick"
37-
const val nodeGestureClickByDouble = "nodeGestureClickByDouble"
3834
const val takeScreenshot = "takeScreenshot"
3935
const val setOverlayFlags = "setOverlayFlags"
4036
const val scanQR = "scanQR"
4137
const val loadWebViewOverlay = "loadWebViewOverlay"
42-
const val getLocalDomain = "getLocalDomain"
43-
}
38+
39+
40+
//手势方法
41+
const val clickByGesture = "clickByGesture"
42+
const val clickNodeByGesture = "clickNodeByGesture"
43+
const val doubleClickNodeByGesture = "doubleClickNodeByGesture"
44+
const val performLinearGesture = "performLinearGesture"
45+
46+
//TODO 获取app信息
47+
const val getAppInfoByPackageName = "getAppInfoByPackageName"
48+
}

0 commit comments

Comments
 (0)