TIM v2.3.1版本的 MD5 值为:d6957e3ee7ce901ccc491cefdea0da8c
以下内容为反编译后的 QQAnimationDrawable.java 源代码,内容仅作参考
package com.tencent.mobileqq.bubble;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.SystemClock;
import com.tencent.mobileqq.troop.utils.TroopBarUtils;
import com.tencent.qphone.base.util.QLog;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
public class QQAnimationDrawable extends Drawable implements Animatable, Runnable {
private static final String f88373a = QQAnimationDrawable.class.getSimpleName();
public static final Executor f20176a = Executors.newSingleThreadExecutor(new pvj());
private static volatile pvm f20177a = new pvm(null);
private static final int f = 0;
private static final int g = 2;
private static final int h = 1;
protected int f20178a;
private long f20179a;
private Context f20180a;
public Bitmap f20181a;
private BitmapFactory.Options f20182a;
private Paint f20183a;
private QQAnimationListener f20184a;
private Object f20185a;
private ArrayList f20186a;
private HashMap f20187a;
private FutureTask f20188a;
public final pvl f20189a;
private pvp f20190a;
public boolean f20191a;
private int[] f20192a;
private String[] f20193a;
int f88374b;
public Bitmap f20194b;
private String f20195b;
public boolean f20196b;
private int f88375c;
private Bitmap f20197c;
private boolean f20198c;
private int d;
private boolean f20199d;
private int e;
private boolean f20200e;
private boolean f20201f;
private boolean f20202g;
private int i;
private int j;
private int k;
public interface QQAnimationListener {
void a();
void b();
}
public QQAnimationDrawable(Context context) {
this(context, null);
}
public QQAnimationDrawable(Context context, QQAnimationListener qQAnimationListener) {
this.f20183a = new Paint(6);
this.f20178a = -1;
this.f20199d = true;
this.d = 1;
this.f20200e = true;
this.f88374b = 160;
this.f20182a = new BitmapFactory.Options();
this.i = 2;
this.f20201f = true;
this.f20186a = new ArrayList();
this.f20187a = new HashMap();
this.f20191a = true;
this.f20196b = true;
this.f20185a = new Object();
this.f20180a = context;
this.f20189a = new pvl(this);
this.f88374b = context.getResources().getDisplayMetrics().densityDpi;
this.f88374b = this.f88374b != 0 ? this.f88374b : 160;
this.f20184a = qQAnimationListener;
d();
}
@Override
public boolean setVisible(boolean z, boolean z2) {
boolean visible = super.setVisible(z, z2);
if (z) {
if (visible || z2) {
d();
}
} else {
unscheduleSelf(this);
}
return visible;
}
@Override
public void start() {
this.f20202g = true;
if (this.f88375c > 0 && this.f20179a > 0 && !isRunning()) {
this.f20200e = true;
a(true, false, true);
}
}
public void a(int i) {
this.f20199d = false;
this.d = i;
if (this.d > 1) {
b(false);
} else if (this.d == 1) {
b(true);
}
start();
}
public void a(boolean z) {
this.f20199d = true;
b(z);
start();
}
public void m5416a(boolean z, int i) {
if (z) {
a(z);
} else {
a(i);
}
}
@Override
public void stop() {
this.f20202g = false;
if (isRunning()) {
unscheduleSelf(this);
}
if (!this.f20199d) {
this.d = 1;
}
m5415a();
}
@Override
public boolean isRunning() {
return this.f20178a > -1;
}
@Override
public void run() {
if (this.f20202g) {
if (!this.f20199d && this.f20178a == a() - 1) {
this.d--;
}
this.f20200e = true;
if (this.f20194b != null) {
this.f20197c = this.f20194b;
}
if (this.f20178a == -1 && this.f20184a != null) {
this.f20184a.b();
}
this.f20178a = this.e;
invalidateSelf();
}
}
@Override
public void unscheduleSelf(Runnable runnable) {
this.f20178a = -1;
super.unscheduleSelf(runnable);
}
public void b(boolean z) {
this.f20198c = z;
}
public void a(long j) {
this.f20179a = j;
}
public void a(int[] iArr) {
b(2);
if (!Arrays.equals(this.f20192a, iArr)) {
c();
this.f20192a = iArr;
}
if (this.f20192a != null) {
this.f88375c = this.f20192a.length;
} else {
this.f88375c = 0;
}
}
public void a(String[] strArr) {
b(0);
if (!Arrays.equals(this.f20193a, strArr)) {
c();
this.f20193a = strArr;
}
if (this.f20193a != null) {
this.f88375c = this.f20193a.length;
} else {
this.f88375c = 0;
}
}
public void a(String str, int i, int i2) {
c();
b(1);
this.f20195b = str;
this.j = i;
this.k = i2;
}
public void b(int i) {
this.i = i;
}
public void c(boolean z) {
this.f20201f = z;
}
public void d(boolean z) {
this.f20191a = z;
}
public void c(int i) {
this.f88375c = i;
}
public int a() {
return this.f88375c;
}
public void m5415a() {
if (QLog.isDevelopLevel()) {
QLog.d(f88373a, 4, " reset");
}
this.d = 1;
this.f20178a = -1;
this.e = 0;
this.f20194b = null;
this.f20197c = null;
b();
}
@Override
public void draw(Canvas canvas) {
synchronized (this.f20185a) {
if (this.f20197c != null && !this.f20197c.isRecycled()) {
canvas.drawBitmap(this.f20197c, (Rect) null, getBounds(), this.f20183a);
}
}
if (!this.f20196b) {
a(false, false, true);
} else {
this.f20196b = false;
}
}
@Override
public int getOpacity() {
return -2;
}
@Override
public void setAlpha(int i) {
this.f20183a.setAlpha(i);
}
@Override
public void setColorFilter(ColorFilter colorFilter) {
this.f20183a.setColorFilter(colorFilter);
}
@Override
public void setFilterBitmap(boolean z) {
this.f20183a.setFilterBitmap(z);
}
@Override
public void setDither(boolean z) {
this.f20183a.setDither(z);
}
private void a(boolean z, boolean z2, boolean z3) {
long uptimeMillis;
int i = this.f20178a + 1;
int i2 = i >= this.f88375c ? 0 : i;
if (z2) {
unscheduleSelf(this);
}
boolean z4 = (this.f20198c || this.d <= 0) && i2 >= this.f88375c + (-1);
if (!z4 && this.f20200e && z3) {
this.f20200e = false;
if (z) {
uptimeMillis = 0;
} else {
uptimeMillis = SystemClock.uptimeMillis() + this.f20179a;
}
this.f20190a = new pvp(this, i2, uptimeMillis);
this.f20188a = new FutureTask(this.f20190a);
f20177a.execute(this.f20188a);
}
if (z4) {
stop();
if (this.f20184a != null) {
this.f20184a.a();
}
}
}
public void b() {
if (f20177a != null) {
f20177a.b();
}
if (this.f20188a != null) {
this.f20188a.cancel(true);
}
}
private void d() {
f20177a.execute(new pvk(this));
}
public Bitmap a(boolean z, int i) {
Bitmap bitmap = null;
if (this.i == 0) {
bitmap = a(z, i, (Bitmap) null);
} else if (this.i == 2) {
bitmap = b(z, i, null);
} else if (this.i == 1) {
bitmap = b(z, i);
}
if (bitmap == null) {
return this.f20194b;
}
return bitmap;
}
private synchronized Bitmap a(boolean z, int i, Bitmap bitmap) {
Bitmap bitmap2;
Bitmap bitmap3;
InputStream fileInputStream;
if (this.f20193a != null && i < this.f20193a.length) {
long currentTimeMillis = System.currentTimeMillis();
String str = this.f20193a[i];
if (str != null) {
if (this.f20201f) {
SoftReference softReference = (SoftReference) this.f20187a.get(str);
if (softReference != null && softReference.get() != null) {
bitmap2 = (Bitmap) softReference.get();
} else {
try {
this.f20182a.inJustDecodeBounds = false;
this.f20182a.inSampleSize = 1;
this.f20182a.inDensity = 320;
this.f20182a.inTargetDensity = this.f88374b;
if (str.startsWith(BubbleManager.d)) {
str = str.substring("file:///android_assets/".length());
fileInputStream = this.f20180a.getAssets().open(str);
} else {
fileInputStream = new FileInputStream(str);
}
bitmap3 = BitmapFactory.decodeStream(fileInputStream, new Rect(), this.f20182a);
try {
this.f20187a.put(str, new SoftReference(bitmap3));
} catch (FileNotFoundException e) {
} catch (IOException e2) {
} catch (OutOfMemoryError e3) {
}
} catch (FileNotFoundException e4) {
bitmap3 = bitmap;
} catch (IOException e5) {
bitmap3 = bitmap;
} catch (OutOfMemoryError e6) {
bitmap3 = bitmap;
}
bitmap = bitmap3;
}
} else {
a(this.f20194b, currentTimeMillis, str);
bitmap = this.f20194b;
}
}
}
bitmap2 = bitmap;
return bitmap2;
}
private synchronized Bitmap b(boolean z, int i, Bitmap bitmap) {
Bitmap bitmap2;
Bitmap bitmap3;
if (this.f20192a != null && i < this.f20192a.length) {
long currentTimeMillis = System.currentTimeMillis();
int i2 = this.f20192a[i];
if (i2 > 0) {
if (this.f20201f) {
SoftReference softReference = (SoftReference) this.f20187a.get(Integer.valueOf(i2));
if (softReference != null && softReference.get() != null) {
bitmap2 = (Bitmap) softReference.get();
} else {
try {
bitmap3 = BitmapFactory.decodeResource(this.f20180a.getResources(), i2);
try {
this.f20187a.put(String.valueOf(i2), new SoftReference(bitmap3));
} catch (OutOfMemoryError e) {
}
} catch (OutOfMemoryError e2) {
bitmap3 = bitmap;
}
bitmap = bitmap3;
}
} else {
a(this.f20194b, currentTimeMillis, i2);
bitmap = this.f20194b;
}
}
}
bitmap2 = bitmap;
return bitmap2;
}
private synchronized Bitmap b(boolean z, int i) {
Bitmap bitmap;
if (i >= this.f20186a.size() || (bitmap = (Bitmap) this.f20186a.get(i)) == null) {
try {
long currentTimeMillis = System.currentTimeMillis();
this.f20182a.inJustDecodeBounds = true;
BitmapFactory.decodeFile(this.f20195b, this.f20182a);
int i2 = (int) (this.f20182a.outWidth / (this.j * 1.0f));
int i3 = (int) (this.f20182a.outHeight / (this.k * 1.0f));
this.f20182a.inJustDecodeBounds = false;
this.f20182a.inDensity = 320;
this.f20182a.inTargetDensity = this.f88374b;
Bitmap decodeFile = BitmapFactory.decodeFile(this.f20195b, this.f20182a);
for (int i4 = 0; i4 < this.k; i4++) {
for (int i5 = 0; i5 < this.j; i5++) {
Bitmap createBitmap = Bitmap.createBitmap(decodeFile, i5 * i2, i4 * i3, i2, i3, (Matrix) null, true);
if (createBitmap != null) {
if (QLog.isDevelopLevel()) {
QLog.d(f88373a, 4, "cache " + ((i4 * 8) + i5));
}
this.f20186a.add(createBitmap);
}
}
}
if (decodeFile != null && !decodeFile.isRecycled()) {
decodeFile.recycle();
}
this.f88375c = this.f20186a.size();
if (QLog.isDevelopLevel()) {
QLog.d(f88373a, 4, "create bitmap " + (System.currentTimeMillis() - currentTimeMillis));
}
} catch (Exception e) {
if (QLog.isDevelopLevel()) {
QLog.e(f88373a, 4, e.getMessage());
}
} catch (OutOfMemoryError e2) {
if (QLog.isDevelopLevel()) {
QLog.e(f88373a, 4, "getBitmapFromFile OOM");
}
}
bitmap = (Bitmap) this.f20186a.get(i);
}
return bitmap;
}
private void a(Bitmap bitmap, long j, String str) {
try {
if (bitmap == null) {
this.f20182a.inJustDecodeBounds = true;
BitmapFactory.decodeFile(str, this.f20182a);
if (QLog.isDevelopLevel()) {
QLog.d(f88373a, 4, "getBitmapFromFile " + str + TroopBarUtils.y + this.f20182a.outWidth + "——" + this.f20182a.outHeight);
}
Bitmap.createBitmap(this.f20182a.outWidth, this.f20182a.outHeight, Bitmap.Config.ARGB_8888);
return;
}
this.f20182a.inJustDecodeBounds = false;
if (Build.VERSION.SDK_INT >= 11) {
this.f20182a.inBitmap = bitmap;
}
this.f20182a.inSampleSize = 1;
this.f20182a.inDensity = 320;
this.f20182a.inTargetDensity = this.f88374b;
BitmapFactory.decodeFile(str, this.f20182a);
if (QLog.isDevelopLevel()) {
QLog.d(f88373a, 4, "getBitmapFromFile " + (System.currentTimeMillis() - j));
}
} catch (Exception e) {
if (QLog.isDevelopLevel()) {
QLog.e(f88373a, 4, e.getMessage());
}
} catch (OutOfMemoryError e2) {
if (QLog.isDevelopLevel()) {
QLog.e(f88373a, 4, "getBitmapFromFile OOM");
}
}
}
private void a(Bitmap bitmap, long j, int i) {
try {
if (bitmap == null) {
this.f20182a.inJustDecodeBounds = true;
BitmapFactory.decodeResource(this.f20180a.getResources(), i, this.f20182a);
Bitmap.createBitmap(this.f20182a.outWidth, this.f20182a.outHeight, Bitmap.Config.ARGB_8888);
return;
}
this.f20182a.inJustDecodeBounds = false;
if (Build.VERSION.SDK_INT >= 11) {
this.f20182a.inBitmap = bitmap;
}
this.f20182a.inSampleSize = 1;
this.f20182a.inDensity = 320;
this.f20182a.inTargetDensity = this.f88374b;
BitmapFactory.decodeResource(this.f20180a.getResources(), i, this.f20182a);
if (QLog.isDevelopLevel()) {
QLog.d(f88373a, 4, "getBitmapFromFile " + (System.currentTimeMillis() - j));
}
} catch (Exception e) {
if (QLog.isDevelopLevel()) {
QLog.e(f88373a, 4, e.getMessage());
}
} catch (OutOfMemoryError e2) {
if (QLog.isDevelopLevel()) {
QLog.e(f88373a, 4, "getBitmapFromFile OOM");
}
}
}
@Override
public int getIntrinsicHeight() {
return this.f20181a != null ? this.f20181a.getScaledHeight(this.f88374b) : super.getIntrinsicHeight();
}
@Override
public int getIntrinsicWidth() {
return this.f20181a != null ? this.f20181a.getScaledWidth(this.f88374b) : super.getIntrinsicWidth();
}
public synchronized void c() {
Bitmap bitmap;
if (this.f20181a != null && !this.f20181a.isRecycled()) {
this.f20181a.recycle();
}
if (this.f20197c != null && !this.f20197c.isRecycled()) {
synchronized (this.f20185a) {
this.f20197c.recycle();
}
}
if (this.f20194b != null && !this.f20194b.isRecycled()) {
this.f20194b.recycle();
}
if (this.f20186a != null) {
Iterator it = this.f20186a.iterator();
while (it.hasNext()) {
Bitmap bitmap2 = (Bitmap) it.next();
if (bitmap2 != null && !bitmap2.isRecycled()) {
bitmap2.recycle();
}
}
this.f20186a.clear();
}
if (this.f20187a != null) {
for (String str : this.f20187a.keySet()) {
SoftReference softReference = (SoftReference) this.f20187a.get(str);
if (softReference != null && (bitmap = (Bitmap) softReference.get()) != null && !bitmap.isRecycled()) {
bitmap.recycle();
}
}
this.f20187a.clear();
}
}
}