|
|
@@ -0,0 +1,129 @@
|
|
|
+package com.nova.brain.glass.ui
|
|
|
+
|
|
|
+import android.R.attr.path
|
|
|
+import android.graphics.BitmapFactory
|
|
|
+import android.os.Environment
|
|
|
+import android.view.WindowManager
|
|
|
+import androidx.recyclerview.widget.RecyclerView
|
|
|
+import com.nova.brain.glass.R
|
|
|
+import com.nova.brain.glass.databinding.ActivitySprayingBinding
|
|
|
+import com.nova.brain.glass.databinding.ActivitySprayingOcrBinding
|
|
|
+import com.nova.brain.glass.helper.OfflineCmdListener
|
|
|
+import com.nova.brain.glass.helper.OfflineCmdServiceHelper
|
|
|
+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
|
|
|
+import com.xuqm.base.adapter.CommonPagedAdapter
|
|
|
+import com.xuqm.base.adapter.ViewHolder
|
|
|
+import com.xuqm.base.common.FileHelper
|
|
|
+import com.xuqm.base.common.LogHelper
|
|
|
+import com.xuqm.base.extensions.showMessage
|
|
|
+import com.xuqm.base.ui.BaseListFormLayoutNormalActivity
|
|
|
+import java.io.File
|
|
|
+import java.util.UUID
|
|
|
+
|
|
|
+class SprayingOCRActivity :
|
|
|
+ BaseListFormLayoutNormalActivity<ItemItem, SprayingVM, ActivitySprayingOcrBinding>() {
|
|
|
+ override fun getLayoutId(): Int = R.layout.activity_spraying_ocr
|
|
|
+ override fun fullscreen(): Boolean = true
|
|
|
+
|
|
|
+ override fun getRecyclerOrientation(): Int = RecyclerView.VERTICAL
|
|
|
+
|
|
|
+ private val listener = object : OfflineCmdListener {
|
|
|
+ override fun onOfflineCmd(cmd: String) {
|
|
|
+ runOnUiThread {
|
|
|
+ when (cmd) {
|
|
|
+ "退出", "返回", "退回" -> {
|
|
|
+ finish()
|
|
|
+ }
|
|
|
+ "开始", "拍照", "开始拍照", "开始任务", "重拍", "重新拍", "在拍一次" -> {
|
|
|
+ runOnUiThread {
|
|
|
+ binding.hint.text = "拍照中,请稍后..."
|
|
|
+ }
|
|
|
+ isPhoto = true
|
|
|
+ takePhoto()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ fun takePhoto() {
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ private val photoCallbackId = UUID.randomUUID().toString()
|
|
|
+
|
|
|
+ private val mPhotoFileCallback = object : PhotoFileCallback.Stub() {
|
|
|
+ override fun onTakePhoto(path: String) {
|
|
|
+ LogHelper.d("onTakePhoto-->path = $path")
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun getCallbackId(): String {
|
|
|
+ return photoCallbackId
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onTakePhotoV2(path: String?, width: Int, height: Int) {
|
|
|
+ LogHelper.d("width:$width--height:$height")
|
|
|
+ if (path == null) {
|
|
|
+ if (isPhoto) {
|
|
|
+ isPhoto = false
|
|
|
+ takePhoto()
|
|
|
+ } else {
|
|
|
+ runOnUiThread {
|
|
|
+ binding.hint.text = "单击或语音输入“重拍”,可重新拍摄"
|
|
|
+ }
|
|
|
+ "相机异常".showMessage()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ runOnUiThread {
|
|
|
+ binding.hint.text = "单击或语音输入“重拍”,可重新拍摄"
|
|
|
+ binding.content.setImageBitmap(BitmapFactory.decodeFile(path))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ override fun initData() {
|
|
|
+ super.initData()
|
|
|
+ window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
|
|
+ OfflineCmdServiceHelper.addOnLineListener(listener)
|
|
|
+ GlassSdk.getGlassMediaService()?.addPhotoCallback(mPhotoFileCallback)
|
|
|
+ intent.getStringExtra("path")?.apply {
|
|
|
+ binding.content.setImageBitmap(BitmapFactory.decodeFile(this))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onDestroy() {
|
|
|
+ super.onDestroy()
|
|
|
+ OfflineCmdServiceHelper.removeOnLineListener(listener)
|
|
|
+ GlassSdk.getGlassMediaService()?.removePhotoCallback(mPhotoFileCallback)
|
|
|
+ }
|
|
|
+
|
|
|
+ private var isPhoto = false
|
|
|
+ private val adapter = 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 = "拍照中,请稍后..."
|
|
|
+ }
|
|
|
+ isPhoto = true
|
|
|
+ takePhoto()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun adapter(): BasePagedAdapter<ItemItem> = adapter
|
|
|
+}
|