Use FrameLayout instead of ViewGroup for Subtitle(Web)View

This is a more specific ViewGroup subclass that handles some of the
layout logic automatically. It's designed to work best with a single
child view, as used here.

PiperOrigin-RevId: 306654947
This commit is contained in:
ibaker 2020-04-15 17:05:43 +01:00 committed by Ian Baker
parent ba0028ca2c
commit 7214ad2d6f
2 changed files with 4 additions and 18 deletions

View file

@ -23,8 +23,8 @@ import android.content.res.Resources;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.CaptioningManager;
import android.widget.FrameLayout;
import androidx.annotation.Dimension;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
@ -39,7 +39,7 @@ import java.util.Collections;
import java.util.List;
/** A view for displaying subtitle {@link Cue}s. */
public final class SubtitleView extends ViewGroup implements TextOutput {
public final class SubtitleView extends FrameLayout implements TextOutput {
/**
* The default fractional text size.
@ -116,13 +116,6 @@ public final class SubtitleView extends ViewGroup implements TextOutput {
output.onCues(cues != null ? cues : Collections.emptyList());
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
if (changed) {
innerSubtitleView.layout(l, t, r, b);
}
}
/**
* Set the type of {@link View} used to display subtitles.
*

View file

@ -25,8 +25,8 @@ import android.text.Layout;
import android.util.AttributeSet;
import android.util.Base64;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.FrameLayout;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.text.CaptionStyleCompat;
@ -45,7 +45,7 @@ import java.util.List;
* <p>NOTE: This is currently extremely experimental and doesn't support most {@link Cue} styling
* properties.
*/
/* package */ final class SubtitleWebView extends ViewGroup implements SubtitleView.Output {
/* package */ final class SubtitleWebView extends FrameLayout implements SubtitleView.Output {
private final WebView webView;
@ -145,13 +145,6 @@ import java.util.List;
updateWebView();
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
if (changed) {
webView.layout(l, t, r, b);
}
}
private void updateWebView() {
StringBuilder html = new StringBuilder();
html.append("<html><body>")