endian11
2020-09-15 389853ce971a3da0e806dddd909bb43f5928c90c
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package safeluck.drive.evaluation.customview
 
import android.app.Dialog
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Build
import android.os.Bundle
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.Button
import androidx.fragment.app.DialogFragment
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
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 MyInputDialog : DialogFragment() {
    lateinit var button: Button
    lateinit var button_cancle: Button
    lateinit var textInput: TextInputEditText
    lateinit var textInputLayout: TextInputLayout
    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_input_dlg,container,false)
        initView(view)
 
        return view
    }
    override fun onStart() {
        super.onStart()
        val dialog: Dialog? = dialog
        if (dialog != null) {
            val dm = DisplayMetrics()
            activity!!.windowManager.defaultDisplay.getMetrics(dm)
            var width:Int = (dm.widthPixels * 0.5).toInt()
 
            dialog.window.setLayout(width , ViewGroup.LayoutParams.WRAP_CONTENT)
        }
    }
    private fun initView(view: View?) {
        mess = arguments?.getString("message")
        button = view!!.findViewById(R.id.btn_sure_)
        textInput = view!!.findViewById(R.id.tiet_road_num)
 
        textInput.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
            override fun afterTextChanged(s: Editable?) {
                if (textInput.text?.length!! > 0) {
                    textInputLayout.isErrorEnabled = false
                }
            }
        })
 
        textInputLayout = view!!.findViewById(R.id.til_password)
        button_cancle = view!!.findViewById(R.id.btn_cancle_)
        button.setOnClickListener {
            var str = textInput.text.toString().trim()
            if (!TextUtils.isEmpty(str)) {
                onClick.onSure(str)
                dismiss()
            } else {
                textInputLayout.error = "线路名称不能为空"
            }
        }
        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):MyInputDialog{
            var myDialog= MyInputDialog()
            var bundle = Bundle()
            bundle.putString("message",message)
            myDialog.arguments = bundle
            return myDialog
 
        }
    }
 
    interface MyOnClickListener{
        fun onSure(string: String)
        fun onCancle()
    }
 
 
 
}