package com.example.chemical.weidith

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.Gravity
import android.view.Window
import android.view.WindowManager
import android.widget.Button
import android.widget.EditText
import com.example.chemical.R

class EdContThDialog (private val ct: Context, private var iLint: IClickLit) : Dialog(ct) {
    private var mHandler: Handler = Handler(Looper.getMainLooper())
    init {
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        setContentView(R.layout.ed_cont_th_dialog)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        window?.setGravity(Gravity.CENTER)
        window?.setLayout(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT
        )
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        findViewById<Button>(R.id.comt).setOnClickListener {
            val toString = findViewById<EditText>(R.id.edCont).text.toString()
            dismiss()
            iLint.onClickClo(toString)
        }
        mHandler.postDelayed({
            dismiss()
        }, 1000 * 15) // 15秒后关闭对话框

    }

    interface IClickLit {
        fun onClickClo(str: String?)
    }

    override fun onStop() {
        super.onStop()
        mHandler.removeCallbacksAndMessages(null)
    }
}