|
@@ -13,6 +13,8 @@ import android.content.pm.PackageManager.PERMISSION_GRANTED
|
|
import android.net.Uri
|
|
import android.net.Uri
|
|
import android.os.Build
|
|
import android.os.Build
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
|
|
+import android.os.Handler
|
|
|
|
+import android.os.Looper
|
|
import android.provider.Settings
|
|
import android.provider.Settings
|
|
import android.util.Log
|
|
import android.util.Log
|
|
import android.util.Size
|
|
import android.util.Size
|
|
@@ -30,6 +32,7 @@ import androidx.constraintlayout.widget.ConstraintLayout
|
|
import androidx.core.app.ActivityCompat
|
|
import androidx.core.app.ActivityCompat
|
|
import androidx.core.content.ContextCompat
|
|
import androidx.core.content.ContextCompat
|
|
import androidx.lifecycle.LifecycleOwner
|
|
import androidx.lifecycle.LifecycleOwner
|
|
|
|
+import androidx.lifecycle.lifecycleScope
|
|
import com.xuexiang.xui.XUI
|
|
import com.xuexiang.xui.XUI
|
|
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
|
|
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
|
|
import jx.cn.escort.R
|
|
import jx.cn.escort.R
|
|
@@ -37,6 +40,8 @@ import jx.cn.escort.databinding.ActivityActionTaskHandleBinding
|
|
import jx.cn.escort.extension.ExtensionBinding.Companion.binding
|
|
import jx.cn.escort.extension.ExtensionBinding.Companion.binding
|
|
import jx.cn.escort.ui.widget.CircleProgressView
|
|
import jx.cn.escort.ui.widget.CircleProgressView
|
|
import jx.cn.escort.utils.ActivityUtils
|
|
import jx.cn.escort.utils.ActivityUtils
|
|
|
|
+import kotlinx.coroutines.delay
|
|
|
|
+import kotlinx.coroutines.launch
|
|
import org.koin.core.component.KoinComponent
|
|
import org.koin.core.component.KoinComponent
|
|
import org.koin.core.component.inject
|
|
import org.koin.core.component.inject
|
|
import java.util.concurrent.ExecutorService
|
|
import java.util.concurrent.ExecutorService
|
|
@@ -57,6 +62,7 @@ class ActionTaskHandActivity : AppCompatActivity(), KoinComponent {
|
|
private var imageCamera: ImageCapture? = null
|
|
private var imageCamera: ImageCapture? = null
|
|
private lateinit var camera: Camera //相机对象
|
|
private lateinit var camera: Camera //相机对象
|
|
private lateinit var imageAnalysis: ImageAnalysis
|
|
private lateinit var imageAnalysis: ImageAnalysis
|
|
|
|
+ private lateinit var circle:CircleProgressView
|
|
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
@@ -77,8 +83,9 @@ class ActionTaskHandActivity : AppCompatActivity(), KoinComponent {
|
|
val li = LayoutInflater.from(this@ActionTaskHandActivity)
|
|
val li = LayoutInflater.from(this@ActionTaskHandActivity)
|
|
val inflate = li.inflate(jx.cn.escort.R.layout.layout_task_face,null)
|
|
val inflate = li.inflate(jx.cn.escort.R.layout.layout_task_face,null)
|
|
val cameralayoutc = inflate.findViewById<ConstraintLayout>(jx.cn.escort.R.id.camera_layoutc)
|
|
val cameralayoutc = inflate.findViewById<ConstraintLayout>(jx.cn.escort.R.id.camera_layoutc)
|
|
- var circle:View= CircleProgressView(this@ActionTaskHandActivity)
|
|
|
|
- //circle.id= androidx.camera.core.R.id.faceCircle
|
|
|
|
|
|
+ circle= CircleProgressView(this@ActionTaskHandActivity)
|
|
|
|
+ // circle.id= androidx.camera.core.R.id.faceCircle
|
|
|
|
+ circle.bringToFront()
|
|
cameralayoutc.addView(circle)
|
|
cameralayoutc.addView(circle)
|
|
val dialog = MaterialDialog.Builder(this@ActionTaskHandActivity)
|
|
val dialog = MaterialDialog.Builder(this@ActionTaskHandActivity)
|
|
.customView(inflate, true)
|
|
.customView(inflate, true)
|
|
@@ -87,7 +94,7 @@ class ActionTaskHandActivity : AppCompatActivity(), KoinComponent {
|
|
if( PackageManager.PERMISSION_GRANTED!= ContextCompat.checkSelfPermission(this@ActionTaskHandActivity , Manifest.permission.CAMERA)){
|
|
if( PackageManager.PERMISSION_GRANTED!= ContextCompat.checkSelfPermission(this@ActionTaskHandActivity , Manifest.permission.CAMERA)){
|
|
|
|
|
|
|
|
|
|
- ActivityCompat.requestPermissions(this@ActionTaskHandActivity , arrayOf(Manifest.permission.CAMERA),100)
|
|
|
|
|
|
+ ActivityCompat.requestPermissions(this@ActionTaskHandActivity , arrayOf(Manifest.permission.CAMERA),100)
|
|
|
|
|
|
//打开自定义授权弹窗
|
|
//打开自定义授权弹窗
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
@@ -116,13 +123,23 @@ class ActionTaskHandActivity : AppCompatActivity(), KoinComponent {
|
|
//弹窗回调完再打开相机
|
|
//弹窗回调完再打开相机
|
|
|
|
|
|
}else{
|
|
}else{
|
|
|
|
+ var mpreview= inflate.findViewById<PreviewView>(R.id.mPreviewView)
|
|
|
|
+
|
|
//打开相机
|
|
//打开相机
|
|
- runCamera(this@ActionTaskHandActivity,cameralayoutc.findViewById(R.id.mPreviewView) , context = this@ActionTaskHandActivity)
|
|
|
|
|
|
+ runCamera(this@ActionTaskHandActivity,mpreview , context = this@ActionTaskHandActivity)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
})
|
|
})
|
|
- dialog.show()
|
|
|
|
|
|
+ dialog.dismissListener(object:DialogInterface.OnDismissListener{
|
|
|
|
+ override fun onDismiss(dialog: DialogInterface?) {
|
|
|
|
+ if (preview != null) {
|
|
|
|
+ cameraProvider?.unbindAll()
|
|
|
|
+ preview = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }).show()
|
|
//检查手机相机权限
|
|
//检查手机相机权限
|
|
|
|
|
|
|
|
|
|
@@ -185,10 +202,26 @@ class ActionTaskHandActivity : AppCompatActivity(), KoinComponent {
|
|
|
|
|
|
|
|
|
|
imageAnalysis.setAnalyzer(cameraExecutor) { imageProxy ->
|
|
imageAnalysis.setAnalyzer(cameraExecutor) { imageProxy ->
|
|
- Log.d("ActionTask", "图片格式${imageProxy.format}")
|
|
|
|
|
|
+ Log.d("ActionTask", "图片格式${imageProxy.format}")
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 定义一个Runnable,它将被重复执行
|
|
|
|
+
|
|
|
|
+ lifecycleScope.launch {
|
|
|
|
+ circle.setProgress(60)
|
|
|
|
+ delay(5000)
|
|
|
|
+ circle.setProgress(80)
|
|
|
|
+ delay(5000)
|
|
|
|
+ circle.setProgress(100)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
try {
|
|
try {
|
|
cameraProvider?.unbindAll()//先解绑所有用例
|
|
cameraProvider?.unbindAll()//先解绑所有用例
|
|
camera = cameraProvider?.bindToLifecycle(
|
|
camera = cameraProvider?.bindToLifecycle(
|
|
@@ -217,13 +250,13 @@ class ActionTaskHandActivity : AppCompatActivity(), KoinComponent {
|
|
camera.cameraInfo.cameraState.observe(lifecycleOwner) { value ->
|
|
camera.cameraInfo.cameraState.observe(lifecycleOwner) { value ->
|
|
when (value.type) {
|
|
when (value.type) {
|
|
CameraState.Type.OPEN ->{
|
|
CameraState.Type.OPEN ->{
|
|
- Log.d("demo", "相机正在打开中" )
|
|
|
|
|
|
+ Log.d("ActionTask", "相机正在打开中" )
|
|
}
|
|
}
|
|
|
|
|
|
- CameraState.Type.PENDING_OPEN -> Log.d("demo", "相机待打开" )
|
|
|
|
- CameraState.Type.OPENING -> Log.d("demo", "相机已打开" )
|
|
|
|
- CameraState.Type.CLOSING ->Log.d("demo", "相机关闭中" )
|
|
|
|
- CameraState.Type.CLOSED -> Log.d("demo", "相机已关闭" )
|
|
|
|
|
|
+ CameraState.Type.PENDING_OPEN -> Log.d("ActionTask", "相机待打开" )
|
|
|
|
+ CameraState.Type.OPENING -> Log.d("ActionTask", "相机已打开" )
|
|
|
|
+ CameraState.Type.CLOSING ->Log.d("ActionTask", "相机关闭中" )
|
|
|
|
+ CameraState.Type.CLOSED -> Log.d("ActionTask", "相机已关闭" )
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|