From bee04fb2b0ba99a7f5d14415c42ea80da31b5623 Mon Sep 17 00:00:00 2001 From: dom Date: Sun, 31 May 2026 11:05:30 +0800 Subject: [PATCH] refa jni Signed-off-by: dom --- .../com/example/piliplus/AndroidHelper.java | 11 + .../com/example/piliplus/MainActivity.kt | 13 +- jnigen.yaml | 11 - lib/main.dart | 7 - lib/pages/live_room/view.dart | 6 +- .../live_room/widgets/header_control.dart | 5 +- lib/pages/video/view.dart | 10 +- lib/pages/video/widgets/header_control.dart | 82 +- lib/plugin/pl_player/controller.dart | 3 +- lib/utils/android/bindings.g.dart | 856 ++++++++++-------- lib/utils/device_utils.dart | 3 +- lib/utils/max_screen_size.dart | 2 +- lib/utils/page_utils.dart | 4 +- pubspec.lock | 4 +- pubspec.yaml | 2 +- tool/README.md | 1 + tool/jnigen.dart | 23 + 17 files changed, 520 insertions(+), 523 deletions(-) delete mode 100644 jnigen.yaml create mode 100644 tool/README.md create mode 100644 tool/jnigen.dart diff --git a/android/app/src/main/java/com/example/piliplus/AndroidHelper.java b/android/app/src/main/java/com/example/piliplus/AndroidHelper.java index 73c2948ba..fbd0f568e 100644 --- a/android/app/src/main/java/com/example/piliplus/AndroidHelper.java +++ b/android/app/src/main/java/com/example/piliplus/AndroidHelper.java @@ -19,8 +19,11 @@ import android.os.Build; import android.provider.MediaStore; import android.provider.Settings; import android.view.WindowManager; + import androidx.annotation.Keep; + import com.github.dart_lang.jni_flutter.JniFlutterPlugin; + import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -29,6 +32,10 @@ import java.util.ArrayList; public final class AndroidHelper { public static volatile boolean isFoldable = false; + public static volatile boolean isPipMode = false; + + public static volatile boolean isPipAvailable = false; + private AndroidHelper() { } @@ -36,6 +43,10 @@ public final class AndroidHelper { return JniFlutterPlugin.getApplicationContext(); } + public static int sdkInt() { + return Build.VERSION.SDK_INT; + } + public static void back() { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); diff --git a/android/app/src/main/kotlin/com/example/piliplus/MainActivity.kt b/android/app/src/main/kotlin/com/example/piliplus/MainActivity.kt index 3f03a3044..28b8e7a99 100644 --- a/android/app/src/main/kotlin/com/example/piliplus/MainActivity.kt +++ b/android/app/src/main/kotlin/com/example/piliplus/MainActivity.kt @@ -48,12 +48,17 @@ class MainActivity : AudioServiceActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - window.attributes.layoutInDisplayCutoutMode = LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES + window.attributes.layoutInDisplayCutoutMode = + LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES } + AndroidHelper.isPipAvailable = + packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { try { - AndroidHelper.isFoldable = packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_HINGE_ANGLE) + AndroidHelper.isFoldable = + packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_HINGE_ANGLE) } catch (_: Exception) { } } @@ -73,8 +78,6 @@ class MainActivity : AudioServiceActivity() { isInPictureInPictureMode: Boolean, newConfig: Configuration? ) { super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig) - MethodChannel(flutterEngine!!.dartExecutor.binaryMessenger, "floating").invokeMethod( - "onPipChanged", isInPictureInPictureMode - ) + AndroidHelper.isPipMode = isInPictureInPictureMode } } diff --git a/jnigen.yaml b/jnigen.yaml deleted file mode 100644 index 73090ab1c..000000000 --- a/jnigen.yaml +++ /dev/null @@ -1,11 +0,0 @@ -output: - dart: - path: lib/utils/android/bindings.g.dart - structure: single_file - -class_path: - - android/app/src/main/java - -classes: - - 'com.example.piliplus.AndroidHelper' - - 'java.lang.Runnable' diff --git a/lib/main.dart b/lib/main.dart index db9d381fe..c686975d7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -18,7 +18,6 @@ import 'package:PiliPlus/services/service_locator.dart'; import 'package:PiliPlus/utils/cache_manager.dart'; import 'package:PiliPlus/utils/calc_window_position.dart'; import 'package:PiliPlus/utils/date_utils.dart'; -import 'package:PiliPlus/utils/device_utils.dart'; import 'package:PiliPlus/utils/extension/theme_ext.dart'; import 'package:PiliPlus/utils/json_file_handler.dart'; import 'package:PiliPlus/utils/max_screen_size.dart'; @@ -32,7 +31,6 @@ import 'package:PiliPlus/utils/theme_utils.dart'; import 'package:PiliPlus/utils/utils.dart'; import 'package:catcher_2/catcher_2.dart'; import 'package:collection/collection.dart'; -import 'package:device_info_plus/device_info_plus.dart'; import 'package:dynamic_color/dynamic_color.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -90,10 +88,6 @@ Future _initAppPath() async { appSupportDirPath = (await getApplicationSupportDirectory()).path; } -Future _initSdkInt() async { - DeviceUtils.sdkInt = (await DeviceInfoPlugin().androidInfo).version.sdkInt; -} - void main() async { ScaledWidgetsFlutterBinding.ensureInitialized(); MediaKit.ensureInitialized(); @@ -117,7 +111,6 @@ void main() async { if (PlatformUtils.isMobile) { if (Platform.isAndroid) MaxScreenSize.init(); await Future.wait([ - if (Platform.isAndroid) _initSdkInt(), if (Pref.horizontalScreen) ?fullMode() else ?portraitUpMode(), setupServiceLocator(), ]); diff --git a/lib/pages/live_room/view.dart b/lib/pages/live_room/view.dart index d27437784..f873a25c8 100644 --- a/lib/pages/live_room/view.dart +++ b/lib/pages/live_room/view.dart @@ -35,6 +35,7 @@ import 'package:PiliPlus/plugin/pl_player/utils/danmaku_options.dart'; import 'package:PiliPlus/plugin/pl_player/utils/fullscreen.dart'; import 'package:PiliPlus/plugin/pl_player/view/view.dart'; import 'package:PiliPlus/services/service_locator.dart'; +import 'package:PiliPlus/utils/android/bindings.g.dart'; import 'package:PiliPlus/utils/extension/num_ext.dart'; import 'package:PiliPlus/utils/extension/size_ext.dart'; import 'package:PiliPlus/utils/extension/theme_ext.dart'; @@ -49,8 +50,7 @@ import 'package:PiliPlus/utils/storage_key.dart'; import 'package:PiliPlus/utils/storage_pref.dart'; import 'package:PiliPlus/utils/utils.dart'; import 'package:cached_network_image/cached_network_image.dart'; -import 'package:canvas_danmaku/canvas_danmaku.dart'; -import 'package:floating/floating.dart'; +import 'package:canvas_danmaku/danmaku_screen.dart'; import 'package:flutter/foundation.dart' show kDebugMode; import 'package:flutter/material.dart' hide PageView; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; @@ -214,7 +214,7 @@ class _LiveRoomPageState extends State @override Widget build(BuildContext context) { Widget child; - if (Platform.isAndroid && Floating().isPipMode) { + if (Platform.isAndroid && AndroidHelper.isPipMode) { child = videoPlayerPanel( isFullScreen, width: maxWidth, diff --git a/lib/pages/live_room/widgets/header_control.dart b/lib/pages/live_room/widgets/header_control.dart index 16b8d27fc..61175e83c 100644 --- a/lib/pages/live_room/widgets/header_control.dart +++ b/lib/pages/live_room/widgets/header_control.dart @@ -7,6 +7,7 @@ import 'package:PiliPlus/plugin/pl_player/controller.dart'; import 'package:PiliPlus/plugin/pl_player/widgets/common_btn.dart'; import 'package:PiliPlus/services/shutdown_timer_service.dart' show shutdownTimerService; +import 'package:PiliPlus/utils/android/bindings.g.dart'; import 'package:PiliPlus/utils/platform_utils.dart'; import 'package:floating/floating.dart'; import 'package:flutter/material.dart'; @@ -159,12 +160,12 @@ class _LiveHeaderControlState extends State ComBtn( height: 30, tooltip: '画中画', - onTap: () async { + onTap: () { if (PlatformUtils.isDesktop) { plPlayerController.toggleDesktopPip(); return; } - if (await Floating().isPipAvailable) { + if (AndroidHelper.isPipAvailable) { plPlayerController.enterPip(); } }, diff --git a/lib/pages/video/view.dart b/lib/pages/video/view.dart index f3fa1d220..19614e10f 100644 --- a/lib/pages/video/view.dart +++ b/lib/pages/video/view.dart @@ -50,6 +50,7 @@ import 'package:PiliPlus/services/service_locator.dart'; import 'package:PiliPlus/services/shutdown_timer_service.dart' show shutdownTimerService; import 'package:PiliPlus/utils/accounts.dart'; +import 'package:PiliPlus/utils/android/bindings.g.dart'; import 'package:PiliPlus/utils/extension/num_ext.dart'; import 'package:PiliPlus/utils/extension/scroll_controller_ext.dart'; import 'package:PiliPlus/utils/extension/theme_ext.dart'; @@ -62,7 +63,6 @@ import 'package:PiliPlus/utils/storage.dart'; import 'package:PiliPlus/utils/storage_key.dart'; import 'package:PiliPlus/utils/theme_utils.dart'; import 'package:extended_nested_scroll_view/extended_nested_scroll_view.dart'; -import 'package:floating/floating.dart'; import 'package:flutter/foundation.dart' show kDebugMode; import 'package:flutter/material.dart'; import 'package:flutter/services.dart' show SystemUiOverlayStyle; @@ -274,16 +274,14 @@ class _VideoDetailPageVState extends State } if (exitFlag) { - // 结束播放退出全屏 if (autoExitFullscreen) { plPlayerController!.triggerFullScreen(status: false); if (plPlayerController!.controlsLock.value) { plPlayerController!.onLockControl(false); } - } - // 播放完展示控制栏 - if (Platform.isAndroid) { - if (await Floating().pipStatus == PiPStatus.disabled) { + } else { + if (plPlayerController!.controlsLock.value && + (!Platform.isAndroid || !AndroidHelper.isPipMode)) { plPlayerController!.onLockControl(false); } } diff --git a/lib/pages/video/widgets/header_control.dart b/lib/pages/video/widgets/header_control.dart index 52a71c50b..eed3f7b46 100644 --- a/lib/pages/video/widgets/header_control.dart +++ b/lib/pages/video/widgets/header_control.dart @@ -35,11 +35,11 @@ import 'package:PiliPlus/pages/video/widgets/header_mixin.dart'; import 'package:PiliPlus/plugin/pl_player/controller.dart'; import 'package:PiliPlus/plugin/pl_player/models/data_source.dart'; import 'package:PiliPlus/plugin/pl_player/models/play_repeat.dart'; -import 'package:PiliPlus/services/service_locator.dart'; import 'package:PiliPlus/services/shutdown_timer_service.dart' show shutdownTimerService; import 'package:PiliPlus/utils/accounts.dart'; import 'package:PiliPlus/utils/accounts/account.dart'; +import 'package:PiliPlus/utils/android/bindings.g.dart'; import 'package:PiliPlus/utils/connectivity_utils.dart'; import 'package:PiliPlus/utils/extension/num_ext.dart'; import 'package:PiliPlus/utils/extension/string_ext.dart'; @@ -58,7 +58,6 @@ import 'package:collection/collection.dart'; import 'package:dio/dio.dart'; import 'package:easy_debounce/easy_throttle.dart'; import 'package:file_picker/file_picker.dart'; -import 'package:floating/floating.dart'; import 'package:flutter/foundation.dart' show compute; import 'package:flutter/material.dart' hide showBottomSheet; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; @@ -1943,87 +1942,12 @@ class HeaderControlState extends State child: IconButton( tooltip: '画中画', style: btnStyle, - onPressed: () async { + onPressed: () { if (PlatformUtils.isDesktop) { plPlayerController.toggleDesktopPip(); return; } - if (await Floating().isPipAvailable) { - if (context.mounted && - !videoPlayerServiceHandler!.enableBackgroundPlay) { - final theme = Theme.of(context); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Column( - children: [ - const Row( - children: [ - Icon( - Icons.check, - color: Colors.green, - ), - SizedBox(width: 10), - Text( - '画中画', - style: TextStyle( - fontSize: 15, - height: 1.5, - ), - ), - ], - ), - const SizedBox(height: 10), - const Text( - '建议开启【后台音频服务】\n' - '避免画中画没有暂停按钮', - style: TextStyle( - fontSize: 12.5, - height: 1.5, - ), - ), - Row( - children: [ - TextButton( - style: ButtonStyle( - foregroundColor: - WidgetStatePropertyAll( - theme - .snackBarTheme - .actionTextColor, - ), - ), - onPressed: () { - plPlayerController.setBackgroundPlay( - true, - ); - SmartDialog.showToast("请重新载入本页面刷新"); - }, - child: const Text('启用后台音频服务'), - ), - const SizedBox(width: 10), - TextButton( - style: ButtonStyle( - foregroundColor: - WidgetStatePropertyAll( - theme - .snackBarTheme - .actionTextColor, - ), - ), - onPressed: () {}, - child: const Text('不启用'), - ), - ], - ), - ], - ), - duration: const Duration(seconds: 2), - showCloseIcon: true, - ), - ); - await Future.delayed(const Duration(seconds: 3)); - } - if (!context.mounted) return; + if (AndroidHelper.isPipAvailable) { plPlayerController.enterPip(); } }, diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index da40d5563..047266477 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -49,7 +49,6 @@ import 'package:PiliPlus/utils/utils.dart'; import 'package:archive/archive.dart' show getCrc32; import 'package:canvas_danmaku/canvas_danmaku.dart'; import 'package:easy_debounce/easy_throttle.dart'; -import 'package:floating/floating.dart'; import 'package:flutter/foundation.dart' show kDebugMode; import 'package:flutter/material.dart'; import 'package:flutter/services.dart' show HapticFeedback, DeviceOrientation; @@ -210,7 +209,7 @@ class PlPlayerController with BlockConfigMixin { late final bool autoPiP = Pref.autoPiP; bool get isPipMode => - (Platform.isAndroid && Floating().isPipMode) || + (Platform.isAndroid && AndroidHelper.isPipMode) || (PlatformUtils.isDesktop && isDesktopPip); late bool isDesktopPip = false; late Rect _lastWindowBounds; diff --git a/lib/utils/android/bindings.g.dart b/lib/utils/android/bindings.g.dart index 5e0a77592..e8965ddc1 100644 --- a/lib/utils/android/bindings.g.dart +++ b/lib/utils/android/bindings.g.dart @@ -38,407 +38,6 @@ import 'package:jni/jni.dart' as jni$_; const _$jniVersionCheck = jni$_.JniVersionCheck(1, 0); -/// from: `com.example.piliplus.AndroidHelper$ToDart` -extension type AndroidHelper$ToDart._(jni$_.JObject _$this) - implements jni$_.JObject { - static final _class = jni$_.JClass.forName( - r'com/example/piliplus/AndroidHelper$ToDart', - ); - - /// The type which includes information such as the signature of this class. - static const jni$_.JType type = - $AndroidHelper$ToDart$Type$(); - static final _id_onUserLeaveHint = _class.staticFieldId( - r'onUserLeaveHint', - r'Ljava/lang/Runnable;', - ); - - /// from: `static public bridge java.lang.Runnable onUserLeaveHint` - /// The returned object must be released after use, by calling the [release] method. - static Runnable? get onUserLeaveHint => - _id_onUserLeaveHint.getNullable(_class, Runnable.type) as Runnable?; - - /// from: `static public bridge java.lang.Runnable onUserLeaveHint` - /// The returned object must be released after use, by calling the [release] method. - static set onUserLeaveHint(Runnable? value) => - _id_onUserLeaveHint.set(_class, Runnable.type, value); - - static final _id_onConfigurationChanged = _class.staticFieldId( - r'onConfigurationChanged', - r'Ljava/lang/Runnable;', - ); - - /// from: `static public bridge java.lang.Runnable onConfigurationChanged` - /// The returned object must be released after use, by calling the [release] method. - static Runnable? get onConfigurationChanged => - _id_onConfigurationChanged.getNullable(_class, Runnable.type) - as Runnable?; - - /// from: `static public bridge java.lang.Runnable onConfigurationChanged` - /// The returned object must be released after use, by calling the [release] method. - static set onConfigurationChanged(Runnable? value) => - _id_onConfigurationChanged.set(_class, Runnable.type, value); -} - -final class $AndroidHelper$ToDart$Type$ - extends jni$_.JType { - @jni$_.internal - const $AndroidHelper$ToDart$Type$(); - - @jni$_.internal - @core$_.override - String get signature => r'Lcom/example/piliplus/AndroidHelper$ToDart;'; -} - -/// from: `com.example.piliplus.AndroidHelper` -extension type AndroidHelper._(jni$_.JObject _$this) implements jni$_.JObject { - static final _class = jni$_.JClass.forName( - r'com/example/piliplus/AndroidHelper', - ); - - /// The type which includes information such as the signature of this class. - static const jni$_.JType type = $AndroidHelper$Type$(); - static final _id_isFoldable = _class.staticFieldId( - r'isFoldable', - r'Z', - ); - - /// from: `static public bridge boolean isFoldable` - static core$_.bool get isFoldable => - _id_isFoldable.getNullable(_class, jni$_.jboolean.type) as core$_.bool; - - /// from: `static public bridge boolean isFoldable` - static set isFoldable(core$_.bool value) => - _id_isFoldable.set(_class, jni$_.jboolean.type, value); - - static final _id_back = _class.staticMethodId( - r'back', - r'()V', - ); - - static final _back = - jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JThrowablePtr Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - ) - > - >('globalEnv_CallStaticVoidMethod') - .asFunction< - jni$_.JThrowablePtr Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - ) - >(); - - /// from: `static public void back()` - static void back() { - final _$$classRef = _class.reference; - _back(_$$classRef.pointer, _id_back.pointer).check(); - } - - static final _id_biliSendCommAntifraud = _class.staticMethodId( - r'biliSendCommAntifraud', - r'(IJIJJJJLjava/lang/String;Ljava/lang/String;Ljava/lang/String;JLjava/lang/String;)V', - ); - - static final _biliSendCommAntifraud = - jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JThrowablePtr Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - jni$_.VarArgs< - ( - jni$_.Int32, - jni$_.Int64, - jni$_.Int32, - jni$_.Int64, - jni$_.Int64, - jni$_.Int64, - jni$_.Int64, - jni$_.Pointer, - jni$_.Pointer, - jni$_.Pointer, - jni$_.Int64, - jni$_.Pointer, - ) - >, - ) - > - >('globalEnv_CallStaticVoidMethod') - .asFunction< - jni$_.JThrowablePtr Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - core$_.int, - core$_.int, - core$_.int, - core$_.int, - core$_.int, - core$_.int, - core$_.int, - jni$_.Pointer, - jni$_.Pointer, - jni$_.Pointer, - core$_.int, - jni$_.Pointer, - ) - >(); - - /// from: `static public void biliSendCommAntifraud(int i, long j, int i1, long j1, long j2, long j3, long j4, java.lang.String string, java.lang.String string1, java.lang.String string2, long j5, java.lang.String string3)` - static void biliSendCommAntifraud( - core$_.int i, - core$_.int j, - core$_.int i1, - core$_.int j1, - core$_.int j2, - core$_.int j3, - core$_.int j4, - jni$_.JString string, - jni$_.JString? string1, - jni$_.JString string2, - core$_.int j5, - jni$_.JString string3, - ) { - final _$$classRef = _class.reference; - final _$string = string.reference; - final _$string1 = string1?.reference ?? jni$_.jNullReference; - final _$string2 = string2.reference; - final _$string3 = string3.reference; - _biliSendCommAntifraud( - _$$classRef.pointer, - _id_biliSendCommAntifraud.pointer, - i, - j, - i1, - j1, - j2, - j3, - j4, - _$string.pointer, - _$string1.pointer, - _$string2.pointer, - j5, - _$string3.pointer, - ).check(); - } - - static final _id_openLinkVerifySettings = _class.staticMethodId( - r'openLinkVerifySettings', - r'()V', - ); - - static final _openLinkVerifySettings = - jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JThrowablePtr Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - ) - > - >('globalEnv_CallStaticVoidMethod') - .asFunction< - jni$_.JThrowablePtr Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - ) - >(); - - /// from: `static public void openLinkVerifySettings()` - static void openLinkVerifySettings() { - final _$$classRef = _class.reference; - _openLinkVerifySettings( - _$$classRef.pointer, - _id_openLinkVerifySettings.pointer, - ).check(); - } - - static final _id_openMusic = _class.staticMethodId( - r'openMusic', - r'(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z', - ); - - static final _openMusic = - jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - jni$_.VarArgs< - ( - jni$_.Pointer, - jni$_.Pointer, - jni$_.Pointer, - ) - >, - ) - > - >('globalEnv_CallStaticBooleanMethod') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - jni$_.Pointer, - jni$_.Pointer, - jni$_.Pointer, - ) - >(); - - /// from: `static public boolean openMusic(java.lang.String string, java.lang.String string1, java.lang.String string2)` - static core$_.bool openMusic( - jni$_.JString string, - jni$_.JString? string1, - jni$_.JString? string2, - ) { - final _$$classRef = _class.reference; - final _$string = string.reference; - final _$string1 = string1?.reference ?? jni$_.jNullReference; - final _$string2 = string2?.reference ?? jni$_.jNullReference; - return _openMusic( - _$$classRef.pointer, - _id_openMusic.pointer, - _$string.pointer, - _$string1.pointer, - _$string2.pointer, - ).boolean; - } - - static final _id_setPipAutoEnterEnabled = _class.staticMethodId( - r'setPipAutoEnterEnabled', - r'(ZJ)V', - ); - - static final _setPipAutoEnterEnabled = - jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JThrowablePtr Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - jni$_.VarArgs<(jni$_.Int32, jni$_.Int64)>, - ) - > - >('globalEnv_CallStaticVoidMethod') - .asFunction< - jni$_.JThrowablePtr Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - core$_.int, - core$_.int, - ) - >(); - - /// from: `static public void setPipAutoEnterEnabled(boolean z, long j)` - static void setPipAutoEnterEnabled( - core$_.bool z, - core$_.int j, - ) { - final _$$classRef = _class.reference; - _setPipAutoEnterEnabled( - _$$classRef.pointer, - _id_setPipAutoEnterEnabled.pointer, - z ? 1 : 0, - j, - ).check(); - } - - static final _id_maxScreenSize = _class.staticMethodId( - r'maxScreenSize', - r'()[I', - ); - - static final _maxScreenSize = - jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - ) - > - >('globalEnv_CallStaticObjectMethod') - .asFunction< - jni$_.JniResult Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - ) - >(); - - /// from: `static public int[] maxScreenSize()` - /// The returned object must be released after use, by calling the [release] method. - static jni$_.JIntArray? maxScreenSize() { - final _$$classRef = _class.reference; - return _maxScreenSize( - _$$classRef.pointer, - _id_maxScreenSize.pointer, - ).object(); - } - - static final _id_createShortcut = _class.staticMethodId( - r'createShortcut', - r'(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V', - ); - - static final _createShortcut = - jni$_.ProtectedJniExtensions.lookup< - jni$_.NativeFunction< - jni$_.JThrowablePtr Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - jni$_.VarArgs< - ( - jni$_.Pointer, - jni$_.Pointer, - jni$_.Pointer, - jni$_.Pointer, - ) - >, - ) - > - >('globalEnv_CallStaticVoidMethod') - .asFunction< - jni$_.JThrowablePtr Function( - jni$_.Pointer, - jni$_.JMethodIDPtr, - jni$_.Pointer, - jni$_.Pointer, - jni$_.Pointer, - jni$_.Pointer, - ) - >(); - - /// from: `static public void createShortcut(java.lang.String string, java.lang.String string1, java.lang.String string2, java.lang.String string3)` - static void createShortcut( - jni$_.JString string, - jni$_.JString string1, - jni$_.JString string2, - jni$_.JString string3, - ) { - final _$$classRef = _class.reference; - final _$string = string.reference; - final _$string1 = string1.reference; - final _$string2 = string2.reference; - final _$string3 = string3.reference; - _createShortcut( - _$$classRef.pointer, - _id_createShortcut.pointer, - _$string.pointer, - _$string1.pointer, - _$string2.pointer, - _$string3.pointer, - ).check(); - } -} - -final class $AndroidHelper$Type$ extends jni$_.JType { - @jni$_.internal - const $AndroidHelper$Type$(); - - @jni$_.internal - @core$_.override - String get signature => r'Lcom/example/piliplus/AndroidHelper;'; -} - /// from: `java.lang.Runnable` extension type Runnable._(jni$_.JObject _$this) implements jni$_.JObject { static final _class = jni$_.JClass.forName(r'java/lang/Runnable'); @@ -584,3 +183,458 @@ final class $Runnable$Type$ extends jni$_.JType { @core$_.override String get signature => r'Ljava/lang/Runnable;'; } + +/// from: `com.example.piliplus.AndroidHelper` +extension type AndroidHelper._(jni$_.JObject _$this) implements jni$_.JObject { + static final _class = jni$_.JClass.forName( + r'com/example/piliplus/AndroidHelper', + ); + + /// The type which includes information such as the signature of this class. + static const jni$_.JType type = $AndroidHelper$Type$(); + static final _id_isFoldable = _class.staticFieldId( + r'isFoldable', + r'Z', + ); + + /// from: `static public volatile boolean isFoldable` + static core$_.bool get isFoldable => + _id_isFoldable.getNullable(_class, jni$_.jboolean.type) as core$_.bool; + + /// from: `static public volatile boolean isFoldable` + static set isFoldable(core$_.bool value) => + _id_isFoldable.set(_class, jni$_.jboolean.type, value); + + static final _id_isPipMode = _class.staticFieldId( + r'isPipMode', + r'Z', + ); + + /// from: `static public volatile boolean isPipMode` + static core$_.bool get isPipMode => + _id_isPipMode.getNullable(_class, jni$_.jboolean.type) as core$_.bool; + + /// from: `static public volatile boolean isPipMode` + static set isPipMode(core$_.bool value) => + _id_isPipMode.set(_class, jni$_.jboolean.type, value); + + static final _id_isPipAvailable = _class.staticFieldId( + r'isPipAvailable', + r'Z', + ); + + /// from: `static public volatile boolean isPipAvailable` + static core$_.bool get isPipAvailable => + _id_isPipAvailable.getNullable(_class, jni$_.jboolean.type) + as core$_.bool; + + /// from: `static public volatile boolean isPipAvailable` + static set isPipAvailable(core$_.bool value) => + _id_isPipAvailable.set(_class, jni$_.jboolean.type, value); + + static final _id_sdkInt = _class.staticMethodId( + r'sdkInt', + r'()I', + ); + + static final _sdkInt = + jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + ) + > + >('globalEnv_CallStaticIntMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + ) + >(); + + /// from: `static public int sdkInt()` + static core$_.int sdkInt() { + final _$$classRef = _class.reference; + return _sdkInt(_$$classRef.pointer, _id_sdkInt.pointer).integer; + } + + static final _id_back = _class.staticMethodId( + r'back', + r'()V', + ); + + static final _back = + jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JThrowablePtr Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + ) + > + >('globalEnv_CallStaticVoidMethod') + .asFunction< + jni$_.JThrowablePtr Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + ) + >(); + + /// from: `static public void back()` + static void back() { + final _$$classRef = _class.reference; + _back(_$$classRef.pointer, _id_back.pointer).check(); + } + + static final _id_biliSendCommAntifraud = _class.staticMethodId( + r'biliSendCommAntifraud', + r'(IJIJJJJLjava/lang/String;Ljava/lang/String;Ljava/lang/String;JLjava/lang/String;)V', + ); + + static final _biliSendCommAntifraud = + jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JThrowablePtr Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.VarArgs< + ( + jni$_.Int32, + jni$_.Int64, + jni$_.Int32, + jni$_.Int64, + jni$_.Int64, + jni$_.Int64, + jni$_.Int64, + jni$_.Pointer, + jni$_.Pointer, + jni$_.Pointer, + jni$_.Int64, + jni$_.Pointer, + ) + >, + ) + > + >('globalEnv_CallStaticVoidMethod') + .asFunction< + jni$_.JThrowablePtr Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + core$_.int, + core$_.int, + core$_.int, + core$_.int, + core$_.int, + core$_.int, + core$_.int, + jni$_.Pointer, + jni$_.Pointer, + jni$_.Pointer, + core$_.int, + jni$_.Pointer, + ) + >(); + + /// from: `static public void biliSendCommAntifraud(int action, long oid, int type, long rpId, long root, long parent, long ctime, java.lang.String commentText, java.lang.String pictures, java.lang.String sourceId, long uid, java.lang.String cookie)` + static void biliSendCommAntifraud( + core$_.int action, + core$_.int oid, + core$_.int type, + core$_.int rpId, + core$_.int root, + core$_.int parent, + core$_.int ctime, + jni$_.JString commentText, + jni$_.JString? pictures, + jni$_.JString sourceId, + core$_.int uid, + jni$_.JString cookie, + ) { + final _$$classRef = _class.reference; + final _$commentText = commentText.reference; + final _$pictures = pictures?.reference ?? jni$_.jNullReference; + final _$sourceId = sourceId.reference; + final _$cookie = cookie.reference; + _biliSendCommAntifraud( + _$$classRef.pointer, + _id_biliSendCommAntifraud.pointer, + action, + oid, + type, + rpId, + root, + parent, + ctime, + _$commentText.pointer, + _$pictures.pointer, + _$sourceId.pointer, + uid, + _$cookie.pointer, + ).check(); + } + + static final _id_openLinkVerifySettings = _class.staticMethodId( + r'openLinkVerifySettings', + r'()V', + ); + + static final _openLinkVerifySettings = + jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JThrowablePtr Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + ) + > + >('globalEnv_CallStaticVoidMethod') + .asFunction< + jni$_.JThrowablePtr Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + ) + >(); + + /// from: `static public void openLinkVerifySettings()` + static void openLinkVerifySettings() { + final _$$classRef = _class.reference; + _openLinkVerifySettings( + _$$classRef.pointer, + _id_openLinkVerifySettings.pointer, + ).check(); + } + + static final _id_openMusic = _class.staticMethodId( + r'openMusic', + r'(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z', + ); + + static final _openMusic = + jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.VarArgs< + ( + jni$_.Pointer, + jni$_.Pointer, + jni$_.Pointer, + ) + >, + ) + > + >('globalEnv_CallStaticBooleanMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.Pointer, + jni$_.Pointer, + jni$_.Pointer, + ) + >(); + + /// from: `static public boolean openMusic(java.lang.String title, java.lang.String artist, java.lang.String album)` + static core$_.bool openMusic( + jni$_.JString title, + jni$_.JString? artist, + jni$_.JString? album, + ) { + final _$$classRef = _class.reference; + final _$title = title.reference; + final _$artist = artist?.reference ?? jni$_.jNullReference; + final _$album = album?.reference ?? jni$_.jNullReference; + return _openMusic( + _$$classRef.pointer, + _id_openMusic.pointer, + _$title.pointer, + _$artist.pointer, + _$album.pointer, + ).boolean; + } + + static final _id_setPipAutoEnterEnabled = _class.staticMethodId( + r'setPipAutoEnterEnabled', + r'(ZJ)V', + ); + + static final _setPipAutoEnterEnabled = + jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JThrowablePtr Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.VarArgs<(jni$_.Int32, jni$_.Int64)>, + ) + > + >('globalEnv_CallStaticVoidMethod') + .asFunction< + jni$_.JThrowablePtr Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + core$_.int, + core$_.int, + ) + >(); + + /// from: `static public void setPipAutoEnterEnabled(boolean autoEnable, long engineId)` + static void setPipAutoEnterEnabled( + core$_.bool autoEnable, + core$_.int engineId, + ) { + final _$$classRef = _class.reference; + _setPipAutoEnterEnabled( + _$$classRef.pointer, + _id_setPipAutoEnterEnabled.pointer, + autoEnable ? 1 : 0, + engineId, + ).check(); + } + + static final _id_maxScreenSize = _class.staticMethodId( + r'maxScreenSize', + r'()[I', + ); + + static final _maxScreenSize = + jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + ) + > + >('globalEnv_CallStaticObjectMethod') + .asFunction< + jni$_.JniResult Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + ) + >(); + + /// from: `static public int[] maxScreenSize()` + /// The returned object must be released after use, by calling the [release] method. + static jni$_.JIntArray? maxScreenSize() { + final _$$classRef = _class.reference; + return _maxScreenSize( + _$$classRef.pointer, + _id_maxScreenSize.pointer, + ).object(); + } + + static final _id_createShortcut = _class.staticMethodId( + r'createShortcut', + r'(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V', + ); + + static final _createShortcut = + jni$_.ProtectedJniExtensions.lookup< + jni$_.NativeFunction< + jni$_.JThrowablePtr Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.VarArgs< + ( + jni$_.Pointer, + jni$_.Pointer, + jni$_.Pointer, + jni$_.Pointer, + ) + >, + ) + > + >('globalEnv_CallStaticVoidMethod') + .asFunction< + jni$_.JThrowablePtr Function( + jni$_.Pointer, + jni$_.JMethodIDPtr, + jni$_.Pointer, + jni$_.Pointer, + jni$_.Pointer, + jni$_.Pointer, + ) + >(); + + /// from: `static public void createShortcut(java.lang.String id, java.lang.String uri, java.lang.String label, java.lang.String icon)` + static void createShortcut( + jni$_.JString id, + jni$_.JString uri, + jni$_.JString label, + jni$_.JString icon, + ) { + final _$$classRef = _class.reference; + final _$id = id.reference; + final _$uri = uri.reference; + final _$label = label.reference; + final _$icon = icon.reference; + _createShortcut( + _$$classRef.pointer, + _id_createShortcut.pointer, + _$id.pointer, + _$uri.pointer, + _$label.pointer, + _$icon.pointer, + ).check(); + } +} + +final class $AndroidHelper$Type$ extends jni$_.JType { + @jni$_.internal + const $AndroidHelper$Type$(); + + @jni$_.internal + @core$_.override + String get signature => r'Lcom/example/piliplus/AndroidHelper;'; +} + +/// from: `com.example.piliplus.AndroidHelper$ToDart` +extension type AndroidHelper$ToDart._(jni$_.JObject _$this) + implements jni$_.JObject { + static final _class = jni$_.JClass.forName( + r'com/example/piliplus/AndroidHelper$ToDart', + ); + + /// The type which includes information such as the signature of this class. + static const jni$_.JType type = + $AndroidHelper$ToDart$Type$(); + static final _id_onUserLeaveHint = _class.staticFieldId( + r'onUserLeaveHint', + r'Ljava/lang/Runnable;', + ); + + /// from: `static public volatile java.lang.Runnable onUserLeaveHint` + /// The returned object must be released after use, by calling the [release] method. + static Runnable? get onUserLeaveHint => + _id_onUserLeaveHint.getNullable(_class, Runnable.type) as Runnable?; + + /// from: `static public volatile java.lang.Runnable onUserLeaveHint` + /// The returned object must be released after use, by calling the [release] method. + static set onUserLeaveHint(Runnable? value) => + _id_onUserLeaveHint.set(_class, Runnable.type, value); + + static final _id_onConfigurationChanged = _class.staticFieldId( + r'onConfigurationChanged', + r'Ljava/lang/Runnable;', + ); + + /// from: `static public volatile java.lang.Runnable onConfigurationChanged` + /// The returned object must be released after use, by calling the [release] method. + static Runnable? get onConfigurationChanged => + _id_onConfigurationChanged.getNullable(_class, Runnable.type) + as Runnable?; + + /// from: `static public volatile java.lang.Runnable onConfigurationChanged` + /// The returned object must be released after use, by calling the [release] method. + static set onConfigurationChanged(Runnable? value) => + _id_onConfigurationChanged.set(_class, Runnable.type, value); +} + +final class $AndroidHelper$ToDart$Type$ + extends jni$_.JType { + @jni$_.internal + const $AndroidHelper$ToDart$Type$(); + + @jni$_.internal + @core$_.override + String get signature => r'Lcom/example/piliplus/AndroidHelper$ToDart;'; +} diff --git a/lib/utils/device_utils.dart b/lib/utils/device_utils.dart index 47cf7be69..c60d26acd 100644 --- a/lib/utils/device_utils.dart +++ b/lib/utils/device_utils.dart @@ -1,8 +1,9 @@ +import 'package:PiliPlus/utils/android/bindings.g.dart'; import 'package:PiliPlus/utils/platform_utils.dart'; import 'package:flutter/widgets.dart' show WidgetsBinding, Size; abstract final class DeviceUtils { - static late int sdkInt; + static final int sdkInt = AndroidHelper.sdkInt(); static bool get isTablet { return size.shortestSide >= 600; diff --git a/lib/utils/max_screen_size.dart b/lib/utils/max_screen_size.dart index bc90951b9..d8f21333c 100644 --- a/lib/utils/max_screen_size.dart +++ b/lib/utils/max_screen_size.dart @@ -10,7 +10,7 @@ abstract final class MaxScreenSize { static void init() { _initScreenSize(); if (AndroidHelper.isFoldable) { - AndroidHelper$ToDart.onUserLeaveHint = Runnable.implement( + AndroidHelper$ToDart.onConfigurationChanged = Runnable.implement( $Runnable(run: _initScreenSize), ); } diff --git a/lib/utils/page_utils.dart b/lib/utils/page_utils.dart index 53ec8e9c5..8dc7ff666 100644 --- a/lib/utils/page_utils.dart +++ b/lib/utils/page_utils.dart @@ -195,13 +195,13 @@ abstract final class PageUtils { : height > width ? const Rational.vertical() : const Rational.landscape(); - Floating().enable( + Floating.enable( isAuto ? AutoEnable(aspectRatio: aspectRatio) : EnableManual(aspectRatio: aspectRatio), ); } else { - Floating().enable(isAuto ? const AutoEnable() : const EnableManual()); + Floating.enable(isAuto ? const AutoEnable() : const EnableManual()); } } diff --git a/pubspec.lock b/pubspec.lock index e327e9462..d844373cb 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -595,8 +595,8 @@ packages: dependency: "direct main" description: path: "." - ref: version-3 - resolved-ref: a66ec0b9dabde6b5880a3f4f3425e57842a38e51 + ref: dev + resolved-ref: fdd44a501d9717ebab04e8004fca2818a6bed236 url: "https://github.com/bggRGjQaUbCoE/floating.git" source: git version: "3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 40f823226..ef83b48b5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -86,7 +86,7 @@ dependencies: floating: git: url: https://github.com/bggRGjQaUbCoE/floating.git - ref: version-3 + ref: dev flutter_cache_manager: ^3.4.1 flutter_displaymode: ^0.7.0 flutter_html: ^3.0.0-beta.2 diff --git a/tool/README.md b/tool/README.md new file mode 100644 index 000000000..c6fb71ecb --- /dev/null +++ b/tool/README.md @@ -0,0 +1 @@ +run `dart run tool/jnigen.dart` \ No newline at end of file diff --git a/tool/jnigen.dart b/tool/jnigen.dart new file mode 100644 index 000000000..9d33d62e3 --- /dev/null +++ b/tool/jnigen.dart @@ -0,0 +1,23 @@ +import 'dart:io' show Platform; + +import 'package:jnigen/jnigen.dart'; + +void main(List args) { + final packageRoot = Platform.script.resolve('../'); + generateJniBindings( + Config( + outputConfig: OutputConfig( + dartConfig: DartCodeOutputConfig( + path: packageRoot.resolve('lib/utils/android/bindings.g.dart'), + structure: .singleFile, + ), + ), + androidSdkConfig: AndroidSdkConfig(addGradleDeps: true), + sourcePath: [packageRoot.resolve('android/app/src/main/java')], + classes: [ + 'com.example.piliplus', + 'java.lang.Runnable', + ], + ), + ); +}