|
@@ -14,26 +14,10 @@ import android.widget.Toast
|
|
import androidx.core.content.ContextCompat
|
|
import androidx.core.content.ContextCompat
|
|
import androidx.lifecycle.lifecycleScope
|
|
import androidx.lifecycle.lifecycleScope
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
|
+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 com.caysn.autoreplyprint.AutoReplyPrint
|
|
|
|
-import xn.hxp.R
|
|
|
|
-import xn.hxp.blu.BluetoothConnectionManager
|
|
|
|
-import xn.hxp.comm.Constants
|
|
|
|
-import xn.hxp.databinding.ActivityChemicalsAlsoBinding
|
|
|
|
-import xn.hxp.receiver.OnSerialScanListener
|
|
|
|
-import xn.hxp.receiver.PortScanHelper
|
|
|
|
-import xn.hxp.receiver.UsbReceiver
|
|
|
|
-import xn.hxp.ui.PrintBean
|
|
|
|
-import xn.hxp.ui.SplashActivity
|
|
|
|
-import xn.hxp.ui.adapter.ReturningChemicalsAdapter
|
|
|
|
-import xn.hxp.ui.common.BaseCountDownActivity
|
|
|
|
-import xn.hxp.ui.verify.TwoVerificationActivity
|
|
|
|
-import xn.hxp.utils.*
|
|
|
|
-import xn.hxp.weidith.*
|
|
|
|
-import com.blankj.utilcode.util.LogUtils
|
|
|
|
-import com.rc.httpcore.HttpClient
|
|
|
|
import com.rc.httpcore.HttpConfig
|
|
import com.rc.httpcore.HttpConfig
|
|
import com.rc.httpcore.bean.GiveBackBean
|
|
import com.rc.httpcore.bean.GiveBackBean
|
|
import com.rc.httpcore.bean.LockVoListBean
|
|
import com.rc.httpcore.bean.LockVoListBean
|
|
@@ -41,17 +25,29 @@ import com.rc.httpcore.bean.ReturnDetailsBean
|
|
import com.rc.httpcore.bean.ReturnGiveBackBean
|
|
import com.rc.httpcore.bean.ReturnGiveBackBean
|
|
import com.rc.httpcore.client.ApiRepository
|
|
import com.rc.httpcore.client.ApiRepository
|
|
import com.rc.httpcore.exception.NetException
|
|
import com.rc.httpcore.exception.NetException
|
|
-import com.sun.jna.Pointer
|
|
|
|
import kotlinx.coroutines.*
|
|
import kotlinx.coroutines.*
|
|
import org.greenrobot.eventbus.EventBus
|
|
import org.greenrobot.eventbus.EventBus
|
|
import org.greenrobot.eventbus.Subscribe
|
|
import org.greenrobot.eventbus.Subscribe
|
|
import org.greenrobot.eventbus.ThreadMode
|
|
import org.greenrobot.eventbus.ThreadMode
|
|
import retrofit2.HttpException
|
|
import retrofit2.HttpException
|
|
|
|
+import xn.hxp.R
|
|
import xn.hxp.app.ChemicalApp
|
|
import xn.hxp.app.ChemicalApp
|
|
|
|
+import xn.hxp.comm.Constants
|
|
|
|
+import xn.hxp.databinding.ActivityChemicalsAlsoBinding
|
|
|
|
+import xn.hxp.receiver.OnSerialScanListener
|
|
|
|
+import xn.hxp.receiver.PortScanHelper
|
|
|
|
+import xn.hxp.receiver.UsbReceiver
|
|
|
|
+import xn.hxp.ui.PrintBean
|
|
|
|
+import xn.hxp.ui.adapter.ReturningChemicalsAdapter
|
|
|
|
+import xn.hxp.ui.common.BaseCountDownActivity
|
|
|
|
+import xn.hxp.ui.verify.TwoVerificationActivity
|
|
|
|
+import xn.hxp.utils.*
|
|
|
|
+import xn.hxp.utils.bluetooth.BluetoothTool
|
|
|
|
+import xn.hxp.utils.bluetooth.BluetoothTool.BluetoothCallBack
|
|
|
|
+import xn.hxp.weidith.*
|
|
import java.lang.Runnable
|
|
import java.lang.Runnable
|
|
import java.net.ConnectException
|
|
import java.net.ConnectException
|
|
import java.net.SocketTimeoutException
|
|
import java.net.SocketTimeoutException
|
|
-import java.nio.charset.StandardCharsets
|
|
|
|
|
|
|
|
//化学品-归还 StorageDialog 柜字信息
|
|
//化学品-归还 StorageDialog 柜字信息
|
|
class ChemicalsAlsoActivity : BaseCountDownActivity<ActivityChemicalsAlsoBinding>() {
|
|
class ChemicalsAlsoActivity : BaseCountDownActivity<ActivityChemicalsAlsoBinding>() {
|
|
@@ -102,12 +98,7 @@ class ChemicalsAlsoActivity : BaseCountDownActivity<ActivityChemicalsAlsoBinding
|
|
EventBus.getDefault().register(this)
|
|
EventBus.getDefault().register(this)
|
|
initTitle()
|
|
initTitle()
|
|
viewBinding.tvOutLogin.setOnClickListener {
|
|
viewBinding.tvOutLogin.setOnClickListener {
|
|
- callLogoutApi {
|
|
|
|
- ChemicalApp.userData = null
|
|
|
|
- HttpClient.token = null
|
|
|
|
- ChemicalApp.subjectId = null
|
|
|
|
- UiManager.switcherCashier(this, SplashActivity::class.java)
|
|
|
|
- }
|
|
|
|
|
|
+ callLogoutApi()
|
|
}
|
|
}
|
|
inAdapter()//初始化适配器
|
|
inAdapter()//初始化适配器
|
|
viewBinding.tvReturn.text = "返回${ChemicalApp.confs!!.backTime}s"
|
|
viewBinding.tvReturn.text = "返回${ChemicalApp.confs!!.backTime}s"
|
|
@@ -283,7 +274,7 @@ class ChemicalsAlsoActivity : BaseCountDownActivity<ActivityChemicalsAlsoBinding
|
|
}
|
|
}
|
|
//
|
|
//
|
|
print.types = "${mDataBean.chemicalCategoryName}"
|
|
print.types = "${mDataBean.chemicalCategoryName}"
|
|
- labelPrint(print)
|
|
|
|
|
|
+ PrintTool.INSTANCE.print(mDataBean.belongType == 2, print)
|
|
}
|
|
}
|
|
|
|
|
|
viewBinding.replaceLabel.setOnClickListener {
|
|
viewBinding.replaceLabel.setOnClickListener {
|
|
@@ -417,7 +408,7 @@ class ChemicalsAlsoActivity : BaseCountDownActivity<ActivityChemicalsAlsoBinding
|
|
}
|
|
}
|
|
//
|
|
//
|
|
print.types = "${mDataBean.chemicalCategoryName}"
|
|
print.types = "${mDataBean.chemicalCategoryName}"
|
|
- labelPrint(print)
|
|
|
|
|
|
+ PrintTool.INSTANCE.print(mDataBean.belongType == 2, print)
|
|
}, { throwable ->
|
|
}, { throwable ->
|
|
dismissLoading()
|
|
dismissLoading()
|
|
showNetError(throwable)
|
|
showNetError(throwable)
|
|
@@ -426,95 +417,6 @@ class ChemicalsAlsoActivity : BaseCountDownActivity<ActivityChemicalsAlsoBinding
|
|
addDisposable(disposable)
|
|
addDisposable(disposable)
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 标签打印
|
|
|
|
- * 补打印
|
|
|
|
- * 化学品信息
|
|
|
|
- */
|
|
|
|
- var h = Pointer.NULL
|
|
|
|
- private fun labelPrint(printDate: PrintBean) {
|
|
|
|
- val thread = Thread {
|
|
|
|
- try {
|
|
|
|
- try {//关闭打印
|
|
|
|
- h = AutoReplyPrint.INSTANCE.CP_Port_OpenUsb("VID:0x0FE6,PID:0x811E", 1)
|
|
|
|
- } catch (e: Exception) {
|
|
|
|
- LogUtils.i("初始化异常")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- val bitmap = BitmapUtils.generateBitmap(printDate) //图片信息
|
|
|
|
- AutoReplyPrint.INSTANCE.CP_Label_BackPaperToPrintPosition(h)
|
|
|
|
- AutoReplyPrint.CP_Pos_PrintRasterImageFromData_Helper.PrintRasterImageFromBitmap(
|
|
|
|
- h,
|
|
|
|
- bitmap!!.width,
|
|
|
|
- bitmap.height,
|
|
|
|
- bitmap,
|
|
|
|
- AutoReplyPrint.CP_ImageBinarizationMethod_Thresholding,
|
|
|
|
- AutoReplyPrint.CP_ImageCompressionMethod_None
|
|
|
|
- )
|
|
|
|
- AutoReplyPrint.INSTANCE.CP_Label_PagePrint(h, 1)
|
|
|
|
- val result = AutoReplyPrint.INSTANCE.CP_Pos_HalfCutPaper(h) //全切
|
|
|
|
- if (result) {
|
|
|
|
- //打印成功
|
|
|
|
- MediaPlayerHelper.playRawMp3(this, R.raw.huaxuepinbiaoqian)
|
|
|
|
- closePort()
|
|
|
|
-// customDialogView(0, "请将标签粘贴在化学品外包装上")
|
|
|
|
- } else {
|
|
|
|
- closePort()
|
|
|
|
- //失败
|
|
|
|
- }
|
|
|
|
- } catch (e: Exception) {
|
|
|
|
- closePort()
|
|
|
|
- // 监听子线程中抛出的异常
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- thread.start() // 启动子线程
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private fun closePort() {
|
|
|
|
- if (h !== Pointer.NULL) {
|
|
|
|
- AutoReplyPrint.INSTANCE.CP_Port_Close(h)
|
|
|
|
- h = Pointer.NULL
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //更换rfid
|
|
|
|
- private fun labelPrint(rfid: String) {
|
|
|
|
- val thread = Thread {
|
|
|
|
- try {
|
|
|
|
- var h = Pointer.NULL
|
|
|
|
- try {//关闭打印
|
|
|
|
- h = AutoReplyPrint.INSTANCE.CP_Port_OpenUsb("VID:0x0FE6,PID:0x811E", 1)
|
|
|
|
- } catch (e: Exception) {
|
|
|
|
- LogUtils.i("初始化异常")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- val bitmap = BitmapUtils.airBottlePrint(rfid) //图片信息
|
|
|
|
- AutoReplyPrint.INSTANCE.CP_Label_BackPaperToPrintPosition(h)
|
|
|
|
- AutoReplyPrint.CP_Pos_PrintRasterImageFromData_Helper.PrintRasterImageFromBitmap(
|
|
|
|
- h,
|
|
|
|
- bitmap!!.width,
|
|
|
|
- bitmap.height,
|
|
|
|
- bitmap,
|
|
|
|
- AutoReplyPrint.CP_ImageBinarizationMethod_Thresholding,
|
|
|
|
- AutoReplyPrint.CP_ImageCompressionMethod_None
|
|
|
|
- )
|
|
|
|
- AutoReplyPrint.INSTANCE.CP_Label_PagePrint(h, 1)
|
|
|
|
- val result = AutoReplyPrint.INSTANCE.CP_Pos_HalfCutPaper(h) //全切
|
|
|
|
- if (result) {
|
|
|
|
- //打印成功
|
|
|
|
- MediaPlayerHelper.playRawMp3(this, R.raw.zhantiefrid)
|
|
|
|
- customDialogView(0, "请将二维码粘贴在RFID标签上")
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- //失败
|
|
|
|
- }
|
|
|
|
- } catch (e: Exception) {
|
|
|
|
- // 监听子线程中抛出的异常
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- thread.start() // 启动子线程
|
|
|
|
- }
|
|
|
|
|
|
|
|
//验证方式
|
|
//验证方式
|
|
private fun verifyChecking() {
|
|
private fun verifyChecking() {
|
|
@@ -836,87 +738,43 @@ class ChemicalsAlsoActivity : BaseCountDownActivity<ActivityChemicalsAlsoBinding
|
|
private fun connectToDeviceWithTimeout() {
|
|
private fun connectToDeviceWithTimeout() {
|
|
showToast("连接中...", Toast.LENGTH_SHORT)
|
|
showToast("连接中...", Toast.LENGTH_SHORT)
|
|
lifecycleScope.launch {
|
|
lifecycleScope.launch {
|
|
- val deviceAddress = withContext(Dispatchers.IO) {
|
|
|
|
- BluetoothConnectionManager.getDeviceAddress()
|
|
|
|
- }
|
|
|
|
- if (deviceAddress != null) {
|
|
|
|
- val socket = withContext(Dispatchers.IO) {
|
|
|
|
- BluetoothConnectionManager.connectToDevice(deviceAddress)
|
|
|
|
- }
|
|
|
|
- if (socket != null) {
|
|
|
|
- // 连接成功后的处理逻辑
|
|
|
|
- // 在这里使用返回的 BluetoothSocket 对象进行后续操作
|
|
|
|
- MediaPlayerHelper.playRawMp3(this@ChemicalsAlsoActivity, R.raw.qing_zheng_zhong)
|
|
|
|
- // 连接成功后的处理逻辑
|
|
|
|
- withContext(Dispatchers.Main) {
|
|
|
|
- do {
|
|
|
|
- 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
|
|
|
|
- )
|
|
|
|
- if ("" == contents || contents.isEmpty()) {
|
|
|
|
- return@withContext
|
|
|
|
- }
|
|
|
|
- val split = contents.split("\n")
|
|
|
|
- if (split.isEmpty()) {
|
|
|
|
- return@withContext
|
|
|
|
- }
|
|
|
|
- val weight = split[0].trim()
|
|
|
|
- if ("" == weight || weight.isEmpty()) {
|
|
|
|
- return@withContext
|
|
|
|
- }
|
|
|
|
- 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) {
|
|
|
|
- taskStarted = true
|
|
|
|
- LogUtils.i("=====执行了")
|
|
|
|
- socket.close()
|
|
|
|
- delayedTaskToUpdateUI()
|
|
|
|
- break
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- mWeighingValue!!.setText("$weight")
|
|
|
|
- } else {
|
|
|
|
- mWeighingValue!!.setText("")
|
|
|
|
|
|
+ MediaPlayerHelper.playRawMp3(this@ChemicalsAlsoActivity, R.raw.qing_zheng_zhong)
|
|
|
|
+ BluetoothTool.INSTANCE.connect(object : BluetoothCallBack {
|
|
|
|
+ override fun callBack(weight: String) {
|
|
|
|
+ if ("" == weight || weight.isEmpty()) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ 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) {
|
|
|
|
+ taskStarted = true
|
|
|
|
+ LogUtils.i("=====执行了")
|
|
|
|
+ delayedTaskToUpdateUI()
|
|
|
|
+ return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- delay(200)
|
|
|
|
- } else {
|
|
|
|
- showToast("请手动输入")
|
|
|
|
- weiView()
|
|
|
|
- break
|
|
|
|
}
|
|
}
|
|
- } while (true)
|
|
|
|
|
|
+ mWeighingValue!!.setText("$weight")
|
|
|
|
+ } else {
|
|
|
|
+ mWeighingValue!!.setText("")
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
|
- // 连接失败的处理逻辑
|
|
|
|
- showToast("连接失败或超时", Toast.LENGTH_SHORT)
|
|
|
|
|
|
+ override fun connectFailed(msg: String) {
|
|
|
|
+ showToast("找不到设备", Toast.LENGTH_SHORT)
|
|
weiView()
|
|
weiView()
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- // 根据设备名称获取的设备地址为空,处理无法找到设备的情况
|
|
|
|
- showToast("找不到设备", Toast.LENGTH_SHORT)
|
|
|
|
- weiView()
|
|
|
|
- }
|
|
|
|
|
|
+ })
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1502,6 +1360,7 @@ class ChemicalsAlsoActivity : BaseCountDownActivity<ActivityChemicalsAlsoBinding
|
|
viewBinding.revert.isChecked = true
|
|
viewBinding.revert.isChecked = true
|
|
viewBinding.revert.isEnabled = true
|
|
viewBinding.revert.isEnabled = true
|
|
viewBinding.chemicalName.text = "${mDataBean.chemicalName}"
|
|
viewBinding.chemicalName.text = "${mDataBean.chemicalName}"
|
|
|
|
+ viewBinding.chemicalName.isSelected = true
|
|
viewBinding.chemicalLevelName.text = "${mDataBean.chemicalLevelName}"
|
|
viewBinding.chemicalLevelName.text = "${mDataBean.chemicalLevelName}"
|
|
viewBinding.chemicalCategoryName.text = "${mDataBean.chemicalCategoryName}"
|
|
viewBinding.chemicalCategoryName.text = "${mDataBean.chemicalCategoryName}"
|
|
viewBinding.tagCode.text = "编码${mDataBean.tagCode}"
|
|
viewBinding.tagCode.text = "编码${mDataBean.tagCode}"
|