Moved loadApng to companion object
This commit is contained in:
parent
f845202a50
commit
e32a52c7e0
|
@ -14,7 +14,7 @@ val imageUrl = "https://upload.wikimedia.org/wikipedia/commons/1/14/Animated_PNG
|
||||||
ApngDecoder.decodeApngAsyncInto(context, URL(url), imageView)
|
ApngDecoder.decodeApngAsyncInto(context, URL(url), imageView)
|
||||||
```
|
```
|
||||||
|
|
||||||
You can load a file, an uri, a ressource int, an url, or an inputStream.
|
You can load a file, an uri, a resource int, an url, or an inputStream.
|
||||||
|
|
||||||
## With a callback :
|
## With a callback :
|
||||||
```kotlin
|
```kotlin
|
||||||
|
|
|
@ -23,86 +23,84 @@ import java.net.URL
|
||||||
// TODO REWRITE
|
// TODO REWRITE
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* USE [ApngDecoder] instead of this class to load an APNG
|
* Class to play APNG
|
||||||
|
* For better performance but lesser features using [oupson.apng.decoder.ApngDecoder] is strongly recommended.
|
||||||
*/
|
*/
|
||||||
|
class ApngAnimator(private val context: Context?) {
|
||||||
/**
|
companion object {
|
||||||
|
/**
|
||||||
* @param file The APNG to load
|
* @param file The APNG to load
|
||||||
* @param speed The speed of the APNG
|
* @param speed The speed of the APNG
|
||||||
* @param apngAnimatorOptions Options of the animator
|
* @param apngAnimatorOptions Options of the animator
|
||||||
* @return [ApngAnimator] The animator
|
* @return [ApngAnimator] The animator
|
||||||
*/
|
*/
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun ImageView.loadApng(file: File, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
|
fun ImageView.loadApng(file: File, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
|
||||||
load(file, speed, apngAnimatorOptions)
|
load(file, speed, apngAnimatorOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param uri The APNG to load
|
* @param uri The APNG to load
|
||||||
* @param speed The speed of the APNG
|
* @param speed The speed of the APNG
|
||||||
* @param apngAnimatorOptions Options of the animator
|
* @param apngAnimatorOptions Options of the animator
|
||||||
* @return [ApngAnimator] The animator
|
* @return [ApngAnimator] The animator
|
||||||
*/
|
*/
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun ImageView.loadApng(uri : Uri, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
|
fun ImageView.loadApng(uri : Uri, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
|
||||||
load(uri, speed, apngAnimatorOptions)
|
load(uri, speed, apngAnimatorOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param url The url of the APNG to load
|
* @param url The url of the APNG to load
|
||||||
* @param speed The speed of the APNG
|
* @param speed The speed of the APNG
|
||||||
* @param apngAnimatorOptions Options of the animator
|
* @param apngAnimatorOptions Options of the animator
|
||||||
* @return [ApngAnimator] The animator
|
* @return [ApngAnimator] The animator
|
||||||
*/
|
*/
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun ImageView.loadApng(url: URL, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
|
fun ImageView.loadApng(url: URL, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
|
||||||
loadUrl(url, speed, apngAnimatorOptions)
|
loadUrl(url, speed, apngAnimatorOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param byteArray The APNG to load
|
* @param byteArray The APNG to load
|
||||||
* @param speed The speed of the APNG
|
* @param speed The speed of the APNG
|
||||||
* @param apngAnimatorOptions Options of the animator
|
* @param apngAnimatorOptions Options of the animator
|
||||||
* @return [ApngAnimator] The animator
|
* @return [ApngAnimator] The animator
|
||||||
*/
|
*/
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun ImageView.loadApng(byteArray: ByteArray, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
|
fun ImageView.loadApng(byteArray: ByteArray, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
|
||||||
load(byteArray, speed, apngAnimatorOptions)
|
load(byteArray, speed, apngAnimatorOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string The path APNG to load
|
* @param string The path APNG to load
|
||||||
* @param speed The speed of the APNG
|
* @param speed The speed of the APNG
|
||||||
* @param apngAnimatorOptions Options of the animator
|
* @param apngAnimatorOptions Options of the animator
|
||||||
* @return [ApngAnimator] The animator
|
* @return [ApngAnimator] The animator
|
||||||
*/
|
*/
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun ImageView.loadApng(string: String, speed : Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
|
fun ImageView.loadApng(string: String, speed : Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
|
||||||
load(string, speed, apngAnimatorOptions)
|
load(string, speed, apngAnimatorOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param res The Resource Int of the APNG to load, must be in the raw folder
|
* @param res The Resource Int of the APNG to load, must be in the raw folder
|
||||||
* @param speed The speed of the APNG
|
* @param speed The speed of the APNG
|
||||||
* @param apngAnimatorOptions Options of the animator
|
* @param apngAnimatorOptions Options of the animator
|
||||||
* @return [ApngAnimator] The animator
|
* @return [ApngAnimator] The animator
|
||||||
*/
|
*/
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun ImageView.loadApng(@RawRes res : Int, speed : Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
|
fun ImageView.loadApng(@RawRes res : Int, speed : Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
|
||||||
load(res, speed, apngAnimatorOptions)
|
load(res, speed, apngAnimatorOptions)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Class to play APNG
|
|
||||||
* For better performance but lesser features use [oupson.apng.decoder.ApngDecoder] instead
|
|
||||||
*/
|
|
||||||
class ApngAnimator(private val context: Context?) {
|
|
||||||
@Suppress("MemberVisibilityCanBePrivate")
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
var isPlaying = true
|
var isPlaying = true
|
||||||
private set
|
private set
|
||||||
|
@ -533,6 +531,7 @@ class ApngAnimator(private val context: Context?) {
|
||||||
* Set animation loop listener
|
* Set animation loop listener
|
||||||
* @param frameChangeListener The listener.
|
* @param frameChangeListener The listener.
|
||||||
*/
|
*/
|
||||||
|
@Suppress("unused")
|
||||||
fun setOnFrameChangeLister(frameChangeListener : (index : Int) -> Unit?) {
|
fun setOnFrameChangeLister(frameChangeListener : (index : Int) -> Unit?) {
|
||||||
if (isApng) {
|
if (isApng) {
|
||||||
this.frameChangeLister = frameChangeListener
|
this.frameChangeLister = frameChangeListener
|
||||||
|
@ -543,6 +542,7 @@ class ApngAnimator(private val context: Context?) {
|
||||||
/**
|
/**
|
||||||
* Execute on loaded
|
* Execute on loaded
|
||||||
*/
|
*/
|
||||||
|
@Suppress("unused")
|
||||||
fun onLoaded(f : (ApngAnimator) -> Unit) {
|
fun onLoaded(f : (ApngAnimator) -> Unit) {
|
||||||
doOnLoaded = f
|
doOnLoaded = f
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import com.google.android.material.shape.MaterialShapeDrawable
|
||||||
import com.google.android.material.shape.ShapeAppearanceModel
|
import com.google.android.material.shape.ShapeAppearanceModel
|
||||||
import com.google.android.material.shape.ShapePath
|
import com.google.android.material.shape.ShapePath
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
import oupson.apngcreator.BuildConfig
|
||||||
import oupson.apngcreator.R
|
import oupson.apngcreator.R
|
||||||
import oupson.apngcreator.fragments.ApngDecoderFragment
|
import oupson.apngcreator.fragments.ApngDecoderFragment
|
||||||
import oupson.apngcreator.fragments.JavaFragment
|
import oupson.apngcreator.fragments.JavaFragment
|
||||||
|
@ -30,7 +31,8 @@ class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
Log.i(TAG, "${supportFragmentManager.fragments.size}")
|
if (BuildConfig.DEBUG)
|
||||||
|
Log.v(TAG, "supportFragmentManager.fragments.size : ${supportFragmentManager.fragments.size}")
|
||||||
|
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import android.widget.SeekBar
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
import oupson.apng.ApngAnimator
|
import oupson.apng.ApngAnimator
|
||||||
import oupson.apng.loadApng
|
import oupson.apng.ApngAnimator.Companion.loadApng
|
||||||
import oupson.apngcreator.BuildConfig
|
import oupson.apngcreator.BuildConfig
|
||||||
import oupson.apngcreator.R
|
import oupson.apngcreator.R
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue