8package org.skia.skottie;
10import android.animation.Animator;
12import android.content.res.TypedArray;
15import android.util.AttributeSet;
22import android.widget.FrameLayout;
23import java.io.FileNotFoundException;
24import java.io.InputStream;
26import org.
skia.skottielib.R;
31 private View mBackingView;
32 private int mBackgroundColor;
34 private int mRepeatCount;
35 private static final int BACKING_VIEW_TEXTURE = 0;
36 private static final int BACKING_VIEW_SURFACE = 1;
37 private final String LOG_TAG =
"SkottieView";
53 s.mBackingView =
new SurfaceView(context);
54 s.mBackgroundColor = backgroundColor;
61 mBackingView =
new TextureView(context);
66 this(context, attrs, 0, 0);
70 this(context, attrs, defStyleAttr, 0);
75 super(context, attrs);
77 .obtainStyledAttributes(attrs,
R.styleable.SkottieView, defStyleAttr, defStyleRes);
80 mRepeatCount =
a.getInteger(
R.styleable.SkottieView_android_repeatCount, 0);
82 switch (
a.getInteger(
R.styleable.SkottieView_backing_view, -1)) {
83 case BACKING_VIEW_TEXTURE:
84 mBackingView =
new TextureView(context);
85 ((TextureView) mBackingView).setOpaque(
false);
86 mBackgroundColor =
a.getColor(
R.styleable.SkottieView_background_color, 0);
88 case BACKING_VIEW_SURFACE:
89 if (!
a.hasValue(
R.styleable.SkottieView_background_color)) {
90 throw new RuntimeException(
"background_color attribute "
91 +
"needed for SurfaceView");
93 mBackingView =
new SurfaceView(context);
94 mBackgroundColor =
a.getColor(
R.styleable.SkottieView_background_color, -1);
95 if (
Color.alpha(mBackgroundColor) != 255) {
96 throw new RuntimeException(
"background_color cannot be transparent");
100 throw new RuntimeException(
"backing_view attribute needed to "
101 +
"specify between texture_view or surface_view");
104 int src =
a.getResourceId(
R.styleable.SkottieView_src, -1);
114 private void initBackingView() {
115 mBackingView.setLayoutParams(
new ViewGroup.LayoutParams(
116 ViewGroup.LayoutParams.MATCH_PARENT,
117 ViewGroup.LayoutParams.MATCH_PARENT));
118 addView(mBackingView);
122 mAnimation = setSourceHelper(inputStream);
126 InputStream inputStream = mBackingView.getResources().openRawResource(resId);
127 mAnimation = setSourceHelper(inputStream);
130 public void setSource(Context context, Uri uri)
throws FileNotFoundException {
131 InputStream inputStream = context.getContentResolver().openInputStream(uri);
132 mAnimation = setSourceHelper(inputStream);
136 SkottieAnimation.Config config =
null;
139 if (mAnimation !=
null) {
143 }
catch (Throwable t) {
144 Log.e(LOG_TAG,
"existing animation couldn't finalize before setting new src");
147 if (mBackingView instanceof TextureView) {
149 .createAnimation(((TextureView) mBackingView), inputStream, mBackgroundColor, mRepeatCount);
152 .createAnimation(((SurfaceView) mBackingView), inputStream, mBackgroundColor, mRepeatCount);
155 if (config !=
null) {
167 mAnimation.removeListener(listener);
171 mAnimation.addListener(listener);
175 public void seek(
float progress) {
176 if(mAnimation !=
null) {
182 if(mAnimation !=
null) {
188 if(mAnimation !=
null) {
194 if(mAnimation !=
null) {
200 if(mAnimation !=
null) {
206 if(mAnimation !=
null) {
213 mRepeatCount = repeatCount;
217 mBackgroundColor = colorRGB;
emscripten::val TypedArray
void setProgress(float progress)
Config getBackingViewConfig()
void setBackingViewConfig(Config config)
void setMaxCacheSize(int maxCacheSize)
static synchronized SkottieRunner getInstance()
void seek(float progress)
void setRepeatCount(int repeatCount)
SkottieView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
SkottieView(Context context, AttributeSet attrs)
void setBackgroundColor(int colorRGB)
SkottieView buildAsTexture(Context context)
void removeListener(Animator.AnimatorListener listener)
static void setMaxCacheSize(int maxCacheSize)
void setSource(Context context, Uri uri)
void setSource(InputStream inputStream)
void setSource(int resId)
SkottieView(Context context)
void addListener(Animator.AnimatorListener listener)
SkottieView(Context context, AttributeSet attrs, int defStyleAttr)
SkottieAnimation getSkottieAnimation()
SkottieView buildAsSurface(Context context, int backgroundColor)
SK_API sk_sp< SkShader > Color(SkColor)
void Log(const char *format,...) SK_PRINTF_LIKE(1