mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-11 23:45:11 +08:00
优化移动端开屏
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:hardwareAccelerated="true"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
|
||||
@@ -3,15 +3,25 @@ package games.wenzi.ogame;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.Window;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import androidx.core.splashscreen.SplashScreen;
|
||||
import androidx.core.view.WindowCompat;
|
||||
import androidx.core.view.WindowInsetsControllerCompat;
|
||||
import com.getcapacitor.BridgeActivity;
|
||||
|
||||
public class MainActivity extends BridgeActivity {
|
||||
private boolean isWebViewReady = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
// 安装 SplashScreen,必须在 super.onCreate 之前调用
|
||||
SplashScreen splashScreen = SplashScreen.installSplashScreen(this);
|
||||
|
||||
// 保持 SplashScreen 直到 WebView 加载完成
|
||||
splashScreen.setKeepOnScreenCondition(() -> !isWebViewReady);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Window window = getWindow();
|
||||
@@ -45,6 +55,18 @@ public class MainActivity extends BridgeActivity {
|
||||
settings.setDatabaseEnabled(true);
|
||||
// 启用硬件加速渲染
|
||||
webView.setLayerType(android.view.View.LAYER_TYPE_HARDWARE, null);
|
||||
|
||||
// 监听页面加载进度,加载完成后隐藏 SplashScreen
|
||||
webView.setWebChromeClient(new WebChromeClient() {
|
||||
@Override
|
||||
public void onProgressChanged(WebView view, int newProgress) {
|
||||
super.onProgressChanged(view, newProgress);
|
||||
// 当页面加载达到 80% 时认为可以显示
|
||||
if (newProgress >= 80) {
|
||||
isWebViewReady = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
android/app/src/main/res/drawable/splash.xml
Normal file
11
android/app/src/main/res/drawable/splash.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- 深色背景 -->
|
||||
<item android:drawable="@color/splash_background" />
|
||||
<!-- 居中的 logo -->
|
||||
<item>
|
||||
<bitmap
|
||||
android:gravity="center"
|
||||
android:src="@drawable/splash" />
|
||||
</item>
|
||||
</layer-list>
|
||||
@@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="status_bar_color">#1a1a2e</color>
|
||||
<color name="splash_background">#0f0f1a</color>
|
||||
</resources>
|
||||
@@ -19,8 +19,10 @@
|
||||
<item name="android:windowTranslucentNavigation">false</item>
|
||||
</style>
|
||||
|
||||
|
||||
<!-- 启动画面主题 - 延长显示直到 WebView 加载完成 -->
|
||||
<style name="AppTheme.NoActionBarLaunch" parent="Theme.SplashScreen">
|
||||
<item name="android:background">@drawable/splash</item>
|
||||
<item name="windowSplashScreenBackground">@color/splash_background</item>
|
||||
<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher</item>
|
||||
<item name="postSplashScreenTheme">@style/AppTheme.NoActionBar</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -5,16 +5,17 @@ const config: CapacitorConfig = {
|
||||
appName: 'OGame Vue Ts',
|
||||
webDir: 'docs',
|
||||
server: {
|
||||
androidScheme: 'https'
|
||||
androidScheme: 'https',
|
||||
cacheControl: 'max-age=31536000'
|
||||
},
|
||||
android: {
|
||||
buildOptions: {
|
||||
keystorePath: undefined,
|
||||
keystoreAlias: undefined
|
||||
},
|
||||
// 启用 WebView 调试,方便排查问题
|
||||
webContentsDebuggingEnabled: true,
|
||||
allowMixedContent: false
|
||||
webContentsDebuggingEnabled: false,
|
||||
allowMixedContent: false,
|
||||
hardwareAcceleration: true
|
||||
},
|
||||
plugins: {
|
||||
// 禁用键盘自动调整视口
|
||||
|
||||
33
index.html
33
index.html
@@ -13,38 +13,9 @@
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
<!-- 统计勿删 - 异步加载避免阻塞页面 -->
|
||||
<!-- 统计勿删 -->
|
||||
<script>
|
||||
// 异步加载外部脚本,不阻塞页面渲染
|
||||
(function() {
|
||||
// 51.la 统计
|
||||
var la = document.createElement('script');
|
||||
la.charset = 'UTF-8';
|
||||
la.id = 'LA_COLLECT';
|
||||
la.src = 'https://sdk.51.la/js-sdk-pro.min.js';
|
||||
la.async = true;
|
||||
la.onload = function() {
|
||||
if (typeof LA !== 'undefined') {
|
||||
LA.init({ id: "L298GYqn6JhAO0VU", ck: "L298GYqn6JhAO0VU", autoTrack: true, hashMode: true });
|
||||
}
|
||||
};
|
||||
la.onerror = function() { console.warn('51.la analytics failed to load'); };
|
||||
document.body.appendChild(la);
|
||||
|
||||
// vConsole - 仅在开发环境或调试时加载
|
||||
if (location.hostname === 'localhost' || location.search.includes('debug=1')) {
|
||||
var vc = document.createElement('script');
|
||||
vc.src = 'https://cdn.bootcdn.net/ajax/libs/vConsole/3.15.1/vconsole.min.js';
|
||||
vc.async = true;
|
||||
vc.onload = function() {
|
||||
if (typeof VConsole !== 'undefined') {
|
||||
window.vConsole = new VConsole();
|
||||
}
|
||||
};
|
||||
vc.onerror = function() { console.warn('vConsole failed to load'); };
|
||||
document.body.appendChild(vc);
|
||||
}
|
||||
})();
|
||||
!function (p) { "use strict"; !function (t) { var s = window, e = document, i = p, c = "".concat("https:" === e.location.protocol ? "https://" : "http://", "sdk.51.la/js-sdk-pro.min.js"), n = e.createElement("script"), r = e.getElementsByTagName("script")[0]; n.type = "text/javascript", n.setAttribute("charset", "UTF-8"), n.async = !0, n.src = c, n.id = "LA_COLLECT", i.d = n; var o = function () { s.LA.ids.push(i) }; s.LA ? s.LA.ids && o() : (s.LA = p, s.LA.ids = [], o()), r.parentNode.insertBefore(n, r) }() }({ id: "L298GYqn6JhAO0VU", ck: "L298GYqn6JhAO0VU", autoTrack: true, hashMode: true });
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user