This repository was archived by the owner on Feb 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 507
Expand file tree
/
Copy pathAnimationFromRVActivity.java
More file actions
110 lines (89 loc) · 3.38 KB
/
AnimationFromRVActivity.java
File metadata and controls
110 lines (89 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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:1290846731@qq.com
*/
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;
}
}