Commit ab348c04 by Oliver Woodman

Merge pull request #7568 from juankysoriano:subtitles-font-size-bug

PiperOrigin-RevId: 319223173
parents 729ec8a1 5c096acc
...@@ -135,6 +135,8 @@ ...@@ -135,6 +135,8 @@
([#7475](https://github.com/google/ExoPlayer/issues/7475)). ([#7475](https://github.com/google/ExoPlayer/issues/7475)).
* Redefine `Cue.lineType=LINE_TYPE_NUMBER` in terms of aligning the cue * Redefine `Cue.lineType=LINE_TYPE_NUMBER` in terms of aligning the cue
text lines to grid of viewport lines, and ignore `Cue.lineAnchor`. text lines to grid of viewport lines, and ignore `Cue.lineAnchor`.
* Check `CaptionManager.isEnabled()` before using it for user-specified
font-scaling.
* DRM: * DRM:
* Add support for attaching DRM sessions to clear content in the demo app. * Add support for attaching DRM sessions to clear content in the demo app.
* Remove `DrmSessionManager` references from all renderers. * Remove `DrmSessionManager` references from all renderers.
......
...@@ -34,7 +34,6 @@ import android.widget.FrameLayout; ...@@ -34,7 +34,6 @@ import android.widget.FrameLayout;
import androidx.annotation.Dimension; import androidx.annotation.Dimension;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.google.android.exoplayer2.text.CaptionStyleCompat; import com.google.android.exoplayer2.text.CaptionStyleCompat;
import com.google.android.exoplayer2.text.Cue; import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.TextOutput; import com.google.android.exoplayer2.text.TextOutput;
...@@ -225,12 +224,13 @@ public final class SubtitleView extends FrameLayout implements TextOutput { ...@@ -225,12 +224,13 @@ public final class SubtitleView extends FrameLayout implements TextOutput {
} }
/** /**
* Sets the text size to one derived from {@link CaptioningManager#getFontScale()}, or to a * Sets the text size based on {@link CaptioningManager#getFontScale()} if {@link
* default size before API level 19. * CaptioningManager} is available and enabled.
*
* <p>Otherwise (and always before API level 19) uses a default font scale of 1.0.
*/ */
public void setUserDefaultTextSize() { public void setUserDefaultTextSize() {
float fontScale = Util.SDK_INT >= 19 && !isInEditMode() ? getUserCaptionFontScaleV19() : 1f; setFractionalTextSize(DEFAULT_TEXT_SIZE_FRACTION * getUserCaptionFontScale());
setFractionalTextSize(DEFAULT_TEXT_SIZE_FRACTION * fontScale);
} }
/** /**
...@@ -291,14 +291,13 @@ public final class SubtitleView extends FrameLayout implements TextOutput { ...@@ -291,14 +291,13 @@ public final class SubtitleView extends FrameLayout implements TextOutput {
} }
/** /**
* Sets the caption style to be equivalent to the one returned by * Styles the captions using {@link CaptioningManager#getUserStyle()} if {@link CaptioningManager}
* {@link CaptioningManager#getUserStyle()}, or to a default style before API level 19. * is available and enabled.
*
* <p>Otherwise (and always before API level 19) uses a default style.
*/ */
public void setUserDefaultStyle() { public void setUserDefaultStyle() {
setStyle( setStyle(getUserCaptionStyle());
Util.SDK_INT >= 19 && isCaptionManagerEnabled() && !isInEditMode()
? getUserCaptionStyleV19()
: CaptionStyleCompat.DEFAULT);
} }
/** /**
...@@ -325,30 +324,28 @@ public final class SubtitleView extends FrameLayout implements TextOutput { ...@@ -325,30 +324,28 @@ public final class SubtitleView extends FrameLayout implements TextOutput {
updateOutput(); updateOutput();
} }
@RequiresApi(19) private float getUserCaptionFontScale() {
private boolean isCaptionManagerEnabled() { if (Util.SDK_INT < 19 || isInEditMode()) {
@Nullable return 1f;
CaptioningManager captioningManager = }
(CaptioningManager) getContext().getSystemService(Context.CAPTIONING_SERVICE);
return captioningManager != null && captioningManager.isEnabled();
}
@RequiresApi(19)
private float getUserCaptionFontScaleV19() {
@Nullable @Nullable
CaptioningManager captioningManager = CaptioningManager captioningManager =
(CaptioningManager) getContext().getSystemService(Context.CAPTIONING_SERVICE); (CaptioningManager) getContext().getSystemService(Context.CAPTIONING_SERVICE);
return captioningManager == null ? 1f : captioningManager.getFontScale(); return captioningManager != null && captioningManager.isEnabled()
? captioningManager.getFontScale()
: 1f;
} }
@RequiresApi(19) private CaptionStyleCompat getUserCaptionStyle() {
private CaptionStyleCompat getUserCaptionStyleV19() { if (Util.SDK_INT < 19 || isInEditMode()) {
return CaptionStyleCompat.DEFAULT;
}
@Nullable @Nullable
CaptioningManager captioningManager = CaptioningManager captioningManager =
(CaptioningManager) getContext().getSystemService(Context.CAPTIONING_SERVICE); (CaptioningManager) getContext().getSystemService(Context.CAPTIONING_SERVICE);
return captioningManager == null return captioningManager != null && captioningManager.isEnabled()
? CaptionStyleCompat.DEFAULT ? CaptionStyleCompat.createFromCaptionStyle(captioningManager.getUserStyle())
: CaptionStyleCompat.createFromCaptionStyle(captioningManager.getUserStyle()); : CaptionStyleCompat.DEFAULT;
} }
private void updateOutput() { private void updateOutput() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment