Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / platform_tools / android / apps / AndroidKit / src / main / java / org / skia / androidkit / SkottieAnimation.java
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
8 package org.skia.androidkit;
9
10 import org.skia.androidkit.Canvas;
11
12 public class SkottieAnimation {
13     private long mNativeInstance;
14
15     /**
16       * Create an animation from the provided JSON string.
17       */
18     public SkottieAnimation(String animation_json) {
19         mNativeInstance = nCreate(animation_json);
20     }
21
22     /**
23       * Returns the animation duration in seconds.
24       */
25     public double getDuration() {
26         return nGetDuration(mNativeInstance);
27     }
28
29     /**
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.
32      */
33     public double getFrameCount() {
34         return nGetFrameCount(mNativeInstance);
35     }
36
37     /**
38       * Returns the intrinsic animation width.
39       */
40     public float getWidth() {
41         return nGetWidth(mNativeInstance);
42     }
43
44     /**
45       * Returns the intrinsic animation height.
46       */
47     public float getHeight() {
48         return nGetHeight(mNativeInstance);
49     }
50
51     /**
52       * Update the animation state to match |t|, specifed in seconds.
53       * The input is clamped to [0..duration).
54       */
55     public void seekTime(double t) {
56         nSeekTime(mNativeInstance, t);
57     }
58
59     /**
60      * Update the animation state to match |f|, specified as a frame index
61      * in the [0..frameCount) domain.
62      *
63      * Fractional values are allowed and meaningful - e.g.
64      *
65      *   0.0 -> first frame
66      *   1.0 -> second frame
67      *   0.5 -> halfway between first and second frame
68      */
69     public void seekFrame(double f) {
70         nSeekFrame(mNativeInstance, f);
71     }
72
73     /**
74       * Draw the current frame to the Canvas.
75       */
76     public void render(Canvas canvas) {
77         nRender(mNativeInstance, canvas.getNativeInstance());
78     }
79
80     /**
81      * Releases any resources associated with this Animation.
82      */
83     public void release() {
84         nRelease(mNativeInstance);
85         mNativeInstance = 0;
86     }
87
88     @Override
89     protected void finalize() throws Throwable {
90         release();
91     }
92
93     private static native long nCreate(String json);
94     private static native void nRelease(long nativeInstance);
95
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);
100
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);
104 }