package p138.p145.p146.p151.p160.p165;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import p000.p001.p002.p003.p004.C0567;
import p037.p119.p120.p121.InterfaceC2522;
import p138.p145.p146.ComponentCallbacks2C2806;
import p138.p145.p146.p148.InterfaceC2830;
import p138.p145.p146.p151.InterfaceC2852;
import p138.p145.p146.p151.p160.p165.C3147;

/* JADX INFO: renamed from: ދ.ؠ.֏.ތ.ތ.ބ.ހ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C3142 extends Drawable implements C3147.InterfaceC3149, Animatable, InterfaceC2522 {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final C3143 f9378;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public boolean f9379;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public boolean f9380;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public boolean f9381;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public boolean f9382;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public int f9383;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public int f9384;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public boolean f9385;

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public Paint f9386;

    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public Rect f9387;

    /* JADX INFO: renamed from: ދ.ؠ.֏.ތ.ތ.ބ.ހ$֏, reason: contains not printable characters */
    public static final class C3143 extends Drawable.ConstantState {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final C3147 f9388;

        public C3143(C3147 c3147) {
            this.f9388 = c3147;
        }

        @Override // android.graphics.drawable.Drawable.ConstantState
        public int getChangingConfigurations() {
            return 0;
        }

        @Override // android.graphics.drawable.Drawable.ConstantState
        public Drawable newDrawable() {
            return new C3142(this);
        }

        @Override // android.graphics.drawable.Drawable.ConstantState
        public Drawable newDrawable(Resources resources) {
            return new C3142(this);
        }
    }

    public C3142(Context context, InterfaceC2830 interfaceC2830, InterfaceC2852<Bitmap> interfaceC2852, int i, int i2, Bitmap bitmap) {
        C3143 c3143 = new C3143(new C3147(ComponentCallbacks2C2806.m4903(context), interfaceC2830, i, i2, interfaceC2852, bitmap));
        this.f9382 = true;
        this.f9384 = -1;
        C0567.m1858(c3143, "Argument must not be null");
        this.f9378 = c3143;
    }

    public C3142(C3143 c3143) {
        this.f9382 = true;
        this.f9384 = -1;
        C0567.m1858(c3143, "Argument must not be null");
        this.f9378 = c3143;
    }

    @Override // android.graphics.drawable.Drawable
    public void draw(Canvas canvas) {
        if (this.f9381) {
            return;
        }
        if (this.f9385) {
            int intrinsicWidth = getIntrinsicWidth();
            int intrinsicHeight = getIntrinsicHeight();
            Rect bounds = getBounds();
            if (this.f9387 == null) {
                this.f9387 = new Rect();
            }
            Gravity.apply(119, intrinsicWidth, intrinsicHeight, bounds, this.f9387);
            this.f9385 = false;
        }
        C3147 c3147 = this.f9378.f9388;
        C3147.C3148 c3148 = c3147.f9399;
        Bitmap bitmap = c3148 != null ? c3148.f9410 : c3147.f9402;
        if (this.f9387 == null) {
            this.f9387 = new Rect();
        }
        canvas.drawBitmap(bitmap, (Rect) null, this.f9387, m5215());
    }

    @Override // android.graphics.drawable.Drawable
    public Drawable.ConstantState getConstantState() {
        return this.f9378;
    }

    @Override // android.graphics.drawable.Drawable
    public int getIntrinsicHeight() {
        return this.f9378.f9388.f9406;
    }

    @Override // android.graphics.drawable.Drawable
    public int getIntrinsicWidth() {
        return this.f9378.f9388.f9405;
    }

    @Override // android.graphics.drawable.Drawable
    public int getOpacity() {
        return -2;
    }

    @Override // android.graphics.drawable.Animatable
    public boolean isRunning() {
        return this.f9379;
    }

    @Override // android.graphics.drawable.Drawable
    public void onBoundsChange(Rect rect) {
        super.onBoundsChange(rect);
        this.f9385 = true;
    }

    @Override // android.graphics.drawable.Drawable
    public void setAlpha(int i) {
        m5215().setAlpha(i);
    }

    @Override // android.graphics.drawable.Drawable
    public void setColorFilter(ColorFilter colorFilter) {
        m5215().setColorFilter(colorFilter);
    }

    @Override // android.graphics.drawable.Drawable
    public boolean setVisible(boolean z, boolean z2) {
        C0567.m1898(!this.f9381, "Cannot change the visibility of a recycled resource. Ensure that you unset the Drawable from your View before changing the View's visibility.");
        this.f9382 = z;
        if (!z) {
            m5217();
        } else if (this.f9380) {
            m5216();
        }
        return super.setVisible(z, z2);
    }

    @Override // android.graphics.drawable.Animatable
    public void start() {
        this.f9380 = true;
        this.f9383 = 0;
        if (this.f9382) {
            m5216();
        }
    }

    @Override // android.graphics.drawable.Animatable
    public void stop() {
        this.f9380 = false;
        m5217();
    }

    @Override // p138.p145.p146.p151.p160.p165.C3147.InterfaceC3149
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void mo5213() {
        Object callback = getCallback();
        while (callback instanceof Drawable) {
            callback = ((Drawable) callback).getCallback();
        }
        if (callback == null) {
            stop();
            invalidateSelf();
            return;
        }
        invalidateSelf();
        C3147.C3148 c3148 = this.f9378.f9388.f9399;
        if ((c3148 != null ? c3148.f9408 : -1) == this.f9378.f9388.f9390.mo4954() - 1) {
            this.f9383++;
        }
        int i = this.f9384;
        if (i == -1 || this.f9383 < i) {
            return;
        }
        stop();
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public Bitmap m5214() {
        return this.f9378.f9388.f9402;
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final Paint m5215() {
        if (this.f9386 == null) {
            this.f9386 = new Paint(2);
        }
        return this.f9386;
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final void m5216() {
        C0567.m1898(!this.f9381, "You cannot start a recycled Drawable. Ensure thatyou clear any references to the Drawable when clearing the corresponding request.");
        if (this.f9378.f9388.f9390.mo4954() == 1) {
            invalidateSelf();
            return;
        }
        if (this.f9379) {
            return;
        }
        this.f9379 = true;
        C3147 c3147 = this.f9378.f9388;
        if (c3147.f9400) {
            throw new IllegalStateException("Cannot subscribe to a cleared frame loader");
        }
        if (c3147.f9392.contains(this)) {
            throw new IllegalStateException("Cannot subscribe twice in a row");
        }
        boolean zIsEmpty = c3147.f9392.isEmpty();
        c3147.f9392.add(this);
        if (zIsEmpty && !c3147.f9395) {
            c3147.f9395 = true;
            c3147.f9400 = false;
            c3147.m5218();
        }
        invalidateSelf();
    }

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final void m5217() {
        this.f9379 = false;
        C3147 c3147 = this.f9378.f9388;
        c3147.f9392.remove(this);
        if (c3147.f9392.isEmpty()) {
            c3147.f9395 = false;
        }
    }
}
