Skip to content

Commit dfc0edb

Browse files
authored
Merge pull request svga#263 from daishengda2018/master
解决内存释放问题
2 parents 7378862 + b060ce8 commit dfc0edb

13 files changed

+447
-303
lines changed

app/src/main/java/com/example/ponycui_home/svgaplayer/AnimationFromAssetsActivity.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.graphics.Color;
55
import android.os.Bundle;
66
import android.support.annotation.Nullable;
7+
import android.util.Log;
78
import android.view.View;
89

910
import com.opensource.svgaplayer.SVGAImageView;
@@ -35,13 +36,18 @@ public void onClick(View view) {
3536
}
3637

3738
private void loadAnimation() {
38-
SVGAParser.Companion.shareParser().decodeFromAssets(this.randomSample(), new SVGAParser.ParseCompletion() {
39-
@Override
40-
public void onComplete(@NotNull SVGAVideoEntity videoItem) {
41-
animationView.setVideoItem(videoItem);
42-
animationView.stepToFrame(0, true);
43-
}
44-
@Override
39+
SVGAParser svgaParser = SVGAParser.Companion.shareParser();
40+
String name = this.randomSample();
41+
Log.d("SVGA", "## name " + name);
42+
svgaParser.setFrameSize(100, 100);
43+
svgaParser.decodeFromAssets(name, new SVGAParser.ParseCompletion() {
44+
@Override
45+
public void onComplete(@NotNull SVGAVideoEntity videoItem) {
46+
animationView.setVideoItem(videoItem);
47+
animationView.stepToFrame(0, true);
48+
}
49+
50+
@Override
4551
public void onError() {
4652

4753
}

app/src/main/java/com/example/ponycui_home/svgaplayer/AnimationFromNetworkActivity.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import android.graphics.Color;
55
import android.os.Bundle;
66
import android.support.annotation.Nullable;
7+
import android.util.Log;
8+
import android.view.ViewGroup;
79

810
import com.opensource.svgaplayer.SVGAImageView;
911
import com.opensource.svgaplayer.SVGAParser;
@@ -23,15 +25,18 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
2325
super.onCreate(savedInstanceState);
2426
animationView = new SVGAImageView(this);
2527
animationView.setBackgroundColor(Color.GRAY);
26-
loadAnimation();
2728
setContentView(animationView);
29+
loadAnimation();
2830
}
2931

3032
private void loadAnimation() {
3133
try { // new URL needs try catch.
32-
SVGAParser.Companion.shareParser().decodeFromURL(new URL("https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true"), new SVGAParser.ParseCompletion() {
34+
SVGAParser svgaParser = SVGAParser.Companion.shareParser();
35+
svgaParser.setFrameSize(100,100);
36+
svgaParser.decodeFromURL(new URL("https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true"), new SVGAParser.ParseCompletion() {
3337
@Override
3438
public void onComplete(@NotNull SVGAVideoEntity videoItem) {
39+
Log.d("##","## FromNetworkActivity load onComplete");
3540
animationView.setVideoItem(videoItem);
3641
animationView.startAnimation();
3742
}

library/src/main/java/com/opensource/svgaplayer/SVGADrawable.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ class SVGADrawable(val videoItem: SVGAVideoEntity, val dynamicItem: SVGADynamicE
4242
}
4343
}
4444

45-
override fun setAlpha(alpha: Int) { }
45+
override fun setAlpha(alpha: Int) {
46+
47+
}
4648

4749
override fun getOpacity(): Int {
4850
return PixelFormat.TRANSPARENT
@@ -52,4 +54,13 @@ class SVGADrawable(val videoItem: SVGAVideoEntity, val dynamicItem: SVGADynamicE
5254

5355
}
5456

57+
internal fun clear() {
58+
videoItem.audioList.forEach { audio ->
59+
audio.playID?.let {
60+
videoItem.soundPool?.stop(it)
61+
}
62+
audio.playID = null
63+
}
64+
videoItem.clear()
65+
}
5566
}

library/src/main/java/com/opensource/svgaplayer/SVGADynamicEntity.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import android.text.StaticLayout
88
import android.text.TextPaint
99
import java.net.HttpURLConnection
1010
import java.net.URL
11-
import kotlin.concurrent.thread
1211

1312
/**
1413
* Created by cuiminghui on 2017/3/30.
@@ -29,8 +28,6 @@ class SVGADynamicEntity {
2928

3029
internal var dynamicDrawer: HashMap<String, (canvas: Canvas, frameIndex: Int) -> Boolean> = hashMapOf()
3130

32-
33-
3431
//点击事件回调map
3532
internal var mClickMap : HashMap<String, IntArray> = hashMapOf()
3633
internal var dynamicIClickArea: HashMap<String, IClickAreaListener> = hashMapOf()
@@ -98,7 +95,7 @@ class SVGADynamicEntity {
9895

9996
fun setClickArea(clickKey: List<String>) {
10097
for(itemKey in clickKey){
101-
dynamicIClickArea.put(itemKey,object : IClickAreaListener{
98+
dynamicIClickArea.put(itemKey,object : IClickAreaListener {
10299
override fun onResponseArea(key: String, x0: Int, y0: Int, x1: Int, y1: Int) {
103100
mClickMap.let {
104101
if(it.get(key) == null){

0 commit comments

Comments
 (0)