From 87a437a4d69e1154fba561afe97c30341e468579 Mon Sep 17 00:00:00 2001 From: Patrick Fekete Date: Thu, 28 Oct 2021 11:19:31 +0200 Subject: [PATCH 1/3] Add config for rotate button --- .../java/com/anyline/reactnative/Offset.java | 21 ++++++++++++++++++ .../reactnative/RotateButtonConfig.java | 22 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 plugin/android/src/main/java/com/anyline/reactnative/Offset.java create mode 100644 plugin/android/src/main/java/com/anyline/reactnative/RotateButtonConfig.java diff --git a/plugin/android/src/main/java/com/anyline/reactnative/Offset.java b/plugin/android/src/main/java/com/anyline/reactnative/Offset.java new file mode 100644 index 00000000..0491d2e1 --- /dev/null +++ b/plugin/android/src/main/java/com/anyline/reactnative/Offset.java @@ -0,0 +1,21 @@ +package com.anyline.reactnative; + +import org.json.JSONObject; + +public class Offset { + private int x; + private int y; + + public Offset(JSONObject jsonObject) { + this.x = jsonObject.optInt("x", 0); + this.y = jsonObject.optInt("y", 0); + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } +} \ No newline at end of file diff --git a/plugin/android/src/main/java/com/anyline/reactnative/RotateButtonConfig.java b/plugin/android/src/main/java/com/anyline/reactnative/RotateButtonConfig.java new file mode 100644 index 00000000..56c3f9dc --- /dev/null +++ b/plugin/android/src/main/java/com/anyline/reactnative/RotateButtonConfig.java @@ -0,0 +1,22 @@ +package com.anyline.reactnative; + +import org.json.JSONException; +import org.json.JSONObject; + +public class RotateButtonConfig { + private Offset offset = null; + + public RotateButtonConfig(JSONObject jsonObject) throws JSONException { + if (jsonObject.has("offset")) { + offset = new Offset(jsonObject.getJSONObject("offset")); + } + } + + public Offset getOffset() { + return offset; + } + + public boolean hasOffset() { + return offset != null; + } +} \ No newline at end of file From c2450722afc0c68a24a855a5f58d0258cfd2c876 Mon Sep 17 00:00:00 2001 From: Patrick Fekete Date: Thu, 28 Oct 2021 11:19:48 +0200 Subject: [PATCH 2/3] Show rotate button if config is available --- .../anyline/reactnative/Anyline4Activity.java | 91 +++++++++++++------ 1 file changed, 62 insertions(+), 29 deletions(-) diff --git a/plugin/android/src/main/java/com/anyline/reactnative/Anyline4Activity.java b/plugin/android/src/main/java/com/anyline/reactnative/Anyline4Activity.java index d3593fa3..ffba3df6 100644 --- a/plugin/android/src/main/java/com/anyline/reactnative/Anyline4Activity.java +++ b/plugin/android/src/main/java/com/anyline/reactnative/Anyline4Activity.java @@ -1,5 +1,6 @@ package com.anyline.reactnative; +import android.content.pm.ActivityInfo; import android.content.res.ColorStateList; import android.graphics.Rect; import android.os.Build; @@ -7,6 +8,7 @@ import android.os.Handler; import android.util.Log; import android.view.View; +import android.widget.Button; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.RelativeLayout; @@ -56,7 +58,6 @@ import io.anyline.view.ScanView; import io.anyline.view.SerialScanViewComposite; -//import at.nineyards.anyline.modules.mrz.Identification; public class Anyline4Activity extends AnylineBaseActivity { private static final String TAG = Anyline4Activity.class.getSimpleName(); @@ -67,6 +68,7 @@ public class Anyline4Activity extends AnylineBaseActivity { private AnylineUIConfig anylineUIConfig; private String cropAndTransformError; private Boolean isFirstCameraOpen; // only if camera is opened the first time get coordinates of the cutout to avoid flickering when switching between analog and digital + private RelativeLayout parentLayout; @Override protected void onCreate(Bundle savedInstanceState) { @@ -76,6 +78,13 @@ protected void onCreate(Bundle savedInstanceState) { // init the scan view anylineScanView = new ScanView(this, null); + parentLayout = new RelativeLayout(this); + + RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( + RelativeLayout.LayoutParams.MATCH_PARENT, + RelativeLayout.LayoutParams.MATCH_PARENT); + parentLayout.addView(anylineScanView, layoutParams); + setContentView(parentLayout, layoutParams); try { // start initialize anyline @@ -157,14 +166,15 @@ private void initAnyline() { scanViewPlugin = anylineScanView.getScanViewPlugin(); } + if (shouldShowRotateButton(json)) { + RotateButtonConfig rotateButtonConfig = new RotateButtonConfig(json.getJSONObject("rotateButton")); + addRotateButtonToView(rotateButtonConfig); + } + if (scanViewPlugin != null) { //set nativeBarcodeMode AnylinePluginHelper.setNativeBarcodeMode(json, anylineScanView); - if (!(scanViewPlugin instanceof MeterScanViewPlugin)) { - setContentView(anylineScanView); - } - if (scanViewPlugin instanceof SerialScanViewComposite || scanViewPlugin instanceof ParallelScanViewComposite) { scanViewPlugin.addScanResultListener(new ScanResultListener() { @Override @@ -276,7 +286,6 @@ public void onResult(ScanResult result) { }); } else if (scanViewPlugin instanceof LicensePlateScanViewPlugin) { if (json.has("reportingEnabled")) { - //(IdScanViewPlugin) scanViewPlugin.setReportingEnabled(json.optBoolean("reportingEnabled", true)); (((IdScanViewPlugin) scanViewPlugin).getScanPlugin()).setReportingEnabled(json.optBoolean("reportingEnabled", true)); } scanViewPlugin.addScanResultListener(new ScanResultListener() { @@ -336,13 +345,11 @@ public void onResult(ScanResult idScanResult) { } }); - } else if (((IdScanPlugin) ((IdScanViewPlugin) scanViewPlugin).getScanPlugin()) - .getIdConfig() instanceof DrivingLicenseConfig) { + } else if (((IdScanPlugin) ((IdScanViewPlugin) scanViewPlugin).getScanPlugin()).getIdConfig() instanceof DrivingLicenseConfig) { scanViewPlugin.addScanResultListener(new ScanResultListener>() { @Override public void onResult(ScanResult idScanResult) { - JSONObject jsonResult = ((DrivingLicenseIdentification) idScanResult.getResult()) - .toJSONObject(); + JSONObject jsonResult = ((DrivingLicenseIdentification) idScanResult.getResult()).toJSONObject(); try { jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, idScanResult, @@ -395,7 +402,6 @@ public void onResult(ScanResult idScanResult) { } } else if (scanViewPlugin instanceof OcrScanViewPlugin) { if (json.has("reportingEnabled")) { - //scanViewPlugin.setReportingEnabled(json.optBoolean("reportingEnabled", true)); (((OcrScanViewPlugin) scanViewPlugin).getScanPlugin()).setReportingEnabled(json.optBoolean("reportingEnabled", true)); } @@ -451,12 +457,11 @@ public void onResult(BarcodeScanResult barcodeScanResult) { } else if (scanViewPlugin instanceof MeterScanViewPlugin) { if (json.has("reportingEnabled")) { - //scanViewPlugin.setReportingEnabled(json.optBoolean("reportingEnabled", true)); (((MeterScanViewPlugin) scanViewPlugin).getScanPlugin()).setReportingEnabled(json.optBoolean("reportingEnabled", true)); } // create the radio button for the UI - createSegmentRadioButtonUI(json); + addSegmentRadioButtonUI(json); anylineScanView.setCameraOpenListener(this); scanViewPlugin.addScanResultListener(new ScanResultListener() { @@ -523,20 +528,21 @@ public void run() { }); } - private void createSegmentRadioButtonUI(JSONObject json) { - + private void addSegmentRadioButtonUI(JSONObject json) { final String scanModeString = ((MeterScanViewPlugin) scanViewPlugin).getScanMode().toString(); anylineUIConfig = new AnylineUIConfig(this, json); - // Creating a new RelativeLayout - final RelativeLayout relativeLayout = new RelativeLayout(this); + RadioGroup radioGroup = createRadioGroup(anylineUIConfig, scanModeString); - // Defining the RelativeLayout layout parameters. - // In this case I want to fill its parent - RelativeLayout.LayoutParams matchParentParams = new RelativeLayout.LayoutParams( - RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); - relativeLayout.addView(anylineScanView, matchParentParams); + if (radioGroup != null) { + RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, + RelativeLayout.LayoutParams.WRAP_CONTENT); + lp.addRule(RelativeLayout.ALIGN_PARENT_TOP); + parentLayout.addView(radioGroup, lp); + } + } + private RadioGroup createRadioGroup(AnylineUIConfig anylineUIConfig, String scanModeString) { ArrayList titles = anylineUIConfig.getTitles(); final ArrayList modes = anylineUIConfig.getModes(); @@ -573,7 +579,6 @@ public void onCheckedChanged(RadioGroup group, int checkedId) { View button = group.findViewById(checkedId); String mode = modes.get(group.indexOfChild(button)); ((MeterScanViewPlugin) scanViewPlugin).setScanMode(MeterScanMode.valueOf(mode)); - //anylineScanView.releaseCameraInBackground(); anylineScanView.stop(); try { Thread.sleep(100); @@ -584,16 +589,44 @@ public void onCheckedChanged(RadioGroup group, int checkedId) { } }); - RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, - RelativeLayout.LayoutParams.WRAP_CONTENT); - lp.addRule(RelativeLayout.ALIGN_PARENT_TOP); - radioGroup.setVisibility(View.INVISIBLE); + return radioGroup; + } + return null; + } + + private void addRotateButtonToView(RotateButtonConfig rotateButtonConfig) { + Button button = new Button(this); + button.setText("Rotate"); + button.setOnClickListener(new View.OnClickListener() { - relativeLayout.addView(radioGroup, lp); + @Override + public void onClick(View v) { + if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } else if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } + } + }); + + RelativeLayout.LayoutParams buttonLayoutParams = new RelativeLayout.LayoutParams( + RelativeLayout.LayoutParams.WRAP_CONTENT, + RelativeLayout.LayoutParams.WRAP_CONTENT); + + if (rotateButtonConfig.hasOffset()) { + Offset offset = rotateButtonConfig.getOffset(); + buttonLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); + buttonLayoutParams.setMargins(offset.getX(), offset.getY(), 0, 0); + } else { + buttonLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); + buttonLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL); } - setContentView(relativeLayout, matchParentParams); + parentLayout.addView(button, buttonLayoutParams); } + private boolean shouldShowRotateButton(JSONObject jsonObject) { + return jsonObject.has("rotateButton"); + } } From 42a93a94f14c0bbfc816ef3397001a766ba71ebf Mon Sep 17 00:00:00 2001 From: Patrick Fekete Date: Thu, 28 Oct 2021 16:13:29 +0200 Subject: [PATCH 3/3] Update version to 34.0.1 --- example/RNExampleApp/package.json | 2 +- plugin/package.json | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/example/RNExampleApp/package.json b/example/RNExampleApp/package.json index b5ee1c33..9cded1da 100644 --- a/example/RNExampleApp/package.json +++ b/example/RNExampleApp/package.json @@ -1,6 +1,6 @@ { "name": "RNExampleApp", - "version": "34.0.0", + "version": "34.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", diff --git a/plugin/package.json b/plugin/package.json index c275c0d7..be65b011 100644 --- a/plugin/package.json +++ b/plugin/package.json @@ -1,6 +1,6 @@ { - "_from": "anyline-ocr-react-native-module@^34.0.0", - "_id": "anyline-ocr-react-native-module@34.0.0", + "_from": "anyline-ocr-react-native-module@^34.0.1", + "_id": "anyline-ocr-react-native-module@34.0.1", "_inBundle": false, "_integrity": "sha512-BGi9zNkSsoxXywDBIqzgBRvKUBniQOJHDKBrozZubKthZNRBAj8Ry5tW0Me0yLXt/fauME//hbC0wsenfPJZqw==", "_location": "/anyline-ocr-react-native-module", @@ -8,19 +8,19 @@ "_requested": { "type": "range", "registry": true, - "raw": "anyline-ocr-react-native-module@^34.0.0", + "raw": "anyline-ocr-react-native-module@^34.0.1", "name": "anyline-ocr-react-native-module", "escapedName": "anyline-ocr-react-native-module", - "rawSpec": "^34.0.0", + "rawSpec": "^34.0.1", "saveSpec": null, - "fetchSpec": "^34.0.0" + "fetchSpec": "^34.0.1" }, "_requiredBy": [ "/" ], - "_resolved": "https://registry.npmjs.org/anyline-ocr-react-native-module/-/anyline-ocr-react-native-module-34.0.0.tgz", - "_shasum": "62ab2a6c30e365851e5c6951546576a711d9183e", - "_spec": "anyline-ocr-react-native-module@^34.0.0", + "_resolved": "https://registry.npmjs.org/anyline-ocr-react-native-module/-/anyline-ocr-react-native-module-34.0.1.tgz", + "_shasum": "bacbcd260cc662244f59393ed81a6edba009b52c", + "_spec": "anyline-ocr-react-native-module@^34.0.1", "_where": "/Users/amiransari/Projects/anyline-ocr-react-native-module1/example/RNExampleApp", "bugs": { "url": "https://github.com/Anyline/anyline-ocr-react-native-module/issues" @@ -47,5 +47,5 @@ "type": "git", "url": "git+https://github.com/Anyline/anyline-ocr-react-native-module.git" }, - "version": "34.0.0" + "version": "34.0.1" }