Removing PiP option for unsupported devices

This commit is contained in:
ByteHamster 2018-04-09 22:20:43 +02:00
parent 64221f7f56
commit d757abedbc
6 changed files with 52 additions and 26 deletions

View File

@ -4,7 +4,6 @@ import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.PixelFormat;
@ -47,6 +46,7 @@ import de.danoeh.antennapod.core.util.Flavors;
import de.danoeh.antennapod.core.util.ShareUtils;
import de.danoeh.antennapod.core.util.StorageUtils;
import de.danoeh.antennapod.core.util.Supplier;
import de.danoeh.antennapod.core.util.gui.PictureInPictureUtil;
import de.danoeh.antennapod.core.util.playback.MediaPlayerError;
import de.danoeh.antennapod.core.util.playback.Playable;
import de.danoeh.antennapod.core.util.playback.PlaybackController;
@ -226,7 +226,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
@Override
protected void onPause() {
if (!compatIsInPictureInPictureMode()) {
if (!PictureInPictureUtil.isInPictureInPictureMode(this)) {
if (controller != null) {
controller.reinitServiceIfPaused();
controller.pause();
@ -908,23 +908,6 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
}
}
/* package */ boolean supportsPictureInPicture() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
PackageManager packageManager = getApplicationContext().getPackageManager();
return packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE);
} else {
return false;
}
}
/* package */ boolean compatIsInPictureInPictureMode() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && supportsPictureInPicture()) {
return isInPictureInPictureMode();
} else {
return false;
}
}
private void checkFavorite() {
Playable playable = controller.getMedia();
if (playable != null && playable instanceof FeedMedia) {

View File

@ -27,6 +27,7 @@ import de.danoeh.antennapod.core.feed.MediaType;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.service.playback.PlayerStatus;
import de.danoeh.antennapod.core.util.gui.PictureInPictureUtil;
import de.danoeh.antennapod.core.util.playback.ExternalMedia;
import de.danoeh.antennapod.core.util.playback.Playable;
import de.danoeh.antennapod.view.AspectRatioVideoView;
@ -102,14 +103,14 @@ public class VideoplayerActivity extends MediaplayerActivity {
@Override
protected void onStop() {
super.onStop();
if (!compatIsInPictureInPictureMode()) {
if (!PictureInPictureUtil.isInPictureInPictureMode(this)) {
videoControlsHider.stop();
}
}
@Override
public void onUserLeaveHint () {
if (!compatIsInPictureInPictureMode() && UserPreferences.getVideoBackgroundBehavior()
if (!PictureInPictureUtil.isInPictureInPictureMode(this) && UserPreferences.getVideoBackgroundBehavior()
== UserPreferences.VideoBackgroundBehavior.PICTURE_IN_PICTURE) {
compatEnterPictureInPicture();
}
@ -117,7 +118,7 @@ public class VideoplayerActivity extends MediaplayerActivity {
@Override
protected void onPause() {
if (!compatIsInPictureInPictureMode()) {
if (!PictureInPictureUtil.isInPictureInPictureMode(this)) {
if (controller != null && controller.getStatus() == PlayerStatus.PLAYING) {
controller.pause();
}
@ -200,7 +201,7 @@ public class VideoplayerActivity extends MediaplayerActivity {
private final View.OnTouchListener onVideoviewTouched = (v, event) -> {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (compatIsInPictureInPictureMode()) {
if (PictureInPictureUtil.isInPictureInPictureMode(this)) {
return true;
}
videoControlsHider.stop();
@ -390,7 +391,7 @@ public class VideoplayerActivity extends MediaplayerActivity {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
if (supportsPictureInPicture()) {
if (PictureInPictureUtil.supportsPictureInPicture(this)) {
menu.findItem(R.id.player_go_to_picture_in_picture).setVisible(true);
}
return true;
@ -406,7 +407,7 @@ public class VideoplayerActivity extends MediaplayerActivity {
}
private void compatEnterPictureInPicture() {
if (supportsPictureInPicture() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (PictureInPictureUtil.supportsPictureInPicture(this) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
getSupportActionBar().hide();
hideVideoControls(false);
enterPictureInPictureMode();

View File

@ -38,8 +38,10 @@ import android.widget.Toast;
import com.afollestad.materialdialogs.MaterialDialog;
import com.afollestad.materialdialogs.prefs.MaterialListPreference;
import de.danoeh.antennapod.activity.ImportExportActivity;
import de.danoeh.antennapod.activity.OpmlImportFromPathActivity;
import de.danoeh.antennapod.core.util.gui.PictureInPictureUtil;
import org.apache.commons.lang3.ArrayUtils;
import java.io.File;
@ -426,6 +428,11 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
return false;
}
);
if (!PictureInPictureUtil.supportsPictureInPicture(activity)) {
MaterialListPreference behaviour = (MaterialListPreference) ui.findPreference(UserPreferences.PREF_VIDEO_BEHAVIOR);
behaviour.setEntries(R.array.video_background_behavior_options_without_pip);
behaviour.setEntryValues(R.array.video_background_behavior_values_without_pip);
}
ui.findPreference(PREF_PROXY).setOnPreferenceClickListener(preference -> {
ProxyDialog dialog = new ProxyDialog(ui.getActivity());
dialog.createDialog().show();

View File

@ -74,7 +74,7 @@ public class UserPreferences {
private static final String PREF_PLAYBACK_SPEED_ARRAY = "prefPlaybackSpeedArray";
private static final String PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS = "prefPauseForFocusLoss";
private static final String PREF_RESUME_AFTER_CALL = "prefResumeAfterCall";
private static final String PREF_VIDEO_BEHAVIOR = "prefVideoBehavior";
public static final String PREF_VIDEO_BEHAVIOR = "prefVideoBehavior";
// Network
private static final String PREF_ENQUEUE_DOWNLOADED = "prefEnqueueDownloaded";

View File

@ -0,0 +1,27 @@
package de.danoeh.antennapod.core.util.gui;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
public class PictureInPictureUtil {
private PictureInPictureUtil() {
}
public static boolean supportsPictureInPicture(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
PackageManager packageManager = activity.getPackageManager();
return packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE);
} else {
return false;
}
}
public static boolean isInPictureInPictureMode(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && supportsPictureInPicture(activity)) {
return activity.isInPictureInPictureMode();
} else {
return false;
}
}
}

View File

@ -234,4 +234,12 @@
<item>stop</item>
<item>pip</item>
</string-array>
<string-array name="video_background_behavior_options_without_pip">
<item>@string/stop_playback</item>
</string-array>
<string-array name="video_background_behavior_values_without_pip">
<item>stop</item>
</string-array>
</resources>