-Code clean up on resize switching.

This commit is contained in:
John Zhen Mo 2018-02-10 19:33:48 -08:00
parent 59f8583895
commit f09b04dce0
3 changed files with 31 additions and 33 deletions

View File

@ -343,19 +343,19 @@ public final class MainVideoPlayer extends Activity {
@Override @Override
protected void setupSubtitleView(@NonNull SubtitleView view, protected void setupSubtitleView(@NonNull SubtitleView view,
@NonNull String captionSizeKey) { @NonNull String captionSizeKey) {
final float captionRatio; final float captionRatioInverse;
if (captionSizeKey.equals(getString(R.string.smaller_caption_size_key))) { 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))) { } else if (captionSizeKey.equals(getString(R.string.larger_caption_size_key))) {
captionRatio = 18f; captionRatioInverse = 18f;
} else { } else {
captionRatio = 20f; captionRatioInverse = 20f;
} }
final DisplayMetrics metrics = context.getResources().getDisplayMetrics(); final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
final int minimumLength = Math.min(metrics.heightPixels, metrics.widthPixels); final int minimumLength = Math.min(metrics.heightPixels, metrics.widthPixels);
view.setFixedTextSize(TypedValue.COMPLEX_UNIT_PX, view.setFixedTextSize(TypedValue.COMPLEX_UNIT_PX,
(float) minimumLength / captionRatio); (float) minimumLength / captionRatioInverse);
} }
@Override @Override
@ -570,20 +570,14 @@ public final class MainVideoPlayer extends Activity {
} }
@Override @Override
protected void onResizeClicked() { protected int nextResizeMode(int currentResizeMode) {
if (getAspectRatioFrameLayout() != null && context != null) { switch (currentResizeMode) {
final int currentResizeMode = getAspectRatioFrameLayout().getResizeMode(); case AspectRatioFrameLayout.RESIZE_MODE_FIT:
final int newResizeMode; return AspectRatioFrameLayout.RESIZE_MODE_FILL;
if (currentResizeMode == AspectRatioFrameLayout.RESIZE_MODE_FIT) { case AspectRatioFrameLayout.RESIZE_MODE_FILL:
newResizeMode = AspectRatioFrameLayout.RESIZE_MODE_FILL; return AspectRatioFrameLayout.RESIZE_MODE_ZOOM;
} else if (currentResizeMode == AspectRatioFrameLayout.RESIZE_MODE_FILL) { default:
newResizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM; return AspectRatioFrameLayout.RESIZE_MODE_FIT;
} else {
newResizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT;
}
getAspectRatioFrameLayout().setResizeMode(newResizeMode);
getResizeView().setText(PlayerHelper.resizeTypeOf(context, newResizeMode));
} }
} }

View File

@ -469,18 +469,11 @@ public final class PopupVideoPlayer extends Service {
} }
@Override @Override
protected void onResizeClicked() { protected int nextResizeMode(int resizeMode) {
if (getAspectRatioFrameLayout() != null && context != null) { if (resizeMode == AspectRatioFrameLayout.RESIZE_MODE_FILL) {
final int currentResizeMode = getAspectRatioFrameLayout().getResizeMode(); return AspectRatioFrameLayout.RESIZE_MODE_FIT;
final int newResizeMode; } else {
if (currentResizeMode == AspectRatioFrameLayout.RESIZE_MODE_FILL) { return AspectRatioFrameLayout.RESIZE_MODE_FILL;
newResizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT;
} else {
newResizeMode = AspectRatioFrameLayout.RESIZE_MODE_FILL;
}
getAspectRatioFrameLayout().setResizeMode(newResizeMode);
getResizeView().setText(PlayerHelper.resizeTypeOf(context, newResizeMode));
} }
} }

View File

@ -519,8 +519,10 @@ public abstract class VideoPlayer extends BasePlayer
String formattedPreferredLanguage = null; String formattedPreferredLanguage = null;
if (preferredLanguage != null) { if (preferredLanguage != null) {
for (final String language : availableLanguages) { for (final String language : availableLanguages) {
if (language.compareToIgnoreCase(preferredLanguage) == 0) if (language.compareToIgnoreCase(preferredLanguage) == 0) {
formattedPreferredLanguage = language; formattedPreferredLanguage = language;
break;
}
} }
} }
@ -685,7 +687,16 @@ public abstract class VideoPlayer extends BasePlayer
showControls(300); 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 // SeekBar Listener
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/