add new DemoActivity to showcase SkottieView xml loading and surface view backing

add resID source as SkottiveView xml attribute

Change-Id: I749dfd320ca0b75cb5fac2a4047442c1b198f07e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/327676
Reviewed-by: Florin Malita <fmalita@chromium.org>
Reviewed-by: Stan Iliev <stani@google.com>
Commit-Queue: Jorge Betancourt <jmbetancourt@google.com>
This commit is contained in:
Jorge Betancourt 2020-10-16 09:47:46 -04:00 committed by Skia Commit-Bot
parent a80a3dc170
commit 0e24265930
5 changed files with 121 additions and 2 deletions

View File

@ -38,10 +38,12 @@ public class SkottieView extends FrameLayout {
TypedArray a = context.getTheme()
.obtainStyledAttributes(attrs, R.styleable.SkottieView, 0, 0);
try {
// set backing view and background color
switch (a.getInteger(R.styleable.SkottieView_backing_view, -1)) {
case BACKING_VIEW_TEXTURE:
mBackingView = new TextureView(context);
((TextureView) mBackingView).setOpaque(false);
mBackgroundColor = a.getColor(R.styleable.SkottieView_background_color, 0);
break;
case BACKING_VIEW_SURFACE:
mBackingView = new SurfaceView(context);
@ -58,6 +60,11 @@ public class SkottieView extends FrameLayout {
throw new RuntimeException("backing_view attribute needed to "
+ "specify between texture_view or surface_view");
}
// set source
int src = a.getResourceId(R.styleable.SkottieView_src, -1);
if (src != -1) {
setSource(src);
}
} finally {
a.recycle();
}
@ -85,7 +92,6 @@ public class SkottieView extends FrameLayout {
addView(mBackingView);
}
//TODO handle SurfaceView
public void setSource(InputStream inputStream) {
mAnimation = setSourceHelper(inputStream);
}

View File

@ -6,5 +6,6 @@
<enum name="surface_view" value="1"/>
</attr>
<attr name="background_color" format="color"/>
<attr name="src" format="reference"/>
</declare-styleable>
</resources>

View File

@ -12,11 +12,15 @@
android:name=".CorrectnessActivity"
android:exported="true">
</activity>
<activity
android:name=".SkottieActivity"
android:exported="true">
</activity>
<activity
android:name=".PerfActivity"
android:exported="true">
</activity>
<activity android:name=".SkottieActivity">
<activity android:name=".DemoActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -0,0 +1,54 @@
package org.skia.skottie;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import java.util.ArrayList;
import java.util.List;
public class DemoActivity extends Activity implements OnClickListener {
private List<SkottieView> skotties = new ArrayList<>();
private boolean playing = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.demo_layout);
LinearLayout skottieContainer = findViewById(R.id.skottie_container);
for (int i = 0; i < skottieContainer.getChildCount(); i++) {
SkottieView s = (SkottieView)skottieContainer.getChildAt(i);
skotties.add(s);
s.play();
}
Button play = findViewById(R.id.play);
play.setOnClickListener(this);
Button reset = findViewById(R.id.reset);
reset.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch(view.getId()) {
case R.id.play:
for (SkottieView s : skotties) {
if (playing) {
s.pause();
} else {
s.play();
}
}
playing = !playing;
break;
case R.id.reset:
for (SkottieView s : skotties) {
s.seek(0f);
}
break;
}
}
}

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Button
android:id="@+id/play"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Play/Pause"/>
<Button
android:id="@+id/reset"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Set progress to 0"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/skottie_container">
<org.skia.skottie.SkottieView
android:layout_width="1000px"
android:layout_height="1000px"
app:backing_view="texture_view"
app:src="@raw/star">
</org.skia.skottie.SkottieView>
<org.skia.skottie.SkottieView
android:layout_width="1000px"
android:layout_height="1000px"
app:backing_view="texture_view"
app:src="@raw/movie_loading">
</org.skia.skottie.SkottieView>
<org.skia.skottie.SkottieView
android:layout_width="1000px"
android:layout_height="1000px"
app:backing_view="surface_view"
app:background_color="#fefefe"
app:src="@raw/uk">
</org.skia.skottie.SkottieView>
<org.skia.skottie.SkottieView
android:layout_width="1000px"
android:layout_height="1000px"
app:backing_view="surface_view"
app:background_color="#fefefe"
app:src="@raw/white_material_wave_loading">
</org.skia.skottie.SkottieView>
</LinearLayout>
</ScrollView>
</LinearLayout>