opt: java

This commit is contained in:
My-Responsitories
2026-06-01 14:52:45 +08:00
parent 2de59b0c9b
commit 6d7ae5d830
3 changed files with 30 additions and 35 deletions

View File

@@ -111,7 +111,7 @@ public final class AndroidHelper {
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} catch (Throwable ignored) {
} catch (Exception ignored) {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
@@ -139,7 +139,7 @@ public final class AndroidHelper {
context.startActivity(intent);
return true;
}
} catch (Throwable ignored) {
} catch (Exception ignored) {
}
try {
@@ -148,7 +148,7 @@ public final class AndroidHelper {
context.startActivity(intent);
return true;
}
} catch (Throwable ignored) {
} catch (Exception ignored) {
}
return false;
@@ -185,23 +185,23 @@ public final class AndroidHelper {
private static void setPipActions(Activity activity, PictureInPictureParams.Builder builder, boolean isLive, boolean isPlaying) {
ComponentName mbrComponent = MediaHelper.getMediaButtonReceiverComponent(activity);
if (mbrComponent == null) return;
ArrayList<RemoteAction> actionList = new ArrayList<>();
ArrayList<RemoteAction> actionList = new ArrayList<>(3);
if (!isLive) {
actionList.add(getRemoteAction(mbrComponent, activity, R.drawable.ic_baseline_replay_10_24, "ACTION_REWIND", PlaybackState.ACTION_REWIND));
actionList.add(getRemoteAction(mbrComponent, activity, R.drawable.ic_baseline_replay_10_24, "ACTION_REWIND", (int) PlaybackState.ACTION_REWIND));
}
if (isPlaying) {
actionList.add(getRemoteAction(mbrComponent, activity, android.R.drawable.ic_media_pause, "ACTION_PAUSE", PlaybackState.ACTION_PAUSE));
actionList.add(getRemoteAction(mbrComponent, activity, android.R.drawable.ic_media_pause, "ACTION_PAUSE", (int) PlaybackState.ACTION_PAUSE));
} else {
actionList.add(getRemoteAction(mbrComponent, activity, android.R.drawable.ic_media_play, "ACTION_PLAY", PlaybackState.ACTION_PLAY));
actionList.add(getRemoteAction(mbrComponent, activity, android.R.drawable.ic_media_play, "ACTION_PLAY", (int) PlaybackState.ACTION_PLAY));
}
if (!isLive) {
actionList.add(getRemoteAction(mbrComponent, activity, R.drawable.ic_baseline_forward_10_24, "ACTION_FAST_FORWARD", PlaybackState.ACTION_FAST_FORWARD));
actionList.add(getRemoteAction(mbrComponent, activity, R.drawable.ic_baseline_forward_10_24, "ACTION_FAST_FORWARD", (int) PlaybackState.ACTION_FAST_FORWARD));
}
builder.setActions(actionList);
}
@RequiresApi(api = Build.VERSION_CODES.O)
private static RemoteAction getRemoteAction(@NonNull ComponentName mbrComponent, Activity activity, @DrawableRes int resId, String title, long action) {
private static RemoteAction getRemoteAction(@NonNull ComponentName mbrComponent, Activity activity, @DrawableRes int resId, String title, int action) {
return new RemoteAction(
Icon.createWithResource(activity, resId),
title,
@@ -235,7 +235,7 @@ public final class AndroidHelper {
wm.getDefaultDisplay().getRealSize(realSize);
return new int[]{Math.round(realSize.x / density), Math.round(realSize.y / density)};
}
} catch (Exception e) {
} catch (Exception ignored) {
return null;
}
}

View File

@@ -29,10 +29,10 @@ import android.view.KeyEvent;
import java.util.List;
public class MediaHelper {
class MediaHelper {
private static final String TAG = "MediaButtonReceiver";
public static PendingIntent buildMediaButtonPendingIntent(Context context, ComponentName mbrComponent, long action) {
static PendingIntent buildMediaButtonPendingIntent(Context context, ComponentName mbrComponent, int action) {
if (mbrComponent == null) {
Log.w(TAG, "The component name of media button receiver should be provided.");
return null;
@@ -48,31 +48,24 @@ public class MediaHelper {
intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
return PendingIntent.getBroadcast(context, keyCode, intent,
Build.VERSION.SDK_INT >= 31 ? PendingIntent.FLAG_MUTABLE : 0);
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? PendingIntent.FLAG_MUTABLE : 0);
}
public static int PlaybackStateCompat_toKeyCode(long action) {
if (action == PlaybackState.ACTION_PLAY) {
return KeyEvent.KEYCODE_MEDIA_PLAY;
} else if (action == PlaybackState.ACTION_PAUSE) {
return KeyEvent.KEYCODE_MEDIA_PAUSE;
} else if (action == PlaybackState.ACTION_SKIP_TO_NEXT) {
return KeyEvent.KEYCODE_MEDIA_NEXT;
} else if (action == PlaybackState.ACTION_SKIP_TO_PREVIOUS) {
return KeyEvent.KEYCODE_MEDIA_PREVIOUS;
} else if (action == PlaybackState.ACTION_STOP) {
return KeyEvent.KEYCODE_MEDIA_STOP;
} else if (action == PlaybackState.ACTION_FAST_FORWARD) {
return KeyEvent.KEYCODE_MEDIA_FAST_FORWARD;
} else if (action == PlaybackState.ACTION_REWIND) {
return KeyEvent.KEYCODE_MEDIA_REWIND;
} else if (action == PlaybackState.ACTION_PLAY_PAUSE) {
return KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
}
return KeyEvent.KEYCODE_UNKNOWN;
private static int PlaybackStateCompat_toKeyCode(int action) {
return switch (action) {
case (int) PlaybackState.ACTION_STOP -> KeyEvent.KEYCODE_MEDIA_STOP;
case (int) PlaybackState.ACTION_PAUSE -> KeyEvent.KEYCODE_MEDIA_PAUSE;
case (int) PlaybackState.ACTION_PLAY -> KeyEvent.KEYCODE_MEDIA_PLAY;
case (int) PlaybackState.ACTION_REWIND -> KeyEvent.KEYCODE_MEDIA_REWIND;
case (int) PlaybackState.ACTION_SKIP_TO_PREVIOUS -> KeyEvent.KEYCODE_MEDIA_PREVIOUS;
case (int) PlaybackState.ACTION_SKIP_TO_NEXT -> KeyEvent.KEYCODE_MEDIA_NEXT;
case (int) PlaybackState.ACTION_FAST_FORWARD -> KeyEvent.KEYCODE_MEDIA_FAST_FORWARD;
case (int) PlaybackState.ACTION_PLAY_PAUSE -> KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
default -> KeyEvent.KEYCODE_UNKNOWN;
};
}
public static ComponentName getMediaButtonReceiverComponent(Context context) {
static ComponentName getMediaButtonReceiverComponent(Context context) {
Intent queryIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
queryIntent.setPackage(context.getPackageName());
PackageManager pm = context.getPackageManager();

View File

@@ -1626,8 +1626,10 @@ class PlPlayerController with BlockConfigMixin {
if (showSeekPreview) {
_clearPreview();
}
AndroidHelper$ToDart.onUserLeaveHint?.release();
AndroidHelper$ToDart.onUserLeaveHint = null;
if (Platform.isAndroid) {
AndroidHelper$ToDart.onUserLeaveHint?.release();
AndroidHelper$ToDart.onUserLeaveHint = null;
}
_timer?.cancel();
// _position.close();
// _playerEventSubs?.cancel();