package com.example.watch.ui.activity

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.viewpager.widget.ViewPager
import com.example.watch.R


class OneActivity : AppCompatActivity() {
    private var vpager_one: ViewPager? = null
    private var aList: ArrayList<View>? = null
    private var mAdapter: MyPagerAdapter? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_one)
        setStatusBarColor(1)
        vpager_one = findViewById<View>(R.id.vpager_one) as ViewPager
        aList = ArrayList<View>()
        val li = layoutInflater
        aList!!.add(li.inflate(R.layout.view_one, null, false))
        aList!!.add(li.inflate(R.layout.view_two, null, false))
        aList!!.add(li.inflate(R.layout.view_three, null, false))
        mAdapter = MyPagerAdapter(aList)
        vpager_one!!.adapter = mAdapter

        setStatusBarColor(0)
//        监听滚动事件
        vpager_one!!.setOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {
            }

            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
            }

            override fun onPageSelected(position: Int) {
                //判断滑动后选择的页面设置相应的RadioButton被选中
                println("position" + position)
                when (position) {
                    //这里的btn_one two the 分别是布局中的三个RadioButton的id，直接调用其方法进行设置
                    0 -> setStatusBarColor(0)
                    1 -> setStatusBarColor(1)
                    2 -> setStatusBarColor(2)
                }
            }

        })
    }

    fun enterClick(view: View?) {
        startActivity(Intent(this, MainActivity::class.java))
    }

    fun setStatusBarColor(number: Number) {
        val window = window
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
        when (number) {
            0 -> window.statusBarColor = resources.getColor(R.color.pink)
            1 -> window.statusBarColor = resources.getColor(R.color.yellow)
            2 -> window.statusBarColor = resources.getColor(R.color.green)
        }

    }

}