Flutter Engine
The Flutter Engine
SkottieAnimation.java
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8package org.skia.jetski;
9
10public class SkottieAnimation {
11 private long mNativeInstance;
12
13 /**
14 * Create an animation from the provided JSON string.
15 */
16 public SkottieAnimation(String animation_json) {
17 mNativeInstance = nCreate(animation_json);
18 }
19
20 /**
21 * Returns the animation duration in seconds.
22 */
23 public double getDuration() {
24 return nGetDuration(mNativeInstance);
25 }
26
27 /**
28 * Returns the animation frame count. This is normally an integral value,
29 * but both the JSON encoding and Skottie's frame-based APIs support fractional frames.
30 */
31 public double getFrameCount() {
32 return nGetFrameCount(mNativeInstance);
33 }
34
35 /**
36 * Returns the intrinsic animation width.
37 */
38 public float getWidth() {
39 return nGetWidth(mNativeInstance);
40 }
41
42 /**
43 * Returns the intrinsic animation height.
44 */
45 public float getHeight() {
46 return nGetHeight(mNativeInstance);
47 }
48
49 /**
50 * Update the animation state to match |t|, specifed in seconds.
51 * The input is clamped to [0..duration).
52 */
53 public void seekTime(double t) {
54 nSeekTime(mNativeInstance, t);
55 }
56
57 /**
58 * Update the animation state to match |f|, specified as a frame index
59 * in the [0..frameCount) domain.
60 *
61 * Fractional values are allowed and meaningful - e.g.
62 *
63 * 0.0 -> first frame
64 * 1.0 -> second frame
65 * 0.5 -> halfway between first and second frame
66 */
67 public void seekFrame(double f) {
68 nSeekFrame(mNativeInstance, f);
69 }
70
71 /**
72 * Draw the current frame to the Canvas.
73 */
74 public void render(Canvas canvas) {
75 nRender(mNativeInstance, canvas.getNativeInstance());
76 }
77
78 /**
79 * Releases any resources associated with this Animation.
80 */
81 public void release() {
82 nRelease(mNativeInstance);
83 mNativeInstance = 0;
84 }
85
86 @Override
87 protected void finalize() throws Throwable {
88 release();
89 }
90
91 private static native long nCreate(String json);
92 private static native void nRelease(long nativeInstance);
93
94 private static native double nGetDuration(long nativeInstance);
95 private static native double nGetFrameCount(long nativeInstance);
96 private static native float nGetWidth(long nativeInstance);
97 private static native float nGetHeight(long nativeInstance);
98
99 private static native void nSeekTime(long nativeInstance, double t);
100 private static native void nSeekFrame(long nativeInstance, double frame);
101 private static native void nRender(long nativeInstance, long nativeCanvas);
102}
SkottieAnimation(String animation_json)
double frame
Definition: examples.cpp:31