[Change]完成摄像头功能

Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
(cherry picked from commit b215dec486)
This commit is contained in:
donghongyu
2022-02-10 20:12:09 +08:00
parent cdee266805
commit 69a0d6a3cc
4 changed files with 23 additions and 9 deletions

View File

@@ -41,7 +41,6 @@ class CarcorderPreviewView private constructor(
init {
LayoutInflater.from(context).inflate(R.layout.view_carcorder_preview, this, true)
initView()
}
companion object {
@@ -113,6 +112,7 @@ class CarcorderPreviewView private constructor(
private val listener: UVCCameraHelper.OnMyDevConnectListener = object : UVCCameraHelper.OnMyDevConnectListener {
override fun onAttachDev(device: UsbDevice?) {
Log.d(TAG, "onAttachDev")
// request open permission
if (!isRequest) {
isRequest = true
@@ -121,6 +121,7 @@ class CarcorderPreviewView private constructor(
}
override fun onDettachDev(device: UsbDevice) {
Log.d(TAG, "onDettachDev")
// close camera
if (isRequest) {
isRequest = false
@@ -130,6 +131,7 @@ class CarcorderPreviewView private constructor(
}
override fun onConnectDev(device: UsbDevice?, isConnected: Boolean) {
Log.d(TAG, "onConnectDev:isConnected=$isConnected")
if (!isConnected) {
showShortMsg("fail to connect,please check resolution params")
isPreview = false
@@ -155,13 +157,14 @@ class CarcorderPreviewView private constructor(
}
override fun onDisConnectDev(device: UsbDevice?) {
Log.d(TAG, "onDisConnectDev")
showShortMsg("相机断开连接")
}
}
private fun showShortMsg(msg: String) {
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show()
//Toast.makeText(context, msg, Toast.LENGTH_SHORT).show()
}
private fun initView() {
@@ -177,6 +180,7 @@ class CarcorderPreviewView private constructor(
override fun onAttachedToWindow() {
super.onAttachedToWindow()
initView()
// step.2 register USB event broadcast
if (mCameraHelper != null) {
mCameraHelper!!.registerUSB()
@@ -189,8 +193,6 @@ class CarcorderPreviewView private constructor(
if (mCameraHelper != null) {
mCameraHelper!!.unregisterUSB()
}
}
override fun onSurfaceCreated(view: CameraViewInterface?, surface: Surface?) {