diff options
Diffstat (limited to 'app/src/main')
7 files changed, 117 insertions, 35 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8c3c86358..5ff41ea30 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -222,7 +222,8 @@ <activity android:name=".activity.VideoplayerActivity" - android:configChanges="keyboardHidden|orientation" + android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize" + android:supportsPictureInPicture="true" android:screenOrientation="sensorLandscape"> <meta-data android:name="android.support.PARENT_ACTIVITY" diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index 232ff4311..f3c0760f3 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -225,9 +225,11 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements @Override protected void onPause() { - if(controller != null) { - controller.reinitServiceIfPaused(); - controller.pause(); + if (Build.VERSION.SDK_INT < 26 || !isInPictureInPictureMode()) { + if (controller != null) { + controller.reinitServiceIfPaused(); + controller.pause(); + } } super.onPause(); } @@ -379,6 +381,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements } else { startActivity(intent); } + finish(); return true; } else { if (media != null) { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java index 54758acf4..be5107d75 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java @@ -10,19 +10,18 @@ import android.support.v4.view.WindowCompat; import android.support.v7.app.ActionBar; import android.util.Log; import android.util.Pair; +import android.view.Menu; +import android.view.MenuItem; import android.view.MotionEvent; import android.view.SurfaceHolder; import android.view.View; import android.view.WindowManager; import android.view.animation.Animation; import android.view.animation.AnimationUtils; +import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.SeekBar; - -import java.lang.ref.WeakReference; -import java.util.concurrent.atomic.AtomicBoolean; - import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.feed.MediaType; import de.danoeh.antennapod.core.service.playback.PlaybackService; @@ -31,6 +30,9 @@ import de.danoeh.antennapod.core.util.playback.ExternalMedia; import de.danoeh.antennapod.core.util.playback.Playable; import de.danoeh.antennapod.view.AspectRatioVideoView; +import java.lang.ref.WeakReference; +import java.util.concurrent.atomic.AtomicBoolean; + /** * Activity for playing video files. */ @@ -52,6 +54,7 @@ public class VideoplayerActivity extends MediaplayerActivity { private LinearLayout videoOverlay; private AspectRatioVideoView videoview; private ProgressBar progressIndicator; + private FrameLayout videoframe; @Override protected void chooseTheme() { @@ -97,9 +100,12 @@ public class VideoplayerActivity extends MediaplayerActivity { @Override protected void onPause() { - videoControlsHider.stop(); - if (controller != null && controller.getStatus() == PlayerStatus.PLAYING) { - controller.pause(); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N + || !isInPictureInPictureMode()) { + videoControlsHider.stop(); + if (controller != null && controller.getStatus() == PlayerStatus.PLAYING) { + controller.pause(); + } } super.onPause(); } @@ -127,7 +133,7 @@ public class VideoplayerActivity extends MediaplayerActivity { @Override protected void setupGUI() { - if(isSetup.getAndSet(true)) { + if (isSetup.getAndSet(true)) { return; } super.setupGUI(); @@ -135,20 +141,23 @@ public class VideoplayerActivity extends MediaplayerActivity { controls = (LinearLayout) findViewById(R.id.controls); videoOverlay = (LinearLayout) findViewById(R.id.overlay); videoview = (AspectRatioVideoView) findViewById(R.id.videoview); + videoframe = (FrameLayout) findViewById(R.id.videoframe); progressIndicator = (ProgressBar) findViewById(R.id.progressIndicator); videoview.getHolder().addCallback(surfaceHolderCallback); - videoview.setOnTouchListener(onVideoviewTouched); + videoframe.setOnTouchListener(onVideoviewTouched); + videoOverlay.setOnTouchListener((view, motionEvent) -> true); // To suppress touches directly below the slider if (Build.VERSION.SDK_INT >= 16) { videoview.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); } - if (Build.VERSION.SDK_INT >= 14) { - videoOverlay.setFitsSystemWindows(true); - } + videoOverlay.setFitsSystemWindows(true); setupVideoControlsToggler(); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); + + videoframe.getViewTreeObserver().addOnGlobalLayoutListener(() -> + videoview.setAvailableSize(videoframe.getWidth(), videoframe.getHeight())); } @Override @@ -176,6 +185,10 @@ public class VideoplayerActivity extends MediaplayerActivity { private final View.OnTouchListener onVideoviewTouched = (v, event) -> { if (event.getAction() == MotionEvent.ACTION_DOWN) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N + && isInPictureInPictureMode()) { + return true; + } videoControlsHider.stop(); toggleVideoControlsVisibility(); if (videoControlsShowing) { @@ -269,6 +282,13 @@ public class VideoplayerActivity extends MediaplayerActivity { @Override protected void onReloadNotification(int notificationCode) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isInPictureInPictureMode()) { + if (notificationCode == PlaybackService.EXTRA_CODE_AUDIO + || notificationCode == PlaybackService.EXTRA_CODE_CAST) { + finish(); + } + return; + } if (notificationCode == PlaybackService.EXTRA_CODE_AUDIO) { Log.d(TAG, "ReloadNotification received, switching to Audioplayer now"); destroyingDueToReload = true; @@ -313,28 +333,31 @@ public class VideoplayerActivity extends MediaplayerActivity { videoOverlay.startAnimation(animation); controls.startAnimation(animation); } - if (Build.VERSION.SDK_INT >= 14) { - videoview.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); - } + videoview.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); } @SuppressLint("NewApi") - private void hideVideoControls() { - final Animation animation = AnimationUtils.loadAnimation(this, R.anim.fade_out); - if (animation != null) { - videoOverlay.startAnimation(animation); - controls.startAnimation(animation); - } - if (Build.VERSION.SDK_INT >= 14) { - int videoviewFlag = (Build.VERSION.SDK_INT >= 16) ? View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION : 0; - getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_FULLSCREEN - | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | videoviewFlag); - videoOverlay.setFitsSystemWindows(true); + private void hideVideoControls(boolean showAnimation) { + if (showAnimation) { + final Animation animation = AnimationUtils.loadAnimation(this, R.anim.fade_out); + if (animation != null) { + videoOverlay.startAnimation(animation); + controls.startAnimation(animation); + } } + int videoviewFlag = (Build.VERSION.SDK_INT >= 16) ? View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION : 0; + getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_FULLSCREEN + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | videoviewFlag); + videoOverlay.setFitsSystemWindows(true); + videoOverlay.setVisibility(View.GONE); controls.setVisibility(View.GONE); } + private void hideVideoControls() { + hideVideoControls(true); + } + @Override protected int getContentViewResourceId() { return R.layout.videoplayer_activity; @@ -350,6 +373,28 @@ public class VideoplayerActivity extends MediaplayerActivity { } } + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + menu.findItem(R.id.player_go_to_picture_in_picture).setVisible(true); + } + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == R.id.player_go_to_picture_in_picture) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + getSupportActionBar().hide(); + hideVideoControls(false); + enterPictureInPictureMode(); + } + return true; + } + return super.onOptionsItemSelected(item); + } + private static class VideoControlsHider extends Handler { private static final int DELAY = 2500; @@ -362,7 +407,7 @@ public class VideoplayerActivity extends MediaplayerActivity { private final Runnable hideVideoControls = () -> { VideoplayerActivity vpa = activity != null ? activity.get() : null; - if(vpa == null) { + if (vpa == null) { return; } if (vpa.videoControlsShowing) { diff --git a/app/src/main/java/de/danoeh/antennapod/config/PlaybackServiceCallbacksImpl.java b/app/src/main/java/de/danoeh/antennapod/config/PlaybackServiceCallbacksImpl.java index 1ab60ef61..83dd3fe9c 100644 --- a/app/src/main/java/de/danoeh/antennapod/config/PlaybackServiceCallbacksImpl.java +++ b/app/src/main/java/de/danoeh/antennapod/config/PlaybackServiceCallbacksImpl.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.config; import android.content.Context; import android.content.Intent; +import android.os.Build; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.AudioplayerActivity; import de.danoeh.antennapod.activity.CastplayerActivity; @@ -18,7 +19,11 @@ public class PlaybackServiceCallbacksImpl implements PlaybackServiceCallbacks { return new Intent(context, CastplayerActivity.class); } if (mediaType == MediaType.VIDEO) { - return new Intent(context, VideoplayerActivity.class); + Intent i = new Intent(context, VideoplayerActivity.class); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + i.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); + } + return i; } else { return new Intent(context, AudioplayerActivity.class); } diff --git a/app/src/main/java/de/danoeh/antennapod/view/AspectRatioVideoView.java b/app/src/main/java/de/danoeh/antennapod/view/AspectRatioVideoView.java index f930c912a..e79389fb3 100644 --- a/app/src/main/java/de/danoeh/antennapod/view/AspectRatioVideoView.java +++ b/app/src/main/java/de/danoeh/antennapod/view/AspectRatioVideoView.java @@ -25,6 +25,8 @@ public class AspectRatioVideoView extends VideoView { private int mVideoWidth; private int mVideoHeight; + private float mAvailableWidth = -1; + private float mAvailableHeight = -1; public AspectRatioVideoView(Context context) { this(context, null); @@ -48,8 +50,13 @@ public class AspectRatioVideoView extends VideoView { return; } - float heightRatio = (float) mVideoHeight / (float) getHeight(); - float widthRatio = (float) mVideoWidth / (float) getWidth(); + if (mAvailableWidth < 0 || mAvailableHeight < 0) { + mAvailableWidth = getWidth(); + mAvailableHeight = getHeight(); + } + + float heightRatio = (float) mVideoHeight / mAvailableHeight; + float widthRatio = (float) mVideoWidth / mAvailableWidth; int scaledHeight; int scaledWidth; @@ -94,4 +101,15 @@ public class AspectRatioVideoView extends VideoView { invalidate(); } + /** + * Sets the maximum size that the view might expand to + * @param width + * @param height + */ + public void setAvailableSize(float width, float height) { + mAvailableWidth = width; + mAvailableHeight = height; + requestLayout(); + } + } diff --git a/app/src/main/res/layout/videoplayer_activity.xml b/app/src/main/res/layout/videoplayer_activity.xml index 4db663e19..10fbf8f49 100644 --- a/app/src/main/res/layout/videoplayer_activity.xml +++ b/app/src/main/res/layout/videoplayer_activity.xml @@ -3,7 +3,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/black" - android:orientation="vertical"> + android:orientation="vertical" + android:id="@+id/videoframe"> <de.danoeh.antennapod.view.AspectRatioVideoView android:id="@+id/videoview" @@ -103,6 +104,7 @@ android:layout_height="wrap_content" android:layout_toLeftOf="@+id/txtvLength" android:layout_toRightOf="@+id/txtvPosition" + android:layout_centerInParent="true" android:max="500" /> </RelativeLayout> diff --git a/app/src/main/res/menu/mediaplayer.xml b/app/src/main/res/menu/mediaplayer.xml index 530eb3400..98c7478a6 100644 --- a/app/src/main/res/menu/mediaplayer.xml +++ b/app/src/main/res/menu/mediaplayer.xml @@ -41,6 +41,14 @@ android:title="@string/visit_website_label" android:visible="false"> </item> + + <item + android:id="@+id/player_go_to_picture_in_picture" + custom:showAsAction="collapseActionView" + android:title="@string/player_go_to_picture_in_picture" + android:visible="false"> + </item> + <item android:id="@+id/share_item" android:icon="?attr/social_share" |