WeighDialog.kt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package xn.hxp.weidith
  2. import android.app.Dialog
  3. import android.content.Context
  4. import android.graphics.Color
  5. import android.graphics.drawable.ColorDrawable
  6. import android.os.Bundle
  7. import android.os.Handler
  8. import android.os.Looper
  9. import android.text.TextUtils
  10. import android.view.Gravity
  11. import android.view.MotionEvent
  12. import android.view.Window
  13. import android.view.WindowManager
  14. import android.widget.EditText
  15. import android.widget.ImageView
  16. import android.widget.TextView
  17. import android.widget.Toast
  18. import androidx.lifecycle.lifecycleScope
  19. import com.bumptech.glide.Glide
  20. import com.bumptech.glide.load.engine.DiskCacheStrategy
  21. import com.bumptech.glide.request.RequestOptions
  22. import xn.hxp.R
  23. import com.blankj.utilcode.util.LogUtils
  24. import com.blankj.utilcode.util.SPUtils
  25. import com.rc.httpcore.HttpConfig
  26. import xn.hxp.app.ChemicalApp
  27. //称重弹框
  28. class WeighDialog(
  29. private val ct: Context,
  30. private var density: String,
  31. private var lint: IViewLint
  32. ) : Dialog(ct) {
  33. init {
  34. setContentView(R.layout.weigh_dialog)
  35. }
  36. override fun onCreate(savedInstanceState: Bundle?) {
  37. super.onCreate(savedInstanceState)
  38. SPUtils.getInstance().put("WeighDialog",true)
  39. if (ChemicalApp.confs!!.weighHintPicture != null) {
  40. LogUtils.i("======称重示意图:${HttpConfig.API_BASE_IMG_URL}${ChemicalApp.confs!!.weighHintPicture}")
  41. val findViewById = findViewById<ImageView>(R.id.imgView)
  42. // 使用 Glide 加载网络图片
  43. Glide.with(ct)
  44. .load("${HttpConfig.API_BASE_IMG_URL}${ChemicalApp.confs!!.weighHintPicture}")
  45. .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
  46. .into(findViewById)
  47. }
  48. findViewById<TextView>(R.id.density).text = "$density"
  49. var weighingValue = findViewById<EditText>(R.id.weigh)
  50. weighingValue.isEnabled = false //禁止输入 需要链接蓝牙称
  51. findViewById<ImageView>(R.id.imgType).setOnClickListener {
  52. //手动输入
  53. weighingValue.isEnabled = true //禁止链接蓝牙称
  54. lint.onMovement()
  55. }
  56. lint.weighingView(weighingValue)
  57. val tvClose = findViewById<TextView>(R.id.tvClose)
  58. tvClose.setOnClickListener {
  59. val weigh = findViewById<EditText>(R.id.weigh).text.toString()
  60. if (TextUtils.isEmpty(weigh)) {
  61. Toast.makeText(ct, "请输入重量", Toast.LENGTH_SHORT).show()
  62. return@setOnClickListener
  63. }
  64. dismiss()
  65. lint.viewCloses()
  66. }
  67. }
  68. interface IViewLint {
  69. fun weighingView(weighingValue: EditText)
  70. fun viewCloses()
  71. fun onMovement() //手动输入 手动编辑 进行输入 需要断开蓝牙称
  72. fun onTimerReply() //重置万层计时器 防止未操作完成就返回页面
  73. }
  74. override fun onStop() {
  75. super.onStop()
  76. SPUtils.getInstance().put("WeighDialog",false)
  77. }
  78. }