{
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/libraryzxing/src/main/java/com/google/zxing/client/android/other/MNScanCallback.java:
--------------------------------------------------------------------------------
1 | package com.google.zxing.client.android.other;
2 |
3 | import android.content.Intent;
4 |
5 | /**
6 | *
7 | * author : maning
8 | * e-mail : xxx@xx
9 | * time : 2018/06/04
10 | * desc :
11 | * version: 1.0
12 | *
13 | */
14 | public interface MNScanCallback {
15 |
16 | void onActivityResult(int resultCode, Intent data);
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/res/anim/mn_scan_activity_bottom_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
10 |
14 |
15 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/res/drawable/mn_scan_result_point_default.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
11 |
12 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/activity_anmie_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
12 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/activity_anmie_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
12 |
16 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/java/com/google/zxing/client/android/other/OnScanCallback.java:
--------------------------------------------------------------------------------
1 | package com.google.zxing.client.android.other;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | /**
6 | * @author : maning
7 | * @date : 2020-09-09
8 | * @desc :
9 | */
10 | public interface OnScanCallback {
11 |
12 | /**
13 | * 扫码成功
14 | * @param resultTxt
15 | * @param barcode
16 | */
17 | void onScanSuccess(String resultTxt, Bitmap barcode);
18 |
19 | /**
20 | * 暂停扫描
21 | */
22 | void onStopScan();
23 |
24 | /**
25 | * 重新扫描
26 | */
27 | void onRestartScan();
28 |
29 | /**
30 | * 失败
31 | * @param msg
32 | */
33 | void onFail(String msg);
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/maning/Desktop/Android/AndroidStudioSDK/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/libraryzxing/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/libraryzxing/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | def versions = rootProject.ext.versions
4 |
5 | android {
6 | compileSdkVersion versions.compileSdkVersion
7 | defaultConfig {
8 | minSdkVersion versions.minSdkVersion
9 | targetSdkVersion versions.targetSdkVersion
10 | versionCode versions.versionCode
11 | versionName versions.versionName
12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | implementation fileTree(include: ['*.jar'], dir: 'libs')
24 | //3.4.0-对应7.0以上+java8
25 | //3.3.3-支持7.0以下版本
26 | compileOnly 'com.google.zxing:core:3.3.3'
27 | }
28 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/res/drawable/mn_scan_seekbar_zoom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
12 |
13 |
14 |
15 | -
16 |
17 |
18 |
19 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/res/layout/mn_scan_result_point_item_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
22 |
23 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_history.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/values/array.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | - L
5 | - M
6 | - Q
7 | - H
8 |
9 |
10 |
11 | - 0
12 | - 1
13 | - 2
14 | - 3
15 | - 4
16 |
17 |
18 |
19 | - 黑色
20 | - 白色
21 | - 蓝色
22 | - 绿色
23 | - 黄色
24 | - 红色
25 |
26 |
27 |
28 | - 白色
29 | - 黑色
30 | - 蓝色
31 | - 绿色
32 | - 黄色
33 | - 红色
34 |
35 |
36 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/java/com/google/zxing/client/android/camera/open/CameraFacing.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.client.android.camera.open;
18 |
19 | /**
20 | * Enumeration of directions a camera may face: front or back.
21 | */
22 | public enum CameraFacing {
23 |
24 | BACK, // must be value 0!
25 | FRONT, // must be value 1!
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 | #android.enableAapt2=false
20 | android.enableJetifier=true
21 | android.useAndroidX=true
--------------------------------------------------------------------------------
/libraryzxing/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 | #FFff3535
18 | #80000000
19 | #CCFF3535
20 | #FFFFFFFF
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_scan.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
29 |
30 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/res/layout/mn_scan_progress_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
20 |
21 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/config.gradle:
--------------------------------------------------------------------------------
1 | /**
2 | * 全局统一配置
3 | */
4 | ext {
5 |
6 | /**
7 | * 版本统一管理
8 | */
9 | versions = [
10 | versionCode : 219, //版本号
11 | versionName : "2.1.9", //版本名称
12 |
13 | compileSdkVersion: 29,
14 | minSdkVersion : 19,
15 | targetSdkVersion : 28,
16 |
17 | ]
18 |
19 | appId = [
20 | "app": "com.maning.zxingcodedemo",
21 | ]
22 |
23 | dependenciesGoogle = [
24 | annotation : 'androidx.annotation:annotation:1.1.0',
25 | supportv4 : 'androidx.legacy:legacy-support-v4:1.0.0',
26 | appcompat : 'androidx.appcompat:appcompat:1.2.0',
27 | design : 'com.google.android.material:material:1.0.0',
28 | recyclerView : 'androidx.recyclerview:recyclerview:1.0.0',
29 | constraintlayout: 'androidx.constraintlayout:constraintlayout:1.1.3',
30 | multidex : 'androidx.multidex:multidex:2.0.0',
31 | ]
32 |
33 | dependenciesOther = [
34 | //颜色选择器
35 | "colorpicker": 'com.github.duanhong169:colorpicker:1.1.6',
36 | "xpopup" : 'com.lxj:xpopup:2.2.19'
37 | ]
38 |
39 | dependenciesDebug = [
40 | "leakcanary": "com.squareup.leakcanary:leakcanary-android:2.5",
41 | ]
42 |
43 | }
--------------------------------------------------------------------------------
/libraryzxing/src/main/java/com/google/zxing/client/android/view/ResizeAbleSurfaceView.java:
--------------------------------------------------------------------------------
1 | package com.google.zxing.client.android.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.SurfaceView;
6 |
7 | /**
8 | * @author : maning
9 | * @date : 2020-06-19
10 | * @desc :
11 | */
12 | public class ResizeAbleSurfaceView extends SurfaceView {
13 |
14 | private int mWidth = -1;
15 | private int mHeight = -1;
16 |
17 | public ResizeAbleSurfaceView(Context context) {
18 | super(context);
19 | }
20 |
21 | public ResizeAbleSurfaceView(Context context, AttributeSet attrs) {
22 | super(context, attrs);
23 | }
24 |
25 | public ResizeAbleSurfaceView(Context context, AttributeSet attrs, int defStyleAttr) {
26 | super(context, attrs, defStyleAttr);
27 | }
28 |
29 | @Override
30 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
31 | if (-1 == mWidth || -1 == mHeight) {
32 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
33 | } else {
34 | setMeasuredDimension(mWidth, mHeight);
35 | }
36 | }
37 |
38 | public void resize(int width, int height) {
39 | mWidth = width;
40 | mHeight = height;
41 | getHolder().setFixedSize(width, height);
42 | requestLayout();
43 | invalidate();
44 | }
45 | }
--------------------------------------------------------------------------------
/libraryzxing/src/main/res/layout/mn_scan_surface_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
14 |
15 |
16 |
21 |
22 |
23 |
27 |
28 |
29 |
35 |
36 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/java/com/google/zxing/client/android/other/OnActResultEventDispatcherFragment.java:
--------------------------------------------------------------------------------
1 | package com.google.zxing.client.android.other;
2 |
3 | import android.app.Fragment;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.util.SparseArray;
7 |
8 | /**
9 | *
10 | * author : maning
11 | * e-mail : xxx@xx
12 | * time : 2018/06/04
13 | * desc :
14 | * version: 1.0
15 | *
16 | */
17 | public class OnActResultEventDispatcherFragment extends Fragment {
18 | public static final String TAG = "on_act_result_event_dispatcher";
19 |
20 | private SparseArray mCallbacks = new SparseArray<>();
21 |
22 | @Override
23 | public void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setRetainInstance(true);
26 | }
27 |
28 | public void startForResult(Intent intent, MNScanCallback callback) {
29 | mCallbacks.put(callback.hashCode(), callback);
30 | startActivityForResult(intent, callback.hashCode());
31 | }
32 |
33 | @Override
34 | public void onActivityResult(int requestCode, int resultCode, Intent data) {
35 | super.onActivityResult(requestCode, resultCode, data);
36 |
37 | MNScanCallback callback = mCallbacks.get(requestCode);
38 | mCallbacks.remove(requestCode);
39 |
40 | if (callback != null) {
41 | callback.onActivityResult(resultCode, data);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | def versions = rootProject.ext.versions
4 | def appId = rootProject.ext.appId
5 | def dependenciesGoogle = rootProject.ext.dependenciesGoogle
6 | def dependenciesOther = rootProject.ext.dependenciesOther
7 |
8 | android {
9 | compileSdkVersion versions.compileSdkVersion
10 | defaultConfig {
11 | applicationId appId.app
12 | minSdkVersion versions.minSdkVersion
13 | targetSdkVersion versions.targetSdkVersion
14 | versionCode versions.versionCode
15 | versionName versions.versionName
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 | implementation 'androidx.appcompat:appcompat:1.1.0'
29 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
30 | // 循环引入库
31 | dependenciesGoogle.each { k, v -> api v }
32 | dependenciesOther.each { k, v -> api v }
33 | dependenciesDebug.each { k, v -> debugImplementation v }
34 |
35 | //3.4.0-对应7.0以上+java8
36 | // implementation 'com.google.zxing:core:3.4.0'
37 | //3.3.3-支持7.0以下版本
38 | implementation 'com.google.zxing:core:3.3.3'
39 |
40 | // implementation 'com.github.maning0303:MNZXingCode:V2.1.9'
41 | implementation project(':libraryzxing')
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
18 |
19 |
26 |
27 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/java/com/google/zxing/client/android/view/ProgressDialog.java:
--------------------------------------------------------------------------------
1 | package com.google.zxing.client.android.view;
2 |
3 | import android.app.Dialog;
4 | import android.content.Context;
5 | import android.view.Gravity;
6 | import android.view.Window;
7 |
8 | import com.google.zxing.client.android.R;
9 |
10 | /**
11 | * @author : maning
12 | * @date : 2020-09-04
13 | * @desc :
14 | */
15 | public class ProgressDialog extends Dialog {
16 |
17 | private static ProgressDialog progressDialog;
18 |
19 | public ProgressDialog(Context context) {
20 | super(context);
21 | }
22 |
23 | public ProgressDialog(Context context, int themeResId) {
24 | super(context, themeResId);
25 | }
26 |
27 | @Override
28 | public void dismiss() {
29 | try {
30 | super.dismiss();
31 | } catch (Exception e) {
32 | e.printStackTrace();
33 | }
34 | }
35 |
36 | public static ProgressDialog show(Context context) {
37 | progressDialog = new ProgressDialog(context, R.style.MNScanProgressDialog);
38 | progressDialog.setContentView(R.layout.mn_scan_progress_dialog);
39 | progressDialog.setCancelable(true);
40 | progressDialog.setCanceledOnTouchOutside(true);
41 | Window window = progressDialog.getWindow();
42 | window.setDimAmount(0.0f);
43 | window.setBackgroundDrawableResource(android.R.color.transparent);
44 | window.getAttributes().gravity = Gravity.CENTER;
45 | progressDialog.show();
46 | return progressDialog;
47 | }
48 |
49 | public static void dismissDialog() {
50 | if (progressDialog != null) {
51 | progressDialog.dismiss();
52 | }
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/java/com/google/zxing/client/android/other/ActResultRequest.java:
--------------------------------------------------------------------------------
1 | package com.google.zxing.client.android.other;
2 |
3 | import android.app.Activity;
4 | import android.app.FragmentManager;
5 | import android.content.Intent;
6 |
7 | /**
8 | *
9 | * author : maning
10 | * e-mail : xxx@xx
11 | * time : 2018/06/04
12 | * desc :
13 | * version: 1.0
14 | *
15 | */
16 | public class ActResultRequest {
17 | private OnActResultEventDispatcherFragment fragment;
18 |
19 | public ActResultRequest(Activity activity) {
20 | fragment = getEventDispatchFragment(activity);
21 | }
22 |
23 | private OnActResultEventDispatcherFragment getEventDispatchFragment(Activity activity) {
24 | final FragmentManager fragmentManager = activity.getFragmentManager();
25 |
26 | OnActResultEventDispatcherFragment fragment = findEventDispatchFragment(fragmentManager);
27 | if (fragment == null) {
28 | fragment = new OnActResultEventDispatcherFragment();
29 | fragmentManager
30 | .beginTransaction()
31 | .add(fragment, OnActResultEventDispatcherFragment.TAG)
32 | .commitAllowingStateLoss();
33 | fragmentManager.executePendingTransactions();
34 | }
35 | return fragment;
36 | }
37 |
38 | private OnActResultEventDispatcherFragment findEventDispatchFragment(FragmentManager manager) {
39 | return (OnActResultEventDispatcherFragment) manager.findFragmentByTag(OnActResultEventDispatcherFragment.TAG);
40 | }
41 |
42 | public void startForResult(Intent intent, MNScanCallback callback) {
43 | fragment.startForResult(intent, callback);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/java/com/google/zxing/client/android/camera/open/OpenCamera.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.client.android.camera.open;
18 |
19 | import android.hardware.Camera;
20 |
21 | /**
22 | * Represents an open {@link Camera} and its metadata, like facing direction and orientation.
23 | */
24 | @SuppressWarnings("deprecation") // camera APIs
25 | public final class OpenCamera {
26 |
27 | private final int index;
28 | private final Camera camera;
29 | private final CameraFacing facing;
30 | private final int orientation;
31 |
32 | public OpenCamera(int index, Camera camera, CameraFacing facing, int orientation) {
33 | this.index = index;
34 | this.camera = camera;
35 | this.facing = facing;
36 | this.orientation = orientation;
37 | }
38 |
39 | public Camera getCamera() {
40 | return camera;
41 | }
42 |
43 | public CameraFacing getFacing() {
44 | return facing;
45 | }
46 |
47 | public int getOrientation() {
48 | return orientation;
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return "Camera #" + index + " : " + facing + ',' + orientation;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
16 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
33 |
34 |
37 |
38 |
39 |
40 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/res/layout/mn_scan_result_point_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
33 |
34 |
35 |
36 |
44 |
45 |
49 |
50 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/res/layout/mn_scan_capture.xml:
--------------------------------------------------------------------------------
1 |
16 |
20 |
21 |
25 |
26 |
30 |
31 |
37 |
38 |
39 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/java/com/google/zxing/client/android/MNScanManager.java:
--------------------------------------------------------------------------------
1 | package com.google.zxing.client.android;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 |
6 | import com.google.zxing.client.android.model.MNScanConfig;
7 | import com.google.zxing.client.android.other.ActResultRequest;
8 | import com.google.zxing.client.android.other.MNScanCallback;
9 |
10 | /**
11 | * Created by maning on 2017/12/7.
12 | * 启动扫描的主类
13 | */
14 |
15 | public class MNScanManager {
16 |
17 | //常量
18 | public static final int RESULT_SUCCESS = 0;
19 | public static final int RESULT_FAIL = 1;
20 | public static final int RESULT_CANCLE = 2;
21 | public static final String INTENT_KEY_RESULT_SUCCESS = "INTENT_KEY_RESULT_SUCCESS";
22 | public static final String INTENT_KEY_RESULT_ERROR = "INTENT_KEY_RESULT_ERROR";
23 | //是否是调试模式
24 | public static final boolean isDebugMode = false;
25 |
26 |
27 | //跳转传入的数据
28 | public static final String INTENT_KEY_CONFIG_MODEL = "INTENT_KEY_CONFIG_MODEL";
29 |
30 |
31 | public static void startScan(Activity activity, MNScanCallback scanCallback) {
32 | startScan(activity, null, scanCallback);
33 | }
34 |
35 | public static void startScan(Activity activity, MNScanConfig mnScanConfig, MNScanCallback scanCallback) {
36 | if (mnScanConfig == null) {
37 | mnScanConfig = new MNScanConfig.Builder().builder();
38 | }
39 | Intent intent = new Intent(activity.getApplicationContext(), CaptureActivity.class);
40 | //传递数据
41 | intent.putExtra(MNScanManager.INTENT_KEY_CONFIG_MODEL, mnScanConfig);
42 | ActResultRequest actResultRequest = new ActResultRequest(activity);
43 | actResultRequest.startForResult(intent, scanCallback);
44 | activity.overridePendingTransition(mnScanConfig.getActivityOpenAnime(), android.R.anim.fade_out);
45 | }
46 |
47 | /**
48 | * 关闭当前页面
49 | */
50 | public static void closeScanPage() {
51 | CaptureActivity.closeScanPage();
52 | }
53 |
54 | /**
55 | * 打开相册扫描图片
56 | */
57 | public static void openAlbumPage() {
58 | CaptureActivity.openAlbumPage();
59 | }
60 |
61 | /**
62 | * 打开手电筒
63 | */
64 | public static void openScanLight() {
65 | CaptureActivity.openScanLight();
66 | }
67 |
68 | /**
69 | * 关闭手电筒
70 | */
71 | public static void closeScanLight() {
72 | CaptureActivity.closeScanLight();
73 | }
74 |
75 | /**
76 | * 手电筒是否开启
77 | */
78 | public static boolean isLightOn() {
79 | return CaptureActivity.isLightOn();
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/java/com/google/zxing/client/android/utils/CommonUtils.java:
--------------------------------------------------------------------------------
1 | package com.google.zxing.client.android.utils;
2 |
3 | import android.content.Context;
4 | import android.graphics.Paint;
5 | import android.graphics.Rect;
6 | import android.text.TextPaint;
7 | import android.util.DisplayMetrics;
8 | import android.view.WindowManager;
9 |
10 | /**
11 | * Created by maning on 2017/11/9.
12 | */
13 |
14 | public class CommonUtils {
15 | /**
16 | * 根据手机分辨率从DP转成PX
17 | *
18 | * @param context
19 | * @param dpValue
20 | * @return
21 | */
22 | public static int dip2px(Context context, float dpValue) {
23 | float scale = context.getResources().getDisplayMetrics().density;
24 | return (int) (dpValue * scale + 0.5f);
25 | }
26 |
27 | /**
28 | * 将sp值转换为px值,保证文字大小不变
29 | *
30 | * @param spValue
31 | * @return
32 | */
33 | public static int sp2px(Context context, float spValue) {
34 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
35 | return (int) (spValue * fontScale + 0.5f);
36 | }
37 |
38 | /**
39 | * 根据手机的分辨率PX(像素)转成DP
40 | *
41 | * @param context
42 | * @param pxValue
43 | * @return
44 | */
45 | public static int px2dip(Context context, float pxValue) {
46 | float scale = context.getResources().getDisplayMetrics().density;
47 | return (int) (pxValue / scale + 0.5f);
48 | }
49 |
50 | /**
51 | * 将px值转换为sp值,保证文字大小不变
52 | *
53 | * @param pxValue
54 | * @return
55 | */
56 |
57 | public static int px2sp(Context context, float pxValue) {
58 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
59 | return (int) (pxValue / fontScale + 0.5f);
60 | }
61 |
62 | public static int getScreenWidth(Context context) {
63 | try {
64 | final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
65 | final DisplayMetrics outMetrics = new DisplayMetrics();
66 | wm.getDefaultDisplay().getMetrics(outMetrics);
67 | return outMetrics.widthPixels;
68 | } catch (Exception e) {
69 | e.printStackTrace();
70 | }
71 |
72 | return 0;
73 | }
74 |
75 | public static int getTextWidth(String text, Paint paint){
76 | Rect rect = new Rect();
77 | paint.getTextBounds(text, 0, text.length(), rect);
78 | return rect.width();
79 | }
80 |
81 | public static int getTextHeight(String text, Paint paint){
82 | Rect rect = new Rect();
83 | paint.getTextBounds(text, 0, text.length(), rect);
84 | return rect.height();
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/java/com/google/zxing/client/android/camera/PreviewCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.client.android.camera;
18 |
19 | import android.graphics.Point;
20 | import android.hardware.Camera;
21 | import android.os.Handler;
22 | import android.os.Message;
23 | import android.util.Log;
24 |
25 | @SuppressWarnings("deprecation") // camera APIs
26 | final class PreviewCallback implements Camera.PreviewCallback {
27 |
28 | private static final String TAG = PreviewCallback.class.getSimpleName();
29 |
30 | private final CameraConfigurationManager configManager;
31 | private Handler previewHandler;
32 | private int previewMessage;
33 |
34 | PreviewCallback(CameraConfigurationManager configManager) {
35 | this.configManager = configManager;
36 | }
37 |
38 | void setHandler(Handler previewHandler, int previewMessage) {
39 | this.previewHandler = previewHandler;
40 | this.previewMessage = previewMessage;
41 | }
42 |
43 | @Override
44 | public void onPreviewFrame(byte[] data, Camera camera) {
45 | // Point cameraResolution = configManager.getCameraResolution();
46 | // Handler thePreviewHandler = previewHandler;
47 | // if (cameraResolution != null && thePreviewHandler != null) {
48 | // Message message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.x,
49 | // cameraResolution.y, data);
50 | // message.sendToTarget();
51 | // previewHandler = null;
52 | // } else {
53 | // Log.d(TAG, "Got preview callback, but no handler or resolution available");
54 | // }
55 |
56 | //改
57 | Point cameraResolution = configManager.getCameraResolution();
58 | Handler thePreviewHandler = previewHandler;
59 | if (cameraResolution != null && thePreviewHandler != null) {
60 | //2017.11.13 添加竖屏代码处理
61 | Point screenResolution = configManager.getScreenResolution();
62 | Message message;
63 | if (screenResolution.x < screenResolution.y) {
64 | // portrait
65 | message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.y,
66 | cameraResolution.x, data);
67 | } else {
68 | // landscape
69 | message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.x,
70 | cameraResolution.y, data);
71 | }
72 | message.sendToTarget();
73 | }
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
45 |
46 |
53 |
54 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/java/com/google/zxing/client/android/camera/open/OpenCameraInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.client.android.camera.open;
18 |
19 | import android.hardware.Camera;
20 | import android.util.Log;
21 |
22 | /**
23 | * Abstraction over the {@link Camera} API that helps open them and return their metadata.
24 | */
25 | @SuppressWarnings("deprecation") // camera APIs
26 | public final class OpenCameraInterface {
27 |
28 | private static final String TAG = OpenCameraInterface.class.getName();
29 |
30 | /** For {@link #open(int)}, means no preference for which camera to open. */
31 | public static final int NO_REQUESTED_CAMERA = -1;
32 |
33 | private OpenCameraInterface() {
34 | }
35 |
36 | /**
37 | * Opens the requested camera with {@link Camera#open(int)}, if one exists.
38 | *
39 | * @param cameraId camera ID of the camera to use. A negative value
40 | * or {@link #NO_REQUESTED_CAMERA} means "no preference", in which case a rear-facing
41 | * camera is returned if possible or else any camera
42 | * @return handle to {@link OpenCamera} that was opened
43 | */
44 | public static OpenCamera open(int cameraId) {
45 |
46 | int numCameras = Camera.getNumberOfCameras();
47 | if (numCameras == 0) {
48 | Log.w(TAG, "No cameras!");
49 | return null;
50 | }
51 |
52 | boolean explicitRequest = cameraId >= 0;
53 |
54 | Camera.CameraInfo selectedCameraInfo = null;
55 | int index;
56 | if (explicitRequest) {
57 | index = cameraId;
58 | selectedCameraInfo = new Camera.CameraInfo();
59 | Camera.getCameraInfo(index, selectedCameraInfo);
60 | } else {
61 | index = 0;
62 | while (index < numCameras) {
63 | Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
64 | Camera.getCameraInfo(index, cameraInfo);
65 | CameraFacing reportedFacing = CameraFacing.values()[cameraInfo.facing];
66 | if (reportedFacing == CameraFacing.BACK) {
67 | selectedCameraInfo = cameraInfo;
68 | break;
69 | }
70 | index++;
71 | }
72 | }
73 |
74 | Camera camera;
75 | if (index < numCameras) {
76 | Log.i(TAG, "Opening camera #" + index);
77 | camera = Camera.open(index);
78 | } else {
79 | if (explicitRequest) {
80 | Log.w(TAG, "Requested camera does not exist: " + cameraId);
81 | camera = null;
82 | } else {
83 | Log.i(TAG, "No camera facing " + CameraFacing.BACK + "; returning camera #0");
84 | camera = Camera.open(0);
85 | selectedCameraInfo = new Camera.CameraInfo();
86 | Camera.getCameraInfo(0, selectedCameraInfo);
87 | }
88 | }
89 |
90 | if (camera == null) {
91 | return null;
92 | }
93 | return new OpenCamera(index,
94 | camera,
95 | CameraFacing.values()[selectedCameraInfo.facing],
96 | selectedCameraInfo.orientation);
97 | }
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/res/layout/mn_scan_action_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
15 |
19 |
20 |
29 |
30 |
35 |
36 |
44 |
45 |
46 |
47 |
54 |
55 |
60 |
61 |
62 |
63 |
71 |
72 |
77 |
78 |
79 |
80 |
81 |
82 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/maning/zxingcodedemo/CustomScanActivity.java:
--------------------------------------------------------------------------------
1 | package com.maning.zxingcodedemo;
2 |
3 | import android.graphics.Bitmap;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.os.Looper;
7 |
8 | import androidx.appcompat.app.AppCompatActivity;
9 |
10 | import android.view.View;
11 | import android.widget.Toast;
12 |
13 | import com.google.zxing.client.android.model.MNScanConfig;
14 | import com.google.zxing.client.android.other.OnScanCallback;
15 | import com.google.zxing.client.android.view.ScanSurfaceView;
16 |
17 | public class CustomScanActivity extends AppCompatActivity {
18 |
19 | private ScanSurfaceView mScanSurfaceView;
20 | private Handler UIHandler = new Handler(Looper.getMainLooper());
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_scan);
26 | initView();
27 | }
28 |
29 | private void initView() {
30 | mScanSurfaceView = (ScanSurfaceView) findViewById(R.id.scan_surface_view);
31 | mScanSurfaceView.init(this);
32 | MNScanConfig scanConfig = new MNScanConfig.Builder()
33 | .setSupportZoom(true)
34 | .setFullScreenScan(true)
35 | .setSupportMultiQRCode(true)
36 | .builder();
37 | mScanSurfaceView.setScanConfig(scanConfig);
38 | mScanSurfaceView.setOnScanCallback(new OnScanCallback() {
39 | @Override
40 | public void onScanSuccess(String resultTxt, Bitmap barcode) {
41 | Toast.makeText(CustomScanActivity.this, "成功:" + resultTxt, Toast.LENGTH_SHORT).show();
42 | UIHandler.postDelayed(new Runnable() {
43 | @Override
44 | public void run() {
45 | //重新开启扫描
46 | mScanSurfaceView.restartScan();
47 | }
48 | }, 2000);
49 | }
50 |
51 | @Override
52 | public void onStopScan() {
53 | //TODO:隐藏UI布局
54 | }
55 |
56 | @Override
57 | public void onRestartScan() {
58 | //TODO:重新展示布局
59 | }
60 |
61 | @Override
62 | public void onFail(String msg) {
63 | Toast.makeText(CustomScanActivity.this, "失败:" + msg, Toast.LENGTH_SHORT).show();
64 | //关闭页面
65 | finish();
66 | }
67 | });
68 | }
69 |
70 | @Override
71 | protected void onResume() {
72 | super.onResume();
73 | mScanSurfaceView.onResume();
74 | }
75 |
76 | @Override
77 | protected void onPause() {
78 | super.onPause();
79 | mScanSurfaceView.onPause();
80 | }
81 |
82 | @Override
83 | protected void onDestroy() {
84 | super.onDestroy();
85 | mScanSurfaceView.onDestroy();
86 | mScanSurfaceView = null;
87 | UIHandler.removeCallbacksAndMessages(null);
88 | }
89 |
90 | public void restartScan(View view) {
91 | if (mScanSurfaceView != null) {
92 | mScanSurfaceView.restartScan();
93 | }
94 | }
95 |
96 | public void stopScan(View view) {
97 | if (mScanSurfaceView != null) {
98 | mScanSurfaceView.stopScan();
99 | }
100 | }
101 |
102 | @Override
103 | public void onBackPressed() {
104 | //多点扫描结果点显示,可以取消
105 | if (mScanSurfaceView != null && mScanSurfaceView.isResultPointViewShow()) {
106 | mScanSurfaceView.hideResultPointView();
107 | mScanSurfaceView.restartScan();
108 | return;
109 | }
110 | super.onBackPressed();
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | xmlns:android
14 |
15 | ^$
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | xmlns:.*
25 |
26 | ^$
27 |
28 |
29 | BY_NAME
30 |
31 |
32 |
33 |
34 |
35 |
36 | .*:id
37 |
38 | http://schemas.android.com/apk/res/android
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | .*:name
48 |
49 | http://schemas.android.com/apk/res/android
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | name
59 |
60 | ^$
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | style
70 |
71 | ^$
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | .*
81 |
82 | ^$
83 |
84 |
85 | BY_NAME
86 |
87 |
88 |
89 |
90 |
91 |
92 | .*
93 |
94 | http://schemas.android.com/apk/res/android
95 |
96 |
97 | ANDROID_ATTRIBUTE_ORDER
98 |
99 |
100 |
101 |
102 |
103 |
104 | .*
105 |
106 | .*
107 |
108 |
109 | BY_NAME
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/java/com/google/zxing/client/android/encode/EncodingUtils.java:
--------------------------------------------------------------------------------
1 | package com.google.zxing.client.android.encode;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Canvas;
5 |
6 | import com.google.zxing.BarcodeFormat;
7 | import com.google.zxing.EncodeHintType;
8 | import com.google.zxing.WriterException;
9 | import com.google.zxing.common.BitMatrix;
10 | import com.google.zxing.qrcode.QRCodeWriter;
11 | import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
12 |
13 | import java.util.HashMap;
14 | import java.util.Map;
15 |
16 | /**
17 | * Created by maning on 2017/11/9.
18 | */
19 |
20 | public class EncodingUtils {
21 |
22 |
23 | /**
24 | * 创建二维码
25 | *
26 | * @param content content
27 | * @param widthPix widthPix
28 | * @param heightPix heightPix
29 | * @param logoBm logoBm
30 | * @return 二维码
31 | */
32 | public static Bitmap createQRCode(String content, int widthPix, int heightPix, Bitmap logoBm) {
33 | try {
34 | if (content == null || "".equals(content)) {
35 | return null;
36 | }
37 | // 配置参数
38 | Map hints = new HashMap<>();
39 | hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
40 | // 容错级别
41 | hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
42 | // 图像数据转换,使用了矩阵转换
43 | BitMatrix bitMatrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, widthPix,
44 | heightPix, hints);
45 | int[] pixels = new int[widthPix * heightPix];
46 | // 下面这里按照二维码的算法,逐个生成二维码的图片,
47 | // 两个for循环是图片横列扫描的结果
48 | for (int y = 0; y < heightPix; y++) {
49 | for (int x = 0; x < widthPix; x++) {
50 | if (bitMatrix.get(x, y)) {
51 | pixels[y * widthPix + x] = 0xff000000;
52 | } else {
53 | pixels[y * widthPix + x] = 0xffffffff;
54 | }
55 | }
56 | }
57 | // 生成二维码图片的格式,使用ARGB_8888
58 | Bitmap bitmap = Bitmap.createBitmap(widthPix, heightPix, Bitmap.Config.ARGB_8888);
59 | bitmap.setPixels(pixels, 0, widthPix, 0, 0, widthPix, heightPix);
60 | if (logoBm != null) {
61 | bitmap = addLogo(bitmap, logoBm);
62 | }
63 | //必须使用compress方法将bitmap保存到文件中再进行读取。直接返回的bitmap是没有任何压缩的,内存消耗巨大!
64 | return bitmap;
65 | } catch (WriterException e) {
66 | e.printStackTrace();
67 | }
68 | return null;
69 | }
70 |
71 | /**
72 | * 在二维码中间添加Logo图案
73 | */
74 | private static Bitmap addLogo(Bitmap src, Bitmap logo) {
75 | if (src == null) {
76 | return null;
77 | }
78 | if (logo == null) {
79 | return src;
80 | }
81 | //获取图片的宽高
82 | int srcWidth = src.getWidth();
83 | int srcHeight = src.getHeight();
84 | int logoWidth = logo.getWidth();
85 | int logoHeight = logo.getHeight();
86 | if (srcWidth == 0 || srcHeight == 0) {
87 | return null;
88 | }
89 | if (logoWidth == 0 || logoHeight == 0) {
90 | return src;
91 | }
92 | //logo大小为二维码整体大小的1/5
93 | float scaleFactor = srcWidth * 1.0f / 5 / logoWidth;
94 | Bitmap bitmap = Bitmap.createBitmap(srcWidth, srcHeight, Bitmap.Config.ARGB_8888);
95 | try {
96 | Canvas canvas = new Canvas(bitmap);
97 | canvas.drawBitmap(src, 0, 0, null);
98 | canvas.scale(scaleFactor, scaleFactor, srcWidth / 2, srcHeight / 2);
99 | canvas.drawBitmap(logo, (srcWidth - logoWidth) / 2, (srcHeight - logoHeight) / 2, null);
100 | canvas.save();
101 | canvas.restore();
102 | } catch (Exception e) {
103 | bitmap = null;
104 | e.getStackTrace();
105 | }
106 | return bitmap;
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/java/com/google/zxing/client/android/decode/DecodeThread.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.client.android.decode;
18 |
19 | import android.content.SharedPreferences;
20 | import android.os.Handler;
21 | import android.os.Looper;
22 | import android.preference.PreferenceManager;
23 | import android.util.Log;
24 |
25 | import com.google.zxing.BarcodeFormat;
26 | import com.google.zxing.DecodeHintType;
27 | import com.google.zxing.ResultPointCallback;
28 | import com.google.zxing.client.android.view.ScanSurfaceView;
29 |
30 | import java.lang.ref.WeakReference;
31 | import java.util.Collection;
32 | import java.util.EnumMap;
33 | import java.util.EnumSet;
34 | import java.util.Map;
35 | import java.util.Vector;
36 | import java.util.concurrent.CountDownLatch;
37 |
38 | /**
39 | * This thread does all the heavy lifting of decoding the images.
40 | *
41 | * @author dswitkin@google.com (Daniel Switkin)
42 | */
43 | public class DecodeThread extends Thread {
44 |
45 | public static final String BARCODE_BITMAP = "barcode_bitmap";
46 | public static final String BARCODE_SCALED_FACTOR = "barcode_scaled_factor";
47 |
48 | private final Map hints;
49 | private Handler handler;
50 | private final CountDownLatch handlerInitLatch;
51 | private WeakReference mSurfaceViewRef;
52 |
53 | public DecodeThread(ScanSurfaceView surfaceView,
54 | Collection decodeFormats,
55 | Map baseHints,
56 | String characterSet,
57 | ResultPointCallback resultPointCallback) {
58 |
59 | mSurfaceViewRef = new WeakReference(surfaceView);
60 | handlerInitLatch = new CountDownLatch(1);
61 |
62 | hints = new EnumMap<>(DecodeHintType.class);
63 | if (baseHints != null) {
64 | hints.putAll(baseHints);
65 | }
66 |
67 | if (decodeFormats == null || decodeFormats.isEmpty()) {
68 | decodeFormats = new Vector();
69 | // 扫描的类型:一维码和二维码
70 | decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
71 | decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
72 | decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
73 | decodeFormats.addAll(DecodeFormatManager.AZTEC_FORMATS);
74 | decodeFormats.addAll(DecodeFormatManager.PDF417_FORMATS);
75 | }
76 | hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
77 |
78 | if (characterSet != null) {
79 | hints.put(DecodeHintType.CHARACTER_SET, characterSet);
80 | }
81 | hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
82 | Log.i("DecodeThread", "Hints: " + hints);
83 | }
84 |
85 | public Handler getHandler() {
86 | try {
87 | handlerInitLatch.await();
88 | } catch (InterruptedException ie) {
89 | // continue?
90 | }
91 | return handler;
92 | }
93 |
94 | @Override
95 | public void run() {
96 | Looper.prepare();
97 | handler = new DecodeHandler(mSurfaceViewRef, hints);
98 | handlerInitLatch.countDown();
99 | Looper.loop();
100 | }
101 |
102 | public void destroyView() {
103 | mSurfaceViewRef = null;
104 | handler.removeCallbacksAndMessages(null);
105 | handler = null;
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/libraryzxing/src/main/java/com/google/zxing/client/android/manager/InactivityTimer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.client.android.manager;
18 |
19 | import android.app.Activity;
20 | import android.content.BroadcastReceiver;
21 | import android.content.Context;
22 | import android.content.Intent;
23 | import android.content.IntentFilter;
24 | import android.os.AsyncTask;
25 | import android.os.BatteryManager;
26 | import android.util.Log;
27 |
28 | import java.util.concurrent.RejectedExecutionException;
29 |
30 | /**
31 | * Finishes an activity after a period of inactivity if the device is on battery power.
32 | */
33 | public class InactivityTimer {
34 |
35 | private static final String TAG = InactivityTimer.class.getSimpleName();
36 |
37 | private static final long INACTIVITY_DELAY_MS = 5 * 60 * 1000L;
38 |
39 | private final Activity activity;
40 | private final BroadcastReceiver powerStatusReceiver;
41 | private boolean registered;
42 | private AsyncTask