From f09b04dce0c87b7dc4d3039e02101b8e96b460db Mon Sep 17 00:00:00 2001 From: John Zhen Mo Date: Sat, 10 Feb 2018 19:33:48 -0800 Subject: [PATCH] -Code clean up on resize switching. --- .../newpipe/player/MainVideoPlayer.java | 32 ++++++++----------- .../newpipe/player/PopupVideoPlayer.java | 17 +++------- .../schabi/newpipe/player/VideoPlayer.java | 15 +++++++-- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java index 5e19e8173..d48994d0f 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -343,19 +343,19 @@ public final class MainVideoPlayer extends Activity { @Override protected void setupSubtitleView(@NonNull SubtitleView view, @NonNull String captionSizeKey) { - final float captionRatio; + final float captionRatioInverse; if (captionSizeKey.equals(getString(R.string.smaller_caption_size_key))) { - captionRatio = 22f; + captionRatioInverse = 22f; } else if (captionSizeKey.equals(getString(R.string.larger_caption_size_key))) { - captionRatio = 18f; + captionRatioInverse = 18f; } else { - captionRatio = 20f; + captionRatioInverse = 20f; } final DisplayMetrics metrics = context.getResources().getDisplayMetrics(); final int minimumLength = Math.min(metrics.heightPixels, metrics.widthPixels); view.setFixedTextSize(TypedValue.COMPLEX_UNIT_PX, - (float) minimumLength / captionRatio); + (float) minimumLength / captionRatioInverse); } @Override @@ -570,20 +570,14 @@ public final class MainVideoPlayer extends Activity { } @Override - protected void onResizeClicked() { - if (getAspectRatioFrameLayout() != null && context != null) { - final int currentResizeMode = getAspectRatioFrameLayout().getResizeMode(); - final int newResizeMode; - if (currentResizeMode == AspectRatioFrameLayout.RESIZE_MODE_FIT) { - newResizeMode = AspectRatioFrameLayout.RESIZE_MODE_FILL; - } else if (currentResizeMode == AspectRatioFrameLayout.RESIZE_MODE_FILL) { - newResizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM; - } else { - newResizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT; - } - - getAspectRatioFrameLayout().setResizeMode(newResizeMode); - getResizeView().setText(PlayerHelper.resizeTypeOf(context, newResizeMode)); + protected int nextResizeMode(int currentResizeMode) { + switch (currentResizeMode) { + case AspectRatioFrameLayout.RESIZE_MODE_FIT: + return AspectRatioFrameLayout.RESIZE_MODE_FILL; + case AspectRatioFrameLayout.RESIZE_MODE_FILL: + return AspectRatioFrameLayout.RESIZE_MODE_ZOOM; + default: + return AspectRatioFrameLayout.RESIZE_MODE_FIT; } } 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 bda2b7aa5..f4e7a0d6a 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -469,18 +469,11 @@ public final class PopupVideoPlayer extends Service { } @Override - protected void onResizeClicked() { - if (getAspectRatioFrameLayout() != null && context != null) { - final int currentResizeMode = getAspectRatioFrameLayout().getResizeMode(); - final int newResizeMode; - if (currentResizeMode == AspectRatioFrameLayout.RESIZE_MODE_FILL) { - newResizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT; - } else { - newResizeMode = AspectRatioFrameLayout.RESIZE_MODE_FILL; - } - - getAspectRatioFrameLayout().setResizeMode(newResizeMode); - getResizeView().setText(PlayerHelper.resizeTypeOf(context, newResizeMode)); + protected int nextResizeMode(int resizeMode) { + if (resizeMode == AspectRatioFrameLayout.RESIZE_MODE_FILL) { + return AspectRatioFrameLayout.RESIZE_MODE_FIT; + } else { + return AspectRatioFrameLayout.RESIZE_MODE_FILL; } } 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 a2f5d22ae..a0bc7223f 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java @@ -519,8 +519,10 @@ public abstract class VideoPlayer extends BasePlayer String formattedPreferredLanguage = null; if (preferredLanguage != null) { for (final String language : availableLanguages) { - if (language.compareToIgnoreCase(preferredLanguage) == 0) + if (language.compareToIgnoreCase(preferredLanguage) == 0) { formattedPreferredLanguage = language; + break; + } } } @@ -685,7 +687,16 @@ public abstract class VideoPlayer extends BasePlayer showControls(300); } - protected abstract void onResizeClicked(); + private void onResizeClicked() { + if (getAspectRatioFrameLayout() != null && context != null) { + final int currentResizeMode = getAspectRatioFrameLayout().getResizeMode(); + final int newResizeMode = nextResizeMode(currentResizeMode); + getAspectRatioFrameLayout().setResizeMode(newResizeMode); + getResizeView().setText(PlayerHelper.resizeTypeOf(context, newResizeMode)); + } + } + + protected abstract int nextResizeMode(@AspectRatioFrameLayout.ResizeMode final int resizeMode); /*////////////////////////////////////////////////////////////////////////// // SeekBar Listener //////////////////////////////////////////////////////////////////////////*/