package androidx.media3.ui;

import android.content.Context;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.util.AttributeSet;
import android.view.View;
import android.view.accessibility.CaptioningManager;
import android.widget.FrameLayout;
import defpackage.C0551;
import defpackage.C0767;
import defpackage.C1437;
import defpackage.C1986;
import defpackage.C4891;
import defpackage.InterfaceC5051;
import defpackage.InterfaceC5579;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/* loaded from: classes3.dex */
public final class SubtitleView extends FrameLayout {

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public int f713;

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public View f714;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public InterfaceC5051 f715;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public boolean f716;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public C4891 f717;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public boolean f718;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public List f719;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public float f720;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public float f721;

    public SubtitleView(Context context) {
        this(context, null);
    }

    public SubtitleView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f719 = Collections.EMPTY_LIST;
        this.f717 = C4891.f18198;
        this.f721 = 0.0533f;
        this.f720 = 0.08f;
        this.f718 = true;
        this.f716 = true;
        C1437 c1437 = new C1437(context, 0);
        this.f715 = c1437;
        this.f714 = c1437;
        addView(c1437);
        this.f713 = 1;
    }

    private List<C0551> getCuesWithStylingPreferencesApplied() {
        if (this.f718 && this.f716) {
            return this.f719;
        }
        ArrayList arrayList = new ArrayList(this.f719.size());
        for (int i = 0; i < this.f719.size(); i++) {
            C0767 c0767M2346 = ((C0551) this.f719.get(i)).m2346();
            if (!this.f718) {
                c0767M2346.f3645 = false;
                CharSequence charSequence = c0767M2346.f3644;
                if (charSequence instanceof Spanned) {
                    if (!(charSequence instanceof Spannable)) {
                        c0767M2346.f3644 = SpannableString.valueOf(charSequence);
                        c0767M2346.f3648 = null;
                    }
                    CharSequence charSequence2 = c0767M2346.f3644;
                    charSequence2.getClass();
                    Spannable spannable = (Spannable) charSequence2;
                    for (Object obj : spannable.getSpans(0, spannable.length(), Object.class)) {
                        if (!(obj instanceof InterfaceC5579)) {
                            spannable.removeSpan(obj);
                        }
                    }
                }
                ᵳـᵔʤ.ᵡˎ(c0767M2346);
            } else if (!this.f716) {
                ᵳـᵔʤ.ᵡˎ(c0767M2346);
            }
            arrayList.add(c0767M2346.m2850());
        }
        return arrayList;
    }

    private float getUserCaptionFontScale() {
        CaptioningManager captioningManager;
        if (isInEditMode() || (captioningManager = (CaptioningManager) getContext().getSystemService("captioning")) == null || !captioningManager.isEnabled()) {
            return 1.0f;
        }
        return captioningManager.getFontScale();
    }

    private C4891 getUserCaptionStyle() {
        CaptioningManager captioningManager;
        boolean zIsInEditMode = isInEditMode();
        C4891 c4891 = C4891.f18198;
        if (zIsInEditMode || (captioningManager = (CaptioningManager) getContext().getSystemService("captioning")) == null || !captioningManager.isEnabled()) {
            return c4891;
        }
        CaptioningManager.CaptionStyle userStyle = captioningManager.getUserStyle();
        return new C4891(userStyle.hasForegroundColor() ? userStyle.foregroundColor : -1, userStyle.hasBackgroundColor() ? userStyle.backgroundColor : -16777216, userStyle.hasWindowColor() ? userStyle.windowColor : 0, userStyle.hasEdgeType() ? userStyle.edgeType : 0, userStyle.hasEdgeColor() ? userStyle.edgeColor : -1, userStyle.getTypeface());
    }

    private <T extends View & InterfaceC5051> void setView(T t) {
        removeView(this.f714);
        View view = this.f714;
        if (view instanceof C1986) {
            ((C1986) view).f7990.destroy();
        }
        this.f714 = t;
        this.f715 = t;
        addView(t);
    }

    public void setApplyEmbeddedFontSizes(boolean z) {
        this.f716 = z;
        m421();
    }

    public void setApplyEmbeddedStyles(boolean z) {
        this.f718 = z;
        m421();
    }

    public void setBottomPaddingFraction(float f) {
        this.f720 = f;
        m421();
    }

    public void setCues(List<C0551> list) {
        if (list == null) {
            list = Collections.EMPTY_LIST;
        }
        this.f719 = list;
        m421();
    }

    public void setFractionalTextSize(float f) {
        this.f721 = f;
        m421();
    }

    public void setStyle(C4891 c4891) {
        this.f717 = c4891;
        m421();
    }

    public void setViewType(int i) {
        if (this.f713 == i) {
            return;
        }
        if (i == 1) {
            setView(new C1437(getContext(), 0));
        } else {
            if (i != 2) {
                ᵨᴵᵺ.ᵻᵢﹳᵰ();
                return;
            }
            setView(new C1986(getContext()));
        }
        this.f713 = i;
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final void m421() {
        this.f715.mo4340(getCuesWithStylingPreferencesApplied(), this.f717, this.f721, this.f720);
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final void m422() {
        setStyle(getUserCaptionStyle());
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final void m423() {
        setFractionalTextSize(getUserCaptionFontScale() * 0.0533f);
    }
}
