6.3.3 - pre2 - PR by 抠脚本人
This commit is contained in:
@@ -64,11 +64,19 @@ module.exports = function (scriptRuntime, scope) {
|
||||
stateListener(listener) {
|
||||
return a11yBridge.setAccessibilityListener(listener);
|
||||
},
|
||||
registerEvents(name, listener) {
|
||||
return rtAutomator.registerEvents(name, listener);
|
||||
registerEvent(name, listener) {
|
||||
return rtAutomator.registerEvent(name, listener);
|
||||
},
|
||||
/** @deprecated */
|
||||
registerEvents(name, listener) {
|
||||
return rtAutomator.registerEvent(name, listener);
|
||||
},
|
||||
removeEvent(name) {
|
||||
return rtAutomator.removeEvent(name);
|
||||
},
|
||||
/** @deprecated */
|
||||
removeEvents(name) {
|
||||
return rtAutomator.removeEvents(name);
|
||||
return rtAutomator.removeEvent(name);
|
||||
},
|
||||
waitFor(timeout) {
|
||||
automator.waitForService(timeout);
|
||||
|
||||
@@ -8,7 +8,7 @@ import android.view.accessibility.AccessibilityEvent
|
||||
import android.view.accessibility.AccessibilityEvent.TYPE_VIEW_FOCUSED
|
||||
import android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
|
||||
import android.view.accessibility.AccessibilityNodeInfo
|
||||
import org.autojs.autojs.AutoJs
|
||||
import org.autojs.autojs.core.accessibility.SimpleActionAutomator.Companion.AccessibilityEventCallback
|
||||
import org.autojs.autojs.core.automator.AccessibilityEventWrapper
|
||||
import org.autojs.autojs.event.EventDispatcher
|
||||
import org.autojs.autojs.pref.Pref
|
||||
@@ -107,7 +107,6 @@ open class AccessibilityService : android.accessibilityservice.AccessibilityServ
|
||||
|
||||
override fun onDestroy() {
|
||||
Log.v(TAG, "onDestroy: $instance")
|
||||
AutoJs.instance.globalConsole.verbose("无障碍服务已关闭")
|
||||
instance = null
|
||||
bridge = null
|
||||
eventExecutor.shutdownNow()
|
||||
@@ -117,7 +116,6 @@ open class AccessibilityService : android.accessibilityservice.AccessibilityServ
|
||||
|
||||
override fun onServiceConnected() {
|
||||
instance = this
|
||||
AutoJs.instance.globalConsole.verbose("无障碍服务已开启${instance}")
|
||||
serviceInfo = serviceInfo.apply {
|
||||
AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS.let {
|
||||
flags = (if (Pref.isStableModeEnabled) flags and it.inv() else flags or it)
|
||||
@@ -168,7 +166,7 @@ open class AccessibilityService : android.accessibilityservice.AccessibilityServ
|
||||
fun isNotRunning() = !isRunning()
|
||||
|
||||
fun addDelegate(uniquePriority: Int, delegate: AccessibilityDelegate) {
|
||||
//用于记录eventTypes中的事件id
|
||||
// 用于记录eventTypes中的事件id
|
||||
delegates[uniquePriority] = delegate
|
||||
val set = delegate.eventTypes
|
||||
if (set == null) {
|
||||
@@ -206,6 +204,7 @@ open class AccessibilityService : android.accessibilityservice.AccessibilityServ
|
||||
LOCK.unlock()
|
||||
}
|
||||
}
|
||||
@JvmStatic
|
||||
fun clearAccessibilityEventCallback() {
|
||||
instance?.eventBox?.clear()
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
package org.autojs.autojs.core.accessibility
|
||||
|
||||
import android.accessibilityservice.AccessibilityService
|
||||
import android.accessibilityservice.GestureDescription
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Rect
|
||||
@@ -15,7 +14,6 @@ import android.view.accessibility.AccessibilityNodeInfo
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat
|
||||
import org.autojs.autojs.annotation.ScriptInterface
|
||||
import org.autojs.autojs.core.accessibility.AccessibilityService.Companion.isRunning
|
||||
import org.autojs.autojs.core.automator.AccessibilityEventWrapper
|
||||
import org.autojs.autojs.core.automator.GlobalActionAutomator
|
||||
import org.autojs.autojs.core.automator.UiObject
|
||||
@@ -29,10 +27,7 @@ import org.autojs.autojs.runtime.api.ScreenMetrics
|
||||
import org.autojs.autojs.runtime.api.ScriptPromiseAdapter
|
||||
import org.autojs.autojs.util.DeveloperUtils
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
interface AccessibilityEventCallback {
|
||||
fun onAccessibilityEvent(event: AccessibilityEventWrapper)
|
||||
}
|
||||
import android.accessibilityservice.AccessibilityService as AndroidAccessibilityService
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/2.
|
||||
@@ -182,21 +177,21 @@ class SimpleActionAutomator(private val accessibilityBridge: AccessibilityBridge
|
||||
fun paste(target: ActionTarget) = performAction(target.createAction(AccessibilityNodeInfo.ACTION_PASTE))
|
||||
|
||||
@ScriptInterface
|
||||
fun isServiceRunning() = isRunning()
|
||||
fun isServiceRunning() = AccessibilityService.isRunning()
|
||||
|
||||
@ScriptInterface
|
||||
fun ensureService() = accessibilityBridge.ensureServiceEnabled()
|
||||
|
||||
//todo:优化实现方式
|
||||
fun registerEvents(eventName: String,callback: AccessibilityEventCallback) {
|
||||
// TODO by SuperMonster003 on Jul 12, 2023.
|
||||
// ! Ref to Auto.js Pro
|
||||
fun registerEvent(eventName: String, callback: AccessibilityEventCallback) {
|
||||
ensureService()
|
||||
val service = org.autojs.autojs.core.accessibility.AccessibilityService.instance
|
||||
service?.addAccessibilityEventCallback(eventName,callback)
|
||||
AccessibilityService.instance?.addAccessibilityEventCallback(eventName, callback)
|
||||
}
|
||||
|
||||
fun removeEvents(eventName: String) {
|
||||
val service = org.autojs.autojs.core.accessibility.AccessibilityService.instance
|
||||
service?.removeAccessibilityEventCallback(eventName)
|
||||
fun removeEvent(eventName: String) {
|
||||
AccessibilityService.instance?.removeAccessibilityEventCallback(eventName)
|
||||
}
|
||||
|
||||
private fun performAction(simpleAction: SimpleAction): Boolean {
|
||||
@@ -221,8 +216,8 @@ class SimpleActionAutomator(private val accessibilityBridge: AccessibilityBridge
|
||||
val promiseAdapter = mPromiseAdapter ?: ScriptPromiseAdapter().also { mPromiseAdapter = it }
|
||||
val service = accessibilityBridge.service!!
|
||||
val executor = service.mainExecutor
|
||||
val callback = object : AccessibilityService.TakeScreenshotCallback {
|
||||
override fun onSuccess(screenshot: AccessibilityService.ScreenshotResult) {
|
||||
val callback = object : AndroidAccessibilityService.TakeScreenshotCallback {
|
||||
override fun onSuccess(screenshot: AndroidAccessibilityService.ScreenshotResult) {
|
||||
val hardwareBuffer = Bitmap.wrapHardwareBuffer(screenshot.hardwareBuffer, screenshot.colorSpace)
|
||||
|
||||
// @Hint by SuperMonster003 on Jun 9, 2023.
|
||||
@@ -239,7 +234,7 @@ class SimpleActionAutomator(private val accessibilityBridge: AccessibilityBridge
|
||||
}
|
||||
|
||||
override fun onFailure(errorCode: Int) {
|
||||
if (errorCode == AccessibilityService.ERROR_TAKE_SCREENSHOT_INTERVAL_TIME_SHORT) {
|
||||
if (errorCode == AndroidAccessibilityService.ERROR_TAKE_SCREENSHOT_INTERVAL_TIME_SHORT) {
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
captureScreen()
|
||||
}, 50)
|
||||
@@ -259,6 +254,9 @@ class SimpleActionAutomator(private val accessibilityBridge: AccessibilityBridge
|
||||
val accessibilityDelegateCounter = AtomicInteger(1000)
|
||||
val TAG: String = SimpleActionAutomator::class.java.name
|
||||
|
||||
interface AccessibilityEventCallback {
|
||||
fun onAccessibilityEvent(event: AccessibilityEventWrapper)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ package org.autojs.autojs.core.automator
|
||||
import android.view.accessibility.AccessibilityEvent
|
||||
import android.view.accessibility.AccessibilityNodeInfo
|
||||
|
||||
/**
|
||||
* Created by 抠脚本人 on Jul 10, 2023.
|
||||
*/
|
||||
class AccessibilityEventWrapper(event: AccessibilityEvent) {
|
||||
val raw = event
|
||||
val packageName: CharSequence? = event.packageName
|
||||
|
||||
@@ -60,17 +60,34 @@ open class UiObject(
|
||||
}
|
||||
} catch (e: IllegalStateException) {
|
||||
// FIXME: 2017/5/5
|
||||
null
|
||||
null.also { e.printStackTrace() }
|
||||
}
|
||||
|
||||
open fun child(i: Int): UiObject? = try {
|
||||
super.getChild(i)?.run { UiObject(unwrap(), depth + 1, i) }
|
||||
} catch (e: IllegalStateException) {
|
||||
// FIXME: 2017/5/5
|
||||
null
|
||||
null.also { e.printStackTrace() }
|
||||
}
|
||||
|
||||
open fun brother(i: Int): UiObject? = parent()?.child(indexInParent() + i)
|
||||
@Deprecated("Deprecated in Java", ReplaceWith("offset(i)"))
|
||||
open fun brother(i: Int): UiObject? = offset(i)
|
||||
|
||||
open fun offset(i: Int): UiObject? = try {
|
||||
parent()?.child(indexInParent + i)
|
||||
} catch (e: ArrayIndexOutOfBoundsException) {
|
||||
null.also { e.printStackTrace() }
|
||||
}
|
||||
|
||||
open fun sibling(i: Int): UiObject? = try {
|
||||
parent()?.child(i)
|
||||
} catch (e: ArrayIndexOutOfBoundsException) {
|
||||
null.also { e.printStackTrace() }
|
||||
}
|
||||
|
||||
open fun nextSibling() = sibling(1)
|
||||
|
||||
open fun previousSibling() = sibling(-1)
|
||||
|
||||
open fun childCount() = childCount
|
||||
|
||||
@@ -344,14 +361,14 @@ open class UiObject(
|
||||
}
|
||||
} catch (e: IllegalStateException) {
|
||||
// FIXME: 2017/5/5
|
||||
false
|
||||
false.also { e.printStackTrace() }
|
||||
}
|
||||
|
||||
override fun performAction(action: Int): Boolean = try {
|
||||
super.performAction(action)
|
||||
} catch (e: IllegalStateException) {
|
||||
// FIXME: 2017/5/5
|
||||
false
|
||||
false.also { e.printStackTrace() }
|
||||
}
|
||||
|
||||
override fun getChild(index: Int): AccessibilityNodeInfoCompat =
|
||||
|
||||
@@ -6,18 +6,16 @@ import org.autojs.autojs.core.ui.inflater.util.Ids
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/14.
|
||||
* Transformed by 抠脚本人 on Jul 10, 2023.
|
||||
*/
|
||||
object JsViewHelper {
|
||||
@JvmStatic
|
||||
fun findViewByStringId(view: View, id: String?): View? {
|
||||
var result = view.findViewById<View>(Ids.parse(id))
|
||||
if (result != null) return result
|
||||
if (view !is ViewGroup) {
|
||||
return null
|
||||
}
|
||||
for (i in 0 until view.childCount) {
|
||||
result = findViewByStringId(view.getChildAt(i), id)
|
||||
if (result != null) return result
|
||||
view.findViewById<View>(Ids.parse(id))?.let { return it }
|
||||
if (view is ViewGroup) {
|
||||
for (i in 0 until view.childCount) {
|
||||
findViewByStringId(view.getChildAt(i), id)?.let { return it }
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.autojs.autojs.model.autocomplete
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2018/2/3.
|
||||
* Transformed by 抠脚本人 on Jul 11, 2023.
|
||||
*/
|
||||
class CodeCompletion {
|
||||
val hint: String
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.autojs.autojs.model.autocomplete
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/9/27.
|
||||
* Transformed by 抠脚本人 on Jul 11, 2023.
|
||||
*/
|
||||
class CodeCompletions(val from: Int, private val mCompletions: List<CodeCompletion>) {
|
||||
fun size(): Int {
|
||||
|
||||
@@ -9,10 +9,10 @@ import java.util.Arrays;
|
||||
public class Symbols {
|
||||
|
||||
private static final CodeCompletions sSymbols = CodeCompletions.just(Arrays.asList(
|
||||
",", ".", "=", ";", "\"", "'", "/", "_",
|
||||
",", ".", "=", ";", "\"", "'", "/", "-", "_",
|
||||
"(", ")", "[", "]", "{", "}", "<", ">",
|
||||
"+", "*", "?", "$", "#", "@", "`",
|
||||
"-", "\\", "&", "|", "!", "%", "×", "÷",
|
||||
"+", "*", "?", ":", "$", "#", "@", "`",
|
||||
"\\", "&", "|", "!", "%", "×", "÷",
|
||||
"∈", "∩", "∪", "∉", "⊙", "∅", "¥", "€",
|
||||
"°", "℃", "∵", "∴", "±", "≠", "≈",
|
||||
"α", "β", "γ", "λ", "μ", "π", "σ", "ω",
|
||||
|
||||
@@ -528,8 +528,10 @@ public class ScriptRuntime {
|
||||
console.hideDelayed();
|
||||
}
|
||||
});
|
||||
//清空无障碍事件
|
||||
ignoresException(AccessibilityService.Companion::clearAccessibilityEventCallback);
|
||||
|
||||
// 清空无障碍事件
|
||||
ignoresException(AccessibilityService::clearAccessibilityEventCallback);
|
||||
|
||||
ignoresException(RootUtils::resetRuntimeOverriddenRootModeState);
|
||||
ignoresException(ImageWrapper::recycleAll);
|
||||
|
||||
|
||||
@@ -286,7 +286,11 @@ open class EditorView : FrameLayout, OnHintClickListener, ClickCallback, Toolbar
|
||||
.setEditView(editor!!.codeEditText)
|
||||
.build()
|
||||
//todo:不清楚作用,暂时注释掉
|
||||
//mFunctionsKeyboard!!.setClickCallback(this)
|
||||
// @Hint by SuperMonster003 on Jul 12, 2023.
|
||||
// ! 此处的点击事件回调注册是为了使功能键盘智能提示的属性可以实现其接口对应的功能:
|
||||
// ! 点击: 自动补全, 并根据情况添加括号或句点符号等.
|
||||
// ! 长按: 以浮动窗口形式展示 [方法/属性/模块] 对应的文档内容 (如果存在的话).
|
||||
mFunctionsKeyboard!!.setClickCallback(this)
|
||||
mShowFunctionsButton!!.setOnLongClickListener {
|
||||
editor!!.beautifyCode()
|
||||
true
|
||||
|
||||
@@ -409,7 +409,7 @@ public class CodeEditor extends HVScrollView {
|
||||
public void onSuccess(String beautifiedCode) {
|
||||
setProgress(false);
|
||||
mCodeEditText.setText(beautifiedCode);
|
||||
//格式化后恢复光标位置
|
||||
// 格式化后恢复光标位置
|
||||
mCodeEditText.setSelection(pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,6 @@ buildscript {
|
||||
}
|
||||
|
||||
dependencies /* Android/Kotlin Gradle Plugin. */ {
|
||||
classpath("com.android.tools.build:gradle:7.1.2")
|
||||
val android = gradlePluginVersionList[platformType]!!["android"]!!
|
||||
val kotlin = gradlePluginVersionList[platformType]!!["kotlin"]!!
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
enableFeaturePreview("STABLE_CONFIGURATION_CACHE")
|
||||
|
||||
include(
|
||||
":app",
|
||||
":libs:android-job-simplified-1.4.3",
|
||||
|
||||
Reference in New Issue
Block a user