189 lines
7.7 KiB
Java
189 lines
7.7 KiB
Java
|
package com.airbnb.lottie.manager;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.content.res.AssetManager;
|
||
|
import android.graphics.Bitmap;
|
||
|
import android.graphics.BitmapFactory;
|
||
|
import android.graphics.drawable.Drawable;
|
||
|
import android.telephony.cdma.CdmaCellLocation;
|
||
|
import android.text.TextUtils;
|
||
|
import android.util.Base64;
|
||
|
import android.view.View;
|
||
|
import android.view.ViewConfiguration;
|
||
|
import com.airbnb.lottie.ImageAssetDelegate;
|
||
|
import com.airbnb.lottie.LottieImageAsset;
|
||
|
import com.airbnb.lottie.utils.Logger;
|
||
|
import com.airbnb.lottie.utils.Utils;
|
||
|
import java.io.IOException;
|
||
|
import java.io.InputStream;
|
||
|
import java.lang.reflect.Method;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
import o.xzZ;
|
||
|
|
||
|
/* loaded from: classes.dex */
|
||
|
public class ImageAssetManager {
|
||
|
private static int b = 1;
|
||
|
private static final Object bitmapHashLock = new Object();
|
||
|
private static int d;
|
||
|
private final Context context;
|
||
|
private ImageAssetDelegate delegate;
|
||
|
private final Map<String, LottieImageAsset> imageAssets;
|
||
|
private final String imagesFolder;
|
||
|
|
||
|
public ImageAssetManager(Drawable.Callback callback, String str, ImageAssetDelegate imageAssetDelegate, Map<String, LottieImageAsset> map) {
|
||
|
if (!TextUtils.isEmpty(str) && str.charAt(str.length() - 1) != '/') {
|
||
|
StringBuilder sb = new StringBuilder();
|
||
|
sb.append(str);
|
||
|
sb.append('/');
|
||
|
str = sb.toString();
|
||
|
}
|
||
|
this.imagesFolder = str;
|
||
|
if (!(callback instanceof View)) {
|
||
|
Logger.warning("LottieDrawable must be inside of a view for images to work.");
|
||
|
this.imageAssets = new HashMap();
|
||
|
this.context = null;
|
||
|
} else {
|
||
|
this.context = ((View) callback).getContext();
|
||
|
this.imageAssets = map;
|
||
|
setDelegate(imageAssetDelegate);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public Bitmap updateBitmap(String str, Bitmap bitmap) {
|
||
|
if (bitmap == null) {
|
||
|
LottieImageAsset lottieImageAsset = this.imageAssets.get(str);
|
||
|
Bitmap bitmap2 = lottieImageAsset.getBitmap();
|
||
|
lottieImageAsset.setBitmap(null);
|
||
|
return bitmap2;
|
||
|
}
|
||
|
Bitmap bitmap3 = this.imageAssets.get(str).getBitmap();
|
||
|
putBitmap(str, bitmap);
|
||
|
return bitmap3;
|
||
|
}
|
||
|
|
||
|
public LottieImageAsset getImageAssetById(String str) {
|
||
|
return this.imageAssets.get(str);
|
||
|
}
|
||
|
|
||
|
public Bitmap bitmapForId(String str) {
|
||
|
int i = 2 % 2;
|
||
|
int i2 = b + 103;
|
||
|
d = i2 % 128;
|
||
|
int i3 = i2 % 2;
|
||
|
LottieImageAsset lottieImageAsset = this.imageAssets.get(str);
|
||
|
if (lottieImageAsset == null) {
|
||
|
int i4 = d + 115;
|
||
|
b = i4 % 128;
|
||
|
int i5 = i4 % 2;
|
||
|
return null;
|
||
|
}
|
||
|
Bitmap bitmap = lottieImageAsset.getBitmap();
|
||
|
if (bitmap != null) {
|
||
|
return bitmap;
|
||
|
}
|
||
|
ImageAssetDelegate imageAssetDelegate = this.delegate;
|
||
|
if (imageAssetDelegate != null) {
|
||
|
int i6 = d + 37;
|
||
|
b = i6 % 128;
|
||
|
int i7 = i6 % 2;
|
||
|
Bitmap fetchBitmap = imageAssetDelegate.fetchBitmap(lottieImageAsset);
|
||
|
if (fetchBitmap != null) {
|
||
|
putBitmap(str, fetchBitmap);
|
||
|
}
|
||
|
int i8 = b + 71;
|
||
|
d = i8 % 128;
|
||
|
int i9 = i8 % 2;
|
||
|
return fetchBitmap;
|
||
|
}
|
||
|
String fileName = lottieImageAsset.getFileName();
|
||
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||
|
options.inScaled = true;
|
||
|
options.inDensity = 160;
|
||
|
try {
|
||
|
if (((Boolean) String.class.getMethod("startsWith", String.class).invoke(fileName, "data:")).booleanValue()) {
|
||
|
if (((Integer) String.class.getMethod("indexOf", String.class).invoke(fileName, "base64,")).intValue() > 0) {
|
||
|
int i10 = b + 43;
|
||
|
d = i10 % 128;
|
||
|
try {
|
||
|
try {
|
||
|
try {
|
||
|
byte[] decode = Base64.decode((String) String.class.getMethod("substring", Integer.TYPE).invoke(fileName, Integer.valueOf(((Integer) String.class.getMethod("indexOf", Integer.TYPE).invoke(fileName, Integer.valueOf(i10 % 2 != 0 ? 7 : 44))).intValue() + 1)), 0);
|
||
|
return putBitmap(str, BitmapFactory.decodeByteArray(decode, 0, decode.length, options));
|
||
|
} catch (Throwable th) {
|
||
|
Throwable cause = th.getCause();
|
||
|
if (cause != null) {
|
||
|
throw cause;
|
||
|
}
|
||
|
throw th;
|
||
|
}
|
||
|
} catch (IllegalArgumentException e) {
|
||
|
Logger.warning("data URL did not have correct base64 format.", e);
|
||
|
return null;
|
||
|
}
|
||
|
} catch (Throwable th2) {
|
||
|
Throwable cause2 = th2.getCause();
|
||
|
if (cause2 != null) {
|
||
|
throw cause2;
|
||
|
}
|
||
|
throw th2;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
try {
|
||
|
if (TextUtils.isEmpty(this.imagesFolder)) {
|
||
|
throw new IllegalStateException("You must set an images folder before loading an image. Set it with LottieComposition#setImagesFolder or LottieDrawable#setImagesFolder");
|
||
|
}
|
||
|
AssetManager assets = this.context.getAssets();
|
||
|
StringBuilder sb = new StringBuilder();
|
||
|
sb.append(this.imagesFolder);
|
||
|
sb.append(fileName);
|
||
|
try {
|
||
|
Object[] objArr = {assets, sb.toString()};
|
||
|
Object obj = xzZ.y.get(-867414553);
|
||
|
if (obj == null) {
|
||
|
obj = ((Class) xzZ.c(5 - (ViewConfiguration.getDoubleTapTimeout() >> 16), (CdmaCellLocation.convertQuartSecToDecDegrees(0) > 0.0d ? 1 : (CdmaCellLocation.convertQuartSecToDecDegrees(0) == 0.0d ? 0 : -1)) + 5, (char) Drawable.resolveOpacity(0, 0))).getMethod("NN_", AssetManager.class, String.class);
|
||
|
xzZ.y.put(-867414553, obj);
|
||
|
}
|
||
|
try {
|
||
|
return putBitmap(str, Utils.resizeBitmapIfNeeded(BitmapFactory.decodeStream((InputStream) ((Method) obj).invoke(null, objArr), null, options), lottieImageAsset.getWidth(), lottieImageAsset.getHeight()));
|
||
|
} catch (IllegalArgumentException e2) {
|
||
|
Logger.warning("Unable to decode image.", e2);
|
||
|
return null;
|
||
|
}
|
||
|
} catch (Throwable th3) {
|
||
|
Throwable cause3 = th3.getCause();
|
||
|
if (cause3 != null) {
|
||
|
throw cause3;
|
||
|
}
|
||
|
throw th3;
|
||
|
}
|
||
|
} catch (IOException e3) {
|
||
|
Logger.warning("Unable to open asset.", e3);
|
||
|
return null;
|
||
|
}
|
||
|
} catch (Throwable th4) {
|
||
|
Throwable cause4 = th4.getCause();
|
||
|
if (cause4 != null) {
|
||
|
throw cause4;
|
||
|
}
|
||
|
throw th4;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public boolean hasSameContext(Context context) {
|
||
|
return (context == null && this.context == null) || this.context.equals(context);
|
||
|
}
|
||
|
|
||
|
private Bitmap putBitmap(String str, Bitmap bitmap) {
|
||
|
synchronized (bitmapHashLock) {
|
||
|
this.imageAssets.get(str).setBitmap(bitmap);
|
||
|
}
|
||
|
return bitmap;
|
||
|
}
|
||
|
|
||
|
public void setDelegate(ImageAssetDelegate imageAssetDelegate) {
|
||
|
this.delegate = imageAssetDelegate;
|
||
|
}
|
||
|
}
|