package com.example.watch.ui.activity

import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.os.Handler
import android.view.View
import android.view.WindowManager
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.example.watch.R


class WelcomeActivity : AppCompatActivity()  {
    var localVersionName: String? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        白色状态栏
        setStatusBarColor()
        //全屏显示
        setContentView(com.example.watch.R.layout.welcome_layout)
        localVersionName = getVersionName()
        //需要在延迟一段时间之后实现页面的跳转，利用handler的信息传递
        //获得应用的版本信息
        val tv = findViewById<View>(com.example.watch.R.id.app_version) as TextView
        tv.text = localVersionName + "版"
//        实现开机动画的效果，利用Handler的延时发送功能
        Handler().postDelayed(Runnable {
            val intent = Intent()
            intent.setClass(this@WelcomeActivity, MainActivity::class.java)
            startActivity(intent);
            //将当前的界面的生命周期给结束
            finish()
            //知识点，包括intent的信息传递，activity的生命周期
        }, 2000)
    }

    fun getVersionName(): String? {
        val name: String
        val pm = this.packageManager
        name = try {
            val info = pm.getPackageInfo(this.packageName, 0)
            info.versionName
        } catch (e: PackageManager.NameNotFoundException) {
            // TODO Auto-generated catch block
            e.printStackTrace()
            return null
        }
        return name
    }

    fun setStatusBarColor() {
        val window = window
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
        window.statusBarColor = resources.getColor(R.color.white)
    }

}
