From b8a135e08180bf4ef37b4768d7b856829df37752 Mon Sep 17 00:00:00 2001 From: jiangdongguo <765067602@qq.com> Date: Mon, 13 Nov 2017 17:06:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=9A=E6=AC=A1=E6=8F=92?= =?UTF-8?q?=E6=8B=94=E8=AE=BE=E5=A4=87=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usbcamera/view/USBCameraActivity.java | 44 +++++++++----- .../main/res/layout/activity_usbcamera.xml | 59 +++++++++++-------- app/src/main/res/values/colors.xml | 1 + .../jiangdg/usbcamera/USBCameraManager.java | 15 ++--- .../usb/common/AbstractUVCCameraHandler.java | 3 +- 5 files changed, 74 insertions(+), 48 deletions(-) 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 9ea4ceb..af66e9c 100644 --- a/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java +++ b/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java @@ -6,6 +6,7 @@ import android.os.Environment; import android.os.Handler; import android.os.Message; import android.support.annotation.Nullable; +import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; @@ -27,6 +28,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import butterknife.BindView; @@ -42,8 +44,6 @@ import butterknife.OnClick; public class USBCameraActivity extends AppCompatActivity implements CameraDialog.CameraDialogParent{ @BindView(R.id.camera_view) public View mTextureView; - @BindView(R.id.camera_view2) - public View mTextureView2; @BindView(R.id.btn_capture_pic) public Button mBtnCapture; @BindView(R.id.btn_rec_video) @@ -52,8 +52,13 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog public Button mBtnUpdateResultion; @BindView(R.id.btn_restart_camera) Button mBtnRestartCamera; + @BindView(R.id.btn_contrast) + Button mBtnContrast; + @BindView(R.id.btn_brightness) + Button mBtnBrightness; private USBCameraManager mUSBManager; + private CameraViewInterface mUVCCameraView; private boolean isRequest; @@ -116,6 +121,7 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog mUSBManager.createUVCCamera(mUVCCameraView); } + @Override protected void onStart() { super.onStart(); @@ -134,26 +140,31 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog } } - @OnClick({R.id.camera_view, R.id.btn_capture_pic, R.id.btn_rec_video,R.id.btn_update_resolution,R.id.btn_restart_camera}) + @OnClick({ R.id.btn_contrast,R.id.btn_brightness,R.id.btn_capture_pic, R.id.btn_rec_video,R.id.btn_update_resolution,R.id.btn_restart_camera}) public void onViewClick(View view) { int vId = view.getId(); switch (vId) { + // 对比度 + case R.id.btn_contrast: + if(mUSBManager == null || !mUSBManager.isCameraOpened()) + return; + int contrast = mUSBManager.getModelValue(USBCameraManager.MODE_CONTRAST); + mUSBManager.setModelValue(USBCameraManager.MODE_CONTRAST,contrast++); + break; + // 亮度 + case R.id.btn_brightness: + if(mUSBManager == null || !mUSBManager.isCameraOpened()) + return; + int brightness = mUSBManager.getModelValue(USBCameraManager.MODE_BRIGHTNESS); + mUSBManager.setModelValue(USBCameraManager.MODE_BRIGHTNESS,brightness++); + break; // 重启Camera case R.id.btn_restart_camera: - if(mUSBManager == null) - return; - mUSBManager.restartUSBCamera((CameraViewInterface) mTextureView2,new USBCameraManager.OnPreviewListener() { - @Override - public void onPreviewResult(boolean isSuccess) { - if(isSuccess) { - showShortMsg("重启成功"); - } - } - }); + break; // 切换分辨率 case R.id.btn_update_resolution: - if(mUSBManager == null) + if(mUSBManager == null || !mUSBManager.isCameraOpened()) return; mUSBManager.updateResolution(320, 240, new USBCameraManager.OnPreviewListener() { @Override @@ -240,7 +251,6 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog @Override protected void onDestroy() { super.onDestroy(); - // 释放资源 if(mUSBManager != null){ mUSBManager.release(); } @@ -261,4 +271,8 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog showShortMsg("取消操作"); } } + + public boolean isCameraOpened() { + return mUSBManager.isCameraOpened(); + } } diff --git a/app/src/main/res/layout/activity_usbcamera.xml b/app/src/main/res/layout/activity_usbcamera.xml index 16c2ab1..3d5a5e6 100644 --- a/app/src/main/res/layout/activity_usbcamera.xml +++ b/app/src/main/res/layout/activity_usbcamera.xml @@ -1,25 +1,34 @@ +