Package com.airbnb.lottie
Class LottieCompositionFactory
- java.lang.Object
-
- com.airbnb.lottie.LottieCompositionFactory
-
public class LottieCompositionFactory extends Object
Helpers to create or cache a LottieComposition.All factory methods take a cache key. The animation will be stored in an LRU cache for future use. In-progress tasks will also be held so they can be returned for subsequent requests for the same animation prior to the cache being populated.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidclearCache(Context context)static LottieTask<LottieComposition>fromAsset(Context context, String fileName)Parse an animation from src/main/assets.static LottieTask<LottieComposition>fromAsset(Context context, String fileName, String cacheKey)Parse an animation from src/main/assets.static LottieResult<LottieComposition>fromAssetSync(Context context, String fileName)Parse an animation from src/main/assets.static LottieResult<LottieComposition>fromAssetSync(Context context, String fileName, String cacheKey)Parse an animation from src/main/assets.static LottieTask<LottieComposition>fromJson(JSONObject json, String cacheKey)Deprecated.static LottieTask<LottieComposition>fromJsonInputStream(InputStream stream, String cacheKey)Auto-closes the stream.static LottieResult<LottieComposition>fromJsonInputStreamSync(InputStream stream, String cacheKey)Return a LottieComposition for the given InputStream to json.static LottieTask<LottieComposition>fromJsonReader(JsonReader reader, String cacheKey)static LottieResult<LottieComposition>fromJsonReaderSync(JsonReader reader, String cacheKey)static LottieTask<LottieComposition>fromJsonString(String json, String cacheKey)static LottieResult<LottieComposition>fromJsonStringSync(String json, String cacheKey)Return a LottieComposition for the specified raw json string.static LottieResult<LottieComposition>fromJsonSync(JSONObject json, String cacheKey)Deprecated.static LottieTask<LottieComposition>fromRawRes(Context context, int rawRes)Parse an animation from raw/res.static LottieTask<LottieComposition>fromRawRes(Context context, int rawRes, String cacheKey)Parse an animation from raw/res.static LottieResult<LottieComposition>fromRawResSync(Context context, int rawRes)Parse an animation from raw/res.static LottieResult<LottieComposition>fromRawResSync(Context context, int rawRes, String cacheKey)Parse an animation from raw/res.static LottieTask<LottieComposition>fromUrl(Context context, String url)Fetch an animation from an http url.static LottieTask<LottieComposition>fromUrl(Context context, String url, String cacheKey)Fetch an animation from an http url.static LottieResult<LottieComposition>fromUrlSync(Context context, String url)Fetch an animation from an http url.static LottieResult<LottieComposition>fromUrlSync(Context context, String url, String cacheKey)Fetch an animation from an http url.static LottieTask<LottieComposition>fromZipStream(ZipInputStream inputStream, String cacheKey)static LottieResult<LottieComposition>fromZipStreamSync(ZipInputStream inputStream, String cacheKey)Parses a zip input stream into a Lottie composition.static voidsetMaxCacheSize(int size)Set the maximum number of compositions to keep cached in memory.
-
-
-
Method Detail
-
setMaxCacheSize
public static void setMaxCacheSize(int size)
Set the maximum number of compositions to keep cached in memory. This must be > 0.
-
clearCache
public static void clearCache(Context context)
-
fromUrl
public static LottieTask<LottieComposition> fromUrl(Context context, String url)
Fetch an animation from an http url. Once it is downloaded once, Lottie will cache the file to disk for future use. Because of this, you may call `fromUrl` ahead of time to warm the cache if you think you might need an animation in the future.To skip the cache, add null as a third parameter.
-
fromUrl
public static LottieTask<LottieComposition> fromUrl(Context context, String url, @Nullable String cacheKey)
Fetch an animation from an http url. Once it is downloaded once, Lottie will cache the file to disk for future use. Because of this, you may call `fromUrl` ahead of time to warm the cache if you think you might need an animation in the future.
-
fromUrlSync
@WorkerThread public static LottieResult<LottieComposition> fromUrlSync(Context context, String url)
Fetch an animation from an http url. Once it is downloaded once, Lottie will cache the file to disk for future use. Because of this, you may call `fromUrl` ahead of time to warm the cache if you think you might need an animation in the future.
-
fromUrlSync
@WorkerThread public static LottieResult<LottieComposition> fromUrlSync(Context context, String url, @Nullable String cacheKey)
Fetch an animation from an http url. Once it is downloaded once, Lottie will cache the file to disk for future use. Because of this, you may call `fromUrl` ahead of time to warm the cache if you think you might need an animation in the future.
-
fromAsset
public static LottieTask<LottieComposition> fromAsset(Context context, String fileName)
Parse an animation from src/main/assets. It is recommended to usefromRawRes(Context, int)instead. The asset file name will be used as a cache key so future usages won't have to parse the json again. However, if your animation has images, you may package the json and images as a single flattened zip file in assets.To skip the cache, add null as a third parameter.
- See Also:
fromZipStream(ZipInputStream, String)
-
fromAsset
public static LottieTask<LottieComposition> fromAsset(Context context, String fileName, @Nullable String cacheKey)
Parse an animation from src/main/assets. It is recommended to usefromRawRes(Context, int)instead. The asset file name will be used as a cache key so future usages won't have to parse the json again. However, if your animation has images, you may package the json and images as a single flattened zip file in assets.Pass null as the cache key to skip the cache.
- See Also:
fromZipStream(ZipInputStream, String)
-
fromAssetSync
@WorkerThread public static LottieResult<LottieComposition> fromAssetSync(Context context, String fileName)
Parse an animation from src/main/assets. It is recommended to usefromRawRes(Context, int)instead. The asset file name will be used as a cache key so future usages won't have to parse the json again. However, if your animation has images, you may package the json and images as a single flattened zip file in assets.To skip the cache, add null as a third parameter.
-
fromAssetSync
@WorkerThread public static LottieResult<LottieComposition> fromAssetSync(Context context, String fileName, @Nullable String cacheKey)
Parse an animation from src/main/assets. It is recommended to usefromRawRes(Context, int)instead. The asset file name will be used as a cache key so future usages won't have to parse the json again. However, if your animation has images, you may package the json and images as a single flattened zip file in assets.Pass null as the cache key to skip the cache.
-
fromRawRes
public static LottieTask<LottieComposition> fromRawRes(Context context, @RawRes int rawRes)
Parse an animation from raw/res. This is recommended over putting your animation in assets because it uses a hard reference to R. The resource id will be used as a cache key so future usages won't parse the json again. Note: to correctly load dark mode (-night) resources, make sure you pass Activity as a context (instead of e.g. the application context). The Activity won't be leaked.To skip the cache, add null as a third parameter.
-
fromRawRes
public static LottieTask<LottieComposition> fromRawRes(Context context, @RawRes int rawRes, @Nullable String cacheKey)
Parse an animation from raw/res. This is recommended over putting your animation in assets because it uses a hard reference to R. The resource id will be used as a cache key so future usages won't parse the json again. Note: to correctly load dark mode (-night) resources, make sure you pass Activity as a context (instead of e.g. the application context). The Activity won't be leaked.Pass null as the cache key to skip caching.
-
fromRawResSync
@WorkerThread public static LottieResult<LottieComposition> fromRawResSync(Context context, @RawRes int rawRes)
Parse an animation from raw/res. This is recommended over putting your animation in assets because it uses a hard reference to R. The resource id will be used as a cache key so future usages won't parse the json again. Note: to correctly load dark mode (-night) resources, make sure you pass Activity as a context (instead of e.g. the application context). The Activity won't be leaked.To skip the cache, add null as a third parameter.
-
fromRawResSync
@WorkerThread public static LottieResult<LottieComposition> fromRawResSync(Context context, @RawRes int rawRes, @Nullable String cacheKey)
Parse an animation from raw/res. This is recommended over putting your animation in assets because it uses a hard reference to R. The resource id will be used as a cache key so future usages won't parse the json again. Note: to correctly load dark mode (-night) resources, make sure you pass Activity as a context (instead of e.g. the application context). The Activity won't be leaked.Pass null as the cache key to skip caching.
-
fromJsonInputStream
public static LottieTask<LottieComposition> fromJsonInputStream(InputStream stream, @Nullable String cacheKey)
Auto-closes the stream.
-
fromJsonInputStreamSync
@WorkerThread public static LottieResult<LottieComposition> fromJsonInputStreamSync(InputStream stream, @Nullable String cacheKey)
Return a LottieComposition for the given InputStream to json.
-
fromJson
@Deprecated public static LottieTask<LottieComposition> fromJson(JSONObject json, @Nullable String cacheKey)
Deprecated.- See Also:
fromJsonSync(JSONObject, String)
-
fromJsonSync
@Deprecated @WorkerThread public static LottieResult<LottieComposition> fromJsonSync(JSONObject json, @Nullable String cacheKey)
Deprecated.Prefer passing in the json string directly. This method just calls `toString()` on your JSONObject. If you are loading this animation from the network, just use the response body string instead of parsing it first for improved performance.
-
fromJsonString
public static LottieTask<LottieComposition> fromJsonString(String json, @Nullable String cacheKey)
- See Also:
fromJsonStringSync(String, String)
-
fromJsonStringSync
@WorkerThread public static LottieResult<LottieComposition> fromJsonStringSync(String json, @Nullable String cacheKey)
Return a LottieComposition for the specified raw json string. If loading from a file, it is preferable to use the InputStream or rawRes version.
-
fromJsonReader
public static LottieTask<LottieComposition> fromJsonReader(JsonReader reader, @Nullable String cacheKey)
-
fromJsonReaderSync
@WorkerThread public static LottieResult<LottieComposition> fromJsonReaderSync(JsonReader reader, @Nullable String cacheKey)
-
fromZipStream
public static LottieTask<LottieComposition> fromZipStream(ZipInputStream inputStream, @Nullable String cacheKey)
-
fromZipStreamSync
@WorkerThread public static LottieResult<LottieComposition> fromZipStreamSync(ZipInputStream inputStream, @Nullable String cacheKey)
Parses a zip input stream into a Lottie composition. Your zip file should just be a folder with your json file and images zipped together. It will automatically store and configure any images inside the animation if they exist.
-
-