8package org.skia.jetski.util;
12import android.content.res.TypedArray;
13import android.util.AttributeSet;
17import android.widget.FrameLayout;
18import java.io.InputStream;
20import org.
skia.jetski.Canvas;
21import org.skia.jetski.Color;
22import org.skia.jetski.Matrix;
23import org.skia.jetski.SkottieAnimation;
24import org.skia.jetski.Surface;
26import org.skia.jetski.R;
29 private float mSurfaceWidth,
31 private Color mBackground;
33 private boolean mPlaying;
36 this.mAnimation = mAnimation;
37 this.mBackground = mBackground;
41 mSurfaceWidth =
surface.getWidth();
42 mSurfaceHeight =
surface.getHeight();
50 double t = (double)ms / 1000 % mAnimation.
getDuration();
53 float s = Math.min(mSurfaceWidth / mAnimation.
getWidth(),
94 private SurfaceView mBackingView;
97 private final String LOG_TAG =
"SkottieView";
101 mBackingView =
new SurfaceView(context);
103 InputStream inputStream = context.getResources().openRawResource(resID);
104 mRenderer =
new SkottieRenderer(makeAnimation(inputStream), background);
105 mBackingView.getHolder().addCallback(mRenderer);
110 mBackingView =
new SurfaceView(context);
115 this(context, attrs, 0, 0);
119 this(context, attrs, defStyleAttr, 0);
124 super(context, attrs);
126 .obtainStyledAttributes(attrs,
R.styleable.SkottieView, defStyleAttr, defStyleRes);
129 mBackingView =
new SurfaceView(context);
131 int backgroundColor =
a.getColor(
R.styleable.SkottieView_background_color, -1);
132 if (backgroundColor == -1) {
133 throw new RuntimeException(
"background_color attribute "
134 +
"needed for SurfaceView");
136 if (
android.graphics.Color.alpha(backgroundColor) != 255) {
137 throw new RuntimeException(
"background_color cannot be transparent");
140 int src =
a.getResourceId(
R.styleable.SkottieView_src, -1);
148 private void initBackingView() {
149 mBackingView.setLayoutParams(
new ViewGroup.LayoutParams(
150 ViewGroup.LayoutParams.MATCH_PARENT,
151 ViewGroup.LayoutParams.MATCH_PARENT));
152 addView(mBackingView);
158 byte[]
data =
new byte[is.available()];
160 json =
new String(
data);
161 }
catch (Exception
e) {}
166 InputStream inputStream = context.getResources().openRawResource(resID);
167 mRenderer =
new SkottieRenderer(makeAnimation(inputStream), background);
168 mBackingView.getHolder().addCallback(mRenderer);
180 mRenderer.
setBaseTime(java.lang.System.currentTimeMillis() - ((
long)t * 1000));
186 double targetTime = (
f % totalFrames) / totalFrames * totalTime;
emscripten::val TypedArray
void render(Canvas canvas)
void onRenderFrame(Canvas canvas, long ms)
SkottieRenderer(SkottieAnimation mAnimation, Color mBackground)
SkottieAnimation getAnimation()
void onSurfaceInitialized(Surface surface)
SkottieView(Context context, int resID, Color background)
void setSource(int resID, Context context, Color background)
SkottieView(Context context, AttributeSet attrs)
SkottieView(Context context)
SkottieView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
SkottieView(Context context, AttributeSet attrs, int defStyleAttr)
void setBaseTime(long millis)
SK_API sk_sp< SkShader > Color(SkColor)
SK_API sk_sp< PrecompileColorFilter > Matrix()
std::shared_ptr< const fml::Mapping > data