lebonprix.apk/java/io/xdrm/lebonprix/GooeySplashScreen.kt

48 lines
1.7 KiB
Kotlin
Raw Normal View History

2018-12-15 11:17:28 +00:00
package io.xdrm.lebonprix
import android.content.Context
import android.content.Intent
import android.media.AudioManager
import android.media.MediaPlayer
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.provider.MediaStore
import android.view.WindowManager
import io.xdrm.lebonprix.anim.GooeySplashAnimation
import kotlinx.android.synthetic.main.activity_gooey_splash_screen.*
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
class GooeySplashScreen : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_gooey_splash_screen)
// 1. launch animation
val anim = GooeySplashAnimation(resources, canvas_wrapper)
anim.duration = 4000
anim.start()
// 2. Override media volume if below a required level
val audio = getSystemService(Context.AUDIO_SERVICE) as AudioManager
val requiredMinimumVolume = audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC) * 0.5
if( audio.getStreamVolume(AudioManager.STREAM_MUSIC) < requiredMinimumVolume )
audio.setStreamVolume(AudioManager.STREAM_MUSIC, requiredMinimumVolume.toInt(), 0)
// 3. play sound + override volume
val player = MediaPlayer.create(this, R.raw.drop)
Handler().postDelayed({ player.start() }, 1000)
// 4. go to Home after delay
Handler().postDelayed({
player.stop()
startActivity( Intent(this, HomeActivity::class.java) )
finish()
}, 4000)
}
}