Flutter Engine
The Flutter Engine
SkottieSample.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.jetskidemo.samples;
9
10import android.content.res.Resources;
11
12import java.io.InputStream;
13
14import org.skia.jetski.Canvas;
15import org.skia.jetski.Matrix;
16import org.skia.jetski.Paint;
17import org.skia.jetski.SkottieAnimation;
18
19public class SkottieSample implements Sample {
20 private Paint mClearPaint = new Paint().setColor(0.8f, 0.8f, 0.8f, 1);
21 private SkottieAnimation mAnimation;
22
23 public SkottieSample(Resources res, int resId) {
24 String json = "";
25
26 try {
27 InputStream is = res.openRawResource(resId);
28 byte[] data = new byte[is.available()];
29 is.read(data);
30 json = new String(data);
31 } catch (Exception e) {}
32
33 mAnimation = new SkottieAnimation(json);
34 }
35
36 public void render(Canvas canvas, long ms, float left, float top, float right, float bottom) {
37 canvas.drawRect(left, top, right, bottom, mClearPaint);
38
39 double t = (double)ms / 1000 % mAnimation.getDuration();
40 mAnimation.seekTime(t);
41
42 float w = right - left,
43 h = bottom - top,
44 s = Math.min(w / mAnimation.getWidth(),
45 h / mAnimation.getHeight());
46
47 canvas.save();
48 canvas.concat(new Matrix().translate(left + (w - s*mAnimation.getWidth() )/2,
49 top + (h - s*mAnimation.getHeight())/2)
50 .scale(s, s));
51
52 mAnimation.render(canvas);
53 canvas.restore();
54 }
55}
void drawRect(float left, float top, float right, float bottom, Paint paint)
Definition: Canvas.java:95
void concat(Matrix m)
Definition: Canvas.java:49
Paint setColor(Color c)
Definition: Paint.java:19
void render(Canvas canvas, long ms, float left, float top, float right, float bottom)
SkottieSample(Resources res, int resId)
struct MyStruct s
SK_API sk_sp< PrecompileColorFilter > Matrix()
SkScalar w
SkScalar h
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63