-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
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;
}
}

View File

@ -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;
}
}

View File

@ -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
//////////////////////////////////////////////////////////////////////////*/