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()
|
}
|
|
|
|
}
|