fctom1215
2020-08-27 7da09f8b376111c4ff5199275dc68f765ae2cfc0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package safeluck.drive.evaluation.customview
 
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.Button
import android.widget.TextView
import androidx.fragment.app.DialogFragment
import safeluck.drive.evaluation.R
 
/**
 *
 * @ProjectName: DriveJudge
 * @Package: safeluck.drive.evaluation.customview
 * @ClassName: MyDialog
 * @Description: java类作用描述
 * @Author: 李占伟
 * @CreateDate: 2020-04-29 16:46
 * @UpdateUser: 更新者
 * @UpdateDate: 2020-04-29 16:46
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
 
class MyDialog : DialogFragment() {
    lateinit var button: Button
    lateinit var button_cancle: Button
    lateinit var textview: TextView
    var mess: String? = null
    lateinit var onClick:MyOnClickListener
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        if(dialog!=null){
            var windown = dialog!!.window;
           windown?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
            windown?.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
            dialog?.setOnShowListener { windown?.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
            hideBottomUIMenu()}
        }
        var view = inflater.inflate(R.layout.layout_dlg,container,false)
        initView(view)
 
        return view
    }
 
    private fun initView(view: View?) {
        mess = arguments?.getString("message")
        button = view!!.findViewById(R.id.btn_sure_)
        textview = view!!.findViewById(R.id.tv_message)
        textview.text =mess
        button_cancle = view!!.findViewById(R.id.btn_cancle_)
        button.setOnClickListener { onClick.onSure()
            dismiss() }
        button_cancle.setOnClickListener {
            onClick.onCancle()
            dismiss()
        }
 
    }
 
    /**
     * 隐藏虚拟按键,并且全屏
     */
    protected fun hideBottomUIMenu() { //隐藏虚拟按键,并且全屏
        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
            val v = this.dialog?.window?.decorView
            v?.systemUiVisibility = View.GONE
        } else if (Build.VERSION.SDK_INT >= 19) { //for new api versions.
            val decorView = dialog?.window?.decorView
            val uiOptions = (View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_FULLSCREEN)
            decorView?.systemUiVisibility = uiOptions
        }
    }
 
    companion object{
        fun newInstance(message:String):MyDialog{
            var myDialog= MyDialog()
            var bundle = Bundle()
            bundle.putString("message",message)
            myDialog.arguments = bundle
            return myDialog
 
        }
    }
 
    interface MyOnClickListener{
        fun onSure()
        fun onCancle()
    }
 
 
 
}