Moved loadApng to companion object

This commit is contained in:
oupson 2020-05-11 14:36:30 +02:00
parent f845202a50
commit e32a52c7e0
4 changed files with 82 additions and 80 deletions

View File

@ -14,7 +14,7 @@ val imageUrl = "https://upload.wikimedia.org/wikipedia/commons/1/14/Animated_PNG
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 :
```kotlin

View File

@ -22,87 +22,85 @@ import java.net.URL
// TODO REWRITE WITH CALLBACKS
// TODO REWRITE
/**
* USE [ApngDecoder] instead of this class to load an APNG
*/
/**
* @param file The APNG to load
* @param speed The speed of the APNG
* @param apngAnimatorOptions Options of the animator
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(file: File, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
load(file, speed, apngAnimatorOptions)
}
/**
* @param uri The APNG to load
* @param speed The speed of the APNG
* @param apngAnimatorOptions Options of the animator
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(uri : Uri, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
load(uri, speed, apngAnimatorOptions)
}
/**
* @param url The url of the APNG to load
* @param speed The speed of the APNG
* @param apngAnimatorOptions Options of the animator
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(url: URL, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
loadUrl(url, speed, apngAnimatorOptions)
}
/**
* @param byteArray The APNG to load
* @param speed The speed of the APNG
* @param apngAnimatorOptions Options of the animator
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(byteArray: ByteArray, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
load(byteArray, speed, apngAnimatorOptions)
}
/**
* @param string The path APNG to load
* @param speed The speed of the APNG
* @param apngAnimatorOptions Options of the animator
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(string: String, speed : Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
load(string, speed, apngAnimatorOptions)
}
/**
* @param res The Resource Int of the APNG to load, must be in the raw folder
* @param speed The speed of the APNG
* @param apngAnimatorOptions Options of the animator
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(@RawRes res : Int, speed : Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
load(res, speed, apngAnimatorOptions)
}
/**
* Class to play APNG
* For better performance but lesser features use [oupson.apng.decoder.ApngDecoder] instead
* 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 speed The speed of the APNG
* @param apngAnimatorOptions Options of the animator
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(file: File, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
load(file, speed, apngAnimatorOptions)
}
/**
* @param uri The APNG to load
* @param speed The speed of the APNG
* @param apngAnimatorOptions Options of the animator
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(uri : Uri, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
load(uri, speed, apngAnimatorOptions)
}
/**
* @param url The url of the APNG to load
* @param speed The speed of the APNG
* @param apngAnimatorOptions Options of the animator
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(url: URL, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
loadUrl(url, speed, apngAnimatorOptions)
}
/**
* @param byteArray The APNG to load
* @param speed The speed of the APNG
* @param apngAnimatorOptions Options of the animator
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(byteArray: ByteArray, speed: Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
load(byteArray, speed, apngAnimatorOptions)
}
/**
* @param string The path APNG to load
* @param speed The speed of the APNG
* @param apngAnimatorOptions Options of the animator
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(string: String, speed : Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
load(string, speed, apngAnimatorOptions)
}
/**
* @param res The Resource Int of the APNG to load, must be in the raw folder
* @param speed The speed of the APNG
* @param apngAnimatorOptions Options of the animator
* @return [ApngAnimator] The animator
*/
@Suppress("unused")
@JvmOverloads
fun ImageView.loadApng(@RawRes res : Int, speed : Float? = null, apngAnimatorOptions: ApngAnimatorOptions? = null) = ApngAnimator(this.context).loadInto(this).apply {
load(res, speed, apngAnimatorOptions)
}
}
@Suppress("MemberVisibilityCanBePrivate")
var isPlaying = true
private set
@ -533,6 +531,7 @@ class ApngAnimator(private val context: Context?) {
* Set animation loop listener
* @param frameChangeListener The listener.
*/
@Suppress("unused")
fun setOnFrameChangeLister(frameChangeListener : (index : Int) -> Unit?) {
if (isApng) {
this.frameChangeLister = frameChangeListener
@ -543,6 +542,7 @@ class ApngAnimator(private val context: Context?) {
/**
* Execute on loaded
*/
@Suppress("unused")
fun onLoaded(f : (ApngAnimator) -> Unit) {
doOnLoaded = f
}

View File

@ -15,6 +15,7 @@ import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import com.google.android.material.shape.ShapePath
import kotlinx.android.synthetic.main.activity_main.*
import oupson.apngcreator.BuildConfig
import oupson.apngcreator.R
import oupson.apngcreator.fragments.ApngDecoderFragment
import oupson.apngcreator.fragments.JavaFragment
@ -30,7 +31,8 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
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)

View File

@ -12,7 +12,7 @@ import android.widget.SeekBar
import androidx.fragment.app.Fragment
import com.squareup.picasso.Picasso
import oupson.apng.ApngAnimator
import oupson.apng.loadApng
import oupson.apng.ApngAnimator.Companion.loadApng
import oupson.apngcreator.BuildConfig
import oupson.apngcreator.R