Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

suport recycleview #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ dependencies {
implementation project(':library')
implementation 'com.squareup.okhttp3:okhttp:3.4.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:recyclerview-v7:28.0.0'
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<activity android:name=".AnimationWithDynamicImageActivity" />
<activity android:name=".AnimationFromLayoutActivity" />
<activity android:name=".AnimationFromClickActivity" />
<activity android:name=".AnimationFromRVActivity"/>
</application>

<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.example.ponycui_home.svgaplayer;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.opensource.svgaplayer.SVGAParser;
import com.opensource.svgaplayer.SVGARVImageView;
import com.opensource.svgaplayer.SVGAVideoEntity;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
* Created by miaojun on 2020-01-08.
* mail:[email protected]
*/
public class AnimationFromRVActivity extends Activity {
RecyclerView mSvgaRecycleView;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSvgaRecycleView = new RecyclerView(this);
setContentView(mSvgaRecycleView);

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
mSvgaRecycleView.setLayoutManager(linearLayoutManager);
SVGAListAdapter adapter = new SVGAListAdapter();
adapter.setDataList(getList());
mSvgaRecycleView.setAdapter(adapter);
}

private List<ItemSVGABean> getList() {
List<ItemSVGABean> list = new ArrayList<>();
for (int i = 0; i < 30; i++) {
ItemSVGABean bean = new ItemSVGABean();
bean.name = "test2.svga";
bean.isNeedResume = true;
list.add(bean);
}
return list;
}

class SVGAListAdapter extends RecyclerView.Adapter<SVGAListAdapter.ViewHolder> {
List<ItemSVGABean> dataList = new ArrayList<>();

void setDataList(List<ItemSVGABean> list) {
dataList.clear();
dataList.addAll(list);
}

@NonNull
@Override
public SVGAListAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.item_svga, viewGroup, false);
return new ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull SVGAListAdapter.ViewHolder viewHolder, int i) {
viewHolder.setItem(dataList.get(i));
}

@Override
public int getItemCount() {
return dataList.size();
}


class ViewHolder extends RecyclerView.ViewHolder {

ViewHolder(@NonNull View itemView) {
super(itemView);
}

void setItem(ItemSVGABean bean) {
((SVGARVImageView) itemView).setNeedResume(bean.isNeedResume);
SVGAParser parser = new SVGAParser(itemView.getContext());
parser.decodeFromAssets(bean.name, new SVGAParser.ParseCompletion() {
@Override
public void onComplete(@NotNull SVGAVideoEntity videoItem) {
((SVGARVImageView) itemView).setVideoItem(videoItem);
((SVGARVImageView) itemView).startAnimation();
}

@Override
public void onError() {

}
});
}

}
}

class ItemSVGABean {
String name;
boolean isNeedResume;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void setupData() {
this.items.add(new SampleItem("Animation From Layout XML", new Intent(this, AnimationFromLayoutActivity.class)));
this.items.add(new SampleItem("Animation With Dynamic Image", new Intent(this, AnimationWithDynamicImageActivity.class)));
this.items.add(new SampleItem("Animation With Dynamic Click", new Intent(this, AnimationFromClickActivity.class)));
this.items.add(new SampleItem("Animation With RecycleView", new Intent(this, AnimationFromRVActivity.class)));
}

void setupListView() {
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/item_svga.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<com.opensource.svgaplayer.SVGARVImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dp">

</com.opensource.svgaplayer.SVGARVImageView>
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ class SVGADynamicEntity {
internal var dynamicDrawer: HashMap<String, (canvas: Canvas, frameIndex: Int) -> Boolean> = hashMapOf()



//点击事件回调map
internal var mClickMap : HashMap<String, IntArray> = hashMapOf()
internal var mClickMap: HashMap<String, IntArray> = hashMapOf()
internal var dynamicIClickArea: HashMap<String, IClickAreaListener> = hashMapOf()

internal var dynamicDrawerSized: HashMap<String, (canvas: Canvas, frameIndex: Int, width: Int, height: Int) -> Boolean> = hashMapOf()
Expand Down Expand Up @@ -87,8 +86,8 @@ class SVGADynamicEntity {

fun setDynamicText(layoutText: BoringLayout, forKey: String) {
this.isTextDirty = true
BoringLayout.isBoring(layoutText.text,layoutText.paint)?.let {
this.dynamicBoringLayoutText.put(forKey,layoutText)
BoringLayout.isBoring(layoutText.text, layoutText.paint)?.let {
this.dynamicBoringLayoutText.put(forKey, layoutText)
}
}

Expand All @@ -98,13 +97,13 @@ class SVGADynamicEntity {


fun setClickArea(clickKey: List<String>) {
for(itemKey in clickKey){
dynamicIClickArea.put(itemKey,object : IClickAreaListener{
for (itemKey in clickKey) {
dynamicIClickArea.put(itemKey, object : IClickAreaListener {
override fun onResponseArea(key: String, x0: Int, y0: Int, x1: Int, y1: Int) {
mClickMap.let {
if(it.get(key) == null){
it.put(key, intArrayOf(x0,y0,x1,y1))
}else{
if (it.get(key) == null) {
it.put(key, intArrayOf(x0, y0, x1, y1))
} else {
it.get(key)?.let {
it[0] = x0
it[1] = y0
Expand All @@ -120,12 +119,12 @@ class SVGADynamicEntity {
}

fun setClickArea(clickKey: String) {
dynamicIClickArea.put(clickKey,object : IClickAreaListener{
dynamicIClickArea.put(clickKey, object : IClickAreaListener {
override fun onResponseArea(key: String, x0: Int, y0: Int, x1: Int, y1: Int) {
mClickMap.let {
if(it.get(key) == null){
it.put(key, intArrayOf(x0,y0,x1,y1))
}else{
if (it.get(key) == null) {
it.put(key, intArrayOf(x0, y0, x1, y1))
} else {
it.get(key)?.let {
it[0] = x0
it[1] = y0
Expand All @@ -138,24 +137,25 @@ class SVGADynamicEntity {

})

fun setDynamicDrawerSized(drawer: (canvas: Canvas, frameIndex: Int, width: Int, height: Int) -> Boolean, forKey: String) {
this.dynamicDrawerSized.put(forKey, drawer)
fun setDynamicDrawerSized(drawer: (canvas: Canvas, frameIndex: Int, width: Int, height: Int) -> Boolean, forKey: String) {
this.dynamicDrawerSized.put(forKey, drawer)

}
}

fun clearDynamicObjects() {
this.isTextDirty = true
this.dynamicHidden.clear()
this.dynamicImage.clear()
this.dynamicText.clear()
this.dynamicTextPaint.clear()
this.dynamicStaticLayoutText.clear()
this.dynamicBoringLayoutText.clear()
this.dynamicDrawer.clear()
this.dynamicIClickArea.clear()
this.mClickMap.clear()
this.dynamicDrawerSized.clear()
fun clearDynamicObjects() {
this.isTextDirty = true
this.dynamicHidden.clear()
this.dynamicImage.clear()
this.dynamicText.clear()
this.dynamicTextPaint.clear()
this.dynamicStaticLayoutText.clear()
this.dynamicBoringLayoutText.clear()
this.dynamicDrawer.clear()
this.dynamicIClickArea.clear()
this.mClickMap.clear()
this.dynamicDrawerSized.clear()

}
}

}
}
28 changes: 28 additions & 0 deletions library/src/main/java/com/opensource/svgaplayer/SVGARVImageView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.opensource.svgaplayer

import android.content.Context
import android.util.AttributeSet

/**
* Created by miaojun on 2020-01-08.
* mail:[email protected]
*/
class SVGARVImageView : SVGAImageView {
var isNeedResume = true

constructor(context: Context?) : super(context)

constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)

constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)

override fun onAttachedToWindow() {
super.onAttachedToWindow()
if(isNeedResume && drawable != null){
startAnimation()
}
}

}