Skip to content

Commit 97a9f65

Browse files
committed
add antiAlias to SVGAVideoEntity.
1 parent 407c1af commit 97a9f65

File tree

6 files changed

+29
-15
lines changed

6 files changed

+29
-15
lines changed

app/src/main/assets/alarm.svga

14.5 KB
Binary file not shown.

app/src/main/res/layout/activity_simple.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<com.opensource.svgaplayer.SVGAImageView
99
android:layout_height="match_parent"
1010
android:layout_width="match_parent"
11-
app:source="posche.svga"/>
11+
app:source="posche.svga"
12+
app:antiAlias="true"/>
1213

1314
</RelativeLayout>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class SVGACanvasDrawer(videoItem: SVGAVideoEntity, val dynamicItem: SVGADynamicE
3333
val drawingBitmap = it
3434
sharedPaint.reset()
3535
sharedContentTransform.reset()
36+
sharedPaint.isAntiAlias = videoItem.antiAlias
3637
sharedPaint.alpha = (sprite.frameEntity.alpha * 255).toInt()
3738
sharedContentTransform.setScale((canvas.width / videoItem.videoSize.width).toFloat(), (canvas.width / videoItem.videoSize.width).toFloat())
3839
sharedContentTransform.preConcat(sprite.frameEntity.transform)

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,30 +104,39 @@ open class SVGAImageView : ImageView {
104104
val typedArray = context.theme.obtainStyledAttributes(attrs, R.styleable.SVGAImageView, 0, 0)
105105
loops = typedArray.getInt(R.styleable.SVGAImageView_loopCount, 0)
106106
clearsAfterStop = typedArray.getBoolean(R.styleable.SVGAImageView_clearsAfterStop, true)
107+
val antiAlias = typedArray.getBoolean(R.styleable.SVGAImageView_antiAlias, false)
107108
typedArray.getString(R.styleable.SVGAImageView_source)?.let {
108109
val parser = SVGAParser(context)
109110
Thread({
110111
if(it.startsWith("http://") || it.startsWith("https://")) {
111112
URL(it)?.let {
112-
parser.parse(it)?.let {
113-
handler.post({
114-
setVideoItem(it)
115-
if (typedArray.getBoolean(R.styleable.SVGAImageView_autoPlay, true)) {
116-
startAnimation()
113+
parser.parse(it, object : SVGAParser.ParseCompletion {
114+
override fun onComplete(videoItem: SVGAVideoEntity) {
115+
handler.post {
116+
videoItem.antiAlias = antiAlias
117+
setVideoItem(videoItem)
118+
if (typedArray.getBoolean(R.styleable.SVGAImageView_autoPlay, true)) {
119+
startAnimation()
120+
}
117121
}
118-
})
119-
}
122+
}
123+
override fun onError() { }
124+
})
120125
return@Thread
121126
}
122127
}
123-
parser.parse(it)?.let {
124-
handler.post({
125-
setVideoItem(it)
126-
if (typedArray.getBoolean(R.styleable.SVGAImageView_autoPlay, true)) {
127-
startAnimation()
128+
parser.parse(it, object : SVGAParser.ParseCompletion {
129+
override fun onComplete(videoItem: SVGAVideoEntity) {
130+
handler.post {
131+
videoItem.antiAlias = antiAlias
132+
setVideoItem(videoItem)
133+
if (typedArray.getBoolean(R.styleable.SVGAImageView_autoPlay, true)) {
134+
startAnimation()
135+
}
128136
}
129-
})
130-
}
137+
}
138+
override fun onError() { }
139+
})
131140
}).start()
132141
}
133142
typedArray.getString(R.styleable.SVGAImageView_fillMode)?.let {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import java.util.HashMap
2020
*/
2121
class SVGAVideoEntity(obj: JSONObject, val cacheDir: File) {
2222

23+
var antiAlias = false
24+
2325
var videoSize = SVGARect(0.0, 0.0, 0.0, 0.0)
2426
private set
2527

library/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<declare-styleable name="SVGAImageView">
44
<attr name="source" format="string" />
55
<attr name="autoPlay" format="boolean" />
6+
<attr name="antiAlias" format="boolean" />
67
<attr name="loopCount" format="integer" />
78
<attr name="clearsAfterStop" format="boolean" />
89
<attr name="fillMode" format="enum">

0 commit comments

Comments
 (0)