Fix loading assets
This commit is contained in:
parent
2b41e938c1
commit
6fe4225380
Binary file not shown.
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import android.content.SharedPreferences
|
||||
import android.graphics.*
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.RawRes
|
||||
import org.jetbrains.anko.doAsync
|
||||
|
@ -256,7 +257,7 @@ class ApngAnimator(private val context: Context?) {
|
|||
* @throws NotApngException
|
||||
*/
|
||||
fun load(string: String, speed : Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) : ApngAnimator {
|
||||
doAsync {
|
||||
doAsync ({throwable -> Log.e("APNG", "Error", throwable)}) {
|
||||
this@ApngAnimator.speed = speed
|
||||
if (string.contains("http") || string.contains("https")) {
|
||||
val url = URL(string)
|
||||
|
@ -277,6 +278,20 @@ class ApngAnimator(private val context: Context?) {
|
|||
throw NotApngException()
|
||||
}
|
||||
}
|
||||
} else if (string.startsWith("file:///android_asset/")) {
|
||||
val bytes = this@ApngAnimator.context?.assets?.open(string.replace("file:///android_asset/", ""))?.readBytes()
|
||||
bytes ?: throw Exception("File are empty")
|
||||
if (isApng(bytes)) {
|
||||
load(bytes, speed, apngAnimatorOptions)
|
||||
} else {
|
||||
if (loadNotApng) {
|
||||
context?.runOnUiThread {
|
||||
imageView?.setImageBitmap(BitmapFactory.decodeByteArray(bytes, 0, bytes.size))
|
||||
}
|
||||
} else {
|
||||
throw NotApngException()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 177 KiB |
|
@ -112,7 +112,7 @@ class MainActivity : AppCompatActivity() {
|
|||
)
|
||||
val imageView = imageView {
|
||||
id = View.generateViewId()
|
||||
animator = this.loadApng(imageUrl).apply {
|
||||
animator = this.loadApng("file:///android_asset/image.png").apply {
|
||||
onLoaded {
|
||||
setOnAnimationLoopListener {
|
||||
// Log.e("app-test", "onLoop")
|
||||
|
|
Loading…
Reference in New Issue