优化识别及增加扫码枪逻辑
This commit is contained in:
@@ -4,7 +4,9 @@ import android.content.Context
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.hardware.display.DisplayManager
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.Display
|
||||
import android.view.KeyEvent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -21,6 +23,7 @@ import com.sw.dualscreen.model.response.PostEvent
|
||||
import com.sw.dualscreen.utils.FileUtil
|
||||
import com.sw.dualscreen.view.CustomDialog
|
||||
import com.sw.dualscreen.viewmodel.BaseViewModel
|
||||
import com.sw.plate.utils.ScanGunKeyEventHelper
|
||||
import com.sw.plate.utils.ToastUtils
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
@@ -56,6 +59,7 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
keyEventHelper?.onDestroy()
|
||||
EventBus.getDefault().unregister(this)
|
||||
super.onDestroy()
|
||||
}
|
||||
@@ -142,4 +146,41 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
fun onPostEvent(event: PostEvent) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 监听扫描枪扫描事件
|
||||
*/
|
||||
fun registerKeyEvent() {
|
||||
keyEventHelper =
|
||||
ScanGunKeyEventHelper(context, object : ScanGunKeyEventHelper.OnScanSuccessListener {
|
||||
override fun onScanSuccess(barcode: String?) {
|
||||
Timber.d("onScanSuccess barcode = $barcode")
|
||||
if (barcode == null) return
|
||||
handleScanKeyInfo(barcode)
|
||||
}
|
||||
})
|
||||
}
|
||||
protected var keyEventHelper: ScanGunKeyEventHelper? = null
|
||||
|
||||
/**
|
||||
* 处理扫描枪数据
|
||||
*/
|
||||
protected open fun handleScanKeyInfo(scanInfo: String) {
|
||||
var payCode = scanInfo
|
||||
//if (scanInfo.length > 6) {
|
||||
// payCode = scanInfo.take(6)
|
||||
//}
|
||||
Log.d("TAG", "handleScanKeyInfo: " + payCode)
|
||||
}
|
||||
|
||||
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
|
||||
if (keyEventHelper != null) {
|
||||
if (keyEventHelper!!.isScanGunEvent(event)) {
|
||||
keyEventHelper!!.analysisKeyEvent(event)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return super.dispatchKeyEvent(event)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user