142 lines
5.0 KiB
Java
142 lines
5.0 KiB
Java
package o;
|
|
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapFactory;
|
|
import android.widget.ImageView;
|
|
import com.android.volley.ParseError;
|
|
import o.C15788ibz;
|
|
import o.HJP;
|
|
import o.InterfaceC17333vqS;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class LcE extends HJP<Bitmap> {
|
|
public static final float DEFAULT_IMAGE_BACKOFF_MULT = 2.0f;
|
|
public static final int DEFAULT_IMAGE_MAX_RETRIES = 2;
|
|
public static final int DEFAULT_IMAGE_TIMEOUT_MS = 1000;
|
|
private static final Object sDecodeLock = new Object();
|
|
private final Bitmap.Config mDecodeConfig;
|
|
private C15788ibz.LWm<Bitmap> mListener;
|
|
private final Object mLock;
|
|
private final int mMaxHeight;
|
|
private final int mMaxWidth;
|
|
private final ImageView.ScaleType mScaleType;
|
|
|
|
public LcE(String str, C15788ibz.LWm<Bitmap> lWm, int i, int i2, ImageView.ScaleType scaleType, Bitmap.Config config, C15788ibz.HBt hBt) {
|
|
super(0, str, hBt);
|
|
this.mLock = new Object();
|
|
setRetryPolicy(new kSb(1000, 2, 2.0f));
|
|
this.mListener = lWm;
|
|
this.mDecodeConfig = config;
|
|
this.mMaxWidth = i;
|
|
this.mMaxHeight = i2;
|
|
this.mScaleType = scaleType;
|
|
}
|
|
|
|
@Deprecated
|
|
public LcE(String str, C15788ibz.LWm<Bitmap> lWm, int i, int i2, Bitmap.Config config, C15788ibz.HBt hBt) {
|
|
this(str, lWm, i, i2, ImageView.ScaleType.CENTER_INSIDE, config, hBt);
|
|
}
|
|
|
|
@Override // o.HJP
|
|
public HJP.Sts getPriority() {
|
|
return HJP.Sts.LOW;
|
|
}
|
|
|
|
private static int getResizedDimension(int i, int i2, int i3, int i4, ImageView.ScaleType scaleType) {
|
|
if (i == 0 && i2 == 0) {
|
|
return i3;
|
|
}
|
|
if (scaleType == ImageView.ScaleType.FIT_XY) {
|
|
return i == 0 ? i3 : i;
|
|
}
|
|
if (i == 0) {
|
|
return (int) (i3 * (i2 / i4));
|
|
}
|
|
if (i2 == 0) {
|
|
return i;
|
|
}
|
|
double d = i4 / i3;
|
|
if (scaleType == ImageView.ScaleType.CENTER_CROP) {
|
|
double d2 = i2;
|
|
return ((double) i) * d < d2 ? (int) (d2 / d) : i;
|
|
}
|
|
double d3 = i2;
|
|
return ((double) i) * d > d3 ? (int) (d3 / d) : i;
|
|
}
|
|
|
|
@Override // o.HJP
|
|
public C15788ibz<Bitmap> parseNetworkResponse(DrQ drQ) {
|
|
C15788ibz<Bitmap> doParse;
|
|
synchronized (sDecodeLock) {
|
|
try {
|
|
doParse = doParse(drQ);
|
|
} catch (OutOfMemoryError e) {
|
|
qWd.a("Caught OOM for %d byte image, url=%s", Integer.valueOf(drQ.c.length), getUrl());
|
|
return C15788ibz.b(new ParseError(e));
|
|
}
|
|
}
|
|
return doParse;
|
|
}
|
|
|
|
private C15788ibz<Bitmap> doParse(DrQ drQ) {
|
|
Bitmap decodeByteArray;
|
|
byte[] bArr = drQ.c;
|
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
if (this.mMaxWidth == 0 && this.mMaxHeight == 0) {
|
|
options.inPreferredConfig = this.mDecodeConfig;
|
|
decodeByteArray = BitmapFactory.decodeByteArray(bArr, 0, bArr.length, options);
|
|
} else {
|
|
options.inJustDecodeBounds = true;
|
|
BitmapFactory.decodeByteArray(bArr, 0, bArr.length, options);
|
|
int i = options.outWidth;
|
|
int i2 = options.outHeight;
|
|
int resizedDimension = getResizedDimension(this.mMaxWidth, this.mMaxHeight, i, i2, this.mScaleType);
|
|
int resizedDimension2 = getResizedDimension(this.mMaxHeight, this.mMaxWidth, i2, i, this.mScaleType);
|
|
options.inJustDecodeBounds = false;
|
|
options.inSampleSize = findBestSampleSize(i, i2, resizedDimension, resizedDimension2);
|
|
decodeByteArray = BitmapFactory.decodeByteArray(bArr, 0, bArr.length, options);
|
|
if (decodeByteArray != null && (decodeByteArray.getWidth() > resizedDimension || decodeByteArray.getHeight() > resizedDimension2)) {
|
|
Bitmap createScaledBitmap = Bitmap.createScaledBitmap(decodeByteArray, resizedDimension, resizedDimension2, true);
|
|
decodeByteArray.recycle();
|
|
decodeByteArray = createScaledBitmap;
|
|
}
|
|
}
|
|
if (decodeByteArray != null) {
|
|
return C15788ibz.b(decodeByteArray, (InterfaceC17333vqS.IeS) HNc.b(new Object[]{drQ}));
|
|
}
|
|
return C15788ibz.b(new ParseError(drQ));
|
|
}
|
|
|
|
@Override // o.HJP
|
|
public void cancel() {
|
|
super.cancel();
|
|
synchronized (this.mLock) {
|
|
this.mListener = null;
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: protected */
|
|
@Override // o.HJP
|
|
public void deliverResponse(Bitmap bitmap) {
|
|
C15788ibz.LWm<Bitmap> lWm;
|
|
synchronized (this.mLock) {
|
|
lWm = this.mListener;
|
|
}
|
|
if (lWm != null) {
|
|
lWm.onResponse(bitmap);
|
|
}
|
|
}
|
|
|
|
static int findBestSampleSize(int i, int i2, int i3, int i4) {
|
|
double min = Math.min(i / i3, i2 / i4);
|
|
float f = 1.0f;
|
|
while (true) {
|
|
float f2 = 2.0f * f;
|
|
if (f2 > min) {
|
|
return (int) f;
|
|
}
|
|
f = f2;
|
|
}
|
|
}
|
|
}
|