From f94f14ab65153b8a95c6a1eed74ff1ed91005592 Mon Sep 17 00:00:00 2001 From: Somethingweirdhere Date: Sat, 21 Apr 2018 21:11:52 +0200 Subject: [PATCH 1/3] Added settings export --- .../newpipe/player/PopupVideoPlayer.java | 13 ++- .../schabi/newpipe/player/VideoPlayer.java | 83 ++++++++++++++++++- app/src/main/res/layout/player_popup.xml | 29 +++++-- 3 files changed, 114 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java index 9528bf2bc..c9da2278b 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -44,6 +44,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; import android.widget.ImageButton; +import android.widget.ImageView; import android.widget.PopupMenu; import android.widget.RemoteViews; import android.widget.SeekBar; @@ -174,10 +175,12 @@ public final class PopupVideoPlayer extends Service { // Init //////////////////////////////////////////////////////////////////////////*/ + View rootView; + @SuppressLint("RtlHardcoded") private void initPopup() { if (DEBUG) Log.d(TAG, "initPopup() called"); - View rootView = View.inflate(this, R.layout.player_popup, null); + rootView = View.inflate(this, R.layout.player_popup, null); playerImpl.setup(rootView); shutdownFlingVelocity = PlayerHelper.getShutdownFlingVelocity(this); @@ -666,7 +669,6 @@ public final class PopupVideoPlayer extends Service { public void onPaused() { super.onPaused(); updateNotification(R.drawable.ic_play_arrow_white); - showAndAnimateControl(R.drawable.ic_play_arrow_white, false); lockManager.releaseWifiAndCpu(); } @@ -730,7 +732,12 @@ public final class PopupVideoPlayer extends Service { public boolean onSingleTapConfirmed(MotionEvent e) { if (DEBUG) Log.d(TAG, "onSingleTapConfirmed() called with: e = [" + e + "]"); if (playerImpl == null || playerImpl.getPlayer() == null) return false; - playerImpl.onPlayPause(); + if (playerImpl.isControlsVisible()) { + playerImpl.hideControls(100, 100); + } else { + playerImpl.showControlsThenHide(); + + } return true; } diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java index 6cf2076eb..239881bf1 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java @@ -40,6 +40,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.SurfaceView; import android.view.View; +import android.widget.ImageButton; import android.widget.ImageView; import android.widget.PopupMenu; import android.widget.ProgressBar; @@ -157,6 +158,8 @@ public abstract class VideoPlayer extends BasePlayer private int captionPopupMenuGroupId = 89; private PopupMenu captionPopupMenu; + private ImageButton buttonPlayPause; + /////////////////////////////////////////////////////////////////////////// public VideoPlayer(String debugTag, Context context) { @@ -211,6 +214,9 @@ public abstract class VideoPlayer extends BasePlayer ((ProgressBar) this.loadingPanel.findViewById(R.id.progressBarLoadingPanel)) .getIndeterminateDrawable().setColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY); + + buttonPlayPause = rootView.findViewById(R.id.videoPlayPause); + buttonPlayPause.setTag(1); } protected abstract void setupSubtitleView(@NonNull SubtitleView view, @@ -226,6 +232,22 @@ public abstract class VideoPlayer extends BasePlayer captionTextView.setOnClickListener(this); resizeView.setOnClickListener(this); playbackLiveSync.setOnClickListener(this); + + buttonPlayPause.setOnClickListener(new View.OnClickListener() { + + public void onClick(View ib) { + if((int)ib.getTag()==2) { + onPlay(); + ib.setBackgroundResource(R.drawable.ic_pause_white); + ib.setTag(1); + } else { + ib.setBackgroundResource(R.drawable.ic_play_arrow_white); + onPause(); + ib.setTag(2); + } + + } + }); } @Override @@ -864,18 +886,68 @@ public abstract class VideoPlayer extends BasePlayer controlViewAnimator.start(); } + public void showPlayPause(final int drawableId) { + if (DEBUG) Log.d(TAG, "showAndAnimateControl() called with: drawableId = [" + drawableId + "], goneOnEnd = [" + false + "]"); + if (controlViewAnimator != null && controlViewAnimator.isRunning()) { + if (DEBUG) Log.d(TAG, "showAndAnimateControl: controlViewAnimator.isRunning"); + controlViewAnimator.end(); + } + + if (drawableId == -1) { + if (controlAnimationView.getVisibility() == View.VISIBLE) { + controlViewAnimator = ObjectAnimator.ofPropertyValuesHolder(controlAnimationView, + PropertyValuesHolder.ofFloat(View.ALPHA, 1f, 0f), + PropertyValuesHolder.ofFloat(View.SCALE_X, 1.4f, 1f), + PropertyValuesHolder.ofFloat(View.SCALE_Y, 1.4f, 1f) + ).setDuration(DEFAULT_CONTROLS_DURATION); + controlViewAnimator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + controlAnimationView.setVisibility(View.GONE); + } + }); + controlViewAnimator.start(); + } + return; + } + + float scaleFrom = 1f, scaleTo = 1.4f; + float alphaFrom = 0f, alphaTo = 1f; + + + controlViewAnimator = ObjectAnimator.ofPropertyValuesHolder(controlAnimationView, + PropertyValuesHolder.ofFloat(View.ALPHA, alphaFrom, alphaTo), + PropertyValuesHolder.ofFloat(View.SCALE_X, scaleFrom, scaleTo), + PropertyValuesHolder.ofFloat(View.SCALE_Y, scaleFrom, scaleTo) + ); + controlViewAnimator.setDuration(500); + controlViewAnimator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + controlAnimationView.setVisibility(View.VISIBLE); + } + }); + + + controlAnimationView.setVisibility(View.VISIBLE); + controlAnimationView.setImageDrawable(ContextCompat.getDrawable(context, drawableId)); + controlViewAnimator.start(); + } + public boolean isSomePopupMenuVisible() { return isSomePopupMenuVisible; } public void showControlsThenHide() { if (DEBUG) Log.d(TAG, "showControlsThenHide() called"); + buttonPlayPause.setVisibility(View.VISIBLE); animateView(controlsRoot, true, DEFAULT_CONTROLS_DURATION, 0, () -> hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME)); } public void showControls(long duration) { if (DEBUG) Log.d(TAG, "showControls() called"); + buttonPlayPause.setVisibility(View.VISIBLE); controlsVisibilityHandler.removeCallbacksAndMessages(null); animateView(controlsRoot, true, duration); } @@ -883,8 +955,15 @@ public abstract class VideoPlayer extends BasePlayer public void hideControls(final long duration, long delay) { if (DEBUG) Log.d(TAG, "hideControls() called with: delay = [" + delay + "]"); controlsVisibilityHandler.removeCallbacksAndMessages(null); - controlsVisibilityHandler.postDelayed( - () -> animateView(controlsRoot, false, duration), delay); + controlsVisibilityHandler.postDelayed(hideControlsHandler(duration), delay); + } + + private Runnable hideControlsHandler(long duration) + { + return () -> { + buttonPlayPause.setVisibility(View.INVISIBLE); + animateView(controlsRoot, false,duration); + }; } /*////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/res/layout/player_popup.xml b/app/src/main/res/layout/player_popup.xml index 5e8ed664e..e17e7670c 100644 --- a/app/src/main/res/layout/player_popup.xml +++ b/app/src/main/res/layout/player_popup.xml @@ -1,6 +1,7 @@ + tools:text="FIT" /> + tools:ignore="ContentDescription,RtlHardcoded" /> + @@ -216,6 +218,21 @@ android:weightSum="5.5"> + + Date: Sun, 22 Apr 2018 00:16:07 +0200 Subject: [PATCH 2/3] PopUpPlayer now has a play and pause button. Tapping now doesnt pause or unpause the video and instead shows this button. --- .../newpipe/player/PopupVideoPlayer.java | 35 +++++++- .../schabi/newpipe/player/VideoPlayer.java | 86 +++---------------- app/src/main/res/layout/player_popup.xml | 36 ++++---- 3 files changed, 61 insertions(+), 96 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java index c9da2278b..d42585e00 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -175,12 +175,10 @@ public final class PopupVideoPlayer extends Service { // Init //////////////////////////////////////////////////////////////////////////*/ - View rootView; - @SuppressLint("RtlHardcoded") private void initPopup() { if (DEBUG) Log.d(TAG, "initPopup() called"); - rootView = View.inflate(this, R.layout.player_popup, null); + View rootView = View.inflate(this, R.layout.player_popup, null); playerImpl.setup(rootView); shutdownFlingVelocity = PlayerHelper.getShutdownFlingVelocity(this); @@ -373,6 +371,7 @@ public final class PopupVideoPlayer extends Service { protected class VideoPlayerImpl extends VideoPlayer implements View.OnLayoutChangeListener { private TextView resizingIndicator; private ImageButton fullScreenButton; + private ImageView videoPlayPause; private View extraOptionsView; @@ -394,6 +393,8 @@ public final class PopupVideoPlayer extends Service { resizingIndicator = rootView.findViewById(R.id.resizing_indicator); fullScreenButton = rootView.findViewById(R.id.fullScreenButton); fullScreenButton.setOnClickListener(v -> onFullScreenButtonClicked()); + videoPlayPause = rootView.findViewById(R.id.videoPlayPause); + videoPlayPause.setOnClickListener(this::onPlayPauseButtonPressed); extraOptionsView = rootView.findViewById(R.id.extraOptionsView); rootView.addOnLayoutChangeListener(this); @@ -409,6 +410,10 @@ public final class PopupVideoPlayer extends Service { view.setStyle(captionStyle); } + private void onPlayPauseButtonPressed(View ib) { + onPlayPause(); + } + @Override public void onLayoutChange(final View view, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { @@ -654,6 +659,7 @@ public final class PopupVideoPlayer extends Service { public void onPlaying() { super.onPlaying(); updateNotification(R.drawable.ic_pause_white); + videoPlayPause.setBackgroundResource(R.drawable.ic_pause_white); lockManager.acquireWifiAndCpu(); hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME); @@ -669,12 +675,14 @@ public final class PopupVideoPlayer extends Service { public void onPaused() { super.onPaused(); updateNotification(R.drawable.ic_play_arrow_white); + videoPlayPause.setBackgroundResource(R.drawable.ic_play_arrow_white); lockManager.releaseWifiAndCpu(); } @Override public void onPausedSeek() { super.onPausedSeek(); + videoPlayPause.setBackgroundResource(R.drawable.ic_pause_white); updateNotification(R.drawable.ic_play_arrow_white); } @@ -682,10 +690,27 @@ public final class PopupVideoPlayer extends Service { public void onCompleted() { super.onCompleted(); updateNotification(R.drawable.ic_replay_white); - showAndAnimateControl(R.drawable.ic_replay_white, false); + videoPlayPause.setBackgroundResource(R.drawable.ic_replay_white); lockManager.releaseWifiAndCpu(); } + @Override + public void showControlsThenHide() { + videoPlayPause.setVisibility(View.VISIBLE); + super.showControlsThenHide(); + } + + public void showControls(long duration) { + videoPlayPause.setVisibility(View.VISIBLE); + super.showControls(duration); + } + + public void hideControls(final long duration, long delay) { + super.hideControlsAndButton(duration, delay, videoPlayPause); + } + + + /*////////////////////////////////////////////////////////////////////////// // Utils //////////////////////////////////////////////////////////////////////////*/ @@ -719,6 +744,8 @@ public final class PopupVideoPlayer extends Service { Log.d(TAG, "onDoubleTap() called with: e = [" + e + "]" + "rawXy = " + e.getRawX() + ", " + e.getRawY() + ", xy = " + e.getX() + ", " + e.getY()); if (playerImpl == null || !playerImpl.isPlaying()) return false; + playerImpl.hideControls(0, 0); + if (e.getX() > popupWidth / 2) { playerImpl.onFastForward(); } else { diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java index 239881bf1..73590e049 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java @@ -40,7 +40,6 @@ import android.view.Menu; import android.view.MenuItem; import android.view.SurfaceView; import android.view.View; -import android.widget.ImageButton; import android.widget.ImageView; import android.widget.PopupMenu; import android.widget.ProgressBar; @@ -158,8 +157,6 @@ public abstract class VideoPlayer extends BasePlayer private int captionPopupMenuGroupId = 89; private PopupMenu captionPopupMenu; - private ImageButton buttonPlayPause; - /////////////////////////////////////////////////////////////////////////// public VideoPlayer(String debugTag, Context context) { @@ -214,9 +211,6 @@ public abstract class VideoPlayer extends BasePlayer ((ProgressBar) this.loadingPanel.findViewById(R.id.progressBarLoadingPanel)) .getIndeterminateDrawable().setColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY); - - buttonPlayPause = rootView.findViewById(R.id.videoPlayPause); - buttonPlayPause.setTag(1); } protected abstract void setupSubtitleView(@NonNull SubtitleView view, @@ -232,22 +226,6 @@ public abstract class VideoPlayer extends BasePlayer captionTextView.setOnClickListener(this); resizeView.setOnClickListener(this); playbackLiveSync.setOnClickListener(this); - - buttonPlayPause.setOnClickListener(new View.OnClickListener() { - - public void onClick(View ib) { - if((int)ib.getTag()==2) { - onPlay(); - ib.setBackgroundResource(R.drawable.ic_pause_white); - ib.setTag(1); - } else { - ib.setBackgroundResource(R.drawable.ic_play_arrow_white); - onPause(); - ib.setTag(2); - } - - } - }); } @Override @@ -886,68 +864,18 @@ public abstract class VideoPlayer extends BasePlayer controlViewAnimator.start(); } - public void showPlayPause(final int drawableId) { - if (DEBUG) Log.d(TAG, "showAndAnimateControl() called with: drawableId = [" + drawableId + "], goneOnEnd = [" + false + "]"); - if (controlViewAnimator != null && controlViewAnimator.isRunning()) { - if (DEBUG) Log.d(TAG, "showAndAnimateControl: controlViewAnimator.isRunning"); - controlViewAnimator.end(); - } - - if (drawableId == -1) { - if (controlAnimationView.getVisibility() == View.VISIBLE) { - controlViewAnimator = ObjectAnimator.ofPropertyValuesHolder(controlAnimationView, - PropertyValuesHolder.ofFloat(View.ALPHA, 1f, 0f), - PropertyValuesHolder.ofFloat(View.SCALE_X, 1.4f, 1f), - PropertyValuesHolder.ofFloat(View.SCALE_Y, 1.4f, 1f) - ).setDuration(DEFAULT_CONTROLS_DURATION); - controlViewAnimator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - controlAnimationView.setVisibility(View.GONE); - } - }); - controlViewAnimator.start(); - } - return; - } - - float scaleFrom = 1f, scaleTo = 1.4f; - float alphaFrom = 0f, alphaTo = 1f; - - - controlViewAnimator = ObjectAnimator.ofPropertyValuesHolder(controlAnimationView, - PropertyValuesHolder.ofFloat(View.ALPHA, alphaFrom, alphaTo), - PropertyValuesHolder.ofFloat(View.SCALE_X, scaleFrom, scaleTo), - PropertyValuesHolder.ofFloat(View.SCALE_Y, scaleFrom, scaleTo) - ); - controlViewAnimator.setDuration(500); - controlViewAnimator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - controlAnimationView.setVisibility(View.VISIBLE); - } - }); - - - controlAnimationView.setVisibility(View.VISIBLE); - controlAnimationView.setImageDrawable(ContextCompat.getDrawable(context, drawableId)); - controlViewAnimator.start(); - } - public boolean isSomePopupMenuVisible() { return isSomePopupMenuVisible; } public void showControlsThenHide() { if (DEBUG) Log.d(TAG, "showControlsThenHide() called"); - buttonPlayPause.setVisibility(View.VISIBLE); animateView(controlsRoot, true, DEFAULT_CONTROLS_DURATION, 0, () -> hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME)); } public void showControls(long duration) { if (DEBUG) Log.d(TAG, "showControls() called"); - buttonPlayPause.setVisibility(View.VISIBLE); controlsVisibilityHandler.removeCallbacksAndMessages(null); animateView(controlsRoot, true, duration); } @@ -955,17 +883,23 @@ public abstract class VideoPlayer extends BasePlayer public void hideControls(final long duration, long delay) { if (DEBUG) Log.d(TAG, "hideControls() called with: delay = [" + delay + "]"); controlsVisibilityHandler.removeCallbacksAndMessages(null); - controlsVisibilityHandler.postDelayed(hideControlsHandler(duration), delay); + controlsVisibilityHandler.postDelayed( + () -> animateView(controlsRoot, false, duration), delay); } - private Runnable hideControlsHandler(long duration) + public void hideControlsAndButton(final long duration, long delay, View button) { + if (DEBUG) Log.d(TAG, "hideControls() called with: delay = [" + delay + "]"); + controlsVisibilityHandler.removeCallbacksAndMessages(null); + controlsVisibilityHandler.postDelayed(hideControlsAndButtonHandler(duration, button), delay); + } + + private Runnable hideControlsAndButtonHandler(long duration, View videoPlayPause) { return () -> { - buttonPlayPause.setVisibility(View.INVISIBLE); + videoPlayPause.setVisibility(View.INVISIBLE); animateView(controlsRoot, false,duration); }; } - /*////////////////////////////////////////////////////////////////////////// // Getters and Setters //////////////////////////////////////////////////////////////////////////*/ diff --git a/app/src/main/res/layout/player_popup.xml b/app/src/main/res/layout/player_popup.xml index e17e7670c..89effe7dd 100644 --- a/app/src/main/res/layout/player_popup.xml +++ b/app/src/main/res/layout/player_popup.xml @@ -1,7 +1,6 @@ - - + + + + + + + Date: Wed, 2 May 2018 22:08:14 +0200 Subject: [PATCH 3/3] Now the play/pause button also has the correct scale! --- app/src/main/res/layout/player_popup.xml | 30 ++++++++---------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/app/src/main/res/layout/player_popup.xml b/app/src/main/res/layout/player_popup.xml index 89effe7dd..f866cf002 100644 --- a/app/src/main/res/layout/player_popup.xml +++ b/app/src/main/res/layout/player_popup.xml @@ -53,6 +53,16 @@ android:visibility="gone" tools:visibility="visible"> + + - - - - - - -