[Change]完成摄像头功能
Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
(cherry picked from commit b215dec486)
This commit is contained in:
@@ -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?) {
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
package="com.mogo.usbcamera">
|
||||
|
||||
|
||||
<uses-feature android:name="android.hardware.usb.host"/>
|
||||
<!-- 声明使用usb -->
|
||||
<uses-feature
|
||||
android:name="android.hardware.usb.host"
|
||||
android:required="true" />
|
||||
|
||||
<application>
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -480,6 +480,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
|
||||
try {
|
||||
mSync.wait();
|
||||
} catch (final InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user