package pl.droidsonroids.gif;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.widget.TextView;
import java.io.IOException;

/* JADX INFO: loaded from: classes3.dex */
public class GifTextView extends TextView {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public androidx.browser.trusted.f f32012a;

    public GifTextView(Context context) {
        super(context);
    }

    private void setCompoundDrawablesVisible(boolean z10) {
        for (Drawable drawable : getCompoundDrawables()) {
            if (drawable != null) {
                drawable.setVisible(z10, false);
            }
        }
        for (Drawable drawable2 : getCompoundDrawablesRelative()) {
            if (drawable2 != null) {
                drawable2.setVisible(z10, false);
            }
        }
    }

    public final Drawable a(int i10) {
        if (i10 == 0) {
            return null;
        }
        Resources resources = getResources();
        String resourceTypeName = resources.getResourceTypeName(i10);
        if (!isInEditMode() && k.f32046a.contains(resourceTypeName)) {
            try {
                return new c(resources, i10);
            } catch (Resources.NotFoundException | IOException unused) {
            }
        }
        return resources.getDrawable(i10, getContext().getTheme());
    }

    public final void b(AttributeSet attributeSet, int i10) {
        if (attributeSet != null) {
            Drawable drawableA = a(attributeSet.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "drawableLeft", 0));
            Drawable drawableA2 = a(attributeSet.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "drawableTop", 0));
            Drawable drawableA3 = a(attributeSet.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "drawableRight", 0));
            Drawable drawableA4 = a(attributeSet.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "drawableBottom", 0));
            Drawable drawableA5 = a(attributeSet.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "drawableStart", 0));
            Drawable drawableA6 = a(attributeSet.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "drawableEnd", 0));
            if (getLayoutDirection() == 0) {
                if (drawableA5 != null) {
                    drawableA = drawableA5;
                }
                if (drawableA6 == null) {
                    drawableA6 = drawableA3;
                }
            } else {
                if (drawableA5 != null) {
                    drawableA3 = drawableA5;
                }
                if (drawableA6 == null) {
                    drawableA6 = drawableA;
                }
                drawableA = drawableA3;
            }
            setCompoundDrawablesRelativeWithIntrinsicBounds(drawableA, drawableA2, drawableA6, drawableA4);
            setBackground(a(attributeSet.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "background", 0)));
            androidx.browser.trusted.f fVar = new androidx.browser.trusted.f(this, attributeSet, i10);
            this.f32012a = fVar;
            if (fVar.f901a >= 0) {
                for (Drawable drawable : getCompoundDrawables()) {
                    k.a(drawable, this.f32012a.f901a);
                }
                for (Drawable drawable2 : getCompoundDrawablesRelative()) {
                    k.a(drawable2, this.f32012a.f901a);
                }
                k.a(getBackground(), this.f32012a.f901a);
            }
        }
        this.f32012a = new androidx.browser.trusted.f(3);
    }

    @Override // android.widget.TextView, android.view.View
    public final void onAttachedToWindow() {
        super.onAttachedToWindow();
        setCompoundDrawablesVisible(true);
    }

    @Override // android.view.View
    public final void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        setCompoundDrawablesVisible(false);
    }

    @Override // android.widget.TextView, android.view.View
    public final void onRestoreInstanceState(Parcelable parcelable) {
        if (!(parcelable instanceof i)) {
            super.onRestoreInstanceState(parcelable);
            return;
        }
        i iVar = (i) parcelable;
        super.onRestoreInstanceState(iVar.getSuperState());
        Drawable[] compoundDrawables = getCompoundDrawables();
        iVar.a(compoundDrawables[0], 0);
        iVar.a(compoundDrawables[1], 1);
        iVar.a(compoundDrawables[2], 2);
        iVar.a(compoundDrawables[3], 3);
        Drawable[] compoundDrawablesRelative = getCompoundDrawablesRelative();
        iVar.a(compoundDrawablesRelative[0], 4);
        iVar.a(compoundDrawablesRelative[2], 5);
        iVar.a(getBackground(), 6);
    }

    @Override // android.widget.TextView, android.view.View
    public final Parcelable onSaveInstanceState() {
        Drawable[] drawableArr = new Drawable[7];
        if (this.f32012a.f902b) {
            Drawable[] compoundDrawables = getCompoundDrawables();
            System.arraycopy(compoundDrawables, 0, drawableArr, 0, compoundDrawables.length);
            Drawable[] compoundDrawablesRelative = getCompoundDrawablesRelative();
            drawableArr[4] = compoundDrawablesRelative[0];
            drawableArr[5] = compoundDrawablesRelative[2];
            drawableArr[6] = getBackground();
        }
        return new i(super.onSaveInstanceState(), drawableArr);
    }

    @Override // android.view.View
    public void setBackgroundResource(int i10) {
        setBackground(a(i10));
    }

    @Override // android.widget.TextView
    public void setCompoundDrawablesRelativeWithIntrinsicBounds(int i10, int i11, int i12, int i13) {
        setCompoundDrawablesRelativeWithIntrinsicBounds(a(i10), a(i11), a(i12), a(i13));
    }

    @Override // android.widget.TextView
    public void setCompoundDrawablesWithIntrinsicBounds(int i10, int i11, int i12, int i13) {
        setCompoundDrawablesWithIntrinsicBounds(a(i10), a(i11), a(i12), a(i13));
    }

    public void setFreezesAnimation(boolean z10) {
        this.f32012a.f902b = z10;
    }

    public GifTextView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        b(attributeSet, 0);
    }

    public GifTextView(Context context, AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
        b(attributeSet, i10);
    }
}
