package wh;

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 ei.k;
import java.nio.ByteBuffer;
import java.util.List;
import jh.l;
import wh.g;

/* loaded from: classes4.dex */
public class c extends Drawable implements g.b, Animatable {

    /* renamed from: p, reason: collision with root package name */
    private final a f49435p;

    /* renamed from: q, reason: collision with root package name */
    private boolean f49436q;

    /* renamed from: r, reason: collision with root package name */
    private boolean f49437r;

    /* renamed from: s, reason: collision with root package name */
    private boolean f49438s;

    /* renamed from: t, reason: collision with root package name */
    private boolean f49439t;

    /* renamed from: u, reason: collision with root package name */
    private int f49440u;

    /* renamed from: v, reason: collision with root package name */
    private int f49441v;

    /* renamed from: w, reason: collision with root package name */
    private boolean f49442w;

    /* renamed from: x, reason: collision with root package name */
    private Paint f49443x;

    /* renamed from: y, reason: collision with root package name */
    private Rect f49444y;

    /* renamed from: z, reason: collision with root package name */
    private List f49445z;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class a extends Drawable.ConstantState {

        /* renamed from: a, reason: collision with root package name */
        final g f49446a;

        a(g gVar) {
            this.f49446a = gVar;
        }

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

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

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

    public c(Context context, hh.a aVar, l lVar, int i10, int i11, Bitmap bitmap) {
        this(new a(new g(com.bumptech.glide.b.c(context), aVar, i10, i11, lVar, bitmap)));
    }

    /* JADX WARN: Multi-variable type inference failed */
    private Drawable.Callback b() {
        Drawable.Callback callback = getCallback();
        while (callback instanceof Drawable) {
            callback = ((Drawable) callback).getCallback();
        }
        return callback;
    }

    private Rect d() {
        if (this.f49444y == null) {
            this.f49444y = new Rect();
        }
        return this.f49444y;
    }

    private Paint h() {
        if (this.f49443x == null) {
            this.f49443x = new Paint(2);
        }
        return this.f49443x;
    }

    private void j() {
        List list = this.f49445z;
        if (list == null || list.size() <= 0) {
            return;
        }
        android.support.v4.media.session.b.a(this.f49445z.get(0));
        throw null;
    }

    private void l() {
        this.f49440u = 0;
    }

    private void n() {
        k.a(!this.f49438s, "You cannot start a recycled Drawable. Ensure thatyou clear any references to the Drawable when clearing the corresponding request.");
        if (this.f49435p.f49446a.f() == 1) {
            invalidateSelf();
        } else {
            if (this.f49436q) {
                return;
            }
            this.f49436q = true;
            this.f49435p.f49446a.r(this);
            invalidateSelf();
        }
    }

    private void o() {
        this.f49436q = false;
        this.f49435p.f49446a.s(this);
    }

    @Override // wh.g.b
    public void a() {
        if (b() == null) {
            stop();
            invalidateSelf();
            return;
        }
        invalidateSelf();
        if (g() == f() - 1) {
            this.f49440u++;
        }
        int i10 = this.f49441v;
        if (i10 == -1 || this.f49440u < i10) {
            return;
        }
        j();
        stop();
    }

    public ByteBuffer c() {
        return this.f49435p.f49446a.b();
    }

    @Override // android.graphics.drawable.Drawable
    public void draw(Canvas canvas) {
        if (this.f49438s) {
            return;
        }
        if (this.f49442w) {
            Gravity.apply(119, getIntrinsicWidth(), getIntrinsicHeight(), getBounds(), d());
            this.f49442w = false;
        }
        canvas.drawBitmap(this.f49435p.f49446a.c(), (Rect) null, d(), h());
    }

    public Bitmap e() {
        return this.f49435p.f49446a.e();
    }

    public int f() {
        return this.f49435p.f49446a.f();
    }

    public int g() {
        return this.f49435p.f49446a.d();
    }

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

    @Override // android.graphics.drawable.Drawable
    public int getIntrinsicHeight() {
        return this.f49435p.f49446a.h();
    }

    @Override // android.graphics.drawable.Drawable
    public int getIntrinsicWidth() {
        return this.f49435p.f49446a.k();
    }

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

    public int i() {
        return this.f49435p.f49446a.j();
    }

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

    public void k() {
        this.f49438s = true;
        this.f49435p.f49446a.a();
    }

    public void m(l lVar, Bitmap bitmap) {
        this.f49435p.f49446a.o(lVar, bitmap);
    }

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

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

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

    @Override // android.graphics.drawable.Drawable
    public boolean setVisible(boolean z10, boolean z11) {
        k.a(!this.f49438s, "Cannot change the visibility of a recycled resource. Ensure that you unset the Drawable from your View before changing the View's visibility.");
        this.f49439t = z10;
        if (!z10) {
            o();
        } else if (this.f49437r) {
            n();
        }
        return super.setVisible(z10, z11);
    }

    @Override // android.graphics.drawable.Animatable
    public void start() {
        this.f49437r = true;
        l();
        if (this.f49439t) {
            n();
        }
    }

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

    c(a aVar) {
        this.f49439t = true;
        this.f49441v = -1;
        this.f49435p = (a) k.d(aVar);
    }
}
