2 * Copyright 2021 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 package org.skia.androidkit;
10 import org.skia.androidkit.Canvas;
12 public class SkottieAnimation {
13 private long mNativeInstance;
16 * Create an animation from the provided JSON string.
18 public SkottieAnimation(String animation_json) {
19 mNativeInstance = nCreate(animation_json);
23 * Returns the animation duration in seconds.
25 public double getDuration() {
26 return nGetDuration(mNativeInstance);
30 * Returns the animation frame count. This is normally an integral value,
31 * but both the JSON encoding and Skottie's frame-based APIs support fractional frames.
33 public double getFrameCount() {
34 return nGetFrameCount(mNativeInstance);
38 * Returns the intrinsic animation width.
40 public float getWidth() {
41 return nGetWidth(mNativeInstance);
45 * Returns the intrinsic animation height.
47 public float getHeight() {
48 return nGetHeight(mNativeInstance);
52 * Update the animation state to match |t|, specifed in seconds.
53 * The input is clamped to [0..duration).
55 public void seekTime(double t) {
56 nSeekTime(mNativeInstance, t);
60 * Update the animation state to match |f|, specified as a frame index
61 * in the [0..frameCount) domain.
63 * Fractional values are allowed and meaningful - e.g.
67 * 0.5 -> halfway between first and second frame
69 public void seekFrame(double f) {
70 nSeekFrame(mNativeInstance, f);
74 * Draw the current frame to the Canvas.
76 public void render(Canvas canvas) {
77 nRender(mNativeInstance, canvas.getNativeInstance());
81 * Releases any resources associated with this Animation.
83 public void release() {
84 nRelease(mNativeInstance);
89 protected void finalize() throws Throwable {
93 private static native long nCreate(String json);
94 private static native void nRelease(long nativeInstance);
96 private static native double nGetDuration(long nativeInstance);
97 private static native double nGetFrameCount(long nativeInstance);
98 private static native float nGetWidth(long nativeInstance);
99 private static native float nGetHeight(long nativeInstance);
101 private static native void nSeekTime(long nativeInstance, double t);
102 private static native void nSeekFrame(long nativeInstance, double frame);
103 private static native void nRender(long nativeInstance, long nativeCanvas);