Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

fix(android): migrate fullscreen control to native insets API

Predidit092e92912034
diff --git a/android/app/src/main/kotlin/com/example/kazumi/MainActivity.kt b/android/app/src/main/kotlin/com/example/kazumi/MainActivity.kt
index a92e189a..d572011c 100644
--- a/android/app/src/main/kotlin/com/example/kazumi/MainActivity.kt
+++ b/android/app/src/main/kotlin/com/example/kazumi/MainActivity.kt
@@ -15,6 +15,9 @@ import android.graphics.drawable.Icon
import android.util.Rational
import androidx.annotation.NonNull
import androidx.core.content.ContextCompat
+import androidx.core.view.WindowCompat
+import androidx.core.view.WindowInsetsCompat
+import androidx.core.view.WindowInsetsControllerCompat
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import com.ryanheise.audioservice.AudioServiceActivity
@@ -33,6 +36,7 @@ class MainActivity: AudioServiceActivity() {
private var pipInPlayerPage = false
private var pipAspectWidth = 16
private var pipAspectHeight = 9
+ private var androidFullscreen = false
private val actionPipPlayPause = "com.predidit.kazumi.pip.PLAY_PAUSE"
private val actionPipForward = "com.predidit.kazumi.pip.FORWARD"
@@ -59,6 +63,13 @@ class MainActivity: AudioServiceActivity() {
super.onDestroy()
}
+ override fun onWindowFocusChanged(hasFocus: Boolean) {
+ super.onWindowFocusChanged(hasFocus)
+ if (hasFocus && androidFullscreen) {
+ applyAndroidFullscreen()
+ }
+ }
+
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
intentChannel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
@@ -78,6 +89,12 @@ class MainActivity: AudioServiceActivity() {
} else if (call.method == "getAndroidSdkVersion") {
val sdkVersion = getAndroidSdkVersion()
result.success(sdkVersion)
+ } else if (call.method == "enterFullscreen") {
+ enterAndroidFullscreen()
+ result.success(null)
+ } else if (call.method == "exitFullscreen") {
+ exitAndroidFullscreen()
+ result.success(null)
} else {
result.notImplemented()
}
@@ -142,6 +159,27 @@ class MainActivity: AudioServiceActivity() {
return Build.VERSION.SDK_INT
}
+ private fun enterAndroidFullscreen() {
+ androidFullscreen = true
+ applyAndroidFullscreen()
+ }
+
+ private fun applyAndroidFullscreen() {
+ WindowCompat.setDecorFitsSystemWindows(window, false)
+ WindowCompat.getInsetsController(window, window.decorView).apply {
+ systemBarsBehavior =
+ WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
+ hide(WindowInsetsCompat.Type.systemBars())
+ }
+ }
+
+ private fun exitAndroidFullscreen() {
+ androidFullscreen = false
+ WindowCompat.setDecorFitsSystemWindows(window, false)
+ WindowCompat.getInsetsController(window, window.decorView)
+ .show(WindowInsetsCompat.Type.systemBars())
+ }
+
private fun isPictureInPictureSupported(): Boolean {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
return false
diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart
index eb678d05..857ea76d 100644
--- a/lib/utils/utils.dart
+++ b/lib/utils/utils.dart
@@ -526,9 +526,14 @@ class Utils {
await windowManager.setFullScreen(true);
return;
}
- await SystemChrome.setEnabledSystemUIMode(
- SystemUiMode.immersiveSticky,
- );
+ if (Platform.isAndroid) {
+ const platform = MethodChannel('com.predidit.kazumi/intent');
+ await platform.invokeMethod('enterFullscreen');
+ } else {
+ await SystemChrome.setEnabledSystemUIMode(
+ SystemUiMode.immersiveSticky,
+ );
+ }
if (!lockOrientation) {
return;
}
@@ -564,26 +569,14 @@ class Utils {
if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) {
await windowManager.setFullScreen(false);
}
- late SystemUiMode mode = SystemUiMode.edgeToEdge;
try {
if (Platform.isAndroid || Platform.isIOS) {
if (Platform.isAndroid) {
const platform = MethodChannel('com.predidit.kazumi/intent');
- try {
- final int sdkVersion =
- await platform.invokeMethod('getAndroidSdkVersion');
- if (sdkVersion < 29) {
- mode = SystemUiMode.manual;
- }
- } on PlatformException catch (e) {
- KazumiLogger()
- .e("Failed to get Android SDK version: '${e.message}'.");
- }
+ await platform.invokeMethod('exitFullscreen');
+ } else {
+ await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
}
- await SystemChrome.setEnabledSystemUIMode(
- mode,
- overlays: SystemUiOverlay.values,
- );
if (Utils.isCompact() && lockOrientation) {
if (Platform.isAndroid) {
bool isInMultiWindowMode = await Utils.isInMultiWindowMode();