• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.airbnb.lottie.samples
2 
3 import android.os.Bundle
4 import android.widget.Toast
5 import androidx.appcompat.app.AppCompatActivity
6 import com.airbnb.lottie.LottieComposition
7 import com.airbnb.lottie.LottieCompositionFactory
8 import com.airbnb.lottie.LottieDrawable
9 import com.airbnb.lottie.model.LottieCompositionCache
10 import kotlinx.android.synthetic.main.activity_simple_animation.*
11 import kotlinx.android.synthetic.main.activity_simple_animation.view.*
12 import java.lang.IllegalArgumentException
13 
14 /**
15  * Useful for performance debugging.
16  * adb shell am start -n com.airbnb.lottie/.samples.SimpleAnimationActivity --es animation LottieLogo1.json --activity-clear-top
17  */
18 class SimpleAnimationActivity : AppCompatActivity() {
19 
onCreatenull20     override fun onCreate(savedInstanceState: Bundle?) {
21         super.onCreate(savedInstanceState)
22         setContentView(R.layout.activity_simple_animation)
23         var composition: LottieComposition? = null
24         parse.setOnClickListener {
25             val assetName = intent.extras?.getString("animation") ?: ""
26             LottieCompositionCache.getInstance().clear()
27             val start = System.currentTimeMillis()
28             composition = LottieCompositionFactory.fromAssetSync(this, assetName).value
29                     ?: throw IllegalArgumentException("Invalid composition $assetName")
30             Toast.makeText(this@SimpleAnimationActivity, "Done ${System.currentTimeMillis() - start}", Toast.LENGTH_SHORT).show()
31         }
32 
33         setComposition.setOnClickListener {
34             val start = System.currentTimeMillis()
35             val drawable = LottieDrawable()
36             drawable.setComposition(composition)
37             Toast.makeText(this@SimpleAnimationActivity, "Done ${System.currentTimeMillis() - start}", Toast.LENGTH_SHORT).show()
38         }
39 
40         play.setOnClickListener {
41             composition?.let { animationView.setComposition(it) }
42             animationView.playAnimation()
43         }
44     }
45 }