package com.app.brush.guitar.ink.eraser

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
import android.widget.ProgressBar
import com.app.brush.guitar.ink.R
import com.app.brush.guitar.ink.iguana.UbiquitousSerene
import kotlin.math.roundToInt


/**
 * 不要修改启动页继承Activity这点
 */
class LauncherSilhouette : Activity() {

    private lateinit var progressBar: ProgressBar
    private var countTime = 1500L
    private lateinit var timer: CountDownTimer

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.tiny_activity_launch_screen)
        UbiquitousSerene.initFullScreen(this,true)
        progressBar = findViewById<ProgressBar>(R.id.nova_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
            }

            override fun onFinish() {
                progressBar.progress = 100
                toHome()
            }

        }
        timer.start()

    }

    private fun toHome() {
        startActivity(Intent(this, CategoryPanorama::class.java))
        finish()
    }

    override fun onDestroy() {
        super.onDestroy()
        timer.cancel()
    }


}