Skip to content

Commit 49f63e8

Browse files
Add support for overlayColor
1 parent a9c506e commit 49f63e8

File tree

4 files changed

+225
-224
lines changed

4 files changed

+225
-224
lines changed

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Created by Andre on 29/11/2017.
1818
*/
1919

20-
public class DocumentScannerViewManager extends ViewGroupManager<MainView>{
20+
public class DocumentScannerViewManager extends ViewGroupManager<MainView> {
2121

2222
public static final String REACT_CLASS = "RNPdfScanner";
2323
private MainView view = null;
@@ -29,8 +29,9 @@ public String getName() {
2929

3030
@Override
3131
protected MainView createViewInstance(final ThemedReactContext reactContext) {
32-
//OpenNoteCameraView view = new OpenNoteCameraView(reactContext, -1, reactContext.getCurrentActivity());
33-
MainView.createInstance(reactContext,(Activity) reactContext.getBaseContext());
32+
// OpenNoteCameraView view = new OpenNoteCameraView(reactContext, -1,
33+
// reactContext.getCurrentActivity());
34+
MainView.createInstance(reactContext, (Activity) reactContext.getBaseContext());
3435

3536
view = MainView.getInstance();
3637
view.setOnProcessingListener(new OpenNoteCameraView.OnProcessingListener() {
@@ -43,10 +44,10 @@ public void onProcessingChange(WritableMap data) {
4344
view.setOnScannerListener(new OpenNoteCameraView.OnScannerListener() {
4445
@Override
4546
public void onPictureTaken(WritableMap data) {
46-
dispatchEvent(reactContext,"onPictureTaken", data);
47+
dispatchEvent(reactContext, "onPictureTaken", data);
4748
}
4849
});
49-
50+
5051
return view;
5152
}
5253

@@ -55,42 +56,42 @@ private void dispatchEvent(ReactContext reactContext, String eventName, @Nullabl
5556
}
5657

5758
@ReactProp(name = "documentAnimation", defaultBoolean = false)
58-
public void setDocumentAnimation(MainView view, boolean animate){
59+
public void setDocumentAnimation(MainView view, boolean animate) {
5960
view.setDocumentAnimation(animate);
6061
}
6162

62-
@ReactProp(name="overlayColor")
63-
public void setOverlayColor(MainView view, String rgbaColor){
64-
63+
@ReactProp(name = "overlayColor")
64+
public void setOverlayColor(MainView view, String rgbaColor) {
65+
view.setOverlayColor(rgbaColor);
6566
}
6667

6768
@ReactProp(name = "detectionCountBeforeCapture", defaultInt = 15)
68-
public void setDetectionCountBeforeCapture(MainView view, int numberOfRectangles){
69+
public void setDetectionCountBeforeCapture(MainView view, int numberOfRectangles) {
6970
view.setDetectionCountBeforeCapture(numberOfRectangles);
7071
}
7172

7273
@ReactProp(name = "enableTorch", defaultBoolean = false)
73-
public void setEnableTorch(MainView view, Boolean enable){
74+
public void setEnableTorch(MainView view, Boolean enable) {
7475
view.setEnableTorch(enable);
7576
}
7677

77-
@ReactProp(name="manualOnly", defaultBoolean = false)
78-
public void setManualOnly(MainView view, Boolean manualOnly){
78+
@ReactProp(name = "manualOnly", defaultBoolean = false)
79+
public void setManualOnly(MainView view, Boolean manualOnly) {
7980
view.setManualOnly(manualOnly);
8081
}
8182

82-
@ReactProp(name="brightness", defaultDouble = 10)
83-
public void setBrightness(MainView view, double brightness){
83+
@ReactProp(name = "brightness", defaultDouble = 10)
84+
public void setBrightness(MainView view, double brightness) {
8485
view.setBrightness(brightness);
8586
}
8687

87-
@ReactProp(name="contrast", defaultDouble = 1)
88-
public void setContrast(MainView view, double contrast){
88+
@ReactProp(name = "contrast", defaultDouble = 1)
89+
public void setContrast(MainView view, double contrast) {
8990
view.setContrast(contrast);
9091
}
9192

92-
@ReactProp(name="noGrayScale", defaultBoolean = false)
93-
public void setRemoveGrayScale(MainView view, boolean bw){
93+
@ReactProp(name = "noGrayScale", defaultBoolean = false)
94+
public void setRemoveGrayScale(MainView view, boolean bw) {
9495
view.setRemoveGrayScale(bw);
9596
}
9697

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

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,7 @@ public void processPicture(Mat picture) {
186186

187187
mMainActivity.getHUD().clear();
188188
mMainActivity.invalidateHUD();
189-
mMainActivity.saveDocument(
190-
doc
191-
);
189+
mMainActivity.saveDocument(doc);
192190
doc.release();
193191
picture.release();
194192

@@ -215,8 +213,7 @@ private ScannedDocument detectDocument(Mat inputRgba) {
215213

216214
sd.originalPoints = new Point[4];
217215

218-
219-
sd.originalPoints[0] = new Point(sd.widthWithRatio - quad.points[3].y,quad.points[3].x); // Topleft
216+
sd.originalPoints[0] = new Point(sd.widthWithRatio - quad.points[3].y, quad.points[3].x); // Topleft
220217
sd.originalPoints[1] = new Point(sd.widthWithRatio - quad.points[0].y, quad.points[0].x); // TopRight
221218
sd.originalPoints[2] = new Point(sd.widthWithRatio - quad.points[1].y, quad.points[1].x); // BottomRight
222219
sd.originalPoints[3] = new Point(sd.widthWithRatio - quad.points[2].y, quad.points[2].x); // BottomLeft
@@ -309,10 +306,10 @@ private void drawDocumentBox(Point[] points, Size stdSize) {
309306
PathShape newBox = new PathShape(path, previewWidth, previewHeight);
310307

311308
Paint paint = new Paint();
312-
paint.setColor(Color.argb(180, 66, 165, 245));
309+
paint.setColor(mMainActivity.parsedOverlayColor());
313310

314311
Paint border = new Paint();
315-
border.setColor(Color.rgb(66, 165, 245));
312+
border.setColor(mMainActivity.parsedOverlayColor());
316313
border.setStrokeWidth(5);
317314

318315
hud.clear();
@@ -391,30 +388,22 @@ private boolean insideArea(Point[] rp, Size size) {
391388

392389
int width = Double.valueOf(size.width).intValue();
393390
int height = Double.valueOf(size.height).intValue();
394-
391+
395392
int minimumSize = width / 10;
396393

397394
boolean isANormalShape = rp[0].x != rp[1].x && rp[1].y != rp[0].y && rp[2].y != rp[3].y && rp[3].x != rp[2].x;
398-
boolean isBigEnough = (
399-
(rp[1].x - rp[0].x >= minimumSize) &&
400-
(rp[2].x - rp[3].x >= minimumSize) &&
401-
(rp[3].y - rp[0].y >= minimumSize) &&
402-
(rp[2].y - rp[1].y >= minimumSize)
403-
);
404-
395+
boolean isBigEnough = ((rp[1].x - rp[0].x >= minimumSize) && (rp[2].x - rp[3].x >= minimumSize)
396+
&& (rp[3].y - rp[0].y >= minimumSize) && (rp[2].y - rp[1].y >= minimumSize));
397+
405398
double leftOffset = rp[0].x - rp[3].x;
406399
double rightOffset = rp[1].x - rp[2].x;
407400
double bottomOffset = rp[0].y - rp[1].y;
408401
double topOffset = rp[2].y - rp[3].y;
409402

410-
boolean isAnActualRectangle = (
411-
(leftOffset <= minimumSize && leftOffset >= -minimumSize) &&
412-
(rightOffset <= minimumSize && rightOffset >= -minimumSize) &&
413-
(bottomOffset <= minimumSize && bottomOffset >= -minimumSize) &&
414-
(topOffset <= minimumSize && topOffset >= -minimumSize)
415-
);
416-
417-
403+
boolean isAnActualRectangle = ((leftOffset <= minimumSize && leftOffset >= -minimumSize)
404+
&& (rightOffset <= minimumSize && rightOffset >= -minimumSize)
405+
&& (bottomOffset <= minimumSize && bottomOffset >= -minimumSize)
406+
&& (topOffset <= minimumSize && topOffset >= -minimumSize));
418407

419408
return isANormalShape && isAnActualRectangle && isBigEnough;
420409
}

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,79 +11,83 @@
1111
* Created by andre on 09/01/2018.
1212
*/
1313

14-
public class MainView extends FrameLayout{
14+
public class MainView extends FrameLayout {
1515
private OpenNoteCameraView view = null;
1616
private FrameLayout frameLayout = null;
1717

1818
public static MainView instance = null;
1919

20-
public static MainView getInstance(){
20+
public static MainView getInstance() {
2121
return instance;
2222
}
2323

24-
public static void createInstance(Context context, Activity activity){
24+
public static void createInstance(Context context, Activity activity) {
2525
instance = new MainView(context, activity);
2626
}
2727

2828
private MainView(Context context, Activity activity) {
2929
super(context);
3030

3131
LayoutInflater lf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
32-
this.frameLayout = (FrameLayout) lf.inflate(R.layout.activity_open_note_scanner,null);
33-
//OpenNoteCameraView.createInstance(context, -1, activity, frameLayout);
32+
this.frameLayout = (FrameLayout) lf.inflate(R.layout.activity_open_note_scanner, null);
33+
// OpenNoteCameraView.createInstance(context, -1, activity, frameLayout);
3434

3535
view = new OpenNoteCameraView(context, -1, activity, frameLayout);
36-
addViewInLayout(view,0,new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
37-
addViewInLayout(frameLayout,1,view.getLayoutParams());
36+
addViewInLayout(view, 0, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
37+
addViewInLayout(frameLayout, 1, view.getLayoutParams());
3838
}
3939

4040
@Override
4141
protected void onLayout(boolean changed, int l, int t, int r, int b) {
42-
for(int i = 0 ; i < getChildCount() ; i++){
42+
for (int i = 0; i < getChildCount(); i++) {
4343
getChildAt(i).layout(l, t, r, b);
4444
}
4545
}
4646

47-
public void setDocumentAnimation(boolean animate){
47+
public void setDocumentAnimation(boolean animate) {
4848
view.setDocumentAnimation(animate);
4949
}
5050

51-
public void setDetectionCountBeforeCapture(int numberOfRectangles){
51+
public void setDetectionCountBeforeCapture(int numberOfRectangles) {
5252
view.setDetectionCountBeforeCapture(numberOfRectangles);
5353
}
5454

55-
public void setEnableTorch(boolean enable){
55+
public void setEnableTorch(boolean enable) {
5656
view.setEnableTorch(enable);
5757
}
5858

59-
public void setOnScannerListener(OpenNoteCameraView.OnScannerListener listener){
59+
public void setOnScannerListener(OpenNoteCameraView.OnScannerListener listener) {
6060
view.setOnScannerListener(listener);
6161
}
62-
public void removeOnScannerListener(){
62+
63+
public void removeOnScannerListener() {
6364
view.removeOnScannerListener();
6465
}
6566

66-
public void setOnProcessingListener(OpenNoteCameraView.OnProcessingListener listener){
67+
public void setOnProcessingListener(OpenNoteCameraView.OnProcessingListener listener) {
6768
view.setOnProcessingListener(listener);
6869
}
69-
public void removeOnProcessingListener(){
70+
71+
public void removeOnProcessingListener() {
7072
view.removeOnProcessingListener();
7173
}
7274

73-
public void setOverlayColor(String rgbaColor){
74-
75+
public void setOverlayColor(String rgbaColor) {
76+
view.setOverlayColor(rgbaColor);
7577
}
7678

77-
public void setBrightness(double brightness){
79+
public void setBrightness(double brightness) {
7880
view.setBrightness(brightness);
7981
}
8082

81-
public void setContrast(double contrast){
83+
public void setContrast(double contrast) {
8284
view.setContrast(contrast);
8385
}
84-
public void setManualOnly(boolean manualOnly){
86+
87+
public void setManualOnly(boolean manualOnly) {
8588
view.setManualOnly(manualOnly);
8689
}
90+
8791
public void setRemoveGrayScale(boolean grayscale) {
8892
view.setRemoveGrayScale(grayscale);
8993
}

0 commit comments

Comments
 (0)