package pl.droidsonroids.gif; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.RectF; import android.graphics.SurfaceTexture; import android.os.Parcelable; import android.util.AttributeSet; import android.util.TypedValue; import android.view.Surface; import android.view.TextureView; import android.widget.ImageView; import androidx.annotation.FloatRange; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import defpackage.cx5; import defpackage.dx5; import java.io.IOException; import java.lang.ref.WeakReference; @RequiresApi(14) public class GifTextureView extends TextureView { public static final ImageView.ScaleType[] g = {ImageView.ScaleType.MATRIX, ImageView.ScaleType.FIT_XY, ImageView.ScaleType.FIT_START, ImageView.ScaleType.FIT_CENTER, ImageView.ScaleType.FIT_END, ImageView.ScaleType.CENTER, ImageView.ScaleType.CENTER_CROP, ImageView.ScaleType.CENTER_INSIDE}; /* renamed from: a reason: collision with root package name */ public ImageView.ScaleType f31043a = ImageView.ScaleType.FIT_CENTER; /* renamed from: b reason: collision with root package name */ public final Matrix f31044b = new Matrix(); public dx5 c; public c d; public float e = 1.0f; public cx5.b f; public static /* synthetic */ class a { /* renamed from: a reason: collision with root package name */ public static final /* synthetic */ int[] f31045a; /* JADX WARNING: Can't wrap try/catch for region: R(18:0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|18) */ /* JADX WARNING: Code restructure failed: missing block: B:19:?, code lost: return; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:11:0x003e */ /* JADX WARNING: Missing exception handler attribute for start block: B:13:0x0049 */ /* JADX WARNING: Missing exception handler attribute for start block: B:15:0x0054 */ /* JADX WARNING: Missing exception handler attribute for start block: B:3:0x0012 */ /* JADX WARNING: Missing exception handler attribute for start block: B:5:0x001d */ /* JADX WARNING: Missing exception handler attribute for start block: B:7:0x0028 */ /* JADX WARNING: Missing exception handler attribute for start block: B:9:0x0033 */ static { int[] iArr = new int[ImageView.ScaleType.values().length]; f31045a = iArr; iArr[ImageView.ScaleType.CENTER.ordinal()] = 1; f31045a[ImageView.ScaleType.CENTER_CROP.ordinal()] = 2; f31045a[ImageView.ScaleType.CENTER_INSIDE.ordinal()] = 3; f31045a[ImageView.ScaleType.FIT_CENTER.ordinal()] = 4; f31045a[ImageView.ScaleType.FIT_END.ordinal()] = 5; f31045a[ImageView.ScaleType.FIT_START.ordinal()] = 6; f31045a[ImageView.ScaleType.FIT_XY.ordinal()] = 7; f31045a[ImageView.ScaleType.MATRIX.ordinal()] = 8; } } public interface b { void a(Canvas canvas); } public static class c extends Thread implements TextureView.SurfaceTextureListener { /* renamed from: a reason: collision with root package name */ public final zw5 f31046a = new zw5(); /* renamed from: b reason: collision with root package name */ public GifInfoHandle f31047b = new GifInfoHandle(); public IOException c; public long[] d; public final WeakReference<GifTextureView> e; public class a implements Runnable { /* renamed from: a reason: collision with root package name */ public final /* synthetic */ GifTextureView f31048a; public a(GifTextureView gifTextureView) { this.f31048a = gifTextureView; } public void run() { this.f31048a.h(c.this.f31047b); } } public c(GifTextureView gifTextureView) { super(d03.b("GifRenderThread", "pl.droidsonroids.gif.GifTextureView$RenderThread")); this.e = new WeakReference<>(gifTextureView); } public void c(@NonNull GifTextureView gifTextureView, @Nullable b bVar) { this.f31046a.b(); gifTextureView.setSuperSurfaceTextureListener(bVar != null ? new gx5(bVar) : null); this.f31047b.r(); interrupt(); } public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i2) { GifTextureView gifTextureView = this.e.get(); if (gifTextureView != null) { gifTextureView.h(this.f31047b); } this.f31046a.c(); } public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) { this.f31046a.b(); this.f31047b.r(); interrupt(); return true; } public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i2) { } public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) { } public void run() { try { GifTextureView gifTextureView = this.e.get(); if (gifTextureView != null) { GifInfoHandle a2 = gifTextureView.c.a(); this.f31047b = a2; a2.B(1, gifTextureView.isOpaque()); if (gifTextureView.f.f25652b >= 0) { this.f31047b.A(gifTextureView.f.f25652b); } GifTextureView gifTextureView2 = this.e.get(); if (gifTextureView2 == null) { this.f31047b.s(); return; } gifTextureView2.setSuperSurfaceTextureListener(this); boolean isAvailable = gifTextureView2.isAvailable(); this.f31046a.d(isAvailable); if (isAvailable) { gifTextureView2.post(new a(gifTextureView2)); } this.f31047b.C(gifTextureView2.e); while (!isInterrupted()) { try { this.f31046a.a(); SurfaceTexture surfaceTexture = gifTextureView2.getSurfaceTexture(); if (surfaceTexture != null) { Surface surface = new Surface(surfaceTexture); try { this.f31047b.a(surface, this.d); } finally { surface.release(); } } } catch (InterruptedException unused) { Thread.currentThread().interrupt(); } } this.f31047b.s(); this.f31047b = new GifInfoHandle(); } } catch (IOException e2) { this.c = e2; } } } public GifTextureView(Context context) { super(context); g(null, 0, 0); } public static dx5 f(TypedArray typedArray) { TypedValue typedValue = new TypedValue(); if (!typedArray.getValue(hx5.GifTextureView_gifSource, typedValue)) { return null; } if (typedValue.resourceId != 0) { String resourceTypeName = typedArray.getResources().getResourceTypeName(typedValue.resourceId); if (cx5.f25650a.contains(resourceTypeName)) { return new dx5.c(typedArray.getResources(), typedValue.resourceId); } if (!"string".equals(resourceTypeName)) { throw new IllegalArgumentException("Expected string, drawable, mipmap or raw resource type. '" + resourceTypeName + "' is not supported"); } } return new dx5.b(typedArray.getResources().getAssets(), typedValue.string.toString()); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void setSuperSurfaceTextureListener(TextureView.SurfaceTextureListener surfaceTextureListener) { super.setSurfaceTextureListener(surfaceTextureListener); } public final void g(AttributeSet attributeSet, int i, int i2) { if (attributeSet != null) { int attributeIntValue = attributeSet.getAttributeIntValue("http://schemas.android.com/apk/res/android", "scaleType", -1); if (attributeIntValue >= 0) { ImageView.ScaleType[] scaleTypeArr = g; if (attributeIntValue < scaleTypeArr.length) { this.f31043a = scaleTypeArr[attributeIntValue]; } } TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, hx5.GifTextureView, i, i2); this.c = f(obtainStyledAttributes); super.setOpaque(obtainStyledAttributes.getBoolean(hx5.GifTextureView_isOpaque, false)); obtainStyledAttributes.recycle(); this.f = new cx5.b(this, attributeSet, i, i2); } else { super.setOpaque(false); this.f = new cx5.b(); } if (!isInEditMode()) { c cVar = new c(this); this.d = cVar; if (this.c != null) { d03.d(cVar, "pl.droidsonroids.gif.GifTextureView"); cVar.start(); } } } @Nullable public IOException getIOException() { if (this.d.c != null) { return this.d.c; } return GifIOException.fromCode(this.d.f31047b.k()); } public ImageView.ScaleType getScaleType() { return this.f31043a; } public TextureView.SurfaceTextureListener getSurfaceTextureListener() { return null; } public Matrix getTransform(Matrix matrix) { if (matrix == null) { matrix = new Matrix(); } matrix.set(this.f31044b); return matrix; } public final void h(GifInfoHandle gifInfoHandle) { Matrix matrix = new Matrix(); float width = (float) getWidth(); float height = (float) getHeight(); float n = ((float) gifInfoHandle.n()) / width; float h = ((float) gifInfoHandle.h()) / height; RectF rectF = new RectF(0.0f, 0.0f, (float) gifInfoHandle.n(), (float) gifInfoHandle.h()); RectF rectF2 = new RectF(0.0f, 0.0f, width, height); float f2 = 1.0f; switch (a.f31045a[this.f31043a.ordinal()]) { case 1: matrix.setScale(n, h, width / 2.0f, height / 2.0f); break; case 2: float min = 1.0f / Math.min(n, h); matrix.setScale(n * min, min * h, width / 2.0f, height / 2.0f); break; case 3: if (((float) gifInfoHandle.n()) > width || ((float) gifInfoHandle.h()) > height) { f2 = Math.min(1.0f / n, 1.0f / h); } matrix.setScale(n * f2, f2 * h, width / 2.0f, height / 2.0f); break; case 4: matrix.setRectToRect(rectF, rectF2, Matrix.ScaleToFit.CENTER); matrix.preScale(n, h); break; case 5: matrix.setRectToRect(rectF, rectF2, Matrix.ScaleToFit.END); matrix.preScale(n, h); break; case 6: matrix.setRectToRect(rectF, rectF2, Matrix.ScaleToFit.START); matrix.preScale(n, h); break; case 7: return; case 8: matrix.set(this.f31044b); matrix.preScale(n, h); break; } super.setTransform(matrix); } public void onDetachedFromWindow() { this.d.c(this, null); super.onDetachedFromWindow(); SurfaceTexture surfaceTexture = getSurfaceTexture(); if (surfaceTexture != null) { surfaceTexture.release(); } } public void onRestoreInstanceState(Parcelable parcelable) { if (!(parcelable instanceof GifViewSavedState)) { super.onRestoreInstanceState(parcelable); return; } GifViewSavedState gifViewSavedState = (GifViewSavedState) parcelable; super.onRestoreInstanceState(gifViewSavedState.getSuperState()); this.d.d = gifViewSavedState.f31050a[0]; } public Parcelable onSaveInstanceState() { c cVar = this.d; cVar.d = cVar.f31047b.m(); return new GifViewSavedState(super.onSaveInstanceState(), this.f.f25651a ? this.d.d : null); } public void setFreezesAnimation(boolean z) { this.f.f25651a = z; } public void setImageMatrix(Matrix matrix) { setTransform(matrix); } public synchronized void setInputSource(@Nullable dx5 dx5) { setInputSource(dx5, null); } public void setOpaque(boolean z) { if (z != isOpaque()) { super.setOpaque(z); setInputSource(this.c); } } public void setScaleType(@NonNull ImageView.ScaleType scaleType) { this.f31043a = scaleType; h(this.d.f31047b); } public void setSpeed(@FloatRange(from = 0.0d, fromInclusive = false) float f2) { this.e = f2; this.d.f31047b.C(f2); } public void setSurfaceTexture(SurfaceTexture surfaceTexture) { throw new UnsupportedOperationException("Changing SurfaceTexture is not supported"); } public void setSurfaceTextureListener(TextureView.SurfaceTextureListener surfaceTextureListener) { throw new UnsupportedOperationException("Changing SurfaceTextureListener is not supported"); } public void setTransform(Matrix matrix) { this.f31044b.set(matrix); h(this.d.f31047b); } public synchronized void setInputSource(@Nullable dx5 dx5, @Nullable b bVar) { this.d.c(this, bVar); try { this.d.join(); } catch (InterruptedException e2) { e2.printStackTrace(); } this.c = dx5; c cVar = new c(this); this.d = cVar; if (dx5 != null) { d03.d(cVar, "pl.droidsonroids.gif.GifTextureView"); cVar.start(); } } public GifTextureView(Context context, AttributeSet attributeSet) { super(context, attributeSet); g(attributeSet, 0, 0); } public GifTextureView(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); g(attributeSet, i, 0); } }