[Change]
开始USB摄像头的功能集成,还无法获取usb连接广播需要调试
Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
(cherry picked from commit b10306fc45)
This commit is contained in:
@@ -62,16 +62,17 @@ dependencies {
|
||||
if (Boolean.valueOf(USE_MAVEN_PACKAGE)) {
|
||||
implementation rootProject.ext.dependencies.androidxrecyclerview
|
||||
implementation rootProject.ext.dependencies.modulecommon
|
||||
implementation project(':libraries:map-usbcamera')
|
||||
|
||||
implementation rootProject.ext.dependencies.mogo_core_res
|
||||
implementation rootProject.ext.dependencies.mogo_core_data
|
||||
implementation rootProject.ext.dependencies.mogo_core_utils
|
||||
implementation rootProject.ext.dependencies.mogo_core_network
|
||||
implementation rootProject.ext.dependencies.mogo_core_function_call
|
||||
// implementation rootProject.ext.dependencies.mogo_core_res
|
||||
} else {
|
||||
implementation project(':modules:mogo-module-common')
|
||||
implementation project(':services:mogo-service-api')
|
||||
implementation project(':libraries:map-usbcamera')
|
||||
|
||||
implementation project(':core:mogo-core-res')
|
||||
implementation project(':core:mogo-core-data')
|
||||
@@ -79,7 +80,6 @@ dependencies {
|
||||
implementation project(':core:mogo-core-res')
|
||||
implementation project(':core:mogo-core-function-api')
|
||||
implementation project(':core:mogo-core-function-call')
|
||||
// implementation project(':core:mogo-core-res')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mogo.eagle.core.function.hmi">
|
||||
|
||||
|
||||
|
||||
<application>
|
||||
|
||||
<receiver android:name="com.mogo.eagle.core.function.hmi.receiver.V2XWarningBroadcastReceiver">
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.mogo.eagle.core.function.hmi.notification.WarningFloat
|
||||
import com.mogo.eagle.core.function.hmi.notification.anim.DefaultAnimator
|
||||
import com.mogo.eagle.core.function.hmi.notification.enums.SidePattern
|
||||
import com.mogo.eagle.core.function.hmi.ui.camera.CameraListView
|
||||
import com.mogo.eagle.core.function.hmi.ui.carcorder.CarcorderPreviewView
|
||||
import com.mogo.eagle.core.function.hmi.ui.notice.NoticeBannerView
|
||||
import com.mogo.eagle.core.function.hmi.ui.notice.NoticeNormalBannerView
|
||||
import com.mogo.eagle.core.function.hmi.ui.setting.DebugSettingView
|
||||
@@ -212,6 +213,11 @@ class MoGoHmiFragment : MvpFragment<MoGoWarningContract.View?, WaringPresenter?>
|
||||
}
|
||||
}
|
||||
|
||||
ivCameraIcon?.setOnLongClickListener {
|
||||
activity?.let { it1 -> CarcorderPreviewView.show(it1) }
|
||||
true
|
||||
}
|
||||
|
||||
ivToolsIcon?.setOnClickListener {
|
||||
if (toolsViewFloat == null) {
|
||||
showToolsFloat()
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
package com.mogo.eagle.core.function.hmi.ui.carcorder
|
||||
|
||||
import android.animation.Animator
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.hardware.usb.UsbDevice
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import android.view.animation.OvershootInterpolator
|
||||
import android.widget.Toast
|
||||
import com.mogo.eagle.core.function.hmi.R
|
||||
import com.mogo.eagle.core.function.hmi.notification.WarningFloat
|
||||
import com.mogo.eagle.core.function.hmi.notification.anim.DefaultAnimator
|
||||
import com.mogo.eagle.core.function.hmi.notification.enums.SidePattern
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
|
||||
import com.mogo.usbcamera.UVCCameraHelper
|
||||
import com.serenegiant.usb.ParentPreviewConstraintLayout
|
||||
import com.serenegiant.usb.widget.CameraViewInterface
|
||||
import kotlinx.android.synthetic.main.view_carcorder_preview.view.*
|
||||
|
||||
/**
|
||||
* @author donghongyu
|
||||
* @date 2021/9/30 8:46 下午
|
||||
* USB-Camera 摄像头预览
|
||||
*
|
||||
* TODO 临时方案,后面考虑封装将摄像头数据流通过 Tensorflow-lite 处理后展示
|
||||
*/
|
||||
class CarcorderPreviewView private constructor(
|
||||
context: Context
|
||||
) : ParentPreviewConstraintLayout(context),
|
||||
CameraViewInterface.Callback {
|
||||
|
||||
private val TAG = "CarcorderPreviewView"
|
||||
|
||||
|
||||
private var mCameraHelper: UVCCameraHelper? = null
|
||||
|
||||
private var isRequest = false
|
||||
private var isPreview = false
|
||||
|
||||
init {
|
||||
LayoutInflater.from(context).inflate(R.layout.view_carcorder_preview, this, true)
|
||||
initView()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private var mCarcorderPreviewViewFloat: WarningFloat.Builder? = null
|
||||
|
||||
@Volatile
|
||||
var instance: CarcorderPreviewView? = null
|
||||
|
||||
fun getInstance(context: Activity): CarcorderPreviewView {
|
||||
if (instance == null) {
|
||||
synchronized(CarcorderPreviewView::class) {
|
||||
if (instance == null) {
|
||||
instance = CarcorderPreviewView(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance!!
|
||||
}
|
||||
|
||||
/**
|
||||
* 展示窗口
|
||||
*/
|
||||
fun show(context: Activity) {
|
||||
if (mCarcorderPreviewViewFloat == null) {
|
||||
val carcorderPreviewVie = getInstance(context)
|
||||
mCarcorderPreviewViewFloat = WarningFloat.with(context)
|
||||
.setTag("CarcorderPreviewView")
|
||||
.setLayout(carcorderPreviewVie)
|
||||
.setSidePattern(SidePattern.RIGHT)
|
||||
.setGravity(Gravity.RIGHT, offsetY = 200)
|
||||
.setImmersionStatusBar(true)
|
||||
.setAnimator(object : DefaultAnimator() {
|
||||
override fun enterAnim(
|
||||
view: View,
|
||||
params: WindowManager.LayoutParams,
|
||||
windowManager: WindowManager,
|
||||
sidePattern: SidePattern
|
||||
): Animator? =
|
||||
super.enterAnim(view, params, windowManager, sidePattern)
|
||||
?.apply {
|
||||
interpolator = OvershootInterpolator()
|
||||
}
|
||||
|
||||
override fun exitAnim(
|
||||
view: View,
|
||||
params: WindowManager.LayoutParams,
|
||||
windowManager: WindowManager,
|
||||
sidePattern: SidePattern
|
||||
): Animator? =
|
||||
super.exitAnim(view, params, windowManager, sidePattern)
|
||||
?.setDuration(200)
|
||||
})
|
||||
.show()
|
||||
} else {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏窗口
|
||||
*/
|
||||
fun dismiss() {
|
||||
if (mCarcorderPreviewViewFloat != null) {
|
||||
WarningFloat.dismiss(mCarcorderPreviewViewFloat!!.config.floatTag, false)
|
||||
mCarcorderPreviewViewFloat = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val listener: UVCCameraHelper.OnMyDevConnectListener = object : UVCCameraHelper.OnMyDevConnectListener {
|
||||
override fun onAttachDev(device: UsbDevice?) {
|
||||
// request open permission
|
||||
if (!isRequest) {
|
||||
isRequest = true
|
||||
mCameraHelper?.requestPermission(0)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDettachDev(device: UsbDevice) {
|
||||
// close camera
|
||||
if (isRequest) {
|
||||
isRequest = false
|
||||
mCameraHelper?.closeCamera()
|
||||
showShortMsg(device.deviceName + " is out")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onConnectDev(device: UsbDevice?, isConnected: Boolean) {
|
||||
if (!isConnected) {
|
||||
showShortMsg("fail to connect,please check resolution params")
|
||||
isPreview = false
|
||||
} else {
|
||||
isPreview = true
|
||||
showShortMsg("相机连接中")
|
||||
// initialize seekbar
|
||||
// need to wait UVCCamera initialize over
|
||||
Thread {
|
||||
try {
|
||||
Thread.sleep(2500)
|
||||
} catch (e: InterruptedException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
Looper.prepare()
|
||||
if (mCameraHelper != null && mCameraHelper!!.isCameraOpened) {
|
||||
Logger.d(TAG, "亮度(brightness):${mCameraHelper!!.getModelValue(UVCCameraHelper.MODE_BRIGHTNESS)}")
|
||||
Logger.d(TAG, "对比度(contrast):${mCameraHelper!!.getModelValue(UVCCameraHelper.MODE_CONTRAST)}")
|
||||
}
|
||||
Looper.loop()
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDisConnectDev(device: UsbDevice?) {
|
||||
showShortMsg("相机断开连接")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun showShortMsg(msg: String) {
|
||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
// step.1 initialize UVCCameraHelper
|
||||
carcorderPreview.setCallback(this)
|
||||
mCameraHelper = UVCCameraHelper.getInstance()
|
||||
mCameraHelper?.setDefaultFrameFormat(UVCCameraHelper.FRAME_FORMAT_MJPEG)
|
||||
mCameraHelper?.initUSBMonitor(context as Activity, carcorderPreview, listener)
|
||||
|
||||
mCameraHelper?.setOnPreviewFrameListener { nv21Yuv -> Log.d(TAG, "onPreviewResult: " + nv21Yuv.size) }
|
||||
}
|
||||
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
// step.2 register USB event broadcast
|
||||
if (mCameraHelper != null) {
|
||||
mCameraHelper!!.registerUSB()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
// step.3 unregister USB event broadcast
|
||||
if (mCameraHelper != null) {
|
||||
mCameraHelper!!.unregisterUSB()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
override fun onSurfaceCreated(view: CameraViewInterface?, surface: Surface?) {
|
||||
if (!isPreview && mCameraHelper!!.isCameraOpened) {
|
||||
mCameraHelper!!.startPreview(carcorderPreview)
|
||||
isPreview = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSurfaceChanged(view: CameraViewInterface?, surface: Surface?, width: Int, height: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun onSurfaceDestroy(view: CameraViewInterface?, surface: Surface?) {
|
||||
if (isPreview && mCameraHelper!!.isCameraOpened) {
|
||||
mCameraHelper!!.stopPreview()
|
||||
isPreview = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="@dimen/dp_768"
|
||||
android:layout_height="@dimen/dp_432"
|
||||
android:background="#FFFFFF">
|
||||
|
||||
|
||||
<com.serenegiant.usb.widget.UVCCameraTextureView
|
||||
android:id="@+id/carcorderPreview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user