mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 07:55:11 +08:00
优化移动端开屏
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:usesCleartextTraffic="true"
|
android:usesCleartextTraffic="true"
|
||||||
|
android:hardwareAccelerated="true"
|
||||||
android:networkSecurityConfig="@xml/network_security_config"
|
android:networkSecurityConfig="@xml/network_security_config"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
|
|
||||||
|
|||||||
@@ -3,15 +3,25 @@ package games.wenzi.ogame;
|
|||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
|
import android.webkit.WebChromeClient;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
import androidx.core.splashscreen.SplashScreen;
|
||||||
import androidx.core.view.WindowCompat;
|
import androidx.core.view.WindowCompat;
|
||||||
import androidx.core.view.WindowInsetsControllerCompat;
|
import androidx.core.view.WindowInsetsControllerCompat;
|
||||||
import com.getcapacitor.BridgeActivity;
|
import com.getcapacitor.BridgeActivity;
|
||||||
|
|
||||||
public class MainActivity extends BridgeActivity {
|
public class MainActivity extends BridgeActivity {
|
||||||
|
private boolean isWebViewReady = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
// 安装 SplashScreen,必须在 super.onCreate 之前调用
|
||||||
|
SplashScreen splashScreen = SplashScreen.installSplashScreen(this);
|
||||||
|
|
||||||
|
// 保持 SplashScreen 直到 WebView 加载完成
|
||||||
|
splashScreen.setKeepOnScreenCondition(() -> !isWebViewReady);
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
Window window = getWindow();
|
Window window = getWindow();
|
||||||
@@ -45,6 +55,18 @@ public class MainActivity extends BridgeActivity {
|
|||||||
settings.setDatabaseEnabled(true);
|
settings.setDatabaseEnabled(true);
|
||||||
// 启用硬件加速渲染
|
// 启用硬件加速渲染
|
||||||
webView.setLayerType(android.view.View.LAYER_TYPE_HARDWARE, null);
|
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"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<color name="status_bar_color">#1a1a2e</color>
|
<color name="status_bar_color">#1a1a2e</color>
|
||||||
|
<color name="splash_background">#0f0f1a</color>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -19,8 +19,10 @@
|
|||||||
<item name="android:windowTranslucentNavigation">false</item>
|
<item name="android:windowTranslucentNavigation">false</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<!-- 启动画面主题 - 延长显示直到 WebView 加载完成 -->
|
||||||
<style name="AppTheme.NoActionBarLaunch" parent="Theme.SplashScreen">
|
<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>
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -5,16 +5,17 @@ const config: CapacitorConfig = {
|
|||||||
appName: 'OGame Vue Ts',
|
appName: 'OGame Vue Ts',
|
||||||
webDir: 'docs',
|
webDir: 'docs',
|
||||||
server: {
|
server: {
|
||||||
androidScheme: 'https'
|
androidScheme: 'https',
|
||||||
|
cacheControl: 'max-age=31536000'
|
||||||
},
|
},
|
||||||
android: {
|
android: {
|
||||||
buildOptions: {
|
buildOptions: {
|
||||||
keystorePath: undefined,
|
keystorePath: undefined,
|
||||||
keystoreAlias: undefined
|
keystoreAlias: undefined
|
||||||
},
|
},
|
||||||
// 启用 WebView 调试,方便排查问题
|
webContentsDebuggingEnabled: false,
|
||||||
webContentsDebuggingEnabled: true,
|
allowMixedContent: false,
|
||||||
allowMixedContent: false
|
hardwareAcceleration: true
|
||||||
},
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
// 禁用键盘自动调整视口
|
// 禁用键盘自动调整视口
|
||||||
|
|||||||
33
index.html
33
index.html
@@ -13,38 +13,9 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script type="module" src="/src/main.ts"></script>
|
<script type="module" src="/src/main.ts"></script>
|
||||||
<!-- 统计勿删 - 异步加载避免阻塞页面 -->
|
<!-- 统计勿删 -->
|
||||||
<script>
|
<script>
|
||||||
// 异步加载外部脚本,不阻塞页面渲染
|
!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 });
|
||||||
(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);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user