[mobile] support pip mode

pull/123/head
FongMi 3 years ago
parent 3a872ec1ae
commit 3749ee81f4
  1. 19
      app/src/main/java/com/fongmi/android/tv/utils/Utils.java
  2. 4
      app/src/mobile/AndroidManifest.xml
  3. 39
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/DetailActivity.java

@ -2,12 +2,16 @@ package com.fongmi.android.tv.utils;
import android.Manifest;
import android.app.Activity;
import android.app.PictureInPictureParams;
import android.content.Context;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.IBinder;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Rational;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
@ -74,6 +78,21 @@ public class Utils {
activity.getWindow().getDecorView().setSystemUiVisibility(flags);
}
public static boolean hasPIP() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && App.get().getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE);
}
public static void enterPIP(Activity activity) {
try {
if (!hasPIP() || activity.isInPictureInPictureMode()) return;
PictureInPictureParams.Builder builder = new PictureInPictureParams.Builder();
builder.setAspectRatio(new Rational(16, 9)).build();
activity.enterPictureInPictureMode(builder.build());
} catch (Exception e) {
e.printStackTrace();
}
}
public static boolean isVideoFormat(String url) {
return isVideoFormat(url, new HashMap<>());
}

@ -19,7 +19,9 @@
<activity
android:name=".ui.activity.DetailActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
android:screenOrientation="fullSensor" />
android:resizeableActivity="true"
android:screenOrientation="fullSensor"
android:supportsPictureInPicture="true" />
</application>
</manifest>

@ -495,7 +495,7 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis
private void enterFullscreen() {
getIjk().getSubtitleView().setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
mBinding.video.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
App.post(() -> setFullscreen(true), 250);
setFullscreen(true);
}
private void exitFullscreen() {
@ -769,18 +769,44 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (ResUtil.isPort()) {
exitFullscreen();
} else if (ResUtil.isLand()) {
enterFullscreen();
if (ResUtil.isLand()) enterFullscreen();
if (ResUtil.isPort()) exitFullscreen();
}
@Override
protected void onUserLeaveHint() {
super.onUserLeaveHint();
Utils.enterPIP(this);
}
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode);
mBinding.progressLayout.setVisibility(isInPictureInPictureMode ? View.GONE : View.VISIBLE);
if (isInPictureInPictureMode) {
hideControl();
hideInfo();
} else if (!mPlayers.isPlaying()) {
finish();
}
}
@Override
protected void onStart() {
super.onStart();
onPlay();
}
@Override
protected void onStop() {
onPause(false);
super.onStop();
}
@Override
protected void onResume() {
super.onResume();
Clock.start(mBinding.widget.time);
onPlay();
}
@Override
@ -788,7 +814,6 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis
super.onPause();
RefreshEvent.history();
Clock.get().release();
onPause(false);
}
@Override

Loading…
Cancel
Save