Skip to content

Commit

Permalink
fix android multi window mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Predidit committed Sep 12, 2024
1 parent 28e005a commit aa62af0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

对于 GNU/Linux 用户,可以从 Flathub 安装:

[![Get it on Flathub](https://flathub.org/api/badge?locale=zh-Hans)](https://flathub.org/apps/io.github.Predidit.Kazumi)
[![Get it on Flathub](https://flathub.org/api/badge?locale=en)](https://flathub.org/apps/io.github.Predidit.Kazumi)

## 贡献

Expand Down
16 changes: 14 additions & 2 deletions android/app/src/main/kotlin/com/example/kazumi/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.kazumi

import android.content.Intent
import android.os.Build;
import android.net.Uri
import android.os.Bundle
import androidx.annotation.NonNull
Expand All @@ -23,9 +24,12 @@ class MainActivity: FlutterActivity() {
} else {
result.error("INVALID_ARGUMENT", "URL and MIME type required", null)
}
} else {
result.notImplemented()
}
if (call.method == "checkIfInMultiWindowMode") {
val isInMultiWindow = checkIfInMultiWindowMode()
result.success(isInMultiWindow)
}
result.notImplemented()
}
}

Expand All @@ -35,4 +39,12 @@ class MainActivity: FlutterActivity() {
intent.setDataAndType(Uri.parse(url), mimeType)
startActivity(intent)
}

private fun checkIfInMultiWindowMode(): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
this.isInMultiWindowMode
} else {
false
}
}
}
26 changes: 14 additions & 12 deletions lib/pages/video/video_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,26 @@ abstract class _VideoPageController with Store {
await windowManager.setFullScreen(true);
return;
}
await landScape();
await SystemChrome.setEnabledSystemUIMode(
SystemUiMode.immersiveSticky,
);
if (Platform.isAndroid) {
bool isInMultiWindowMode = await Utils.isInMultiWindowMode();
if (isInMultiWindowMode) {
return;
}
}
await landScape();
}

//退出全屏显示
Future<void> exitFullScreen() async {
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
await windowManager.setFullScreen(false);
}
dynamic document;
late SystemUiMode mode = SystemUiMode.edgeToEdge;
try {
if (kIsWeb) {
document.exitFullscreen();
} else if (Platform.isAndroid || Platform.isIOS) {
if (Platform.isAndroid || Platform.isIOS) {
if (Platform.isAndroid &&
(await DeviceInfoPlugin().androidInfo).version.sdkInt < 29) {
mode = SystemUiMode.manual;
Expand All @@ -102,6 +105,12 @@ abstract class _VideoPageController with Store {
overlays: SystemUiOverlay.values,
);
if (Utils.isCompact()) {
if (Platform.isAndroid) {
bool isInMultiWindowMode = await Utils.isInMultiWindowMode();
if (isInMultiWindowMode) {
return;
}
}
verticalScreen();
}
}
Expand All @@ -118,21 +127,14 @@ abstract class _VideoPageController with Store {
if (kIsWeb) {
await document.documentElement?.requestFullscreen();
} else if (Platform.isAndroid || Platform.isIOS) {
// await SystemChrome.setEnabledSystemUIMode(
// SystemUiMode.immersiveSticky,
// overlays: [],
// );
await SystemChrome.setPreferredOrientations(
[
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
],
);
// await AutoOrientation.landscapeAutoMode(forceSensor: true);
}
} catch (exception, stacktrace) {
// debugPrint(exception.toString());
// debugPrint(stacktrace.toString());
KazumiLogger()
.log(Level.error, exception.toString(), stackTrace: stacktrace);
}
Expand Down
18 changes: 17 additions & 1 deletion lib/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class Utils {

static String getRandomUA() {
final random = Random();
String randomElement = userAgentsList[random.nextInt(userAgentsList.length)];
String randomElement =
userAgentsList[random.nextInt(userAgentsList.length)];
return randomElement;
}

Expand Down Expand Up @@ -445,4 +446,19 @@ class Utils {
static bool isCompact() {
return !isDesktop() && !isWideScreen();
}

/// 判断是否分屏模式 (android only)
static Future<bool> isInMultiWindowMode() async {
if (Platform.isAndroid) {
const platform = MethodChannel('com.predidit.kazumi/intent');
try {
final bool result = await platform.invokeMethod('checkIfInMultiWindowMode');
return result;
} on PlatformException catch (e) {
print("Failed to check multi window mode: '${e.message}'.");
return false;
}
}
return false;
}
}

0 comments on commit aa62af0

Please sign in to comment.