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 @@ - - + + + + + + +