Package 

Class LottieDrawable

  • All Implemented Interfaces:
    android.graphics.drawable.Animatable , android.graphics.drawable.Drawable.Callback

    
    public class LottieDrawable
    extends Drawable implements Drawable.Callback, Animatable
                        

    This can be used to show an lottie animation in any place that would normally take a drawable.

    • Constructor Detail

      • LottieDrawable

        LottieDrawable()
    • Method Detail

      • setSafeMode

         void setSafeMode(boolean safeMode)

        If you are experiencing a device specific crash that happens during drawing, you can set this to truefor those devices. If set to true, draw will be wrapped with a try/catch which will cause Lottie torender an empty frame rather than crash your app.

        Ideally, you will never need this and the vast majority of apps and animations won't. However, you may usethis for very specific cases if absolutely necessary.

      • setImageAssetDelegate

         void setImageAssetDelegate(ImageAssetDelegate assetDelegate)

        Use this if you can't bundle images with your app. This may be useful if you download theanimations from the network or have the images saved to an SD Card. In that case, Lottiewill defer the loading of the bitmap to this delegate.

        Be wary if you are using many images, however. Lottie is designed to work with vector shapesfrom After Effects. If your images look like they could be represented with vector shapes,see if it is possible to convert them to shape layers and re-export your animation. Checkthe documentation at http://airbnb.io/lottie for more information about importing shapes fromSketch or Illustrator to avoid this.

      • setFontMap

         void setFontMap(@Nullable() Map<String, Typeface> fontMap)

        Set a map from font name keys to Typefaces.The keys can be in the form:* fontFamily* fontFamily-fontStyle* fontNameAll 3 are defined as fName, fFamily, and fStyle in the Lottie file.

        If you change a value in fontMap, create a new map or call invalidateSelf. Setting the same map again will noop.

      • setDefaultFontFileExtension

         void setDefaultFontFileExtension(String extension)

        By default, Lottie will look in src/assets/fonts/FONT_NAME.ttfwhere FONT_NAME is the fFamily specified in your Lottie file.If your fonts have a different extension, you can override thedefault here.

        Alternatively, you can use setFontAssetDelegate for more control.

      • getMaintainOriginalImageBounds

         boolean getMaintainOriginalImageBounds()

        When true, dynamically set bitmaps will be drawn with the exact bounds of the original animation, regardless of the bitmap size.When false, dynamically set bitmaps will be drawn at the top left of the original image but with its own bounds.

        Defaults to false.

      • setMaintainOriginalImageBounds

         void setMaintainOriginalImageBounds(boolean maintainOriginalImageBounds)

        When true, dynamically set bitmaps will be drawn with the exact bounds of the original animation, regardless of the bitmap size.When false, dynamically set bitmaps will be drawn at the top left of the original image but with its own bounds.

        Defaults to false.

      • getClipToCompositionBounds

         boolean getClipToCompositionBounds()

        Gets whether or not Lottie should clip to the original animation composition bounds.

        Defaults to true.

      • setClipToCompositionBounds

         void setClipToCompositionBounds(boolean clipToCompositionBounds)

        Sets whether or not Lottie should clip to the original animation composition bounds.

        Defaults to true.

      • setOutlineMasksAndMattes

         void setOutlineMasksAndMattes(boolean outline)

        Enable this to debug slow animations by outlining masks and mattes. The performance overhead of the masks and mattes willbe proportional to the surface area of all of the masks/mattes combined.

        DO NOT leave this enabled in production.

      • setClipTextToBoundingBox

         void setClipTextToBoundingBox(boolean clipTextToBoundingBox)

        When true, if there is a bounding box set on a text layer (paragraph text), any textthat overflows past its height will not be drawn.

      • getRenderMode

         RenderMode getRenderMode()

        Returns the actual render mode being used. It will always be HARDWARE or SOFTWARE.When the render mode is set to AUTOMATIC, the value will be derived from useSoftwareRendering.

      • setRenderMode

         void setRenderMode(RenderMode renderMode)

        Call this to set whether or not to render with hardware or software acceleration.Lottie defaults to Automatic which will use hardware acceleration unless:1) There are dash paths and the device is pre-Pie.2) There are more than 4 masks and mattes and the device is pre-Pie.Hardware acceleration is generally faster for those devices unlessthere are many large mattes and masks in which case there is a lotof GPU uploadTexture thrashing which makes it much slower.

        In most cases, hardware rendering will be faster, even if you have mattes and masks.However, if you have multiple mattes and masks (especially large ones), youshould test both render modes. You should also test on pre-Pie and Pie+ devicesbecause the underlying rendering engine changed significantly.

      • hasMasks

         boolean hasMasks()

        Returns whether or not any layers in this composition has masks.

      • hasMatte

         boolean hasMatte()

        Returns whether or not any layers in this composition has a matte layer.

      • enableMergePathsForKitKatAndAbove

        @Deprecated() void enableMergePathsForKitKatAndAbove(boolean enable)

        Enable this to get merge path support for devices running KitKat (19) and above.Deprecated: Use enableFeatureFlag(LottieFeatureFlags.FeatureFlag.MergePathsApi19, enable)

        Merge paths currently don't work if the the operand shape is entirely contained within thefirst shape. If you need to cut out one shape from another shape, use an even-odd fill typeinstead of using merge paths.

      • enableFeatureFlag

         void enableFeatureFlag(LottieFeatureFlag flag, boolean enable)

        Enable the specified feature for this drawable.

        Features guarded by LottieFeatureFlags are experimental or only supported by a subset of API levels.Please ensure that the animation supported by the enabled feature looks acceptable across alltargeted API levels.

      • setImagesAssetsFolder

         void setImagesAssetsFolder(@Nullable() String imageAssetsFolder)

        If you use image assets, you must explicitly specify the folder in assets/ in which they arelocated because bodymovin uses the name filenames across all compositions (img_#).Do NOT rename the images themselves.

        If your images are located in src/main/assets/airbnb_loader/ then call`setImageAssetsFolder("airbnb_loader/");`.

        Be wary if you are using many images, however. Lottie is designed to work with vector shapesfrom After Effects. If your images look like they could be represented with vector shapes,see if it is possible to convert them to shape layers and re-export your animation. Checkthe documentation at airbnb.io/lottie for more information about importing shapes fromSketch or Illustrator to avoid this.

      • getAsyncUpdatesEnabled

         boolean getAsyncUpdatesEnabled()

        Similar to getAsyncUpdates except it returns the actualboolean value for whether async updates are enabled or not.This is useful when the mode is automatic and you want to knowwhether automatic is defaulting to enabled or not.

      • setApplyingOpacityToLayersEnabled

         void setApplyingOpacityToLayersEnabled(boolean isApplyingOpacityToLayersEnabled)

        Sets whether to apply opacity to the each layer instead of shape.

        Opacity is normally applied directly to a shape. In cases where translucent shapes overlap, applying opacity to a layer will be more accurateat the expense of performance.

        The default value is false.

        Note: This process is very expensive. The performance impact will be reduced when hardware acceleration is enabled.

      • setApplyingShadowToLayersEnabled

         void setApplyingShadowToLayersEnabled(boolean isApplyingShadowsToLayersEnabled)

        Sets whether to apply drop shadows to each layer instead of shape.

        When true, the behavior will be more correct: it will mimic lottie-web and other renderers, in that drop shadows will be applied to a layeras a whole, no matter its contents.

        When false, the performance will be better at the expense of correctness: for each shape element individually, the first drop shadow upwardsin the hierarchy is applied to it directly. Visually, this may manifest as phantom shadows or artifacts where the artist has intended to treat alayer as a whole, and this option exposes its internal structure.

        The default value is true.

      • playAnimation

        @MainThread() void playAnimation()

        Plays the animation from the beginning. If speed is {@literal <} 0, it will start at the endand play towards the beginning

      • getMarkerForAnimationsDisabled

        @RestrictTo(value = RestrictTo.Scope.LIBRARY) Marker getMarkerForAnimationsDisabled()

        This method is used to get the marker for animations when system animations are disabled.It iterates over the list of allowed reduced motion markers and returns the first non-null marker it finds.If no non-null marker is found, it returns null.

      • resumeAnimation

        @MainThread() void resumeAnimation()

        Continues playing the animation from its current position. If speed {@literal <} 0, it will play backwardsfrom the current position.

      • setMinFrame

         void setMinFrame(int minFrame)

        Sets the minimum frame that the animation will start from when playing or looping.

      • setMinProgress

         void setMinProgress(float minProgress)

        Sets the minimum progress that the animation will start from when playing or looping.

      • setMaxFrame

         void setMaxFrame(int maxFrame)

        Sets the maximum frame that the animation will end at when playing or looping.

        The value will be clamped to the composition bounds. For example, setting Integer.MAX_VALUE would result in the samething as composition.endFrame.

      • setMaxProgress

         void setMaxProgress(@FloatRange(from = 0f, to = 1f) float maxProgress)

        Sets the maximum progress that the animation will end at when playing or looping.

      • setMinFrame

         void setMinFrame(String markerName)

        Sets the minimum frame to the start time of the specified marker.

      • setMaxFrame

         void setMaxFrame(String markerName)

        Sets the maximum frame to the start time + duration of the specified marker.

      • setMinAndMaxFrame

         void setMinAndMaxFrame(String markerName)

        Sets the minimum and maximum frame to the start time and start time + durationof the specified marker.

      • setMinAndMaxFrame

         void setMinAndMaxFrame(String startMarkerName, String endMarkerName, boolean playEndMarkerStartFrame)

        Sets the minimum and maximum frame to the start marker start and the maximum frame to the end marker start.playEndMarkerStartFrame determines whether or not to play the frame that the end marker is on. If the end markerrepresents the end of the section that you want, it should be true. If the marker represents the beginning of thenext section, it should be false.

      • reverseAnimationSpeed

         void reverseAnimationSpeed()

        Reverses the current animation speed. This does NOT play the animation.

      • setSpeed

         void setSpeed(float speed)

        Sets the playback speed. If speed {@literal <} 0, the animation will play backwards.

      • getSpeed

         float getSpeed()

        Returns the current playback speed. This will be {@literal <} 0 if the animation is playing backwards.

      • setFrame

         void setFrame(int frame)

        Sets the progress to the specified frame.If the composition isn't set yet, the progress will be set to the frame whenit is.

      • getFrame

         int getFrame()

        Get the currently rendered frame.

      • setRepeatMode

         void setRepeatMode(int mode)

        Defines what this animation should do when it reaches the end. Thissetting is applied only when the repeat count is either greater than0 or INFINITE. Defaults to RESTART.

        Parameters:
        mode - RESTART or REVERSE
      • getRepeatMode

         int getRepeatMode()

        Defines what this animation should do when it reaches the end.

      • setRepeatCount

         void setRepeatCount(int count)

        Sets how many times the animation should be repeated. If the repeatcount is 0, the animation is never repeated. If the repeat count isgreater than 0 or INFINITE, the repeat mode will be takeninto account. The repeat count is 0 by default.

        Parameters:
        count - the number of times the animation should be repeated
      • getRepeatCount

         int getRepeatCount()

        Defines how many times the animation should repeat. The default valueis 0.

      • setSystemAnimationsAreEnabled

        @Deprecated() void setSystemAnimationsAreEnabled(Boolean areEnabled)

        Tell Lottie that system animations are disabled. When using LottieAnimationView or Compose {@code LottieAnimation}, this is doneautomatically. However, if you are using LottieDrawable on its own, you should set this to false when getAnimationScale is 0. If the animation is provided a "reduced motion"marker name, they will be shown instead of the first or last frame. Supported marker names are case insensitive, and include:- reduced motion- reducedMotion- reduced_motion- reduced-motion

      • setIgnoreDisabledSystemAnimations

        @Deprecated() void setIgnoreDisabledSystemAnimations(boolean ignore)

        Allows ignoring system animations settings, therefore allowing animations to run even if they are disabled.

        Defaults to false.

        Parameters:
        ignore - if true animations will run even when they are disabled in the system settings.
      • setUseCompositionFrameRate

         void setUseCompositionFrameRate(boolean useCompositionFrameRate)

        Lottie files can specify a target frame rate. By default, Lottie ignores it and re-renderson every frame. If that behavior is undesirable, you can set this to true to use the compositionframe rate instead.

        Note: composition frame rates are usually lower than display frame ratesso this will likely make your animation feel janky. However, it may be desirablefor specific situations such as pixel art that are intended to have low frame rates.

      • resolveKeyPath

         List<KeyPath> resolveKeyPath(KeyPath keyPath)

        Takes a KeyPath, potentially with wildcards or globstars and resolve it to a list ofzero or more actual Keypaths that exist in the current animation.

        If you want to set value callbacks for any of these values, it is recommend to use thereturned KeyPath objects because they will be internally resolved to their contentand won't trigger a tree walk of the animation contents when applied.

      • addValueCallback

         <T> void addValueCallback(KeyPath keyPath, T property, @Nullable() LottieValueCallback<T> callback)

        Add an property callback for the specified KeyPath. This KeyPath can resolveto multiple contents. In that case, the callback's value will apply to all of them.

        Internally, this will check if the KeyPath has already been resolved with resolveKeyPath and will resolve it if it hasn't.

        Set the callback to null to clear it.

      • addValueCallback

         <T> void addValueCallback(KeyPath keyPath, T property, SimpleLottieValueCallback<T> callback)

        Overload of addValueCallback that takes an interface. This allows you to use a single abstractmethod code block in Kotlin such as:drawable.addValueCallback(yourKeyPath, LottieProperty.COLOR) { yourColor }

      • getBitmapForId

        @Nullable() Bitmap getBitmapForId(String id)

        Returns the bitmap that will be rendered for the given id in the Lottie animation file.The id is the asset reference id stored in the "id" property of each object in the "assets" array.

        The returned bitmap could be from:* Embedded in the animation file as a base64 string.* In the same directory as the animation file.* In the same zip file as the animation file.* Returned from an ImageAssetDelegate.or null if the image doesn't exist from any of those places.

      • getLottieImageAssetForId

        @Nullable() LottieImageAsset getLottieImageAssetForId(String id)

        Returns the LottieImageAsset that will be rendered for the given id in the Lottie animation file.The id is the asset reference id stored in the "id" property of each object in the "assets" array.

        The returned bitmap could be from:* Embedded in the animation file as a base64 string.* In the same directory as the animation file.* In the same zip file as the animation file.* Returned from an ImageAssetDelegate.or null if the image doesn't exist from any of those places.

      • setVisible

         boolean setVisible(boolean visible, boolean restart)
      • invalidateDrawable

         void invalidateDrawable(@NonNull() Drawable who)

        These Drawable.Callback methods proxy the calls so that this is the drawable that isactually invalidated, not a child one which will not pass the view's validateDrawable check.