package l5;

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 java.util.ArrayList;
import t5.n;

/* JADX INFO: loaded from: classes.dex */
public final class d extends Drawable implements h, Animatable {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final c f30126a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public boolean f30127b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public boolean f30128c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public boolean f30129d;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f30131f;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public boolean f30133h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public Paint f30134i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public Rect f30135j;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public boolean f30130e = true;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final int f30132g = -1;

    public d(c cVar) {
        this.f30126a = (c) n.checkNotNull(cVar);
    }

    public final void a() {
        n.a("You cannot start a recycled Drawable. Ensure thatyou clear any references to the Drawable when clearing the corresponding request.", !this.f30129d);
        k kVar = this.f30126a.f30125a;
        if (((y4.e) kVar.f30143a).f36840m.f36815c == 1) {
            invalidateSelf();
            return;
        }
        if (this.f30127b) {
            return;
        }
        this.f30127b = true;
        if (kVar.f30152j) {
            throw new IllegalStateException("Cannot subscribe to a cleared frame loader");
        }
        ArrayList arrayList = kVar.f30145c;
        if (arrayList.contains(this)) {
            throw new IllegalStateException("Cannot subscribe twice in a row");
        }
        boolean zIsEmpty = arrayList.isEmpty();
        arrayList.add(this);
        if (zIsEmpty && !kVar.f30148f) {
            kVar.f30148f = true;
            kVar.f30152j = false;
            kVar.a();
        }
        invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    public final void draw(Canvas canvas) {
        if (this.f30129d) {
            return;
        }
        if (this.f30133h) {
            int intrinsicWidth = getIntrinsicWidth();
            int intrinsicHeight = getIntrinsicHeight();
            Rect bounds = getBounds();
            if (this.f30135j == null) {
                this.f30135j = new Rect();
            }
            Gravity.apply(119, intrinsicWidth, intrinsicHeight, bounds, this.f30135j);
            this.f30133h = false;
        }
        k kVar = this.f30126a.f30125a;
        g gVar = kVar.f30151i;
        Bitmap bitmap = gVar != null ? gVar.f30140f : kVar.f30154l;
        if (this.f30135j == null) {
            this.f30135j = new Rect();
        }
        Rect rect = this.f30135j;
        if (this.f30134i == null) {
            this.f30134i = new Paint(2);
        }
        canvas.drawBitmap(bitmap, (Rect) null, rect, this.f30134i);
    }

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

    @Override // android.graphics.drawable.Drawable
    public final int getIntrinsicHeight() {
        return this.f30126a.f30125a.f30158p;
    }

    @Override // android.graphics.drawable.Drawable
    public final int getIntrinsicWidth() {
        return this.f30126a.f30125a.f30157o;
    }

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

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

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

    @Override // android.graphics.drawable.Drawable
    public final void setAlpha(int i10) {
        if (this.f30134i == null) {
            this.f30134i = new Paint(2);
        }
        this.f30134i.setAlpha(i10);
    }

    @Override // android.graphics.drawable.Drawable
    public final void setColorFilter(ColorFilter colorFilter) {
        if (this.f30134i == null) {
            this.f30134i = new Paint(2);
        }
        this.f30134i.setColorFilter(colorFilter);
    }

    @Override // android.graphics.drawable.Drawable
    public final boolean setVisible(boolean z10, boolean z11) {
        n.a("Cannot change the visibility of a recycled resource. Ensure that you unset the Drawable from your View before changing the View's visibility.", !this.f30129d);
        this.f30130e = z10;
        if (!z10) {
            this.f30127b = false;
            k kVar = this.f30126a.f30125a;
            ArrayList arrayList = kVar.f30145c;
            arrayList.remove(this);
            if (arrayList.isEmpty()) {
                kVar.f30148f = false;
            }
        } else if (this.f30128c) {
            a();
        }
        return super.setVisible(z10, z11);
    }

    @Override // android.graphics.drawable.Animatable
    public final void start() {
        this.f30128c = true;
        this.f30131f = 0;
        if (this.f30130e) {
            a();
        }
    }

    @Override // android.graphics.drawable.Animatable
    public final void stop() {
        this.f30128c = false;
        this.f30127b = false;
        k kVar = this.f30126a.f30125a;
        ArrayList arrayList = kVar.f30145c;
        arrayList.remove(this);
        if (arrayList.isEmpty()) {
            kVar.f30148f = false;
        }
    }
}
