Class LottieDrawable

    • Field Detail

      • RESTART

        public static final int RESTART
        When the animation reaches the end and repeatCount is INFINITE or a positive value, the animation restarts from the beginning.
        See Also:
        Constant Field Values
      • REVERSE

        public static final int REVERSE
        When the animation reaches the end and repeatCount is INFINITE or a positive value, the animation reverses direction on every iteration.
        See Also:
        Constant Field Values
    • Constructor Detail

      • LottieDrawable

        public LottieDrawable()
    • Method Detail

      • hasMasks

        public boolean hasMasks()
        Returns whether or not any layers in this composition has masks.
      • hasMatte

        public boolean hasMatte()
        Returns whether or not any layers in this composition has a matte layer.
      • enableMergePathsForKitKatAndAbove

        public boolean enableMergePathsForKitKatAndAbove()
      • enableMergePathsForKitKatAndAbove

        public void enableMergePathsForKitKatAndAbove​(boolean enable)
        Enable this to get merge path support for devices running KitKat (19) and above.

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

      • isMergePathsEnabledForKitKatAndAbove

        public boolean isMergePathsEnabledForKitKatAndAbove()
      • setImagesAssetsFolder

        public void setImagesAssetsFolder​(@Nullable
                                          java.lang.String imageAssetsFolder)
        If you use image assets, you must explicitly specify the folder in assets/ in which they are located 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 shapes from 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. Check the documentation at http://airbnb.io/lottie for more information about importing shapes from Sketch or Illustrator to avoid this.

      • getImageAssetsFolder

        @Nullable
        public java.lang.String getImageAssetsFolder()
      • setComposition

        public boolean setComposition​(LottieComposition composition)
        Create a composition with LottieCompositionFactory
        Returns:
        True if the composition is different from the previously set composition, false otherwise.
      • setPerformanceTrackingEnabled

        public void setPerformanceTrackingEnabled​(boolean enabled)
      • setOutlineMasksAndMattes

        public void setOutlineMasksAndMattes​(boolean outline)
        Enable this to debug slow animations by outlining masks and mattes. The performance overhead of the masks and mattes will be proportional to the surface area of all of the masks/mattes combined. DO NOT leave this enabled in production.
      • setApplyingOpacityToLayersEnabled

        public 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 accurate at 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.

        See Also:
        View.setLayerType(int, android.graphics.Paint), LottieAnimationView.setRenderMode(RenderMode)
      • disableExtraScaleModeInFitXY

        public void disableExtraScaleModeInFitXY()
        Disable the extraScale mode in draw(Canvas) function when scaleType is FitXY. It doesn't affect the rendering with other scaleTypes.

        When there are 2 animation layout side by side, the default extra scale mode might leave 1 pixel not drawn between 2 animation, and disabling the extraScale mode can fix this problem

        Attention: Disable the extra scale mode can downgrade the performance and may lead to larger memory footprint. Please only disable this mode when using animation with a reasonable dimension (smaller than screen size).
        See Also:
        drawWithNewAspectRatio(Canvas)
      • isApplyingOpacityToLayersEnabled

        public boolean isApplyingOpacityToLayersEnabled()
      • clearComposition

        public void clearComposition()
      • setSafeMode

        public void setSafeMode​(boolean safeMode)
        If you are experiencing a device specific crash that happens during drawing, you can set this to true for those devices. If set to true, draw will be wrapped with a try/catch which will cause Lottie to render 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 use this for very specific cases if absolutely necessary.
      • setAlpha

        public void setAlpha​(int alpha)
        Specified by:
        setAlpha in class Drawable
      • draw

        public void draw​(@NonNull
                         Canvas canvas)
        Specified by:
        draw in class Drawable
      • start

        @MainThread
        public void start()
        Specified by:
        start in interface Animatable
      • stop

        @MainThread
        public void stop()
        Specified by:
        stop in interface Animatable
      • playAnimation

        @MainThread
        public void playAnimation()
        Plays the animation from the beginning. If speed is < 0, it will start at the end and play towards the beginning
      • endAnimation

        @MainThread
        public void endAnimation()
      • resumeAnimation

        @MainThread
        public void resumeAnimation()
        Continues playing the animation from its current position. If speed < 0, it will play backwards from the current position.
      • setMinFrame

        public void setMinFrame​(int minFrame)
        Sets the minimum frame that the animation will start from when playing or looping.
      • setMinProgress

        public void setMinProgress​(float minProgress)
        Sets the minimum progress that the animation will start from when playing or looping.
      • setMaxFrame

        public 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 same thing as composition.endFrame.
      • setMaxProgress

        public void setMaxProgress​(float maxProgress)
        Sets the maximum progress that the animation will end at when playing or looping.
      • setMinFrame

        public void setMinFrame​(java.lang.String markerName)
        Sets the minimum frame to the start time of the specified marker.
        Throws:
        java.lang.IllegalArgumentException - if the marker is not found.
      • setMaxFrame

        public void setMaxFrame​(java.lang.String markerName)
        Sets the maximum frame to the start time + duration of the specified marker.
        Throws:
        java.lang.IllegalArgumentException - if the marker is not found.
      • setMinAndMaxFrame

        public void setMinAndMaxFrame​(java.lang.String markerName)
        Sets the minimum and maximum frame to the start time and start time + duration of the specified marker.
        Throws:
        java.lang.IllegalArgumentException - if the marker is not found.
      • setMinAndMaxFrame

        public void setMinAndMaxFrame​(java.lang.String startMarkerName,
                                      java.lang.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 marker represents the end of the section that you want, it should be true. If the marker represents the beginning of the next section, it should be false.
        Throws:
        java.lang.IllegalArgumentException - if either marker is not found.
      • setSpeed

        public void setSpeed​(float speed)
        Sets the playback speed. If speed < 0, the animation will play backwards.
      • getSpeed

        public float getSpeed()
        Returns the current playback speed. This will be < 0 if the animation is playing backwards.
      • removeAllUpdateListeners

        public void removeAllUpdateListeners()
      • removeAllAnimatorListeners

        public void removeAllAnimatorListeners()
      • setFrame

        public 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 when it is.
      • getFrame

        public int getFrame()
        Get the currently rendered frame.
      • setProgress

        public void setProgress​(float progress)
      • loop

        @Deprecated
        public void loop​(boolean loop)
        Deprecated.
        See Also:
        setRepeatCount(int)
      • setRepeatMode

        public void setRepeatMode​(int mode)
        Defines what this animation should do when it reaches the end. This setting is applied only when the repeat count is either greater than 0 or INFINITE. Defaults to RESTART.
        Parameters:
        mode - RESTART or REVERSE
      • getRepeatMode

        public int getRepeatMode()
        Defines what this animation should do when it reaches the end.
        Returns:
        either one of REVERSE or RESTART
      • setRepeatCount

        public void setRepeatCount​(int count)
        Sets how many times the animation should be repeated. If the repeat count is 0, the animation is never repeated. If the repeat count is greater than 0 or INFINITE, the repeat mode will be taken into account. The repeat count is 0 by default.
        Parameters:
        count - the number of times the animation should be repeated
      • getRepeatCount

        public int getRepeatCount()
        Defines how many times the animation should repeat. The default value is 0.
        Returns:
        the number of times the animation should repeat, or INFINITE
      • isLooping

        public boolean isLooping()
      • isAnimating

        public boolean isAnimating()
      • setScale

        public void setScale​(float scale)
        Set the scale on the current composition. The only cost of this function is re-rendering the current frame so you may call it frequent to scale something up or down.

        The smaller the animation is, the better the performance will be. You may find that scaling an animation down then rendering it in a larger ImageView and letting ImageView scale it back up with a scaleType such as centerInside will yield better performance with little perceivable quality loss.

        You can also use a fixed view width/height in conjunction with the normal ImageView scaleTypes centerCrop and centerInside.

      • setImageAssetDelegate

        public void setImageAssetDelegate​(ImageAssetDelegate assetDelegate)
        Use this if you can't bundle images with your app. This may be useful if you download the animations from the network or have the images saved to an SD Card. In that case, Lottie will 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 shapes from 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. Check the documentation at http://airbnb.io/lottie for more information about importing shapes from Sketch or Illustrator to avoid this.

      • setFontAssetDelegate

        public void setFontAssetDelegate​(FontAssetDelegate assetDelegate)
        Use this to manually set fonts.
      • setTextDelegate

        public void setTextDelegate​(TextDelegate textDelegate)
      • getTextDelegate

        @Nullable
        public TextDelegate getTextDelegate()
      • useTextGlyphs

        public boolean useTextGlyphs()
      • getScale

        public float getScale()
      • cancelAnimation

        public void cancelAnimation()
      • pauseAnimation

        public void pauseAnimation()
      • getProgress

        public float getProgress()
      • resolveKeyPath

        public java.util.List<KeyPath> resolveKeyPath​(KeyPath keyPath)
        Takes a KeyPath, potentially with wildcards or globstars and resolve it to a list of zero 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 the returned KeyPath objects because they will be internally resolved to their content and won't trigger a tree walk of the animation contents when applied.

      • addValueCallback

        public <T> void addValueCallback​(KeyPath keyPath,
                                         T property,
                                         LottieValueCallback<T> callback)
        Add an property callback for the specified KeyPath. This KeyPath can resolve to 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(KeyPath) and will resolve it if it hasn't.

      • updateBitmap

        @Nullable
        public Bitmap updateBitmap​(java.lang.String id,
                                   @Nullable
                                   Bitmap bitmap)
        Allows you to modify or clear a bitmap that was loaded for an image either automatically through setImagesAssetsFolder(String) or with an ImageAssetDelegate.
        Returns:
        the previous Bitmap or null.
      • getImageAsset

        @Nullable
        public Bitmap getImageAsset​(java.lang.String id)
      • getTypeface

        @Nullable
        public Typeface getTypeface​(java.lang.String fontFamily,
                                    java.lang.String style)
      • invalidateDrawable

        public void invalidateDrawable​(@NonNull
                                       Drawable who)
        These Drawable.Callback methods proxy the calls so that this is the drawable that is actually invalidated, not a child one which will not pass the view's validateDrawable check.
        Specified by:
        invalidateDrawable in interface Drawable.Callback