refactor(camera): 将照片分辨率从1080P调整为720P并优化拍照流程
- 将 InspectionActivity、InspectionResultActivity、SprayingActivity 和 SprayingOCRActivity 中的照片分辨率从 RESOLUTION_1080P 更改为 RESOLUTION_720P - 在 SprayingActivity 中添加明确的变量类型声明 - 重构 SprayingActivity 中的拍照逻辑,将重复代码提取到 startCapture 方法中 - 添加 isCaptureInFlight 和 hasNavigatedNextPage 状态控制变量, 防止重复操作 - 在 SprayingActivity 的 onDestroy 和 onResume 生命周期方法中重置 状态变量 - 移除多余的 runOnUiThread 调用,在主线程安全的环境中直接更新 UI - 在完成拍照后移除注册的回调监听器,避免内存泄漏
这个提交包含在:
父节点
aab4eb9413
当前提交
70ee0c7d64
@ -294,7 +294,7 @@ class InspectionActivity :
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
|
||||
fileName
|
||||
)
|
||||
GlassMediaServiceHelper.takePhoto(PhotoResolution.RESOLUTION_1080P, file.absolutePath)
|
||||
GlassMediaServiceHelper.takePhoto(PhotoResolution.RESOLUTION_720P, file.absolutePath)
|
||||
}
|
||||
|
||||
private val photoCallbackId = UUID.randomUUID().toString()
|
||||
|
||||
@ -172,7 +172,7 @@ class InspectionResultActivity :
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
|
||||
fileName
|
||||
)
|
||||
GlassMediaServiceHelper.takePhoto(PhotoResolution.RESOLUTION_1080P, file.absolutePath)
|
||||
GlassMediaServiceHelper.takePhoto(PhotoResolution.RESOLUTION_720P, file.absolutePath)
|
||||
}
|
||||
|
||||
private val photoCallbackId = UUID.randomUUID().toString()
|
||||
|
||||
@ -35,7 +35,7 @@ class SprayingActivity :
|
||||
}
|
||||
private var productionInfoId: String = ""
|
||||
|
||||
private val listener = object : OfflineCmdListener {
|
||||
private val listener: OfflineCmdListener = object : OfflineCmdListener {
|
||||
override fun onOfflineCmd(cmd: String) {
|
||||
runOnUiThread {
|
||||
when (cmd) {
|
||||
@ -44,12 +44,7 @@ class SprayingActivity :
|
||||
}
|
||||
|
||||
"开始", "拍照", "开始拍照", "开始任务" -> {
|
||||
runOnUiThread {
|
||||
binding.hint.text = "拍照中,请稍后..."
|
||||
}
|
||||
SprayingPhotoManager.clear()
|
||||
isPhoto = true
|
||||
takePhoto()
|
||||
startCapture(resetSession = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -62,12 +57,12 @@ class SprayingActivity :
|
||||
val publicPicturesDir =
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
|
||||
val file = File(publicPicturesDir, fileName)
|
||||
GlassMediaServiceHelper.takePhoto(PhotoResolution.RESOLUTION_1080P, file.absolutePath)
|
||||
GlassMediaServiceHelper.takePhoto(PhotoResolution.RESOLUTION_720P, file.absolutePath)
|
||||
}
|
||||
|
||||
private val photoCallbackId = UUID.randomUUID().toString()
|
||||
|
||||
private val mPhotoFileCallback = object : PhotoFileCallback.Stub() {
|
||||
private val mPhotoFileCallback: PhotoFileCallback = object : PhotoFileCallback.Stub() {
|
||||
override fun onTakePhoto(path: String) {
|
||||
LogHelper.d("onTakePhoto-->path = $path")
|
||||
}
|
||||
@ -83,13 +78,22 @@ class SprayingActivity :
|
||||
isPhoto = false
|
||||
takePhoto()
|
||||
} else {
|
||||
isCaptureInFlight = false
|
||||
runOnUiThread {
|
||||
binding.hint.text = "单击或语音输入“开始”,进入下一步"
|
||||
}
|
||||
"相机异常".showMessage()
|
||||
}
|
||||
} else {
|
||||
if (hasNavigatedNextPage) {
|
||||
return
|
||||
}
|
||||
hasNavigatedNextPage = true
|
||||
isCaptureInFlight = false
|
||||
SprayingPhotoManager.addPhoto(path)
|
||||
GlassMediaServiceHelper.removePhotoCallback(mPhotoFileCallback)
|
||||
OfflineCmdServiceHelper.removeListenerSpraying()
|
||||
OfflineCmdServiceHelper.removeOnLineListener(listener)
|
||||
startActivity(Intent(this@SprayingActivity, SprayingOCRActivity::class.java).apply {
|
||||
putExtra("path", path)
|
||||
putExtra("taskId", taskId)
|
||||
@ -123,6 +127,8 @@ class SprayingActivity :
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
hasNavigatedNextPage = false
|
||||
isCaptureInFlight = false
|
||||
GlassMediaServiceHelper.addPhotoCallback(mPhotoFileCallback)
|
||||
OfflineCmdServiceHelper.addOnLineListener(listener)
|
||||
OfflineCmdServiceHelper.addListenerSpraying()
|
||||
@ -136,23 +142,37 @@ class SprayingActivity :
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
isCaptureInFlight = false
|
||||
hasNavigatedNextPage = false
|
||||
super.onDestroy()
|
||||
window.clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
|
||||
private var isPhoto = false
|
||||
private val adapter = object : CommonPagedAdapter<ItemItem>(R.layout.item_photo) {
|
||||
private var isCaptureInFlight = false
|
||||
private var hasNavigatedNextPage = false
|
||||
|
||||
private fun startCapture(resetSession: Boolean) {
|
||||
if (isCaptureInFlight || hasNavigatedNextPage) {
|
||||
return
|
||||
}
|
||||
if (resetSession) {
|
||||
SprayingPhotoManager.clear()
|
||||
}
|
||||
binding.hint.text = "拍照中,请稍后..."
|
||||
isPhoto = true
|
||||
isCaptureInFlight = true
|
||||
takePhoto()
|
||||
}
|
||||
|
||||
private val adapter: BasePagedAdapter<ItemItem> =
|
||||
object : CommonPagedAdapter<ItemItem>(R.layout.item_photo) {
|
||||
override fun convert(holder: ViewHolder, item: ItemItem, position: Int) {
|
||||
holder
|
||||
.setClickListener(R.id.photo) {
|
||||
when (item.text) {
|
||||
"开始任务" -> {
|
||||
runOnUiThread {
|
||||
binding.hint.text = "拍照中,请稍后..."
|
||||
}
|
||||
SprayingPhotoManager.clear()
|
||||
isPhoto = true
|
||||
takePhoto()
|
||||
startCapture(resetSession = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ class SprayingOCRActivity :
|
||||
val fileName = "test_${System.currentTimeMillis()}.png"
|
||||
val publicPicturesDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
|
||||
val file = File(publicPicturesDir, fileName)
|
||||
GlassMediaServiceHelper.takePhoto(PhotoResolution.RESOLUTION_1080P, file.absolutePath)
|
||||
GlassMediaServiceHelper.takePhoto(PhotoResolution.RESOLUTION_720P, file.absolutePath)
|
||||
}
|
||||
private val photoCallbackId = UUID.randomUUID().toString()
|
||||
private val imageDecodeExecutor = Executors.newSingleThreadExecutor()
|
||||
|
||||
@ -121,7 +121,7 @@ class SprayingResultActivity :
|
||||
val fileName = "test_${System.currentTimeMillis()}.png"
|
||||
val publicPicturesDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
|
||||
val file = File(publicPicturesDir, fileName)
|
||||
GlassMediaServiceHelper.takePhoto(PhotoResolution.RESOLUTION_1080P, file.absolutePath)
|
||||
GlassMediaServiceHelper.takePhoto(PhotoResolution.RESOLUTION_720P, file.absolutePath)
|
||||
}
|
||||
|
||||
fun rest() {
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户