6.6.3 - Alpha5 - 新增 ui.keepScreenOn 方法及 root 属性 (getter)
This commit is contained in:
@@ -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": [
|
||||
"主页文档标签显示在线文档时部分内容被系统导航栏遮挡的问题",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"ui";
|
||||
|
||||
showLoginUI();
|
||||
ui.statusBarColor("#000000")
|
||||
// ui.statusBarColor("#000000")
|
||||
|
||||
//显示登录界面
|
||||
function showLoginUI(){
|
||||
|
||||
51
app/src/main/assets-app/sample/布局/简单 Android 布局 [v6.6.3+].js
Normal file
51
app/src/main/assets-app/sample/布局/简单 Android 布局 [v6.6.3+].js
Normal file
@@ -0,0 +1,51 @@
|
||||
'ui';
|
||||
|
||||
const themeColor = Color(autojs.themeColor);
|
||||
|
||||
ui.layout(
|
||||
<org.autojs.autojs.core.ui.widget.JsTextClock
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/text_clock"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:format24Hour="HH:mm"
|
||||
android:textSize="36sp"/>,
|
||||
);
|
||||
|
||||
/* 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);
|
||||
@@ -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<Pair<String, Supplier<Any?>>>(
|
||||
"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<out Any?>): 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)
|
||||
|
||||
Reference in New Issue
Block a user