- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
136 lines
5.9 KiB
Java
136 lines
5.9 KiB
Java
package com.google.android.exoplayer2.ui;
|
|
|
|
import android.content.Context;
|
|
import android.util.AttributeSet;
|
|
import android.util.Base64;
|
|
import android.view.MotionEvent;
|
|
import android.webkit.WebView;
|
|
import android.widget.FrameLayout;
|
|
import androidx.annotation.Nullable;
|
|
import com.amazonaws.handlers.HandlerChainFactory$$ExternalSyntheticThrowCCEIfNotNull0;
|
|
import com.google.android.exoplayer2.ui.SubtitleView;
|
|
import com.google.android.exoplayer2.util.Util;
|
|
import com.google.common.base.Charsets;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes2.dex */
|
|
final class WebViewSubtitleOutput extends FrameLayout implements SubtitleView.Output {
|
|
public float bottomPaddingFraction;
|
|
public final CanvasSubtitleOutput canvasSubtitleOutput;
|
|
public float defaultTextSize;
|
|
public int defaultTextSizeType;
|
|
public CaptionStyleCompat style;
|
|
public List textCues;
|
|
public final WebView webView;
|
|
|
|
public WebViewSubtitleOutput(Context context) {
|
|
this(context, null);
|
|
}
|
|
|
|
public WebViewSubtitleOutput(Context context, @Nullable AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
this.textCues = Collections.emptyList();
|
|
this.style = CaptionStyleCompat.DEFAULT;
|
|
this.defaultTextSize = 0.0533f;
|
|
this.defaultTextSizeType = 0;
|
|
this.bottomPaddingFraction = 0.08f;
|
|
CanvasSubtitleOutput canvasSubtitleOutput = new CanvasSubtitleOutput(context, attributeSet);
|
|
this.canvasSubtitleOutput = canvasSubtitleOutput;
|
|
WebView webView = new WebView(this, context, attributeSet) { // from class: com.google.android.exoplayer2.ui.WebViewSubtitleOutput.1
|
|
@Override // android.webkit.WebView, android.view.View
|
|
public boolean onTouchEvent(MotionEvent motionEvent) {
|
|
super.onTouchEvent(motionEvent);
|
|
return false;
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public boolean performClick() {
|
|
super.performClick();
|
|
return false;
|
|
}
|
|
};
|
|
this.webView = webView;
|
|
webView.setBackgroundColor(0);
|
|
addView(canvasSubtitleOutput);
|
|
addView(webView);
|
|
}
|
|
|
|
@Override // com.google.android.exoplayer2.ui.SubtitleView.Output
|
|
public void update(List list, CaptionStyleCompat captionStyleCompat, float f, int i, float f2) {
|
|
this.style = captionStyleCompat;
|
|
this.defaultTextSize = f;
|
|
this.defaultTextSizeType = i;
|
|
this.bottomPaddingFraction = f2;
|
|
ArrayList arrayList = new ArrayList();
|
|
ArrayList arrayList2 = new ArrayList();
|
|
if (list.size() > 0) {
|
|
HandlerChainFactory$$ExternalSyntheticThrowCCEIfNotNull0.m(list.get(0));
|
|
throw null;
|
|
}
|
|
if (!this.textCues.isEmpty() || !arrayList2.isEmpty()) {
|
|
this.textCues = arrayList2;
|
|
updateWebView();
|
|
}
|
|
this.canvasSubtitleOutput.update(arrayList, captionStyleCompat, f, i, f2);
|
|
invalidate();
|
|
}
|
|
|
|
@Override // android.widget.FrameLayout, android.view.ViewGroup, android.view.View
|
|
public void onLayout(boolean z, int i, int i2, int i3, int i4) {
|
|
super.onLayout(z, i, i2, i3, i4);
|
|
if (!z || this.textCues.isEmpty()) {
|
|
return;
|
|
}
|
|
updateWebView();
|
|
}
|
|
|
|
public void destroy() {
|
|
this.webView.destroy();
|
|
}
|
|
|
|
public final void updateWebView() {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append(Util.formatInvariant("<body><div style='-webkit-user-select:none;position:fixed;top:0;bottom:0;left:0;right:0;color:%s;font-size:%s;line-height:%.2f;text-shadow:%s;'>", HtmlUtils.toCssRgba(this.style.foregroundColor), convertTextSizeToCss(this.defaultTextSizeType, this.defaultTextSize), Float.valueOf(1.2f), convertCaptionStyleToCssTextShadow(this.style)));
|
|
HashMap hashMap = new HashMap();
|
|
hashMap.put(HtmlUtils.cssAllClassDescendantsSelector("default_bg"), Util.formatInvariant("background-color:%s;", HtmlUtils.toCssRgba(this.style.backgroundColor)));
|
|
if (this.textCues.size() > 0) {
|
|
HandlerChainFactory$$ExternalSyntheticThrowCCEIfNotNull0.m(this.textCues.get(0));
|
|
throw null;
|
|
}
|
|
sb.append("</div></body></html>");
|
|
StringBuilder sb2 = new StringBuilder();
|
|
sb2.append("<html><head><style>");
|
|
for (String str : hashMap.keySet()) {
|
|
sb2.append(str);
|
|
sb2.append("{");
|
|
sb2.append((String) hashMap.get(str));
|
|
sb2.append("}");
|
|
}
|
|
sb2.append("</style></head>");
|
|
sb.insert(0, sb2.toString());
|
|
this.webView.loadData(Base64.encodeToString(sb.toString().getBytes(Charsets.UTF_8), 1), "text/html", "base64");
|
|
}
|
|
|
|
public final String convertTextSizeToCss(int i, float f) {
|
|
float resolveTextSize = SubtitleViewUtils.resolveTextSize(i, f, getHeight(), (getHeight() - getPaddingTop()) - getPaddingBottom());
|
|
return resolveTextSize == -3.4028235E38f ? "unset" : Util.formatInvariant("%.2fpx", Float.valueOf(resolveTextSize / getContext().getResources().getDisplayMetrics().density));
|
|
}
|
|
|
|
public static String convertCaptionStyleToCssTextShadow(CaptionStyleCompat captionStyleCompat) {
|
|
int i = captionStyleCompat.edgeType;
|
|
if (i == 1) {
|
|
return Util.formatInvariant("1px 1px 0 %1$s, 1px -1px 0 %1$s, -1px 1px 0 %1$s, -1px -1px 0 %1$s", HtmlUtils.toCssRgba(captionStyleCompat.edgeColor));
|
|
}
|
|
if (i == 2) {
|
|
return Util.formatInvariant("0.1em 0.12em 0.15em %s", HtmlUtils.toCssRgba(captionStyleCompat.edgeColor));
|
|
}
|
|
if (i != 3) {
|
|
return i != 4 ? "unset" : Util.formatInvariant("-0.05em -0.05em 0.15em %s", HtmlUtils.toCssRgba(captionStyleCompat.edgeColor));
|
|
}
|
|
return Util.formatInvariant("0.06em 0.08em 0.15em %s", HtmlUtils.toCssRgba(captionStyleCompat.edgeColor));
|
|
}
|
|
}
|