2.11 优化了保存配置的时候,重新加载页面方法,去设置初始化屏幕方向,已经init.json中添加了字段备注信息

This commit is contained in:
2025-10-09 11:11:05 +08:00
parent c3e3d6de61
commit 55cd99687b
3 changed files with 24 additions and 1 deletions

View File

@ -0,0 +1,9 @@
{
"备注": "下面所有的字段删除前面的_就是配置的字段在没有手动配置的情况下会读取字段中的信息从而实现默认配置",
"_ip":"ip地址",
"_port":"端口号",
"_path":"访问路径",
"_screen_rotation":"屏幕旋转1竖、2横、3横竖、4禁止",
"_hide_bar":"状态拦1隐藏、2显示",
"_start_direction":"默认屏幕方向1正竖、2倒竖、3正横、4倒横"
}

View File

@ -407,6 +407,7 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
}
}catch (Exception e) {
Log.e("MainActivity", "get init file error");
return "file:///android_asset/demo/index.html";
}
if (map == null) {
return "file:///android_asset/demo/index.html";
@ -423,6 +424,18 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
@JavascriptInterface
public void reload() {
// 第一次设置,点击保存,初始化屏幕方向问题
int rotate = 1;
if (startDirection == 1) {
rotate = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; // 正竖屏
}else if (startDirection == 2) {
rotate = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; // 倒竖屏
}else if (startDirection == 3) {
rotate = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; // 正横屏
}else if (startDirection == 4) {
rotate = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; // 倒横屏
}
this.setRequestedOrientation(rotate);
runOnUiThread(() -> {
webView.loadUrl(url());
});