From 69a0d6a3ccbc02c4e50d654973a5c1411280fdc1 Mon Sep 17 00:00:00 2001 From: donghongyu Date: Thu, 10 Feb 2022 20:12:09 +0800 Subject: [PATCH] =?UTF-8?q?[Change]=E5=AE=8C=E6=88=90=E6=91=84=E5=83=8F?= =?UTF-8?q?=E5=A4=B4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: donghongyu (cherry picked from commit b215dec486bd3f4f8ad29684f983df7af86fd4e5) --- .../hmi/ui/carcorder/CarcorderPreviewView.kt | 10 ++++++---- .../map-usbcamera/src/main/AndroidManifest.xml | 5 ++++- .../java/com/serenegiant/usb/USBMonitor.java | 16 ++++++++++++---- .../usb/common/AbstractUVCCameraHandler.java | 1 + 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/carcorder/CarcorderPreviewView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/carcorder/CarcorderPreviewView.kt index cb7b0b955d..52b9fb36a5 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/carcorder/CarcorderPreviewView.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/carcorder/CarcorderPreviewView.kt @@ -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?) { diff --git a/libraries/map-usbcamera/src/main/AndroidManifest.xml b/libraries/map-usbcamera/src/main/AndroidManifest.xml index 9f80e8f54e..70e75d7b52 100644 --- a/libraries/map-usbcamera/src/main/AndroidManifest.xml +++ b/libraries/map-usbcamera/src/main/AndroidManifest.xml @@ -2,7 +2,10 @@ package="com.mogo.usbcamera"> - + + diff --git a/libraries/map-usbcamera/src/main/java/com/serenegiant/usb/USBMonitor.java b/libraries/map-usbcamera/src/main/java/com/serenegiant/usb/USBMonitor.java index f58754f413..1eea770006 100644 --- a/libraries/map-usbcamera/src/main/java/com/serenegiant/usb/USBMonitor.java +++ b/libraries/map-usbcamera/src/main/java/com/serenegiant/usb/USBMonitor.java @@ -108,7 +108,9 @@ public final class USBMonitor { mOnDeviceConnectListener = listener; mAsyncHandler = HandlerThreadHandler.createHandler(TAG); destroyed = false; - if (DEBUG) Log.v(TAG, "USBMonitor:mUsbManager=" + mUsbManager); + if (DEBUG) { + Log.v(TAG, "USBMonitor:mUsbManager=" + mUsbManager); + } } /** @@ -116,7 +118,9 @@ public final class USBMonitor { * never reuse again */ public void destroy() { - if (DEBUG) Log.i(TAG, "destroy:"); + if (DEBUG) { + Log.i(TAG, "destroy:"); + } unregister(); if (!destroyed) { destroyed = true; @@ -149,9 +153,13 @@ public final class USBMonitor { * @throws IllegalStateException */ public synchronized void register() throws IllegalStateException { - if (destroyed) throw new IllegalStateException("already destroyed"); + if (destroyed) { + throw new IllegalStateException("already destroyed"); + } if (mPermissionIntent == null) { - if (DEBUG) Log.i(TAG, "register:"); + if (DEBUG) { + Log.i(TAG, "register:"); + } final Context context = mWeakContext.get(); if (context != null) { mPermissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), 0); diff --git a/libraries/map-usbcamera/src/main/java/com/serenegiant/usb/common/AbstractUVCCameraHandler.java b/libraries/map-usbcamera/src/main/java/com/serenegiant/usb/common/AbstractUVCCameraHandler.java index f8630fee5d..00aa36d45a 100644 --- a/libraries/map-usbcamera/src/main/java/com/serenegiant/usb/common/AbstractUVCCameraHandler.java +++ b/libraries/map-usbcamera/src/main/java/com/serenegiant/usb/common/AbstractUVCCameraHandler.java @@ -480,6 +480,7 @@ public abstract class AbstractUVCCameraHandler extends Handler { try { mSync.wait(); } catch (final InterruptedException e) { + e.printStackTrace(); } } }