|
@@ -1,11 +1,9 @@
|
|
package xn.hxp.ui.uses
|
|
package xn.hxp.ui.uses
|
|
|
|
|
|
-import android.os.Bundle
|
|
|
|
import android.os.CountDownTimer
|
|
import android.os.CountDownTimer
|
|
import android.os.Handler
|
|
import android.os.Handler
|
|
import android.os.Looper
|
|
import android.os.Looper
|
|
import android.view.KeyEvent
|
|
import android.view.KeyEvent
|
|
-import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
import android.view.View
|
|
import android.widget.EditText
|
|
import android.widget.EditText
|
|
import android.widget.Toast
|
|
import android.widget.Toast
|
|
@@ -13,12 +11,22 @@ import androidx.core.content.ContextCompat
|
|
import androidx.lifecycle.lifecycleScope
|
|
import androidx.lifecycle.lifecycleScope
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import androidx.viewbinding.ViewBinding
|
|
import androidx.viewbinding.ViewBinding
|
|
|
|
+import com.blankj.utilcode.util.LogUtils
|
|
import com.bumptech.glide.Glide
|
|
import com.bumptech.glide.Glide
|
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
|
import com.bumptech.glide.request.RequestOptions
|
|
import com.bumptech.glide.request.RequestOptions
|
|
-import xn.hxp.app.ChemicalApp
|
|
|
|
|
|
+import com.rc.core.ui.activity.BaseActivity
|
|
|
|
+import com.rc.httpcore.HttpConfig
|
|
|
|
+import com.rc.httpcore.bean.ChemistryBean
|
|
|
|
+import com.rc.httpcore.bean.LockVoListBean
|
|
|
|
+import com.rc.httpcore.bean.TimeWarBean
|
|
|
|
+import com.rc.httpcore.bean.UseBean
|
|
|
|
+import com.rc.httpcore.bean.UsePostDataBean
|
|
|
|
+import com.rc.httpcore.client.ApiRepository
|
|
|
|
+import com.rc.httpcore.client.HttpTool
|
|
|
|
+import kotlinx.coroutines.cancel
|
|
import xn.hxp.R
|
|
import xn.hxp.R
|
|
-import xn.hxp.blu.BluetoothConnectionManager
|
|
|
|
|
|
+import xn.hxp.app.ChemicalApp
|
|
import xn.hxp.comm.Constants
|
|
import xn.hxp.comm.Constants
|
|
import xn.hxp.databinding.ActivityUseBinding
|
|
import xn.hxp.databinding.ActivityUseBinding
|
|
import xn.hxp.ui.adapter.CabinetDoorAdapter
|
|
import xn.hxp.ui.adapter.CabinetDoorAdapter
|
|
@@ -26,22 +34,18 @@ import xn.hxp.ui.adapter.CabinetDoorRighAdapter
|
|
import xn.hxp.ui.adapter.UsageLabelDialogAdapter
|
|
import xn.hxp.ui.adapter.UsageLabelDialogAdapter
|
|
import xn.hxp.ui.adapter.UseListAdapter
|
|
import xn.hxp.ui.adapter.UseListAdapter
|
|
import xn.hxp.ui.verify.TwoVerificationActivity
|
|
import xn.hxp.ui.verify.TwoVerificationActivity
|
|
-import xn.hxp.utils.*
|
|
|
|
|
|
+import xn.hxp.utils.AudioPlayer
|
|
|
|
+import xn.hxp.utils.BigDecimalUtils
|
|
|
|
+import xn.hxp.utils.HandlerUtil
|
|
|
|
+import xn.hxp.utils.SharedPreferencesHelper
|
|
|
|
+import xn.hxp.utils.TimeUpdater
|
|
|
|
+import xn.hxp.utils.UiManager
|
|
|
|
+import xn.hxp.utils.bluetooth.BleTool
|
|
import xn.hxp.weidith.CustomDialog
|
|
import xn.hxp.weidith.CustomDialog
|
|
import xn.hxp.weidith.StorageDialog
|
|
import xn.hxp.weidith.StorageDialog
|
|
import xn.hxp.weidith.UsageLabelDialog
|
|
import xn.hxp.weidith.UsageLabelDialog
|
|
import xn.hxp.weidith.WeighDialog
|
|
import xn.hxp.weidith.WeighDialog
|
|
-import com.blankj.utilcode.util.LogUtils
|
|
|
|
-import com.rc.core.ui.activity.BaseActivity
|
|
|
|
-import com.rc.httpcore.HttpClient
|
|
|
|
-import com.rc.httpcore.HttpConfig
|
|
|
|
-import com.rc.httpcore.bean.*
|
|
|
|
-import com.rc.httpcore.client.ApiRepository
|
|
|
|
-import com.rc.httpcore.client.HttpTool
|
|
|
|
-import kotlinx.coroutines.*
|
|
|
|
-import java.lang.Runnable
|
|
|
|
import java.math.BigDecimal
|
|
import java.math.BigDecimal
|
|
-import java.nio.charset.StandardCharsets
|
|
|
|
|
|
|
|
//化学品 领用
|
|
//化学品 领用
|
|
class UseActivity : BaseActivity() {
|
|
class UseActivity : BaseActivity() {
|
|
@@ -491,6 +495,9 @@ class UseActivity : BaseActivity() {
|
|
}
|
|
}
|
|
|
|
|
|
override fun viewCloses() {
|
|
override fun viewCloses() {
|
|
|
|
+ BleTool.INSTANCE.setBleCallback(null)
|
|
|
|
+ BleTool.INSTANCE.disconnect()
|
|
|
|
+ closEnd()
|
|
closEndTwo()
|
|
closEndTwo()
|
|
try {
|
|
try {
|
|
lifecycleScope.cancel()
|
|
lifecycleScope.cancel()
|
|
@@ -538,87 +545,24 @@ class UseActivity : BaseActivity() {
|
|
|
|
|
|
private fun connectToDeviceWithTimeout() {
|
|
private fun connectToDeviceWithTimeout() {
|
|
showToast("连接中...", Toast.LENGTH_SHORT)
|
|
showToast("连接中...", Toast.LENGTH_SHORT)
|
|
- lifecycleScope.launch {
|
|
|
|
- val deviceAddress = withContext(Dispatchers.IO) {
|
|
|
|
- BluetoothConnectionManager.getDeviceAddress()
|
|
|
|
|
|
+ BleTool.INSTANCE.setBleCallback(object : BleTool.BleCallback {
|
|
|
|
+ override fun onSuccess() {
|
|
|
|
+ AudioPlayer.getInstance().play(R.raw.qing_zheng_zhong)
|
|
}
|
|
}
|
|
- if (deviceAddress != null) {
|
|
|
|
- val socket = withContext(Dispatchers.IO) {
|
|
|
|
- BluetoothConnectionManager.connectToDevice(deviceAddress)
|
|
|
|
- }
|
|
|
|
- if (socket != null) {
|
|
|
|
- // 连接成功后的处理逻辑
|
|
|
|
- // 在这里使用返回的 BluetoothSocket 对象进行后续操作
|
|
|
|
- AudioPlayer.getInstance().play(R.raw.qing_zheng_zhong)
|
|
|
|
- // 连接成功后的处理逻辑
|
|
|
|
- withContext(Dispatchers.Main) {
|
|
|
|
- do {
|
|
|
|
-// try {
|
|
|
|
- val inputStream = socket!!.inputStream
|
|
|
|
- val bt = ByteArray(1024)
|
|
|
|
- val content = inputStream!!.read(bt)
|
|
|
|
- if (content != null && content > 0) {
|
|
|
|
- val contents = String(
|
|
|
|
- bt,
|
|
|
|
- 0,
|
|
|
|
- content,
|
|
|
|
- StandardCharsets.UTF_8
|
|
|
|
- )
|
|
|
|
- val split = contents.split("\n")
|
|
|
|
- val weight = split[0].trim()
|
|
|
|
- LogUtils.i("===================称重未处理之前=======$contents")
|
|
|
|
- LogUtils.i("===================weight=======$weight")
|
|
|
|
- LogUtils.i("=====称重数据$weight $taskStarted ${mWeighingValue!!.text.toString()}")
|
|
|
|
- if (weight.toDouble() > 2999) {
|
|
|
|
- turnOffWeighing()
|
|
|
|
- } else {
|
|
|
|
- if (weight.toDouble() > 0) {
|
|
|
|
- if (mWeighingValue!!.text.toString().trim()
|
|
|
|
- .isNotEmpty()
|
|
|
|
- ) {
|
|
|
|
- if (weight.toDouble() == mWeighingValue!!.text.toString()
|
|
|
|
- .trim().toDouble()
|
|
|
|
- ) {
|
|
|
|
- if (taskStarted == false) {
|
|
|
|
- taskStarted = true
|
|
|
|
- LogUtils.i("=====执行了")
|
|
|
|
- socket.close()
|
|
|
|
- delayedTaskToUpdateUI()
|
|
|
|
- break
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- mWeighingValue!!.setText("$weight")
|
|
|
|
- } else {
|
|
|
|
- mWeighingValue!!.setText("")
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- delay(200)
|
|
|
|
- } else {
|
|
|
|
-// jobTow?.cancel()
|
|
|
|
- showToast("请手动输入")
|
|
|
|
- weiView()
|
|
|
|
- break
|
|
|
|
- }
|
|
|
|
-// } catch (e: Exception) {
|
|
|
|
-// jobTow?.cancel()
|
|
|
|
-// weiView()
|
|
|
|
-// break
|
|
|
|
-// }
|
|
|
|
- } while (mWeighDialog != null && mWeighDialog!!.isShowing)
|
|
|
|
- }
|
|
|
|
|
|
|
|
- } else {
|
|
|
|
- // 连接失败的处理逻辑
|
|
|
|
- showToast("连接失败或超时", Toast.LENGTH_SHORT)
|
|
|
|
|
|
+ override fun onNotifyFailure(exception: java.lang.Exception?) {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override fun onChanged(weight: String) {
|
|
|
|
+ if (weight.isEmpty()) {
|
|
|
|
+ showToast("请手动输入")
|
|
weiView()
|
|
weiView()
|
|
|
|
+ } else {
|
|
|
|
+ mWeighingValue!!.setText("$weight")
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- // 根据设备名称获取的设备地址为空,处理无法找到设备的情况
|
|
|
|
- showToast("找不到设备", Toast.LENGTH_SHORT)
|
|
|
|
- weiView()
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ })
|
|
|
|
+ BleTool.INSTANCE.connect()
|
|
}
|
|
}
|
|
|
|
|
|
private fun showToast(message: String, duration: Int) {
|
|
private fun showToast(message: String, duration: Int) {
|
|
@@ -719,30 +663,6 @@ class UseActivity : BaseActivity() {
|
|
|
|
|
|
var taskStarted = false
|
|
var taskStarted = false
|
|
|
|
|
|
- // 声明一个全局的 Handler 变量
|
|
|
|
- private var mHandlerTime: Handler? = null
|
|
|
|
-
|
|
|
|
- // 在需要执行任务的地方调用这个函数
|
|
|
|
- private fun delayedTaskToUpdateUI() {
|
|
|
|
- // 初始化 Handler,并关联到主线程 Looper
|
|
|
|
- mHandlerTime = Handler(Looper.getMainLooper())
|
|
|
|
-
|
|
|
|
- // 定义一个延迟执行的任务
|
|
|
|
- val updateUITask = Runnable {
|
|
|
|
- LogUtils.i("=====执行了")
|
|
|
|
- // 在这里执行更新 UI 的操作
|
|
|
|
- // 例如,更新 TextView 的文本
|
|
|
|
- // textView.text = "Updated text"
|
|
|
|
- closEnd()
|
|
|
|
- taskStarted = false
|
|
|
|
- // 执行完更新操作后,可以关闭 Handler
|
|
|
|
- mHandlerTime?.removeCallbacksAndMessages(null)
|
|
|
|
- mHandlerTime = null
|
|
|
|
- }
|
|
|
|
- // 延迟 3 秒执行任务
|
|
|
|
- mHandlerTime?.postDelayed(updateUITask, 3300)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
//超过量程
|
|
//超过量程
|
|
private fun turnOffWeighing() {
|
|
private fun turnOffWeighing() {
|
|
showToast("超过量程,手动输入")
|
|
showToast("超过量程,手动输入")
|
|
@@ -1326,6 +1246,8 @@ class UseActivity : BaseActivity() {
|
|
|
|
|
|
override fun onDestroy() {
|
|
override fun onDestroy() {
|
|
super.onDestroy()
|
|
super.onDestroy()
|
|
|
|
+ BleTool.INSTANCE.setBleCallback(null)
|
|
|
|
+ BleTool.INSTANCE.disconnect()
|
|
// jobTow?.cancel()
|
|
// jobTow?.cancel()
|
|
try {
|
|
try {
|
|
handlerUtil.stopAllTasks()
|
|
handlerUtil.stopAllTasks()
|