Skip to content

Commit

Permalink
1. 优化拍照按钮点击事件 2. 增加设备是否支持闪光灯判断
Browse files Browse the repository at this point in the history
  • Loading branch information
wildma committed Jul 16, 2019
1 parent a726208 commit cc5e16d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
4 changes: 2 additions & 2 deletions idcardcamera/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 26
versionCode 110
versionName "1.1.0"
versionCode 111
versionName "1.1.1"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.wildma.idcardcamera.cropper.CropImageView;
import com.wildma.idcardcamera.cropper.CropListener;
import com.wildma.idcardcamera.global.Constant;
import com.wildma.idcardcamera.utils.CommonUtils;
import com.wildma.idcardcamera.utils.FileUtils;
import com.wildma.idcardcamera.utils.ImageUtils;
import com.wildma.idcardcamera.utils.PermissionUtils;
Expand Down Expand Up @@ -170,10 +171,16 @@ public void onClick(View v) {
} else if (id == R.id.iv_camera_close) {
finish();
} else if (id == R.id.iv_camera_take) {
takePhoto();
if (!CommonUtils.isFastClick()) {
takePhoto();
}
} else if (id == R.id.iv_camera_flash) {
boolean isFlashOn = mCameraPreview.switchFlashLight();
mIvCameraFlash.setImageResource(isFlashOn ? R.mipmap.camera_flash_on : R.mipmap.camera_flash_off);
if (CameraUtils.hasFlash(this)) {
boolean isFlashOn = mCameraPreview.switchFlashLight();
mIvCameraFlash.setImageResource(isFlashOn ? R.mipmap.camera_flash_on : R.mipmap.camera_flash_off);
} else {
Toast.makeText(this, R.string.no_flash, Toast.LENGTH_SHORT).show();
}
} else if (id == R.id.iv_camera_result_ok) {
confirm();
} else if (id == R.id.iv_camera_result_cancel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@ public static Camera openCamera() {
public static Camera getCamera() {
return camera;
}

/**
* 检查是否有闪光灯
*
* @return true:有,false:无
*/
public static boolean hasFlash(Context context) {
return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.wildma.idcardcamera.utils;

/**
* Author wildma
* Github https://github.com/wildma
* Date 2019/07/16
* Desc ${公用工具类}
*/
public class CommonUtils {

private static long lastClickTime;

/**
* 判断是否是快速点击
*
* @return true:是,false:否
*/
public static boolean isFastClick() {
return isFastClick(1000);
}

/**
* 判断是否是快速点击
*
* @param intervalTime 间隔时间,单位毫秒。
* @return true:是,false:否
*/
public static boolean isFastClick(long intervalTime) {
long time = System.currentTimeMillis();
if (time - lastClickTime < intervalTime) {
return true;
}
lastClickTime = time;
return false;
}
}
1 change: 1 addition & 0 deletions idcardcamera/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

<string name="touch_to_focus">触摸屏幕对焦</string>
<string name="crop_fail">裁剪失败</string>
<string name="no_flash">该设备不支持闪光灯</string>
</resources>

0 comments on commit cc5e16d

Please sign in to comment.