From d08f5c3ab1eb991d05f53f4a6b75cc1cb3dd648e Mon Sep 17 00:00:00 2001 From: jiangdongguo <765067602@qq.com> Date: Fri, 13 Oct 2017 09:11:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=BE=B9=E6=8E=A8=E6=B5=81?= =?UTF-8?q?=EF=BC=8C=E8=BE=B9=E6=9C=AC=E5=9C=B0=E5=BD=95=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 4 +--- .../jiangdg/usbcamera/view/USBCameraActivity.java | 15 +++++++++++---- libusbcamera/build.gradle | 2 +- .../com/jiangdg/usbcamera/USBCameraManager.java | 1 - 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a32ac10..b873162 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,7 +5,7 @@ android { buildToolsVersion "26.0.1" defaultConfig { applicationId "com.jiangdg.usbcamera" - minSdkVersion 18 + minSdkVersion 16 targetSdkVersion 22 versionCode 1 versionName "1.0" @@ -29,6 +29,4 @@ dependencies { compile project(':libusbcamera') compile 'com.jakewharton:butterknife:8.8.1' compile 'com.jakewharton:butterknife-compiler:8.8.1' - compile 'com.jakewharton:butterknife:8.8.1' - compile 'com.jakewharton:butterknife-compiler:8.8.1' } diff --git a/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java b/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java index 2b2d6c5..0ecf3b9 100644 --- a/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java +++ b/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java @@ -47,15 +47,18 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog private boolean isRequest; - // USB设备监听器 + /** + * USB设备事件监听器 + * */ private USBCameraManager.OnMyDevConnectListener listener = new USBCameraManager.OnMyDevConnectListener() { + // 插入USB设备 @Override public void onAttachDev(UsbDevice device) { if(mUSBManager == null || mUSBManager.getUsbDeviceCount() == 0){ showShortMsg("未检测到USB摄像头设备"); return; } - + // 请求打开摄像头 if(! isRequest){ isRequest = true; if(mUSBManager != null){ @@ -64,23 +67,27 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog } } + // 拔出USB设备 @Override public void onDettachDev(UsbDevice device) { if(isRequest){ + // 关闭摄像头 isRequest = false; mUSBManager.closeCamera(); showShortMsg(device.getDeviceName()+"已拨出"); } } + // 连接USB设备成功 @Override public void onConnectDev(UsbDevice device) { - // 处理连接到设备后的逻辑 + } + // 与USB设备断开连接 @Override public void onDisConnectDev(UsbDevice device) { - // 处理与设备断开后的逻辑 + } }; private FileOutputStream fos; diff --git a/libusbcamera/build.gradle b/libusbcamera/build.gradle index ae16b05..84bf920 100644 --- a/libusbcamera/build.gradle +++ b/libusbcamera/build.gradle @@ -5,7 +5,7 @@ android { buildToolsVersion "26.0.1" defaultConfig { - minSdkVersion 18 + minSdkVersion 16 targetSdkVersion 22 versionCode 1 versionName "1.0" diff --git a/libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java b/libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java index 7774df0..dad39e8 100644 --- a/libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java +++ b/libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java @@ -7,7 +7,6 @@ import android.hardware.usb.UsbDevice; import android.os.Environment; import com.jiangdg.libusbcamera.R; -import com.serenegiant.usb.CameraDialog; import com.serenegiant.usb.DeviceFilter; import com.serenegiant.usb.USBMonitor; import com.serenegiant.usb.common.AbstractUVCCameraHandler;