package com.keypalette.theme.activity import android.content.Intent import android.os.Bundle import android.os.CountDownTimer import android.widget.ProgressBar import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import com.keypalette.theme.R import com.keypalette.theme.other.Helper import kotlin.math.roundToInt class PageSplash : AppCompatActivity() { private lateinit var progressBar: ProgressBar private var countTime = 2000L private lateinit var timer: CountDownTimer private lateinit var tvProgress:TextView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.page_splash) Helper.initFullScreen(this,true) progressBar = findViewById(R.id.progress) tvProgress = findViewById(R.id.tv_progress) init() } private fun init() { timer = object : CountDownTimer(countTime,100){ override fun onTick(millisUntilFinished: Long) { val percentage: Float = 100 - millisUntilFinished.toFloat() / countTime * 100 val round = percentage.roundToInt() progressBar.progress = round val format =getString(R.string.tv_wel_progress, round) tvProgress.text = format } override fun onFinish() { progressBar.progress = 100 tvProgress.text = getString(R.string.tv_wel_progress, 100) toHome() } } timer.start() } private fun toHome() { startActivity(Intent(this, PageMain::class.java)) finish() } override fun onDestroy() { super.onDestroy() timer.cancel() } }