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