Skip to content

Commit 83a3ab2

Browse files
authored
Upstream fixes (#26)
Upstream fixes
2 parents 5e6ea1c + 7c52445 commit 83a3ab2

13 files changed

+120
-133
lines changed

android/build.gradle

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,5 @@ android {
3030

3131
dependencies {
3232
implementation project(':openCVLibrary310')
33-
implementation 'com.android.support:appcompat-v7:26.1.0'
34-
implementation 'com.facebook.react:react-native:0.19.+'
35-
implementation 'com.google.zxing:core:3.0.1'
36-
// implementation 'com.android.support:design:26.1.0'
37-
implementation 'org.piwik.sdk:piwik-sdk:0.0.4'
38-
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
39-
implementation 'us.feras.mdv:markdownview:1.1.0'
33+
implementation 'com.facebook.react:react-native:+'
4034
}

android/src/main/java/com/documentscanner/DocumentScannerModule.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
import com.facebook.react.bridge.ReactApplicationContext;
55
import com.facebook.react.bridge.ReactContextBaseJavaModule;
66
import com.facebook.react.bridge.ReactMethod;
7-
8-
/**
9-
* Created by andre on 28/11/2017.
10-
*/
7+
import com.facebook.react.uimanager.NativeViewHierarchyManager;
8+
import com.facebook.react.uimanager.UIBlock;
9+
import com.facebook.react.uimanager.UIManagerModule;
1110

1211
public class DocumentScannerModule extends ReactContextBaseJavaModule{
1312

@@ -22,8 +21,19 @@ public String getName() {
2221
}
2322

2423
@ReactMethod
25-
public void capture(){
26-
MainView view = MainView.getInstance();
27-
view.capture();
24+
public void capture(final int viewTag) {
25+
final ReactApplicationContext context = getReactApplicationContext();
26+
UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
27+
uiManager.addUIBlock(new UIBlock() {
28+
@Override
29+
public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
30+
try {
31+
MainView view = (MainView) nativeViewHierarchyManager.resolveView(viewTag);
32+
view.capture();
33+
} catch (Exception e) {
34+
e.printStackTrace();
35+
}
36+
}
37+
});
2838
}
2939
}

android/src/main/java/com/documentscanner/DocumentScannerPackage.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
import java.util.Collections;
1111
import java.util.List;
1212

13-
/**
14-
* Created by andre on 28/11/2017.
15-
*/
16-
1713
public class DocumentScannerPackage implements ReactPackage {
1814

1915

@@ -24,7 +20,7 @@ public List<NativeModule> createNativeModules(ReactApplicationContext reactConte
2420
);
2521
}
2622

27-
@Override
23+
// Deprecated in RN 0.47
2824
public List<Class<? extends JavaScriptModule>> createJSModules() {
2925
return Collections.emptyList();
3026
}

android/src/main/java/com/documentscanner/DocumentScannerViewManager.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313

1414
import javax.annotation.Nullable;
1515

16-
/**
17-
* Created by Andre on 29/11/2017.
18-
*/
19-
2016
public class DocumentScannerViewManager extends ViewGroupManager<MainView> {
2117

2218
private static final String REACT_CLASS = "RNPdfScanner";
@@ -29,11 +25,7 @@ public String getName() {
2925

3026
@Override
3127
protected MainView createViewInstance(final ThemedReactContext reactContext) {
32-
// OpenNoteCameraView view = new OpenNoteCameraView(reactContext, -1,
33-
// reactContext.getCurrentActivity());
34-
MainView.createInstance(reactContext, (Activity) reactContext.getBaseContext());
35-
36-
view = MainView.getInstance();
28+
view = new MainView(reactContext, (Activity) reactContext.getBaseContext());
3729
view.setOnProcessingListener(new OpenNoteCameraView.OnProcessingListener() {
3830
@Override
3931
public void onProcessingChange(WritableMap data) {
@@ -75,6 +67,11 @@ public void setDetectionCountBeforeCapture(MainView view, int numberOfRectangles
7567
view.setDetectionCountBeforeCapture(numberOfRectangles);
7668
}
7769

70+
@ReactProp(name = "durationBetweenCaptures", defaultDouble = 0)
71+
public void setDurationBetweenCaptures(MainView view, double durationBetweenCaptures) {
72+
view.setDurationBetweenCaptures(durationBetweenCaptures);
73+
}
74+
7875
@ReactProp(name = "enableTorch", defaultBoolean = false)
7976
public void setEnableTorch(MainView view, Boolean enable) {
8077
view.setEnableTorch(enable);

android/src/main/java/com/documentscanner/ImageProcessor.java

Lines changed: 11 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@
1313
import android.util.Log;
1414

1515
import com.documentscanner.views.OpenNoteCameraView;
16-
import com.google.zxing.BinaryBitmap;
17-
import com.google.zxing.LuminanceSource;
18-
import com.google.zxing.NotFoundException;
19-
import com.google.zxing.RGBLuminanceSource;
20-
import com.google.zxing.Result;
21-
import com.google.zxing.ResultPoint;
22-
import com.google.zxing.common.HybridBinarizer;
23-
import com.google.zxing.multi.qrcode.QRCodeMultiReader;
2416
import com.documentscanner.helpers.OpenNoteMessage;
2517
import com.documentscanner.helpers.PreviewFrame;
2618
import com.documentscanner.helpers.Quadrilateral;
@@ -56,6 +48,8 @@ public class ImageProcessor extends Handler {
5648
private Point[] mPreviewPoints;
5749
private int numOfSquares = 0;
5850
private int numOfRectangles = 10;
51+
private double lastCaptureTime = 0;
52+
private double durationBetweenCaptures = 0;
5953

6054
public ImageProcessor(Looper looper, OpenNoteCameraView mainActivity, Context context) {
6155
super(looper);
@@ -68,6 +62,10 @@ public void setNumOfRectangles(int numOfRectangles) {
6862
this.numOfRectangles = numOfRectangles;
6963
}
7064

65+
public void setDurationBetweenCaptures(double durationBetweenCaptures) {
66+
this.durationBetweenCaptures = durationBetweenCaptures;
67+
}
68+
7169
public void setBrightness(double brightness) {
7270
this.colorBias = brightness;
7371
}
@@ -99,27 +97,16 @@ private void processPreviewFrame(PreviewFrame previewFrame) {
9997

10098
Mat frame = previewFrame.getFrame();
10199

102-
Result[] results = zxing(frame);
103-
104-
for (Result result : results) {
105-
String qrText = result.getText();
106-
if (Utils.isMatch(qrText, "^P.. V.. S[0-9]+") && checkQR(qrText)) {
107-
Log.d(TAG, "QR Code valid: " + result.getText());
108-
ResultPoint[] qrResultPoints = result.getResultPoints();
109-
break;
110-
} else {
111-
Log.d(TAG, "QR Code ignored: " + result.getText());
112-
}
113-
}
114-
115100
boolean focused = mMainActivity.isFocused();
116101

117102
if (detectPreviewDocument(frame) && focused) {
118103
numOfSquares++;
119-
if (numOfSquares == numOfRectangles) {
104+
double now = (double)(new Date()).getTime() / 1000.0;
105+
if (numOfSquares == numOfRectangles && now < lastCaptureTime + durationBetweenCaptures) {
106+
lastCaptureTime = now;
107+
numOfSquares = 0;
120108
mMainActivity.requestPicture();
121109
mMainActivity.waitSpinnerVisible();
122-
numOfSquares = 0;
123110
}
124111
} else {
125112
numOfSquares = 0;
@@ -447,44 +434,8 @@ public int compare(MatOfPoint lhs, MatOfPoint rhs) {
447434
return contours;
448435
}
449436

450-
private final QRCodeMultiReader qrCodeMultiReader = new QRCodeMultiReader();
451-
452-
private Result[] zxing(Mat inputImage) {
453-
454-
int w = inputImage.width();
455-
int h = inputImage.height();
456-
457-
Mat southEast;
458-
459-
if (mBugRotate) {
460-
southEast = inputImage.submat(h - h / 4, h, 0, w / 2 - h / 4);
461-
} else {
462-
southEast = inputImage.submat(0, h / 4, w / 2 + h / 4, w);
463-
}
464-
465-
Bitmap bMap = Bitmap.createBitmap(southEast.width(), southEast.height(), Bitmap.Config.ARGB_8888);
466-
org.opencv.android.Utils.matToBitmap(southEast, bMap);
467-
southEast.release();
468-
int[] intArray = new int[bMap.getWidth() * bMap.getHeight()];
469-
// copy pixel data from the Bitmap into the 'intArray' array
470-
bMap.getPixels(intArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight());
471-
472-
LuminanceSource source = new RGBLuminanceSource(bMap.getWidth(), bMap.getHeight(), intArray);
473-
474-
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
475-
476-
Result[] results = {};
477-
try {
478-
results = qrCodeMultiReader.decodeMultiple(bitmap);
479-
} catch (NotFoundException ignored) {
480-
}
481-
482-
return results;
483-
484-
}
485-
486437
public void setBugRotate(boolean bugRotate) {
487438
mBugRotate = bugRotate;
488439
}
489440

490-
}
441+
}

android/src/main/java/com/documentscanner/views/MainView.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,7 @@
1414
public class MainView extends FrameLayout {
1515
private OpenNoteCameraView view;
1616

17-
public static MainView instance = null;
18-
19-
public static MainView getInstance() {
20-
return instance;
21-
}
22-
23-
public static void createInstance(Context context, Activity activity) {
24-
instance = new MainView(context, activity);
25-
}
26-
27-
private MainView(Context context, Activity activity) {
17+
public MainView(Context context, Activity activity) {
2818
super(context);
2919

3020
LayoutInflater lf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@@ -46,6 +36,10 @@ public void setDetectionCountBeforeCapture(int numberOfRectangles) {
4636
view.setDetectionCountBeforeCapture(numberOfRectangles);
4737
}
4838

39+
public void setDurationBetweenCaptures(double durationBetweenCaptures) {
40+
view.setDurationBetweenCaptures(durationBetweenCaptures);
41+
}
42+
4943
public void setEnableTorch(boolean enable) {
5044
view.setEnableTorch(enable);
5145
}

android/src/main/java/com/documentscanner/views/OpenNoteCameraView.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public class OpenNoteCameraView extends JavaCameraView implements PictureCallbac
7272
private PictureCallback pCallback;
7373

7474
private int numberOfRectangles = 15;
75+
private double durationBetweenCaptures = 0.0;
7576
private Boolean enableTorch = false;
7677
private String overlayColor = null;
7778
private Boolean saveOnDevice = false;
@@ -136,6 +137,10 @@ public void setDetectionCountBeforeCapture(int numberOfRectangles) {
136137
this.numberOfRectangles = numberOfRectangles;
137138
}
138139

140+
public void setDurationBetweenCaptures(double durationBetweenCaptures) {
141+
this.durationBetweenCaptures = durationBetweenCaptures;
142+
}
143+
139144
public void setEnableTorch(boolean enableTorch) {
140145
this.enableTorch = enableTorch;
141146

@@ -379,6 +384,7 @@ public void surfaceCreated(SurfaceHolder holder) {
379384
if (mImageProcessor != null) {
380385
mImageProcessor.setBugRotate(mBugRotate);
381386
mImageProcessor.setNumOfRectangles(numberOfRectangles);
387+
mImageProcessor.setDurationBetweenCaptures(durationBetweenCaptures);
382388
}
383389

384390
try {
@@ -677,4 +683,4 @@ public int parsedOverlayColor() {
677683

678684
}
679685
}
680-
}
686+
}

ios/DocumentScannerView.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
@property (nonatomic, copy) RCTBubblingEventBlock onPictureTaken;
77
@property (nonatomic, copy) RCTBubblingEventBlock onRectangleDetect;
88
@property (nonatomic, assign) NSInteger detectionCountBeforeCapture;
9-
@property (assign, nonatomic) NSInteger stableCounter;
9+
@property (nonatomic, assign) NSInteger stableCounter;
10+
@property (nonatomic, assign) double durationBetweenCaptures;
11+
@property (nonatomic, assign) double lastCaptureTime;
1012
@property (nonatomic, assign) float quality;
1113
@property (nonatomic, assign) BOOL useBase64;
1214
@property (nonatomic, assign) BOOL captureMultiple;

ios/DocumentScannerView.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ - (void) didDetectRectangle:(CIRectangleFeature *)rectangle withType:(IPDFRectan
2727
self.onRectangleDetect(@{@"stableCounter": @(self.stableCounter), @"lastDetectionType": @(type)});
2828
}
2929

30-
if (self.stableCounter > self.detectionCountBeforeCapture){
30+
if (self.stableCounter > self.detectionCountBeforeCapture &&
31+
[NSDate timeIntervalSinceReferenceDate] > self.lastCaptureTime + self.durationBetweenCaptures) {
32+
self.lastCaptureTime = [NSDate timeIntervalSinceReferenceDate];
33+
self.stableCounter = 0;
3134
[self capture];
3235
}
3336
}
@@ -51,7 +54,7 @@ - (void) capture {
5154
while rectangleFeature returns a rectangle viewed from landscape, which explains the nonsense of the mapping below.
5255
Sorry about that.
5356
*/
54-
NSDictionary *rectangleCoordinates = rectangleFeature ? @{
57+
id rectangleCoordinates = rectangleFeature ? @{
5558
@"topLeft": @{ @"y": @(rectangleFeature.bottomLeft.x + 30), @"x": @(rectangleFeature.bottomLeft.y)},
5659
@"topRight": @{ @"y": @(rectangleFeature.topLeft.x + 30), @"x": @(rectangleFeature.topLeft.y)},
5760
@"bottomLeft": @{ @"y": @(rectangleFeature.bottomRight.x), @"x": @(rectangleFeature.bottomRight.y)},

ios/IPDFCameraViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ typedef NS_ENUM(NSInteger, IPDFRectangeType)
4242

4343
@property (nonatomic,assign) IPDFCameraViewType cameraViewType;
4444

45-
- (void)focusAtPoint:(CGPoint)point completionHandler:(void(^)())completionHandler;
45+
- (void)focusAtPoint:(CGPoint)point completionHandler:(void(^)(void))completionHandler;
4646

4747
- (void)captureImageWithCompletionHander:(void(^)(UIImage *data, UIImage *initialData, CIRectangleFeature *rectangleFeature))completionHandler;
4848

0 commit comments

Comments
 (0)