Allow ImageAssetDelegate to be used with a LottieDrawable that doesn't have a callback (#2183)
Fixes #2112
diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
index 366fde0..646dde8 100644
--- a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
+++ b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
@@ -1255,11 +1255,6 @@
}
private ImageAssetManager getImageAssetManager() {
- if (getCallback() == null) {
- // We can't get a bitmap since we can't get a Context from the callback.
- return null;
- }
-
if (imageAssetManager != null && !imageAssetManager.hasSameContext(getContext())) {
imageAssetManager = null;
}
diff --git a/lottie/src/main/java/com/airbnb/lottie/manager/ImageAssetManager.java b/lottie/src/main/java/com/airbnb/lottie/manager/ImageAssetManager.java
index f36fc6b..2f7921c 100644
--- a/lottie/src/main/java/com/airbnb/lottie/manager/ImageAssetManager.java
+++ b/lottie/src/main/java/com/airbnb/lottie/manager/ImageAssetManager.java
@@ -19,7 +19,7 @@
public class ImageAssetManager {
private static final Object bitmapHashLock = new Object();
- private final Context context;
+ @Nullable private final Context context;
private final String imagesFolder;
@Nullable private ImageAssetDelegate delegate;
private final Map<String, LottieImageAsset> imageAssets;
@@ -31,16 +31,14 @@
} else {
this.imagesFolder = imagesFolder;
}
+ this.imageAssets = imageAssets;
+ setDelegate(delegate);
if (!(callback instanceof View)) {
- Logger.warning("LottieDrawable must be inside of a view for images to work.");
- this.imageAssets = new HashMap<>();
context = null;
return;
}
context = ((View) callback).getContext().getApplicationContext();
- this.imageAssets = imageAssets;
- setDelegate(delegate);
}
public void setDelegate(@Nullable ImageAssetDelegate assetDelegate) {
@@ -84,6 +82,12 @@
}
return bitmap;
}
+ Context context = this.context;
+ if (context == null) {
+ // If there is no context, the image has to be embedded or provided via
+ // a delegate.
+ return null;
+ }
String filename = asset.getFileName();
BitmapFactory.Options opts = new BitmapFactory.Options();