6.6.3 - Alpha5 - 新增 ui.keepScreenOn 方法及 root 属性 (getter)
This commit is contained in:
@@ -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