diff --git a/.changelog/lang_zh-Hans.json b/.changelog/lang_zh-Hans.json
index c5b782ae..71519ea2 100644
--- a/.changelog/lang_zh-Hans.json
+++ b/.changelog/lang_zh-Hans.json
@@ -9,7 +9,9 @@
"images.detectMultiColors 方法, 用于多点颜色校验 _[`issue #374`](http://issues.autojs6.com/374)_",
"images.matchFeatures/detectAndComputeFeatures 方法, 支持全分辨率找图 (Ref to [Auto.js Pro](https://g.pro.autojs.org/)) _[`issue #366`](http://issues.autojs6.com/366)_",
"images.compressToBytes 方法, 用于压缩图像并生成字节数组",
- "images.downsample 方法, 用于像素降采样并生成新的 ImageWrapper"
+ "images.downsample 方法, 用于像素降采样并生成新的 ImageWrapper",
+ "ui.keepScreenOn 方法, 用于 UI 页面获取焦点时保持设备屏幕常亮",
+ "ui.root 属性 (getter), 用于获取 UI 页面布局的 \"窗口内容根容器\" 节点",
],
"fix": [
"主页文档标签显示在线文档时部分内容被系统导航栏遮挡的问题",
diff --git a/app/src/main/assets-app/sample/布局/登录界面.js b/app/src/main/assets-app/sample/布局/登录界面.js
index 62ae478d..993c5e0e 100644
--- a/app/src/main/assets-app/sample/布局/登录界面.js
+++ b/app/src/main/assets-app/sample/布局/登录界面.js
@@ -1,7 +1,7 @@
"ui";
showLoginUI();
-ui.statusBarColor("#000000")
+// ui.statusBarColor("#000000")
//显示登录界面
function showLoginUI(){
diff --git a/app/src/main/assets-app/sample/布局/简单 Android 布局 [v6.6.3+].js b/app/src/main/assets-app/sample/布局/简单 Android 布局 [v6.6.3+].js
new file mode 100644
index 00000000..4c81b701
--- /dev/null
+++ b/app/src/main/assets-app/sample/布局/简单 Android 布局 [v6.6.3+].js
@@ -0,0 +1,51 @@
+'ui';
+
+const themeColor = Color(autojs.themeColor);
+
+ui.layout(
+ ,
+);
+
+/* 1 秒钟后应用自定义样式. */
+setTimeout(() => {
+ ui.keepScreenOn();
+
+ ui.backgroundColor(themeColor);
+
+ ui.statusBarColor(themeColor);
+ ui.statusBarAppearanceLightBy(themeColor);
+
+ ui.navigationBarColor(themeColor);
+ ui.navigationBarAppearanceLightBy(themeColor);
+
+ /** @type {JsTextClock} */
+ let textClockView = ui['text_clock'];
+
+ textClockView.attr('color', ColorUtils.adjustThemeColorForContrast(themeColor.toInt()));
+ textClockView.attr('size', '64');
+ textClockView.attr('layout_gravity', 'center');
+ textClockView.attr('format24Hour', 'HH:mm:ss');
+
+ let textSizeSp = DisplayUtils.pxToSp(textClockView.getTextSize());
+ let detector = new ScaleGestureDetector(context,
+ new JavaAdapter(ScaleGestureDetector.SimpleOnScaleGestureListener, {
+ onScale(det) {
+ textSizeSp *= det.getScaleFactor();
+ textSizeSp = Math.max(8, Math.min(textSizeSp, 512));
+ textClockView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSizeSp);
+ return true;
+ },
+ }),
+ );
+ ui.root.setOnTouchListener({
+ onTouch(v, me) {
+ return detector.onTouchEvent(me);
+ },
+ });
+}, 1e3);
\ No newline at end of file
diff --git a/app/src/main/assets-app/sample/布局/简单安卓布局.js b/app/src/main/assets-app/sample/布局/简单 Android 布局.js
similarity index 100%
rename from app/src/main/assets-app/sample/布局/简单安卓布局.js
rename to app/src/main/assets-app/sample/布局/简单 Android 布局.js
diff --git a/app/src/main/java/org/autojs/autojs/runtime/api/augment/ui/UI.kt b/app/src/main/java/org/autojs/autojs/runtime/api/augment/ui/UI.kt
index 0dd60e69..56de11a4 100644
--- a/app/src/main/java/org/autojs/autojs/runtime/api/augment/ui/UI.kt
+++ b/app/src/main/java/org/autojs/autojs/runtime/api/augment/ui/UI.kt
@@ -4,6 +4,7 @@ import android.os.Build
import android.view.ContextThemeWrapper
import android.view.View
import android.view.ViewGroup
+import android.view.WindowManager
import androidx.core.graphics.drawable.toDrawable
import org.autojs.autojs.annotation.RhinoFunctionBody
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
@@ -122,18 +123,23 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
::findByStringId.name,
::findView.name,
::finish.name,
+ ::keepScreenOn.name,
)
override val selfAssignmentGetters = listOf>>(
"R" to Supplier { scriptRuntime.topLevelScope.prop("R").jsUnwrapped() },
"__widgets__" to Supplier { scriptRuntime.ui.widgets },
+ "root" to Supplier {
+ val activity = getActivity(scriptRuntime)
+ (activity as? ScriptExecuteActivity)?.findViewById(android.R.id.content)
+ },
"emitter" to Supplier {
val activity = getActivity(scriptRuntime)
(activity as? ScriptExecuteActivity)?.eventEmitter
},
"statusBarHeight" to Supplier {
ViewUtils.getStatusBarHeightByDimen(globalContext)
- }
+ },
)
init {
@@ -678,6 +684,15 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
UNDEFINED
}
+ @JvmStatic
+ @RhinoRuntimeFunctionInterface
+ fun keepScreenOn(scriptRuntime: ScriptRuntime, args: Array): Undefined = ensureArgumentsIsEmpty(args) {
+ ensureActivity(scriptRuntime) { activity ->
+ activity.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
+ }
+ UNDEFINED
+ }
+
private fun initWidgetConstructor(ctor: BaseFunction) {
val prototype = ctor.prop("prototype") as? ScriptableObject ?: newNativeObject()
assignWidgetProperties(prototype)