Skip to content

Commit

Permalink
Merge pull request #122 from Anyline/release/34.0.1
Browse files Browse the repository at this point in the history
Release/34.0.1
  • Loading branch information
patrickAnyline authored Oct 28, 2021
2 parents 542ab9c + 42a93a9 commit 584b3ae
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 39 deletions.
2 changes: 1 addition & 1 deletion example/RNExampleApp/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.anyline.reactnative;

import android.content.pm.ActivityInfo;
import android.content.res.ColorStateList;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
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;
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<LicensePlateScanResult>() {
Expand Down Expand Up @@ -336,13 +345,11 @@ public void onResult(ScanResult<ID> idScanResult) {
}

});
} else if (((IdScanPlugin) ((IdScanViewPlugin) scanViewPlugin).getScanPlugin())
.getIdConfig() instanceof DrivingLicenseConfig) {
} else if (((IdScanPlugin) ((IdScanViewPlugin) scanViewPlugin).getScanPlugin()).getIdConfig() instanceof DrivingLicenseConfig) {
scanViewPlugin.addScanResultListener(new ScanResultListener<ScanResult<ID>>() {
@Override
public void onResult(ScanResult<ID> idScanResult) {
JSONObject jsonResult = ((DrivingLicenseIdentification) idScanResult.getResult())
.toJSONObject();
JSONObject jsonResult = ((DrivingLicenseIdentification) idScanResult.getResult()).toJSONObject();

try {
jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, idScanResult,
Expand Down Expand Up @@ -395,7 +402,6 @@ public void onResult(ScanResult<ID> idScanResult) {
}
} else if (scanViewPlugin instanceof OcrScanViewPlugin) {
if (json.has("reportingEnabled")) {
//scanViewPlugin.setReportingEnabled(json.optBoolean("reportingEnabled", true));
(((OcrScanViewPlugin) scanViewPlugin).getScanPlugin()).setReportingEnabled(json.optBoolean("reportingEnabled", true));
}

Expand Down Expand Up @@ -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<MeterScanResult>() {
Expand Down Expand Up @@ -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<String> titles = anylineUIConfig.getTitles();
final ArrayList<String> modes = anylineUIConfig.getModes();

Expand Down Expand Up @@ -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);
Expand All @@ -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");
}
}
21 changes: 21 additions & 0 deletions plugin/android/src/main/java/com/anyline/reactnative/Offset.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
18 changes: 9 additions & 9 deletions plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"_from": "anyline-ocr-react-native-module@^34.0.0",
"_id": "[email protected].0",
"_from": "anyline-ocr-react-native-module@^34.0.1",
"_id": "[email protected].1",
"_inBundle": false,
"_integrity": "sha512-BGi9zNkSsoxXywDBIqzgBRvKUBniQOJHDKBrozZubKthZNRBAj8Ry5tW0Me0yLXt/fauME//hbC0wsenfPJZqw==",
"_location": "/anyline-ocr-react-native-module",
"_phantomChildren": {},
"_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"
Expand All @@ -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"
}

0 comments on commit 584b3ae

Please sign in to comment.