refactor(glass): 使用 GlassMediaServiceHelper 替换直接的 GlassSdk 调用
- 在 SprayingActivity 中使用 GlassMediaServiceHelper.takePhoto 替换 GlassSdk.getGlassMediaService().takePhoto - 在 SprayingActivity 中使用 GlassMediaServiceHelper.addPhotoCallback 和 removePhotoCallback - 在 SprayingOCRActivity 中实现相同的 GlassMediaServiceHelper 替换 - 在 SprayingResultActivity 中实现相同的 GlassMediaServiceHelper 替换 - 为 SprayingFinishActivity 和 SprayingOCRActivity 添加图片资源清理 - 在 SprayingResultActivity 的 submit 操作后启动 TaskListActivity - 创建 GlassMediaServiceHelper 单例类封装媒体服务操作
这个提交包含在:
父节点
88ff873959
当前提交
719eb1cd7c
@ -0,0 +1,37 @@
|
||||
package com.nova.brain.glass.helper
|
||||
|
||||
import com.rokid.security.glass3.open.sdk.GlassSdk
|
||||
import com.rokid.security.system.server.media.callback.PhotoFileCallback
|
||||
|
||||
object GlassMediaServiceHelper {
|
||||
@Volatile
|
||||
private var mediaService: Any? = null
|
||||
|
||||
private fun service(): Any? {
|
||||
val cached = mediaService
|
||||
if (cached != null) {
|
||||
return cached
|
||||
}
|
||||
return GlassSdk.getGlassMediaService()?.also {
|
||||
mediaService = it
|
||||
}
|
||||
}
|
||||
|
||||
fun takePhoto(resolution: Int, path: String) {
|
||||
val service = service() ?: return
|
||||
service.javaClass.getMethod("takePhoto", Int::class.javaPrimitiveType, String::class.java)
|
||||
.invoke(service, resolution, path)
|
||||
}
|
||||
|
||||
fun addPhotoCallback(callback: PhotoFileCallback) {
|
||||
val service = service() ?: return
|
||||
service.javaClass.getMethod("addPhotoCallback", PhotoFileCallback::class.java)
|
||||
.invoke(service, callback)
|
||||
}
|
||||
|
||||
fun removePhotoCallback(callback: PhotoFileCallback) {
|
||||
val service = service() ?: return
|
||||
service.javaClass.getMethod("removePhotoCallback", PhotoFileCallback::class.java)
|
||||
.invoke(service, callback)
|
||||
}
|
||||
}
|
||||
@ -5,12 +5,12 @@ import android.os.Environment
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.nova.brain.glass.R
|
||||
import com.nova.brain.glass.databinding.ActivitySprayingBinding
|
||||
import com.nova.brain.glass.helper.GlassMediaServiceHelper
|
||||
import com.nova.brain.glass.helper.OfflineCmdListener
|
||||
import com.nova.brain.glass.helper.OfflineCmdServiceHelper
|
||||
import com.nova.brain.glass.helper.SprayingPhotoManager
|
||||
import com.nova.brain.glass.model.ItemItem
|
||||
import com.nova.brain.glass.viewmodel.SprayingVM
|
||||
import com.rokid.security.glass3.open.sdk.GlassSdk
|
||||
import com.rokid.security.glass3.sdk.base.data.media.PhotoResolution
|
||||
import com.rokid.security.system.server.media.callback.PhotoFileCallback
|
||||
import com.xuqm.base.adapter.BasePagedAdapter
|
||||
@ -56,8 +56,7 @@ class SprayingActivity :
|
||||
val publicPicturesDir =
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
|
||||
val file = File(publicPicturesDir, fileName)
|
||||
GlassSdk.getGlassMediaService()
|
||||
?.takePhoto(PhotoResolution.RESOLUTION_480P, file.absolutePath)
|
||||
GlassMediaServiceHelper.takePhoto(PhotoResolution.RESOLUTION_480P, file.absolutePath)
|
||||
}
|
||||
|
||||
private val photoCallbackId = UUID.randomUUID().toString()
|
||||
@ -105,14 +104,14 @@ class SprayingActivity :
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
GlassSdk.getGlassMediaService()?.addPhotoCallback(mPhotoFileCallback)
|
||||
GlassMediaServiceHelper.addPhotoCallback(mPhotoFileCallback)
|
||||
OfflineCmdServiceHelper.addOnLineListener(listener)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
OfflineCmdServiceHelper.removeOnLineListener(listener)
|
||||
GlassSdk.getGlassMediaService()?.removePhotoCallback(mPhotoFileCallback)
|
||||
GlassMediaServiceHelper.removePhotoCallback(mPhotoFileCallback)
|
||||
}
|
||||
|
||||
private var isPhoto = false
|
||||
|
||||
@ -46,6 +46,9 @@ class SprayingFinishActivity :
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
binding.photo1.setImageDrawable(null)
|
||||
binding.photo2.setImageDrawable(null)
|
||||
binding.photo3.setImageDrawable(null)
|
||||
OfflineCmdServiceHelper.removeOnLineListener(listener)
|
||||
}
|
||||
|
||||
|
||||
@ -9,13 +9,12 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import com.nova.brain.glass.R
|
||||
import com.nova.brain.glass.databinding.ActivitySprayingOcrBinding
|
||||
import com.nova.brain.glass.helper.BitmapDecodeHelper
|
||||
import com.nova.brain.glass.helper.GlassMediaServiceHelper
|
||||
import com.nova.brain.glass.helper.OfflineCmdListener
|
||||
import com.nova.brain.glass.helper.OfflineCmdServiceHelper
|
||||
import com.nova.brain.glass.helper.SprayingPhotoManager
|
||||
import com.nova.brain.glass.model.ItemItem
|
||||
import com.nova.brain.glass.viewmodel.SprayingOCRVM
|
||||
import com.nova.brain.glass.viewmodel.SprayingVM
|
||||
import com.rokid.security.glass3.open.sdk.GlassSdk
|
||||
import com.rokid.security.glass3.sdk.base.data.media.PhotoResolution
|
||||
import com.rokid.security.system.server.media.callback.PhotoFileCallback
|
||||
import com.xuqm.base.adapter.BasePagedAdapter
|
||||
@ -61,7 +60,7 @@ class SprayingOCRActivity :
|
||||
val fileName = "test_${System.currentTimeMillis()}.png"
|
||||
val publicPicturesDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
|
||||
val file = File(publicPicturesDir, fileName)
|
||||
GlassSdk.getGlassMediaService()?.takePhoto(PhotoResolution.RESOLUTION_480P, file.absolutePath)
|
||||
GlassMediaServiceHelper.takePhoto(PhotoResolution.RESOLUTION_480P, file.absolutePath)
|
||||
}
|
||||
private val photoCallbackId = UUID.randomUUID().toString()
|
||||
private var resultCountdown: CountDownTimer? = null
|
||||
@ -111,13 +110,18 @@ class SprayingOCRActivity :
|
||||
super.onResume()
|
||||
|
||||
OfflineCmdServiceHelper.addOnLineListener(listener)
|
||||
GlassSdk.getGlassMediaService()?.addPhotoCallback(mPhotoFileCallback)
|
||||
GlassMediaServiceHelper.addPhotoCallback(mPhotoFileCallback)
|
||||
}
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
resultCountdown?.cancel()
|
||||
OfflineCmdServiceHelper.removeOnLineListener(listener)
|
||||
GlassSdk.getGlassMediaService()?.removePhotoCallback(mPhotoFileCallback)
|
||||
GlassMediaServiceHelper.removePhotoCallback(mPhotoFileCallback)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
binding.content.setImageDrawable(null)
|
||||
}
|
||||
|
||||
private var isPhoto = false
|
||||
|
||||
@ -11,12 +11,12 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import com.nova.brain.glass.R
|
||||
import com.nova.brain.glass.databinding.ActivitySprayingResultBinding
|
||||
import com.nova.brain.glass.helper.BitmapDecodeHelper
|
||||
import com.nova.brain.glass.helper.GlassMediaServiceHelper
|
||||
import com.nova.brain.glass.helper.OfflineCmdListener
|
||||
import com.nova.brain.glass.helper.OfflineCmdServiceHelper
|
||||
import com.nova.brain.glass.helper.SprayingPhotoManager
|
||||
import com.nova.brain.glass.model.ItemItem
|
||||
import com.nova.brain.glass.viewmodel.SprayingResultVM
|
||||
import com.rokid.security.glass3.open.sdk.GlassSdk
|
||||
import com.rokid.security.glass3.sdk.base.data.media.PhotoResolution
|
||||
import com.rokid.security.system.server.media.callback.PhotoFileCallback
|
||||
import com.xuqm.base.adapter.BasePagedAdapter
|
||||
@ -70,6 +70,9 @@ class SprayingResultActivity :
|
||||
|
||||
SprayingFinishActivity.ACTION_SUBMIT -> {
|
||||
SprayingPhotoManager.clear()
|
||||
startActivity(Intent(this, TaskListActivity::class.java).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||
})
|
||||
finish()
|
||||
}
|
||||
}
|
||||
@ -108,8 +111,7 @@ class SprayingResultActivity :
|
||||
val publicPicturesDir =
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
|
||||
val file = File(publicPicturesDir, fileName)
|
||||
GlassSdk.getGlassMediaService()
|
||||
?.takePhoto(PhotoResolution.RESOLUTION_480P, file.absolutePath)
|
||||
GlassMediaServiceHelper.takePhoto(PhotoResolution.RESOLUTION_480P, file.absolutePath)
|
||||
}
|
||||
|
||||
fun rest() {
|
||||
@ -185,15 +187,16 @@ class SprayingResultActivity :
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
OfflineCmdServiceHelper.addOnLineListener(listener)
|
||||
GlassSdk.getGlassMediaService()?.addPhotoCallback(mPhotoFileCallback)
|
||||
GlassMediaServiceHelper.addPhotoCallback(mPhotoFileCallback)
|
||||
}
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
OfflineCmdServiceHelper.removeOnLineListener(listener)
|
||||
GlassSdk.getGlassMediaService()?.removePhotoCallback(mPhotoFileCallback)
|
||||
GlassMediaServiceHelper.removePhotoCallback(mPhotoFileCallback)
|
||||
}
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
binding.iv.setImageDrawable(null)
|
||||
}
|
||||
|
||||
private var isPhoto = false
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户