mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
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:
parent
ba0028ca2c
commit
7214ad2d6f
2 changed files with 4 additions and 18 deletions
|
|
@ -23,8 +23,8 @@ import android.content.res.Resources;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.view.accessibility.CaptioningManager;
|
import android.view.accessibility.CaptioningManager;
|
||||||
|
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;
|
||||||
|
|
@ -39,7 +39,7 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/** A view for displaying subtitle {@link Cue}s. */
|
/** 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.
|
* The default fractional text size.
|
||||||
|
|
@ -116,13 +116,6 @@ public final class SubtitleView extends ViewGroup implements TextOutput {
|
||||||
output.onCues(cues != null ? cues : Collections.emptyList());
|
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.
|
* Set the type of {@link View} used to display subtitles.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ import android.text.Layout;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.text.CaptionStyleCompat;
|
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
|
* <p>NOTE: This is currently extremely experimental and doesn't support most {@link Cue} styling
|
||||||
* properties.
|
* properties.
|
||||||
*/
|
*/
|
||||||
/* package */ final class SubtitleWebView extends ViewGroup implements SubtitleView.Output {
|
/* package */ final class SubtitleWebView extends FrameLayout implements SubtitleView.Output {
|
||||||
|
|
||||||
private final WebView webView;
|
private final WebView webView;
|
||||||
|
|
||||||
|
|
@ -145,13 +145,6 @@ import java.util.List;
|
||||||
updateWebView();
|
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() {
|
private void updateWebView() {
|
||||||
StringBuilder html = new StringBuilder();
|
StringBuilder html = new StringBuilder();
|
||||||
html.append("<html><body>")
|
html.append("<html><body>")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue