mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-20 09:20:13 +08:00
@@ -1,6 +1,8 @@
|
||||
package com.example.piliplus;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.PictureInPictureParams;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
@@ -11,6 +13,7 @@ import android.graphics.drawable.Icon;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.util.Rational;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
@@ -85,4 +88,14 @@ public final class AndroidHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void enterPip(long engineId, int width, int height) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
Activity activity = JniFlutterPlugin.getActivity(engineId);
|
||||
PictureInPictureParams.Builder builder = new PictureInPictureParams.Builder()
|
||||
.setAspectRatio(new Rational(width, height));
|
||||
assert activity != null;
|
||||
activity.enterPictureInPictureMode(builder.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -255,12 +255,11 @@ class PlPlayerController with BlockConfigMixin {
|
||||
}
|
||||
}
|
||||
|
||||
void enterPip({bool isAuto = false}) {
|
||||
void enterPip() {
|
||||
if (videoPlayerController != null) {
|
||||
controls = false;
|
||||
final state = videoPlayerController!.state;
|
||||
PageUtils.enterPip(
|
||||
isAuto: isAuto,
|
||||
width: state.width == 0 ? width : state.width,
|
||||
height: state.height == 0 ? height : state.height,
|
||||
);
|
||||
|
||||
@@ -357,6 +357,47 @@ extension type AndroidHelper._(jni$_.JObject _$this) implements jni$_.JObject {
|
||||
_$icon.pointer,
|
||||
).check();
|
||||
}
|
||||
|
||||
static final _id_enterPip = _class.staticMethodId(
|
||||
r'enterPip',
|
||||
r'(JII)V',
|
||||
);
|
||||
|
||||
static final _enterPip =
|
||||
jni$_.ProtectedJniExtensions.lookup<
|
||||
jni$_.NativeFunction<
|
||||
jni$_.JThrowablePtr Function(
|
||||
jni$_.Pointer<jni$_.Void>,
|
||||
jni$_.JMethodIDPtr,
|
||||
jni$_.VarArgs<(jni$_.Int64, jni$_.Int32, jni$_.Int32)>,
|
||||
)
|
||||
>
|
||||
>('globalEnv_CallStaticVoidMethod')
|
||||
.asFunction<
|
||||
jni$_.JThrowablePtr Function(
|
||||
jni$_.Pointer<jni$_.Void>,
|
||||
jni$_.JMethodIDPtr,
|
||||
core$_.int,
|
||||
core$_.int,
|
||||
core$_.int,
|
||||
)
|
||||
>();
|
||||
|
||||
/// from: `static public void enterPip(long engineId, int width, int height)`
|
||||
static void enterPip(
|
||||
core$_.int engineId,
|
||||
core$_.int width,
|
||||
core$_.int height,
|
||||
) {
|
||||
final _$$classRef = _class.reference;
|
||||
_enterPip(
|
||||
_$$classRef.pointer,
|
||||
_id_enterPip.pointer,
|
||||
engineId,
|
||||
width,
|
||||
height,
|
||||
).check();
|
||||
}
|
||||
}
|
||||
|
||||
final class $AndroidHelper$Type$ extends jni$_.JType<AndroidHelper> {
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import 'package:floating/floating.dart';
|
||||
|
||||
extension RationalExt on Rational {
|
||||
/// Checks whether given [Rational] instance fits into Android requirements
|
||||
/// or not.
|
||||
///
|
||||
/// Android docs specified boundaries as inclusive.
|
||||
bool get fitsInAndroidRequirements {
|
||||
final aspectRatio = numerator / denominator;
|
||||
const min = 1 / 2.39;
|
||||
const max = 2.39;
|
||||
return (min <= aspectRatio) && (aspectRatio <= max);
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,9 @@ import 'package:PiliPlus/pages/contact/view.dart';
|
||||
import 'package:PiliPlus/pages/fav_panel/view.dart';
|
||||
import 'package:PiliPlus/pages/share/view.dart';
|
||||
import 'package:PiliPlus/pages/webview/view.dart';
|
||||
import 'package:PiliPlus/utils/android/bindings.g.dart';
|
||||
import 'package:PiliPlus/utils/app_scheme.dart';
|
||||
import 'package:PiliPlus/utils/extension/context_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension/extension.dart';
|
||||
import 'package:PiliPlus/utils/extension/size_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension/string_ext.dart';
|
||||
import 'package:PiliPlus/utils/global_data.dart';
|
||||
@@ -29,8 +29,7 @@ import 'package:PiliPlus/utils/platform_utils.dart';
|
||||
import 'package:PiliPlus/utils/url_utils.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:floating/floating.dart';
|
||||
import 'package:flutter/foundation.dart' show kDebugMode;
|
||||
import 'package:flutter/foundation.dart' show kDebugMode, PlatformDispatcher;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -183,22 +182,30 @@ abstract final class PageUtils {
|
||||
WebViewPage.toWebView('https://www.bilibili.com/appeal/?avid=$aid');
|
||||
}
|
||||
|
||||
static void enterPip({int? width, int? height, bool isAuto = false}) {
|
||||
if (width != null && height != null) {
|
||||
Rational aspectRatio = Rational(width, height);
|
||||
aspectRatio = aspectRatio.fitsInAndroidRequirements
|
||||
? aspectRatio
|
||||
: height > width
|
||||
? const Rational.vertical()
|
||||
: const Rational.landscape();
|
||||
Floating.enable(
|
||||
isAuto
|
||||
? AutoEnable(aspectRatio: aspectRatio)
|
||||
: EnableManual(aspectRatio: aspectRatio),
|
||||
);
|
||||
} else {
|
||||
Floating.enable(isAuto ? const AutoEnable() : const EnableManual());
|
||||
static bool _fitsInAndroidRequirements(int width, int height) {
|
||||
final aspectRatio = width / height;
|
||||
const min = 1 / 2.39;
|
||||
const max = 2.39;
|
||||
return (min <= aspectRatio) && (aspectRatio <= max);
|
||||
}
|
||||
|
||||
static void enterPip({int? width, int? height}) {
|
||||
if (width != null &&
|
||||
height != null &&
|
||||
!_fitsInAndroidRequirements(width, height)) {
|
||||
if (height > width) {
|
||||
width = 9;
|
||||
height = 16;
|
||||
} else {
|
||||
width = 16;
|
||||
height = 9;
|
||||
}
|
||||
}
|
||||
AndroidHelper.enterPip(
|
||||
PlatformDispatcher.instance.engineId!,
|
||||
width ?? 16,
|
||||
height ?? 9,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<void> pushDynDetail(
|
||||
|
||||
@@ -559,15 +559,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.0.1"
|
||||
floating:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: dev
|
||||
resolved-ref: fdd44a501d9717ebab04e8004fca2818a6bed236
|
||||
url: "https://github.com/bggRGjQaUbCoE/floating.git"
|
||||
source: git
|
||||
version: "3.0.0"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
|
||||
@@ -81,10 +81,6 @@ dependencies:
|
||||
ref: dev
|
||||
fixnum: ^1.1.1
|
||||
flex_seed_scheme: ^4.0.1
|
||||
floating:
|
||||
git:
|
||||
url: https://github.com/bggRGjQaUbCoE/floating.git
|
||||
ref: dev
|
||||
flutter_cache_manager: ^3.4.1
|
||||
flutter_html: ^3.0.0-beta.2
|
||||
flutter_inappwebview: ^6.1.5
|
||||
|
||||
Reference in New Issue
Block a user