Move InputStream handling of SkottieLib to SkottieView
An effort to hide nuts and bolts from developers who wish to use SkottieLib in their own application. Change-Id: I2020e73279a53de8852d5b04d90d0e28bdbb5c6e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/298978 Reviewed-by: Derek Sollenberger <djsollen@google.com> Reviewed-by: Stan Iliev <stani@google.com> Commit-Queue: Jorge Betancourt <jmbetancourt@google.com>
This commit is contained in:
parent
65513a9834
commit
1449d835af
@ -8,9 +8,11 @@
|
||||
package org.skia.skottie;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.TextureView;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class SkottieView extends TextureView {
|
||||
@ -45,6 +47,16 @@ public class SkottieView extends TextureView {
|
||||
mAnimation = SkottieRunner.getInstance().createAnimation(this, inputStream);
|
||||
}
|
||||
|
||||
public void setSkottieResource(int resId) {
|
||||
InputStream inputStream = getResources().openRawResource(resId);
|
||||
mAnimation = SkottieRunner.getInstance().createAnimation(this, inputStream);
|
||||
}
|
||||
|
||||
public void setSkottieURI(Context context, Uri uri) throws FileNotFoundException {
|
||||
InputStream inputStream = context.getContentResolver().openInputStream(uri);
|
||||
mAnimation = SkottieRunner.getInstance().createAnimation(this, inputStream);
|
||||
}
|
||||
|
||||
public SkottieAnimation getSkottieAnimation() {
|
||||
return mAnimation;
|
||||
}
|
||||
|
@ -59,15 +59,14 @@ public class SkottieActivity extends Activity implements View.OnClickListener {
|
||||
|
||||
for (int resId : rawAssets) {
|
||||
SkottieView view = new SkottieView(this);
|
||||
view.setSource(getResources().openRawResource(resId));
|
||||
view.setSkottieResource(resId);
|
||||
mAnimations.add(view);
|
||||
}
|
||||
|
||||
for (Uri uri : mAnimationFiles) {
|
||||
try {
|
||||
InputStream inputStream = getContentResolver().openInputStream(uri);
|
||||
SkottieView view = new SkottieView(this);
|
||||
view.setSource(inputStream);
|
||||
view.setSkottieURI(this, uri);
|
||||
mAnimations.add(view);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
@ -186,11 +185,10 @@ public class SkottieActivity extends Activity implements View.OnClickListener {
|
||||
}
|
||||
|
||||
private void addLottie(Uri uri) throws FileNotFoundException {
|
||||
InputStream inputStream = getContentResolver().openInputStream(uri);
|
||||
int animations = mAnimations.size();
|
||||
if (animations < mRowCount * mColumnCount) {
|
||||
SkottieView view = new SkottieView(this);
|
||||
view.setSource(inputStream);
|
||||
view.setSkottieURI(this, uri);
|
||||
int row = animations / mColumnCount, column = animations % mColumnCount;
|
||||
mAnimations.add(view);
|
||||
mAnimationFiles.add(uri);
|
||||
|
Loading…
Reference in New Issue
Block a user