-Added settings for managing caption font size.

This commit is contained in:
John Zhen Mo 2018-02-09 13:26:03 -08:00
parent f506fc0478
commit 59f8583895
6 changed files with 73 additions and 8 deletions

View file

@ -51,6 +51,7 @@ import android.widget.Toast;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.ui.SubtitleView;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.stream.StreamInfo;
@ -337,8 +338,24 @@ public final class MainVideoPlayer extends Activity {
channelTextView.setSelected(true);
getRootView().setKeepScreenOn(true);
getSubtitleView().setFixedTextSize(TypedValue.COMPLEX_UNIT_PX,
getCaptionSizePx(context));
}
@Override
protected void setupSubtitleView(@NonNull SubtitleView view,
@NonNull String captionSizeKey) {
final float captionRatio;
if (captionSizeKey.equals(getString(R.string.smaller_caption_size_key))) {
captionRatio = 22f;
} else if (captionSizeKey.equals(getString(R.string.larger_caption_size_key))) {
captionRatio = 18f;
} else {
captionRatio = 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);
}
@Override
@ -768,12 +785,6 @@ public final class MainVideoPlayer extends Activity {
};
}
private float getCaptionSizePx(@NonNull Context context) {
final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
final int minimumLength = Math.min(metrics.heightPixels, metrics.widthPixels);
// todo: expose size control to users
return (float) minimumLength / 20f;
}
///////////////////////////////////////////////////////////////////////////
// Getters
///////////////////////////////////////////////////////////////////////////

View file

@ -53,6 +53,7 @@ import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.ui.SubtitleView;
import org.schabi.newpipe.BuildConfig;
import org.schabi.newpipe.R;
@ -391,6 +392,18 @@ public final class PopupVideoPlayer extends Service {
rootView.addOnLayoutChangeListener(this);
}
@Override
protected void setupSubtitleView(@NonNull SubtitleView view,
@NonNull String captionSizeKey) {
float captionRatio = SubtitleView.DEFAULT_TEXT_SIZE_FRACTION;
if (captionSizeKey.equals(getString(R.string.smaller_caption_size_key))) {
captionRatio *= 0.9;
} else if (captionSizeKey.equals(getString(R.string.larger_caption_size_key))) {
captionRatio *= 1.1;
}
view.setFractionalTextSize(captionRatio);
}
@Override
public void onLayoutChange(final View view, int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) {

View file

@ -32,6 +32,7 @@ import android.graphics.PorterDuff;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
@ -183,7 +184,12 @@ public abstract class VideoPlayer extends BasePlayer
this.bottomControlsRoot = rootView.findViewById(R.id.bottomControls);
this.topControlsRoot = rootView.findViewById(R.id.topControls);
this.qualityTextView = rootView.findViewById(R.id.qualityTextView);
this.subtitleView = rootView.findViewById(R.id.subtitleView);
final String captionSizeKey = PreferenceManager.getDefaultSharedPreferences(context)
.getString(context.getString(R.string.caption_size_key),
context.getString(R.string.caption_size_default));
setupSubtitleView(subtitleView, captionSizeKey);
this.resizeView = rootView.findViewById(R.id.resizeTextView);
resizeView.setText(PlayerHelper.resizeTypeOf(context, aspectRatioFrameLayout.getResizeMode()));
@ -204,6 +210,9 @@ public abstract class VideoPlayer extends BasePlayer
.getIndeterminateDrawable().setColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY);
}
protected abstract void setupSubtitleView(@NonNull SubtitleView view,
@NonNull String captionSizeKey);
@Override
public void initListeners() {
super.initListeners();