240 lines
6.1 KiB
Java
240 lines
6.1 KiB
Java
package com.bumptech.glide.load.resource.gif;
|
|
|
|
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 com.bumptech.glide.Glide;
|
|
import com.bumptech.glide.gifdecoder.GifDecoder;
|
|
import com.bumptech.glide.load.Transformation;
|
|
import com.bumptech.glide.load.resource.gif.GifFrameLoader;
|
|
import com.bumptech.glide.util.Preconditions;
|
|
import java.nio.ByteBuffer;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class GifDrawable extends Drawable implements GifFrameLoader.FrameCallback, Animatable {
|
|
private final GifState a;
|
|
private boolean b;
|
|
private boolean c;
|
|
private boolean d;
|
|
private boolean e;
|
|
private int f;
|
|
private int g;
|
|
private boolean h;
|
|
private Paint i;
|
|
private Rect j;
|
|
|
|
static final class GifState extends Drawable.ConstantState {
|
|
final GifFrameLoader a;
|
|
|
|
GifState(GifFrameLoader gifFrameLoader) {
|
|
this.a = gifFrameLoader;
|
|
}
|
|
|
|
@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 GifDrawable(this);
|
|
}
|
|
}
|
|
|
|
public GifDrawable(Context context, GifDecoder gifDecoder, Transformation<Bitmap> transformation, int i, int i2, Bitmap bitmap) {
|
|
this(new GifState(new GifFrameLoader(Glide.b(context), gifDecoder, i, i2, transformation, bitmap)));
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
private Drawable.Callback h() {
|
|
Drawable.Callback callback = getCallback();
|
|
while (callback instanceof Drawable) {
|
|
callback = ((Drawable) callback).getCallback();
|
|
}
|
|
return callback;
|
|
}
|
|
|
|
private Rect i() {
|
|
if (this.j == null) {
|
|
this.j = new Rect();
|
|
}
|
|
return this.j;
|
|
}
|
|
|
|
private Paint j() {
|
|
if (this.i == null) {
|
|
this.i = new Paint(2);
|
|
}
|
|
return this.i;
|
|
}
|
|
|
|
private void k() {
|
|
this.f = 0;
|
|
}
|
|
|
|
private void l() {
|
|
Preconditions.a(!this.d, "You cannot start a recycled Drawable. Ensure thatyou clear any references to the Drawable when clearing the corresponding request.");
|
|
if (this.a.a.f() == 1) {
|
|
invalidateSelf();
|
|
} else {
|
|
if (this.b) {
|
|
return;
|
|
}
|
|
this.b = true;
|
|
this.a.a.a(this);
|
|
invalidateSelf();
|
|
}
|
|
}
|
|
|
|
private void m() {
|
|
this.b = false;
|
|
this.a.a.b(this);
|
|
}
|
|
|
|
public void a(Transformation<Bitmap> transformation, Bitmap bitmap) {
|
|
this.a.a.a(transformation, bitmap);
|
|
}
|
|
|
|
public ByteBuffer b() {
|
|
return this.a.a.b();
|
|
}
|
|
|
|
public Bitmap c() {
|
|
return this.a.a.e();
|
|
}
|
|
|
|
public int d() {
|
|
return this.a.a.f();
|
|
}
|
|
|
|
@Override // android.graphics.drawable.Drawable
|
|
public void draw(Canvas canvas) {
|
|
if (this.d) {
|
|
return;
|
|
}
|
|
if (this.h) {
|
|
Gravity.apply(119, getIntrinsicWidth(), getIntrinsicHeight(), getBounds(), i());
|
|
this.h = false;
|
|
}
|
|
canvas.drawBitmap(this.a.a.c(), (Rect) null, i(), j());
|
|
}
|
|
|
|
public int e() {
|
|
return this.a.a.d();
|
|
}
|
|
|
|
public int f() {
|
|
return this.a.a.h();
|
|
}
|
|
|
|
public void g() {
|
|
this.d = true;
|
|
this.a.a.a();
|
|
}
|
|
|
|
@Override // android.graphics.drawable.Drawable
|
|
public Drawable.ConstantState getConstantState() {
|
|
return this.a;
|
|
}
|
|
|
|
@Override // android.graphics.drawable.Drawable
|
|
public int getIntrinsicHeight() {
|
|
return this.a.a.g();
|
|
}
|
|
|
|
@Override // android.graphics.drawable.Drawable
|
|
public int getIntrinsicWidth() {
|
|
return this.a.a.i();
|
|
}
|
|
|
|
@Override // android.graphics.drawable.Drawable
|
|
public int getOpacity() {
|
|
return -2;
|
|
}
|
|
|
|
@Override // android.graphics.drawable.Animatable
|
|
public boolean isRunning() {
|
|
return this.b;
|
|
}
|
|
|
|
@Override // android.graphics.drawable.Drawable
|
|
protected void onBoundsChange(Rect rect) {
|
|
super.onBoundsChange(rect);
|
|
this.h = true;
|
|
}
|
|
|
|
@Override // android.graphics.drawable.Drawable
|
|
public void setAlpha(int i) {
|
|
j().setAlpha(i);
|
|
}
|
|
|
|
@Override // android.graphics.drawable.Drawable
|
|
public void setColorFilter(ColorFilter colorFilter) {
|
|
j().setColorFilter(colorFilter);
|
|
}
|
|
|
|
@Override // android.graphics.drawable.Drawable
|
|
public boolean setVisible(boolean z, boolean z2) {
|
|
Preconditions.a(!this.d, "Cannot change the visibility of a recycled resource. Ensure that you unset the Drawable from your View before changing the View's visibility.");
|
|
this.e = z;
|
|
if (!z) {
|
|
m();
|
|
} else if (this.c) {
|
|
l();
|
|
}
|
|
return super.setVisible(z, z2);
|
|
}
|
|
|
|
@Override // android.graphics.drawable.Animatable
|
|
public void start() {
|
|
this.c = true;
|
|
k();
|
|
if (this.e) {
|
|
l();
|
|
}
|
|
}
|
|
|
|
@Override // android.graphics.drawable.Animatable
|
|
public void stop() {
|
|
this.c = false;
|
|
m();
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.resource.gif.GifFrameLoader.FrameCallback
|
|
public void a() {
|
|
if (h() == null) {
|
|
stop();
|
|
invalidateSelf();
|
|
return;
|
|
}
|
|
invalidateSelf();
|
|
if (e() == d() - 1) {
|
|
this.f++;
|
|
}
|
|
int i = this.g;
|
|
if (i == -1 || this.f < i) {
|
|
return;
|
|
}
|
|
stop();
|
|
}
|
|
|
|
GifDrawable(GifState gifState) {
|
|
this.e = true;
|
|
this.g = -1;
|
|
Preconditions.a(gifState);
|
|
this.a = gifState;
|
|
}
|
|
}
|