diff --git a/.idea/misc.xml b/.idea/misc.xml index 635999d..ba7052b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -24,7 +24,7 @@ - + diff --git a/app/src/main/java/com/maning/zxingcodedemo/MainActivity.java b/app/src/main/java/com/maning/zxingcodedemo/MainActivity.java index c3bc74e..e81f47e 100644 --- a/app/src/main/java/com/maning/zxingcodedemo/MainActivity.java +++ b/app/src/main/java/com/maning/zxingcodedemo/MainActivity.java @@ -1,8 +1,11 @@ package com.maning.zxingcodedemo; +import android.Manifest; import android.content.Intent; +import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.os.Build; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; @@ -37,9 +40,20 @@ protected void onCreate(Bundle savedInstanceState) { imageView = (ImageView) findViewById(R.id.imageView); editText = (EditText) findViewById(R.id.editText); checkbox = (CheckBox) findViewById(R.id.checkbox); + + } + + public void requestCameraPerm() { + //判断权限 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { + requestPermissions(new String[]{Manifest.permission.CAMERA}, 10010); + } + } } public void scanCodeDefault(View view) { + requestCameraPerm(); MNScanManager.startScan(this, new MNScanCallback() { @Override public void onActivityResult(int resultCode, Intent data) { @@ -49,6 +63,7 @@ public void onActivityResult(int resultCode, Intent data) { } public void scanCode(View view) { + requestCameraPerm(); MNScanConfig scanConfig = new MNScanConfig.Builder() //设置完成震动 .isShowVibrate(false) @@ -58,6 +73,8 @@ public void scanCode(View view) { .isShowPhotoAlbum(true) //打开扫描页面的动画 .setActivityOpenAnime(R.anim.activity_anmie_in) + //退出扫描页面动画 + .setActivityExitAnime(R.anim.activity_anmie_out) //自定义文案 .setScanHintText("我是自定义文字") //扫描线的颜色 diff --git a/app/src/main/res/anim/activity_anmie_in.xml b/app/src/main/res/anim/activity_anmie_in.xml index 4e0c2f1..920e2ef 100644 --- a/app/src/main/res/anim/activity_anmie_in.xml +++ b/app/src/main/res/anim/activity_anmie_in.xml @@ -2,7 +2,7 @@ \ No newline at end of file diff --git a/app/src/main/res/anim/activity_anmie_out.xml b/app/src/main/res/anim/activity_anmie_out.xml new file mode 100644 index 0000000..f50c259 --- /dev/null +++ b/app/src/main/res/anim/activity_anmie_out.xml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/libraryzxing/src/main/java/com/google/zxing/client/android/CaptureActivity.java b/libraryzxing/src/main/java/com/google/zxing/client/android/CaptureActivity.java index 48319f4..21520dc 100755 --- a/libraryzxing/src/main/java/com/google/zxing/client/android/CaptureActivity.java +++ b/libraryzxing/src/main/java/com/google/zxing/client/android/CaptureActivity.java @@ -16,11 +16,13 @@ package com.google.zxing.client.android; +import android.Manifest; import android.app.Activity; import android.content.ContentUris; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -92,6 +94,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal private boolean is_light_on = false; private boolean beepFlag = true; private boolean vibrateFlag = true; + private int exitAnime = 0; private SurfaceView surfaceView; public Handler getHandler() { @@ -168,6 +171,7 @@ public void onClick(View v) { }); } + private void initIntent() { Intent intent = getIntent(); String hintText = intent.getStringExtra(MNScanManager.INTENT_KEY_HINTTEXT); @@ -175,6 +179,7 @@ private void initIntent() { boolean photoFlag = intent.getBooleanExtra(MNScanManager.INTENT_KEY_PHOTO_FLAG, true); beepFlag = intent.getBooleanExtra(MNScanManager.INTENT_KEY_BEEP_FLAG, true); vibrateFlag = intent.getBooleanExtra(MNScanManager.INTENT_KEY_VIBRATE_FLAG, true); + exitAnime = intent.getIntExtra(MNScanManager.INTENT_KEY_ACTIVITY_EXIT_ANIME, 0); if (!TextUtils.isEmpty(hintText)) { viewfinderView.setHintText(hintText); } @@ -184,6 +189,9 @@ private void initIntent() { if (!photoFlag) { btn_photo.setVisibility(View.GONE); } + if (exitAnime == 0) { + exitAnime = R.anim.mn_scan_activity_bottom_out; + } } /** @@ -295,6 +303,7 @@ protected void onPause() { cameraManager.closeDriver(); //historyManager = null; // Keep for onActivityResult if (!hasSurface) { + SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view); SurfaceHolder surfaceHolder = surfaceView.getHolder(); surfaceHolder.removeCallback(this); } @@ -344,11 +353,10 @@ private void finishSuccess(String result) { finishFinal(); } - private void finishFinal(){ + private void finishFinal() { this.finish(); //关闭窗体动画显示 - overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out); -// this.overridePendingTransition(R.anim.mn_scan_activity_bottom_out, android.R.anim.fade_in); + this.overridePendingTransition(0, exitAnime); } @Override @@ -387,7 +395,7 @@ private void initCamera(SurfaceHolder surfaceHolder) { handler = new CaptureActivityHandler(this, decodeFormats, decodeHints, characterSet, cameraManager); } } catch (Exception e) { - displayFrameworkBugMessageAndExit("开启摄像头异常:" + e.toString()); + displayFrameworkBugMessageAndExit("open camera fail:" + e.toString()); } } diff --git a/libraryzxing/src/main/java/com/google/zxing/client/android/MNScanManager.java b/libraryzxing/src/main/java/com/google/zxing/client/android/MNScanManager.java index f7bf4c7..e380a85 100644 --- a/libraryzxing/src/main/java/com/google/zxing/client/android/MNScanManager.java +++ b/libraryzxing/src/main/java/com/google/zxing/client/android/MNScanManager.java @@ -18,23 +18,27 @@ public class MNScanManager { public static final int RESULT_SUCCESS = 0; public static final int RESULT_FAIL = 1; public static final int RESULT_CANCLE = 2; - public static final String INTENT_KEY_RESULT_SUCCESS = "intent_key_result_success"; - public static final String INTENT_KEY_RESULT_ERROR = "intent_key_result_error"; + public static final String INTENT_KEY_RESULT_SUCCESS = "INTENT_KEY_RESULT_SUCCESS"; + public static final String INTENT_KEY_RESULT_ERROR = "INTENT_KEY_RESULT_ERROR"; //跳转传入的数据 - public static final String INTENT_KEY_HINTTEXT = "intent_key_hinttext"; - public static final String INTENT_KEY_SCSNCOLOR = "intent_key_scsncolor"; - public static final String INTENT_KEY_PHOTO_FLAG = "intent_key_photo_flag"; - public static final String INTENT_KEY_BEEP_FLAG = "intent_key_beep_flag"; - public static final String INTENT_KEY_VIBRATE_FLAG = "intent_key_vibrate_flag"; + //提示文案 + public static final String INTENT_KEY_HINTTEXT = "INTENT_KEY_HINTTEXT"; + //扫描线的颜色 + public static final String INTENT_KEY_SCSNCOLOR = "INTENT_KEY_SCSNCOLOR"; + //相机是否显示 + public static final String INTENT_KEY_PHOTO_FLAG = "INTENT_KEY_PHOTO_FLAG"; + //识别声音 + public static final String INTENT_KEY_BEEP_FLAG = "INTENT_KEY_BEEP_FLAG"; + //识别震动 + public static final String INTENT_KEY_VIBRATE_FLAG = "INTENT_KEY_VIBRATE_FLAG"; + //扫描退出动画 + public static final String INTENT_KEY_ACTIVITY_EXIT_ANIME = "INTENT_KEY_ACTIVITY_EXIT_ANIME"; public static void startScan(Activity activity, MNScanCallback scanCallback) { - Intent intent = new Intent(activity.getApplicationContext(), CaptureActivity.class); - ActResultRequest actResultRequest = new ActResultRequest(activity); - actResultRequest.startForResult(intent, scanCallback); - activity.overridePendingTransition(R.anim.mn_scan_activity_bottom_in, R.anim.mn_scan_activity_no_anim); + startScan(activity, null, scanCallback); } public static void startScan(Activity activity, MNScanConfig mnScanConfig, MNScanCallback scanCallback) { @@ -52,10 +56,12 @@ public static void startScan(Activity activity, MNScanConfig mnScanConfig, MNSca intent.putExtra(MNScanManager.INTENT_KEY_SCSNCOLOR, mnScanConfig.getScanColor()); //扫码框上面的提示文案 intent.putExtra(MNScanManager.INTENT_KEY_HINTTEXT, mnScanConfig.getScanHintText()); + //退出动画 + intent.putExtra(MNScanManager.INTENT_KEY_ACTIVITY_EXIT_ANIME, mnScanConfig.getActivityExitAnime()); ActResultRequest actResultRequest = new ActResultRequest(activity); actResultRequest.startForResult(intent, scanCallback); - activity.overridePendingTransition(mnScanConfig.getActivityOpenAnime(), R.anim.mn_scan_activity_no_anim); + activity.overridePendingTransition(mnScanConfig.getActivityOpenAnime(), android.R.anim.fade_out); } } diff --git a/libraryzxing/src/main/java/com/google/zxing/client/android/model/MNScanConfig.java b/libraryzxing/src/main/java/com/google/zxing/client/android/model/MNScanConfig.java index 8c70288..1498d63 100644 --- a/libraryzxing/src/main/java/com/google/zxing/client/android/model/MNScanConfig.java +++ b/libraryzxing/src/main/java/com/google/zxing/client/android/model/MNScanConfig.java @@ -2,12 +2,16 @@ import com.google.zxing.client.android.R; +import java.io.Serializable; + /** * Created by maning on 2017/12/7. * 启动Activity的一些配置参数 */ -public class MNScanConfig { +public class MNScanConfig implements Serializable { + + private static final long serialVersionUID = -5260676142223049891L; //是否显示相册 private boolean showPhotoAlbum; @@ -21,6 +25,8 @@ public class MNScanConfig { private String scanHintText; //开启Activity动画 private int activityOpenAnime; + //关闭Activity动画 + private int activityExitAnime; private MNScanConfig() { @@ -33,6 +39,7 @@ private MNScanConfig(Builder builder) { scanColor = builder.scanColor; scanHintText = builder.scanHintText; activityOpenAnime = builder.activityOpenAnime; + activityExitAnime = builder.activityExitAnime; } public boolean isShowPhotoAlbum() { @@ -59,6 +66,14 @@ public int getActivityOpenAnime() { return activityOpenAnime; } + public int getActivityExitAnime() { + return activityExitAnime; + } + + public void setActivityExitAnime(int activityExitAnime) { + this.activityExitAnime = activityExitAnime; + } + public static class Builder { private boolean showPhotoAlbum = true; private boolean showBeep = true; @@ -66,6 +81,7 @@ public static class Builder { private String scanColor; private String scanHintText; private int activityOpenAnime = R.anim.mn_scan_activity_bottom_in; + private int activityExitAnime = R.anim.mn_scan_activity_bottom_out; public MNScanConfig builder() { return new MNScanConfig(this); @@ -101,6 +117,11 @@ public Builder setActivityOpenAnime(int activityOpenAnime) { return this; } + public Builder setActivityExitAnime(int activityExitAnime) { + this.activityExitAnime = activityExitAnime; + return this; + } + } } diff --git a/libraryzxing/src/main/res/anim/mn_scan_activity_bottom_in.xml b/libraryzxing/src/main/res/anim/mn_scan_activity_bottom_in.xml index 8db8d18..90d248c 100644 --- a/libraryzxing/src/main/res/anim/mn_scan_activity_bottom_in.xml +++ b/libraryzxing/src/main/res/anim/mn_scan_activity_bottom_in.xml @@ -1,7 +1,15 @@ - \ No newline at end of file + + + + + + + \ No newline at end of file diff --git a/libraryzxing/src/main/res/anim/mn_scan_activity_bottom_out.xml b/libraryzxing/src/main/res/anim/mn_scan_activity_bottom_out.xml index 245985e..70f2a52 100644 --- a/libraryzxing/src/main/res/anim/mn_scan_activity_bottom_out.xml +++ b/libraryzxing/src/main/res/anim/mn_scan_activity_bottom_out.xml @@ -1,6 +1,14 @@ - \ No newline at end of file + + + + + + + \ No newline at end of file diff --git a/libraryzxing/src/main/res/anim/mn_scan_activity_no_anim.xml b/libraryzxing/src/main/res/anim/mn_scan_activity_no_anim.xml deleted file mode 100644 index bb5ad07..0000000 --- a/libraryzxing/src/main/res/anim/mn_scan_activity_no_anim.xml +++ /dev/null @@ -1,3 +0,0 @@ - - \ No newline at end of file diff --git a/libraryzxing/src/main/res/layout/mn_scan_capture.xml b/libraryzxing/src/main/res/layout/mn_scan_capture.xml index 9184155..0846b3d 100755 --- a/libraryzxing/src/main/res/layout/mn_scan_capture.xml +++ b/libraryzxing/src/main/res/layout/mn_scan_capture.xml @@ -36,14 +36,15 @@ android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" - android:layout_marginBottom="30dp" + android:layout_marginBottom="20dp" android:gravity="center" android:orientation="vertical"> + android:layout_height="50dp" + android:gravity="center" + android:paddingLeft="20dp" + android:paddingRight="16dp"> @@ -78,16 +78,15 @@ + android:gravity="center" + android:paddingLeft="16dp" + android:paddingRight="20dp"> diff --git a/libraryzxing/src/main/res/values/colors.xml b/libraryzxing/src/main/res/values/colors.xml index fb7857f..c585c02 100755 --- a/libraryzxing/src/main/res/values/colors.xml +++ b/libraryzxing/src/main/res/values/colors.xml @@ -14,6 +14,6 @@ limitations under the License. --> - #FFff3535 - #a2000000 + #FFff3535 + #7b000000 diff --git a/libraryzxing/src/main/res/values/styles.xml b/libraryzxing/src/main/res/values/styles.xml index 59966db..1401a1a 100755 --- a/libraryzxing/src/main/res/values/styles.xml +++ b/libraryzxing/src/main/res/values/styles.xml @@ -42,10 +42,12 @@ @null @null +