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

Commit

Permalink
Merge pull request #263 from daishengda2018/master
Browse files Browse the repository at this point in the history
解决内存释放问题
  • Loading branch information
PonyCui authored Jul 13, 2020
2 parents 7378862 + b060ce8 commit dfc0edb
Show file tree
Hide file tree
Showing 13 changed files with 447 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;

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

private void loadAnimation() {
SVGAParser.Companion.shareParser().decodeFromAssets(this.randomSample(), new SVGAParser.ParseCompletion() {
@Override
public void onComplete(@NotNull SVGAVideoEntity videoItem) {
animationView.setVideoItem(videoItem);
animationView.stepToFrame(0, true);
}
@Override
SVGAParser svgaParser = SVGAParser.Companion.shareParser();
String name = this.randomSample();
Log.d("SVGA", "## name " + name);
svgaParser.setFrameSize(100, 100);
svgaParser.decodeFromAssets(name, new SVGAParser.ParseCompletion() {
@Override
public void onComplete(@NotNull SVGAVideoEntity videoItem) {
animationView.setVideoItem(videoItem);
animationView.stepToFrame(0, true);
}

@Override
public void onError() {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.ViewGroup;

import com.opensource.svgaplayer.SVGAImageView;
import com.opensource.svgaplayer.SVGAParser;
Expand All @@ -23,15 +25,18 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
animationView = new SVGAImageView(this);
animationView.setBackgroundColor(Color.GRAY);
loadAnimation();
setContentView(animationView);
loadAnimation();
}

private void loadAnimation() {
try { // new URL needs try catch.
SVGAParser.Companion.shareParser().decodeFromURL(new URL("https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true"), new SVGAParser.ParseCompletion() {
SVGAParser svgaParser = SVGAParser.Companion.shareParser();
svgaParser.setFrameSize(100,100);
svgaParser.decodeFromURL(new URL("https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true"), new SVGAParser.ParseCompletion() {
@Override
public void onComplete(@NotNull SVGAVideoEntity videoItem) {
Log.d("##","## FromNetworkActivity load onComplete");
animationView.setVideoItem(videoItem);
animationView.startAnimation();
}
Expand Down
13 changes: 12 additions & 1 deletion library/src/main/java/com/opensource/svgaplayer/SVGADrawable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class SVGADrawable(val videoItem: SVGAVideoEntity, val dynamicItem: SVGADynamicE
}
}

override fun setAlpha(alpha: Int) { }
override fun setAlpha(alpha: Int) {

}

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

}

internal fun clear() {
videoItem.audioList.forEach { audio ->
audio.playID?.let {
videoItem.soundPool?.stop(it)
}
audio.playID = null
}
videoItem.clear()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.text.StaticLayout
import android.text.TextPaint
import java.net.HttpURLConnection
import java.net.URL
import kotlin.concurrent.thread

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

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



//点击事件回调map
internal var mClickMap : HashMap<String, IntArray> = hashMapOf()
internal var dynamicIClickArea: HashMap<String, IClickAreaListener> = hashMapOf()
Expand Down Expand Up @@ -98,7 +95,7 @@ class SVGADynamicEntity {

fun setClickArea(clickKey: List<String>) {
for(itemKey in clickKey){
dynamicIClickArea.put(itemKey,object : IClickAreaListener{
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){
Expand Down
Loading

0 comments on commit dfc0edb

Please sign in to comment.