From a5312c1341c9cf3a6edd350955a2b8a63ad09a0b Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Tue, 15 Sep 2020 19:50:46 +0300 Subject: [PATCH] Perfect shadow --- .../fragments/detail/VideoDetailFragment.java | 4 +-- .../schabi/newpipe/player/VideoPlayer.java | 24 +++++++++++----- .../newpipe/player/VideoPlayerImpl.java | 19 ++++++------- app/src/main/res/layout-large-land/player.xml | 28 +++++++++++-------- app/src/main/res/layout/player.xml | 28 +++++++++++-------- 5 files changed, 59 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 6ab9d8995..bbb30f818 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -17,7 +17,6 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; -import androidx.core.app.ActivityCompat; import androidx.core.text.HtmlCompat; import androidx.preference.PreferenceManager; import android.provider.Settings; @@ -2040,8 +2039,7 @@ public class VideoDetailFragment if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && (isInMultiWindow() || (player != null && player.isFullscreen()))) { activity.getWindow().setStatusBarColor(Color.TRANSPARENT); - activity.getWindow().setNavigationBarColor( - ActivityCompat.getColor(activity, R.color.video_overlay_color)); + activity.getWindow().setNavigationBarColor(Color.TRANSPARENT); } activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); } 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 a5a53f7a9..46ab57786 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java @@ -128,6 +128,8 @@ public abstract class VideoPlayer extends BasePlayer private View controlsRoot; private TextView currentDisplaySeek; + private View playerTopShadow; + private View playerBottomShadow; private View bottomControlsRoot; private SeekBar playbackSeekBar; @@ -190,6 +192,8 @@ public abstract class VideoPlayer extends BasePlayer this.controlAnimationView = view.findViewById(R.id.controlAnimationView); this.controlsRoot = view.findViewById(R.id.playbackControlRoot); this.currentDisplaySeek = view.findViewById(R.id.currentDisplaySeek); + this.playerTopShadow = view.findViewById(R.id.playerTopShadow); + this.playerBottomShadow = view.findViewById(R.id.playerBottomShadow); this.playbackSeekBar = view.findViewById(R.id.playbackSeekBar); this.playbackCurrentTime = view.findViewById(R.id.playbackCurrentTime); this.playbackEndTime = view.findViewById(R.id.playbackEndTime); @@ -359,8 +363,8 @@ public abstract class VideoPlayer extends BasePlayer if (userPreferredLanguage != null && (captionLanguage.equals(userPreferredLanguage) || searchForAutogenerated && captionLanguage.startsWith(userPreferredLanguage) || userPreferredLanguage.contains("(") && captionLanguage.startsWith( - userPreferredLanguage - .substring(0, userPreferredLanguage.indexOf('('))))) { + userPreferredLanguage + .substring(0, userPreferredLanguage.indexOf('('))))) { final int textRendererIndex = getRendererIndex(C.TRACK_TYPE_TEXT); if (textRendererIndex != RENDERER_UNAVAILABLE) { trackSelector.setPreferredTextLanguage(captionLanguage); @@ -754,7 +758,6 @@ public abstract class VideoPlayer extends BasePlayer } qualityPopupMenu.show(); isSomePopupMenuVisible = true; - showControls(DEFAULT_CONTROLS_DURATION); final VideoStream videoStream = getSelectedVideoStream(); if (videoStream != null) { @@ -772,7 +775,6 @@ public abstract class VideoPlayer extends BasePlayer } playbackSpeedPopupMenu.show(); isSomePopupMenuVisible = true; - showControls(DEFAULT_CONTROLS_DURATION); } private void onCaptionClicked() { @@ -781,7 +783,6 @@ public abstract class VideoPlayer extends BasePlayer } captionPopupMenu.show(); isSomePopupMenuVisible = true; - showControls(DEFAULT_CONTROLS_DURATION); } void onResizeClicked() { @@ -958,6 +959,7 @@ public abstract class VideoPlayer extends BasePlayer ? DEFAULT_CONTROLS_HIDE_TIME : DPAD_CONTROLS_HIDE_TIME; + showHideShadow(true, DEFAULT_CONTROLS_DURATION, 0); animateView(controlsRoot, true, DEFAULT_CONTROLS_DURATION, 0, () -> hideControls(DEFAULT_CONTROLS_DURATION, hideTime)); } @@ -967,6 +969,7 @@ public abstract class VideoPlayer extends BasePlayer Log.d(TAG, "showControls() called"); } controlsVisibilityHandler.removeCallbacksAndMessages(null); + showHideShadow(true, duration, 0); animateView(controlsRoot, true, duration); } @@ -986,8 +989,10 @@ public abstract class VideoPlayer extends BasePlayer Log.d(TAG, "hideControls() called with: delay = [" + delay + "]"); } controlsVisibilityHandler.removeCallbacksAndMessages(null); - controlsVisibilityHandler.postDelayed(() -> - animateView(controlsRoot, false, duration), delay); + controlsVisibilityHandler.postDelayed(() -> { + showHideShadow(false, duration, 0); + animateView(controlsRoot, false, duration); + }, delay); } public void hideControlsAndButton(final long duration, final long delay, final View button) { @@ -1006,6 +1011,11 @@ public abstract class VideoPlayer extends BasePlayer }; } + void showHideShadow(final boolean show, final long duration, final long delay) { + animateView(playerTopShadow, show, duration, delay, null); + animateView(playerBottomShadow, show, duration, delay, null); + } + public abstract void hideSystemUIIfNeeded(); /*////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java index 40d4a9cd4..c131ed96b 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java @@ -27,13 +27,12 @@ import android.content.IntentFilter; import android.content.SharedPreferences; import android.database.ContentObserver; import android.graphics.Bitmap; +import android.graphics.Color; import android.graphics.PixelFormat; import android.net.Uri; import android.os.Build; import android.os.Handler; import android.view.DisplayCutout; -import androidx.annotation.ColorInt; -import androidx.core.app.ActivityCompat; import androidx.preference.PreferenceManager; import android.provider.Settings; import android.util.DisplayMetrics; @@ -813,6 +812,7 @@ public class VideoPlayerImpl extends VideoPlayer if (getCurrentState() != STATE_COMPLETED) { getControlsVisibilityHandler().removeCallbacksAndMessages(null); + showHideShadow(true, DEFAULT_CONTROLS_DURATION, 0); animateView(getControlsRoot(), true, DEFAULT_CONTROLS_DURATION, 0, () -> { if (getCurrentState() == STATE_PLAYING && !isSomePopupMenuVisible()) { if (v.getId() == playPauseButton.getId()) { @@ -842,7 +842,7 @@ public class VideoPlayerImpl extends VideoPlayer buildQueue(); updatePlaybackButtons(); - getControlsRoot().setVisibility(View.INVISIBLE); + hideControls(0, 0); queueLayout.requestFocus(); animateView(queueLayout, SLIDE_AND_ALPHA, true, DEFAULT_CONTROLS_DURATION); @@ -1436,9 +1436,10 @@ public class VideoPlayerImpl extends VideoPlayer showOrHideButtons(); getControlsVisibilityHandler().removeCallbacksAndMessages(null); - getControlsVisibilityHandler().postDelayed(() -> - animateView(getControlsRoot(), false, duration, 0, - this::hideSystemUIIfNeeded), delay + getControlsVisibilityHandler().postDelayed(() -> { + showHideShadow(false, duration, 0); + animateView(getControlsRoot(), false, duration, 0, this::hideSystemUIIfNeeded); + }, delay ); } @@ -1469,10 +1470,8 @@ public class VideoPlayerImpl extends VideoPlayer final AppCompatActivity activity = getParentActivity(); if (isFullscreen() && activity != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - @ColorInt final int systemUiColor = - ActivityCompat.getColor(service, R.color.video_overlay_color); - activity.getWindow().setStatusBarColor(systemUiColor); - activity.getWindow().setNavigationBarColor(systemUiColor); + activity.getWindow().setStatusBarColor(Color.TRANSPARENT); + activity.getWindow().setNavigationBarColor(Color.TRANSPARENT); } final int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN diff --git a/app/src/main/res/layout-large-land/player.xml b/app/src/main/res/layout-large-land/player.xml index 0301e5b1f..6c500edb6 100644 --- a/app/src/main/res/layout-large-land/player.xml +++ b/app/src/main/res/layout-large-land/player.xml @@ -28,6 +28,22 @@ android:layout_centerInParent="true" android:layout_gravity="center"/> + + + + - - - - + + + + - - - -