Skip to content

Commit

Permalink
MainPlayer/PopupPlayer: Use system settings for subtitle size
Browse files Browse the repository at this point in the history
This will use the exact subtitle sizes the user requested, both for
the main and the popup player. They will always be the same fraction
of the video, even if the popup player is resized.
  • Loading branch information
Thompson3142 authored and Profpatsch committed Jan 21, 2025
1 parent 70748fa commit 86203d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
10 changes: 3 additions & 7 deletions app/src/main/java/org/schabi/newpipe/player/ui/MainPlayerUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -44,6 +42,7 @@
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.exoplayer2.ui.SubtitleView;
import com.google.android.exoplayer2.video.VideoSize;

import org.schabi.newpipe.R;
Expand Down Expand Up @@ -522,11 +521,8 @@ private void showHideKodiButton() {

@Override
protected void setupSubtitleView(final float captionScale) {
final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
final int minimumLength = Math.min(metrics.heightPixels, metrics.widthPixels);
final float captionRatioInverse = 20f + 4f * (1.0f - captionScale);
binding.subtitleView.setFixedTextSize(
TypedValue.COMPLEX_UNIT_PX, minimumLength / captionRatioInverse);
binding.subtitleView.setFractionalTextSize(
SubtitleView.DEFAULT_TEXT_SIZE_FRACTION * captionScale);
}
//endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,8 @@ public void onCompleted() {

@Override
protected void setupSubtitleView(final float captionScale) {
final float captionRatio = (captionScale - 1.0f) / 5.0f + 1.0f;
binding.subtitleView.setFractionalTextSize(
SubtitleView.DEFAULT_TEXT_SIZE_FRACTION * captionRatio);
SubtitleView.DEFAULT_TEXT_SIZE_FRACTION * captionScale);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,10 @@ private void setupSubtitleView() {
binding.subtitleView.setStyle(captionStyle);
}

/**
*
* @param captionScale Value returned by {@link PlayerHelper#getCaptionScale}.
*/
protected abstract void setupSubtitleView(float captionScale);
//endregion

Expand Down

0 comments on commit 86203d6

Please sign in to comment.