Skip to content

Commit 8767fa2

Browse files
committed
1.3.0
1 parent ac3822f commit 8767fa2

File tree

7 files changed

+49
-6
lines changed

7 files changed

+49
-6
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## 1.3.0
2+
- add huawei sdk for android decoder
13
## 1.2.0
24
- fix android decode qrcode from image
35
## 1.1.1

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# scan
22

3-
flutter widget to scan qrcode customly.
3+
scan qrcode in widget tree.
44

5-
Get qrcode from image.
5+
decode qrcode image from path.
66

77
> if you want to generate qrcode image, you should use [qr_flutter](https://pub.dev/packages/qr_flutter)
88

android/build.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ buildscript {
55
repositories {
66
google()
77
jcenter()
8+
maven {url 'https://developer.huawei.com/repo/'}
89
}
910

1011
dependencies {
@@ -16,6 +17,7 @@ rootProject.allprojects {
1617
repositories {
1718
google()
1819
jcenter()
20+
maven {url 'https://developer.huawei.com/repo/'}
1921
}
2022
}
2123

@@ -37,4 +39,6 @@ dependencies {
3739
implementation('com.journeyapps:zxing-android-embedded:4.1.0') { transitive = false }
3840
implementation 'androidx.appcompat:appcompat:1.2.0'
3941
implementation 'com.google.zxing:core:3.3.0'
42+
// implementation 'com.huawei.hms:scanplus:1.3.1.300'
43+
implementation 'com.huawei.hms:scan:1.3.1.300'
4044
}

android/src/main/java/com/chavesgu/scan/QRCodeDecoder.java

+17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.chavesgu.scan;
22

3+
import android.content.Context;
34
import android.graphics.Bitmap;
45
import android.graphics.BitmapFactory;
56
import android.util.Log;
@@ -17,6 +18,9 @@
1718
import com.google.zxing.RGBLuminanceSource;
1819
import com.google.zxing.common.GlobalHistogramBinarizer;
1920
import com.google.zxing.common.HybridBinarizer;
21+
import com.huawei.hms.hmsscankit.ScanUtil;
22+
import com.huawei.hms.ml.scan.HmsScan;
23+
import com.huawei.hms.ml.scan.HmsScanAnalyzerOptions;
2024

2125
import java.util.ArrayList;
2226
import java.util.Arrays;
@@ -199,4 +203,17 @@ private static void encodeYUV420SP(byte[] yuv420sp, int[] argb, int width, int h
199203
}
200204
}
201205
}
206+
207+
208+
public static String decodeQRCode(Context context, String path) {
209+
Bitmap bitmap = BitmapFactory.decodeFile(path);
210+
211+
HmsScanAnalyzerOptions options = new HmsScanAnalyzerOptions.Creator().setPhotoMode(true).create();
212+
HmsScan[] hmsScans = ScanUtil.decodeWithBitmap(context, bitmap, options);
213+
214+
if (hmsScans != null && hmsScans.length > 0) {
215+
return hmsScans[0].getOriginalValue();
216+
}
217+
return syncDecodeQRCode(path);
218+
}
202219
}

android/src/main/java/com/chavesgu/scan/ScanPlugin.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import android.graphics.Bitmap;
55
import android.graphics.BitmapFactory;
66
import android.os.AsyncTask;
7+
import android.os.Build;
8+
import android.os.VibrationEffect;
9+
import android.os.Vibrator;
710

811
import com.google.zxing.BarcodeFormat;
912
import com.google.zxing.BinaryBitmap;
@@ -34,6 +37,8 @@
3437
import io.flutter.plugin.common.MethodChannel.Result;
3538
import io.flutter.plugin.common.PluginRegistry.Registrar;
3639

40+
import static android.content.Context.VIBRATOR_SERVICE;
41+
3742
/** ScanPlugin */
3843
public class ScanPlugin implements FlutterPlugin, MethodCallHandler, ActivityAware {
3944
private MethodChannel channel;
@@ -113,7 +118,7 @@ public QrCodeAsyncTask(ScanPlugin plugin, String path) {
113118
@Override
114119
protected String doInBackground(String... strings) {
115120
// 解析二维码/条码
116-
return QRCodeDecoder.syncDecodeQRCode(path);
121+
return QRCodeDecoder.decodeQRCode(mWeakReference.get().flutterPluginBinding.getApplicationContext(), path);
117122
}
118123

119124
@Override
@@ -124,6 +129,16 @@ protected void onPostExecute(String s) {
124129
plugin._result.success(s);
125130
plugin.task.cancel(true);
126131
plugin.task = null;
132+
if (s!=null) {
133+
Vibrator myVib = (Vibrator) plugin.flutterPluginBinding.getApplicationContext().getSystemService(VIBRATOR_SERVICE);
134+
if (myVib != null) {
135+
if (Build.VERSION.SDK_INT >= 26) {
136+
myVib.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE));
137+
} else {
138+
myVib.vibrate(50);
139+
}
140+
}
141+
}
127142
}
128143
}
129144
}

android/src/main/java/com/chavesgu/scan/ScanViewNew.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.content.pm.ActivityInfo;
88
import android.os.Build;
99
import android.os.Bundle;
10+
import android.os.VibrationEffect;
1011
import android.os.Vibrator;
1112
import android.util.AttributeSet;
1213
import android.util.Log;
@@ -66,7 +67,11 @@ public void barcodeResult(BarcodeResult result) {
6667
captureListener.onCapture(result.getText());
6768
Vibrator myVib = (Vibrator) context.getSystemService(VIBRATOR_SERVICE);
6869
if (myVib != null) {
69-
myVib.vibrate(50);
70+
if (Build.VERSION.SDK_INT >= 26) {
71+
myVib.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE));
72+
} else {
73+
myVib.vibrate(50);
74+
}
7075
}
7176
}
7277
});

pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: scan
2-
description: flutter widget to scan qrcode customly.Get qrcode from image path.
3-
version: 1.2.0
2+
description: scan qrcode in widget tree.decode qrcode image from path.
3+
version: 1.3.0
44
homepage: https://github.com/chavesgu/FlutterScan
55

66
environment:

0 commit comments

Comments
 (0)