Skip to content

Commit

Permalink
1. 解决个别手机首次申请权限导致预览界面启动慢的问题 2. 优化裁剪框线条与边框的间距
Browse files Browse the repository at this point in the history
  • Loading branch information
wildma committed Aug 21, 2018
1 parent 63ed6e1 commit db1ad1e
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 5 deletions.
2 changes: 1 addition & 1 deletion idcardcamera/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
>
<activity
android:name=".camera.CameraActivity"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"/>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.view.View;
Expand Down Expand Up @@ -40,7 +41,7 @@ public class CameraActivity extends Activity implements View.OnClickListener {
public final static int TYPE_IDCARD_BACK = 2;//身份证反面
public final static int REQUEST_CODE = 0X11;//请求码
public final static int RESULT_CODE = 0X12;//结果码
public final static int PERMISSION_CODE_SECOND = 0x13;//权限请求码
public final static int PERMISSION_CODE_FIRST = 0x13;//权限请求码
public final static String TAKE_TYPE = "take_type";//拍摄类型标记
public final static String IMAGE_PATH = "image_path";//图片路径标记
public static int mType;//拍摄类型
Expand Down Expand Up @@ -88,9 +89,9 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

/*动态请求需要的权限*/
boolean checkPermissionSecond = PermissionUtils.checkPermissionFirst(this, PERMISSION_CODE_SECOND,
boolean checkPermissionFirst = PermissionUtils.checkPermissionFirst(this, PERMISSION_CODE_FIRST,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA});
if (checkPermissionSecond) {
if (checkPermissionFirst) {
init();
}
}
Expand Down Expand Up @@ -168,6 +169,19 @@ private void initView() {
mIvCameraCrop.setImageResource(R.mipmap.camera_idcard_back);
break;
}

/*增加0.5秒过渡界面,解决个别手机首次申请权限导致预览界面启动慢的问题*/
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
mCameraPreview.setVisibility(View.VISIBLE);
}
});
}
}, 500);
}

private void initListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private void resetPoints() {
if (maxX - minX < defaultMargin || maxY - minY < defaultMargin)
defaultMargin = 0; // remove min
else
defaultMargin = 100;
defaultMargin = 30;

Log.e("stk", "maxX - minX=" + (maxX - minX));
Log.e("stk", "maxY - minY=" + (maxY - minY));
Expand Down
1 change: 1 addition & 0 deletions idcardcamera/src/main/res/layout-land/activity_camera.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<!--相机预览-->
<com.wildma.idcardcamera.camera.CameraPreview
android:id="@+id/camera_preview"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent" />

Expand Down
140 changes: 140 additions & 0 deletions idcardcamera/src/main/res/layout/activity_camera.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_000000">

<!--相机预览-->
<com.wildma.idcardcamera.camera.CameraPreview
android:id="@+id/camera_preview"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<!--左侧相机预览布局-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">

<!--相机裁剪区域左边-->
<View
android:id="@+id/view_camera_crop_left"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@color/preview_mock" />

<LinearLayout
android:id="@+id/ll_camera_crop_container"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical">

<!--相机裁剪区域顶部-->
<View
android:id="@+id/view_camera_crop_top"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/preview_mock" />

<!--相机裁剪区域-->
<ImageView
android:id="@+id/iv_camera_crop"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="fitXY" />

<!--手动裁剪区域-->
<com.wildma.idcardcamera.cropper.CropImageView
android:visibility="gone"
android:id="@+id/crop_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<!--相机裁剪区域底部-->
<TextView
android:id="@+id/view_camera_crop_bottom"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/preview_mock"
android:gravity="center"
android:text="@string/touch_to_focus"
android:textColor="@color/color_afff"
android:textSize="16dp" />

</LinearLayout>

</LinearLayout>

<!--右侧操作布局-->
<FrameLayout
android:layout_width="136dp"
android:layout_height="match_parent"
android:background="@color/preview_mock">

<!--拍照前操作布局-->
<LinearLayout
android:id="@+id/ll_camera_option"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">

<ImageView
android:id="@+id/iv_camera_flash"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@mipmap/camera_flash_off" />

<ImageView
android:id="@+id/iv_camera_take"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_margin="32dp"
android:src="@mipmap/camera_take" />

<ImageView
android:id="@+id/iv_camera_close"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@mipmap/camera_close" />

</LinearLayout>

<!--拍照后操作布局-->
<LinearLayout
android:id="@+id/ll_camera_result"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">

<ImageView
android:id="@+id/iv_camera_result_ok"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@mipmap/camera_result_ok" />

<ImageView
android:id="@+id/iv_camera_result_cancel"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="80dp"
android:src="@mipmap/camera_result_cancel" />

</LinearLayout>

</FrameLayout>

</LinearLayout>
</RelativeLayout>

0 comments on commit db1ad1e

Please sign in to comment.