Skip to content

Instantly share code, notes, and snippets.

@roberto-o-r
Created June 8, 2018 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roberto-o-r/6ebe69d7b49f5c5f3536a2bd102cbebd to your computer and use it in GitHub Desktop.
Save roberto-o-r/6ebe69d7b49f5c5f3536a2bd102cbebd to your computer and use it in GitHub Desktop.
SplashActivity.kt
package com.isscroberto.powernap.splash
import android.animation.Animator
import android.animation.ValueAnimator
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import com.isscroberto.powernap.R
import com.isscroberto.powernap.start.StartActivity
import android.view.animation.BounceInterpolator
import kotlinx.android.synthetic.main.activity_splash.*
class SplashActivity : AppCompatActivity() {
val ANIMATION_DURATION:Long = 1000
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
// Start intro animation.
startAnimation()
}
private fun startAnimation() {
// Intro animation configuration.
val valueAnimator = ValueAnimator.ofFloat(0f, 1f)
valueAnimator.addUpdateListener {
val value = it.animatedValue as Float
textTitle.scaleX = value
textTitle.scaleY = value
}
valueAnimator.interpolator = BounceInterpolator()
valueAnimator.duration = ANIMATION_DURATION
// Set animator listener.
val intent = Intent(this, StartActivity::class.java)
valueAnimator.addListener(object : Animator.AnimatorListener {
override fun onAnimationRepeat(p0: Animator?) {}
override fun onAnimationEnd(p0: Animator?) {
// Navigate to main activity on navigation end.
startActivity(intent)
finish()
}
override fun onAnimationCancel(p0: Animator?) {}
override fun onAnimationStart(p0: Animator?) {}
})
// Start animation.
valueAnimator.start()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment