Skip to content

Commit 01a29ac

Browse files
Merge pull request #10 from OutSystems/development
RMET-3028 Barcode Plugin - Prepare release of version 1.0.0
2 parents ecff2e1 + cd255cc commit 01a29ac

39 files changed

+6410
-84
lines changed

CHANGELOG.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
The changes documented here do not include those from the original repository.
88

9-
## 1.0.0
9+
## [1.0.0]
10+
11+
### iOS
12+
13+
- Fix error codes and messages (https://outsystemsrd.atlassian.net/browse/RMET-3038).
14+
- Add `scanOrientation` argument to `scanBarcode` (https://outsystemsrd.atlassian.net/browse/RMET-2753).
15+
- Add `cameraDirection` argument to `scanBarcode` (https://outsystemsrd.atlassian.net/browse/RMET-2754).
16+
- Add `scanButtonText` argument to `scanBarcode` (https://outsystemsrd.atlassian.net/browse/RMET-2752).
17+
- Add `scanInstructions` argument to `scanBarcode` (https://outsystemsrd.atlassian.net/browse/RMET-2751).
18+
- Implement `scanBarcode` (https://outsystemsrd.atlassian.net/browse/RMET-2748).
19+
20+
### Android
21+
22+
#### 09-01-2024
23+
- Update error codes and messages (https://outsystemsrd.atlassian.net/browse/RMET-3037).
24+
25+
#### 08-11-2023
26+
Android - Scan barcode feature (https://outsystemsrd.atlassian.net/browse/RMET-2758)
27+
28+
### Cordova Wrapper
29+
30+
- Add support for plugin's old version of the `scanBarcode` method (https://outsystemsrd.atlassian.net/browse/RMET-2916).
31+
- Add `scanBarcode` method (https://outsystemsrd.atlassian.net/browse/RMET-2916).

README.md

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,116 @@
11
# cordova-outsystems-barcode
22

3-
## Cordova Bridge for the OutSystems Officially Supported Barcode Plugin.
3+
*This plugin is SUPPORTED by OutSystems. Customers entitled to Support Services may obtain assistance through Support.*
4+
5+
A barcode scanner for your mobile application. Supports many popular encoding types of 1D and 2D barcodes, presented in the following table.
6+
7+
**1D Barcodes**
8+
9+
|Code|iOS|Android's ML Kit|Android's ZXing|
10+
|:-|:-:|:-:|:-:|
11+
|Codabar|:warning:<br>(Available from 15.0)|:white_check_mark:|:white_check_mark:|
12+
|Code 39|:white_check_mark:|:white_check_mark:|:white_check_mark:|
13+
|Code 93|:white_check_mark:|:white_check_mark:|:white_check_mark:|
14+
|Code 128|:white_check_mark:|:white_check_mark:|:white_check_mark:|
15+
|Databar (GS1)|:warning:<br>(Available from 15.0)|:x:|:white_check_mark:|
16+
|EAN-8|:white_check_mark:|:white_check_mark:|:white_check_mark:|
17+
|EAN-13|:white_check_mark:|:white_check_mark:|:white_check_mark:|
18+
|ITF|:white_check_mark:|:white_check_mark:|:white_check_mark:|
19+
|ITF-14|:white_check_mark:|:x:|:x:|
20+
|ISBN-10|:white_check_mark:|:white_check_mark:|:white_check_mark:|
21+
|ISBN-13|:white_check_mark:|:white_check_mark:|:white_check_mark:|
22+
|ISBN-13 Dual Barcode|:white_check_mark:|:white_check_mark:|:white_check_mark:|
23+
|RSSExpanded|:warning:<br>(Available from 15.0)|:x:|:white_check_mark:|
24+
|UPC-A|:white_check_mark:|:white_check_mark:|:white_check_mark:|
25+
|UPC-E|:white_check_mark:|:white_check_mark:|:white_check_mark:|
26+
27+
**2D Barcodes**
28+
29+
|Code|iOS|Android's ML Kit|Android's ZXing|
30+
|:-|:-:|:-:|:-:|
31+
|Aztec Code|:white_check_mark:|:white_check_mark:|:white_check_mark:|
32+
|Data Matrix|:white_check_mark:|:white_check_mark:|:white_check_mark:|
33+
|MaxiCode|:x:|:x:|:white_check_mark:|
34+
|Micro PDF 417|:warning:<br>(Available from 15.0)|:x:|:x:|
35+
|Micro QR|:warning:<br>(Available from 15.0)|:x:|:x:|
36+
|PDF 417|:white_check_mark:|:white_check_mark:|:white_check_mark:|
37+
|QR Code|:white_check_mark:|:white_check_mark:|:white_check_mark:|
38+
39+
## Installation
40+
41+
```console
42+
cordova plugin add <path-to-repo-local-clone>
43+
```
44+
45+
It's also possible to install via the repo's URL directly.
46+
47+
```console
48+
cordova plugin add https://github.com/OutSystems/cordova-outsystems-barcode
49+
```
50+
51+
## Supported Platforms
52+
53+
- iOS
54+
- Android
55+
56+
## Methods
57+
58+
* OSBarcode
59+
* [scanBarcode](#scan-barcode)
60+
61+
* OSBarcodeScanner
62+
* [scan](#scan)
63+
64+
### Scan Barcode
65+
66+
```js
67+
cordova.plugins.OSBarcode.scanBarcode(options, successCallback, errorCallback);
68+
```
69+
70+
An action that triggers the barcode reader. If successful, it returns the text associated with the scanned barcode as a String. In case of an error, it returns the associated error code and message (TODO: link to the table).
71+
72+
The action is composed of the following parameters:
73+
74+
- **options**: A structure containing some configurations to apply to the barcode reader. It's composed of the following properties:
75+
- **scanInstructions**: A text containing the scanning instructions.
76+
- **cameraDirection**: An integer that indicates if the back (1) or front (2) camera will be used when triggering a new scan action.
77+
- **scanOrientation**: An integer that indicates which orientation will the scanner assume: Portrait (1), Landscape (2) or Adaptive (3). "Adaptive" uses the device's current orientation.
78+
- **scanButton**: A boolean that will display a scan button on the barcode reader. With the button, scanning will only be triggered when pressing the button instead of automatically when framing the barcode. A second click on the button disables scannning.
79+
- **scanText**: A text to be displayed on the scan button. It will only be shown if **scanButton** is set to true.
80+
- **androidScanningLibrary**: A text equivalent to the **OSBarcodeConstants.AndroidScanningLibrary** structure. It indicates which library will be used to perform the scan: MLKit or ZXing. As the name indicates, it's only applicable to "Android".
81+
- **successCallback**: A structure indicating that the action was successful. It returns a **ScanResult**: a text containing the value associated with the scanned barcode.
82+
- **errorCallback**: A structure indicating that the action was not successful. It returns an "error" structure, composed of:
83+
- **code**: A text containing the error code.
84+
- **message**: A text containing the error message.
85+
86+
### Scan
87+
88+
```js
89+
cordova.plugins.OSBarcodeScanner.scan(options, successCallback, errorCallback);
90+
```
91+
92+
Being the older way to trigger the barcode reader, this was kept to keep retro compatibility. This action calls the [Scan Barcode](#scan-barcode) action, with the possible outputs being the same.
93+
94+
The action is composed of the following parameters:
95+
96+
- **options**: A structure containing some configurations to apply to the barcode reader. It's composed of the following properties:
97+
- **scanInstructions**: A text containing the scanning instructions.
98+
- **cameraDirection**: An integer that indicates if the back (1) or front (2) camera will be used when triggering a new scan action.
99+
- **scanOrientation**: An integer that indicates which orientation will the scanner assume: Portrait (1), Landscape (2) or Adaptive (3). "Adaptive" uses the device's current orientation.
100+
- **scanButton**: A boolean that will display a scan button on the barcode reader. With the button, scanning will only be triggered when pressing the button instead of automatically when framing the barcode. A second click on the button disables scannning.
101+
- **scanText**: A text to be displayed on the scan button. It will only be shown if **scanButton** is set to true.
102+
- **successCallback**: A structure indicating that the action was successful. It returns a **ScanResult**: a text containing the value associated with the scanned barcode.
103+
- **errorCallback**: A structure indicating that the action was not successful. It returns an "error" structure, composed of:
104+
- **code**: A text containing the error code.
105+
- **message**: A text containing the error message.
106+
107+
## Errors
108+
109+
|Code|Message|iOS|Android|
110+
|:-|:-|:-:|:-:|
111+
|OS-PLUG-BARC-0004|Error while trying to scan code.|:white_check_mark:|:white_check_mark:|
112+
|OS-PLUG-BARC-0006|Couldn't scan because the process was cancelled.|:white_check_mark:|:white_check_mark:|
113+
|OS-PLUG-BARC-0007|Couldn't scan because camera access wasn’t provided. Check your camera permissions and try again.|:white_check_mark:|:white_check_mark:|
114+
|OS-PLUG-BARC-0008|Scanning parameters are invalid.|:white_check_mark:|:white_check_mark:|
115+
|OS-PLUG-BARC-0009|There was an error scanning the barcode with ZXing.|:x:|:white_check_mark:|
116+
|OS-PLUG-BARC-0010|There was an error scanning the barcode with ML Kit.|:x:|:white_check_mark:|

plugin.xml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,47 @@
66
<js-module name="OSBarcode" src="www/OSBarcode.js">
77
<clobbers target="cordova.plugins.OSBarcode"/>
88
</js-module>
9+
10+
<js-module name="OSBarcodeScanner" src="www/OSBarcodeScanner.js">
11+
<clobbers target="cordova.plugins.OSBarcodeScanner"/>
12+
</js-module>
13+
14+
<js-module name="OSBarcodeConstants" src="www/OSBarcodeConstants.js">
15+
<clobbers target="OSBarcodeConstants"/>
16+
</js-module>
17+
918
<platform name="android">
1019
<config-file parent="/*" target="res/xml/config.xml">
1120
<feature name="OSBarcode">
1221
<param name="android-package" value="com.outsystems.plugins.barcode.OSBarcode"/>
1322
</feature>
23+
<preference name="GradlePluginKotlinEnabled" value="true" />
24+
<preference name="GradlePluginKotlinCodeStyle" value="official" />
1425
</config-file>
1526
<config-file parent="/*" target="AndroidManifest.xml"/>
16-
<source-file src="src/android/com/outsystems/plugins/barcode/OSBarcode.java" target-dir="src/com/outsystems/plugins/barcode"/>
27+
<source-file src="src/android/com/outsystems/plugins/barcode/OSBarcode.kt" target-dir="app/src/main/kotlin/com/outsystems/plugins/barcode"/>
28+
<framework src="src/android/com/outsystems/plugins/barcode/build.gradle" custom="true" type="gradleReference" />
1729
</platform>
1830
<platform name="ios">
1931
<config-file parent="/*" target="config.xml">
2032
<feature name="OSBarcode">
2133
<param name="ios-package" value="OSBarcode"/>
2234
</feature>
2335
</config-file>
24-
<source-file src="src/ios/OSBarcode.m"/>
25-
<header-file src="src/ios/OSBarcode.h"/>
36+
37+
<dependency id="cordova-plugin-add-swift-support" url="https://github.com/OutSystems/cordova-plugin-add-swift-support.git#2.0.3-OS1"/>
38+
39+
<preference name="CAMERA_USAGE_DESCRIPTION" default=" " />
40+
<config-file target="*-Info.plist" parent="NSCameraUsageDescription">
41+
<string>$CAMERA_USAGE_DESCRIPTION</string>
42+
</config-file>
43+
44+
<source-file src="src/ios/OSBarcode.swift" />
45+
<source-file src="src/ios/OSBarcodeError.swift" />
46+
<source-file src="src/ios/OSBarcodeScanArgumentsModel.swift" />
47+
48+
<source-file src="src/ios/frameworks/OSBARCArgumentMappable.swift" target-dir="extensions" />
49+
<framework src="src/ios/frameworks/OSBarcodeLib.xcframework" embed="true" custom="true" />
50+
2651
</platform>
2752
</plugin>

src/android/com/outsystems/plugins/barcode/OSBarcode.java

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.outsystems.plugins.barcode
2+
3+
import android.content.Intent
4+
import com.google.gson.Gson
5+
import com.outsystems.plugins.barcode.controller.OSBARCController
6+
import com.outsystems.plugins.barcode.model.OSBARCError
7+
import com.outsystems.plugins.barcode.model.OSBARCScanParameters
8+
import com.outsystems.plugins.oscordova.CordovaImplementation
9+
import kotlinx.coroutines.runBlocking
10+
import org.apache.cordova.CallbackContext
11+
import org.apache.cordova.CordovaInterface
12+
import org.apache.cordova.CordovaWebView
13+
import org.json.JSONArray
14+
15+
class OSBarcode : CordovaImplementation() {
16+
17+
companion object {
18+
private const val ERROR_FORMAT_PREFIX = "OS-PLUG-BARC-"
19+
}
20+
21+
override var callbackContext: CallbackContext? = null
22+
private lateinit var barcodeController: OSBARCController
23+
val gson by lazy { Gson() }
24+
25+
override fun execute(
26+
action: String,
27+
args: JSONArray,
28+
callbackContext: CallbackContext
29+
): Boolean {
30+
this.callbackContext = callbackContext
31+
val result = runBlocking {
32+
when (action) {
33+
"scanBarcode" -> {
34+
scan(args)
35+
}
36+
37+
else -> false
38+
}
39+
true
40+
}
41+
return result
42+
}
43+
44+
override fun initialize(cordova: CordovaInterface, webView: CordovaWebView) {
45+
super.initialize(cordova, webView)
46+
barcodeController = OSBARCController()
47+
}
48+
49+
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
50+
super.onActivityResult(requestCode, resultCode, intent)
51+
barcodeController.handleActivityResult(requestCode, resultCode, intent,
52+
{ result ->
53+
sendPluginResult(result, null)
54+
},
55+
{ error ->
56+
sendPluginResult(null, Pair(formatErrorCode(error.code), error.description))
57+
})
58+
}
59+
60+
override fun onRequestPermissionResult(
61+
requestCode: Int,
62+
permissions: Array<String>,
63+
grantResults: IntArray
64+
) {
65+
// do nothing
66+
}
67+
68+
override fun areGooglePlayServicesAvailable(): Boolean {
69+
// do nothing
70+
return true
71+
}
72+
73+
private fun scan(args: JSONArray) {
74+
setAsActivityResultCallback()
75+
val parameters = buildScanParameters(args)
76+
if (parameters != null) {
77+
barcodeController.scanCode(getActivity(), parameters)
78+
} else {
79+
sendPluginResult(
80+
null,
81+
Pair(
82+
formatErrorCode(OSBARCError.INVALID_PARAMETERS_ERROR.code),
83+
OSBARCError.INVALID_PARAMETERS_ERROR.description
84+
)
85+
)
86+
}
87+
}
88+
89+
private fun buildScanParameters(args: JSONArray): OSBARCScanParameters? {
90+
return try {
91+
gson.fromJson(args.getString(0), OSBARCScanParameters::class.java)
92+
} catch (e: Exception) {
93+
null
94+
}
95+
}
96+
97+
private fun formatErrorCode(code: Int): String {
98+
return ERROR_FORMAT_PREFIX + code.toString().padStart(4, '0')
99+
}
100+
101+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
buildscript {
2+
repositories {
3+
google()
4+
mavenCentral()
5+
}
6+
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:8.1.1'
9+
}
10+
}
11+
12+
repositories {
13+
google()
14+
mavenCentral()
15+
repositories {
16+
maven { url 'https://pkgs.dev.azure.com/OutSystemsRD/9e79bc5b-69b2-4476-9ca5-d67594972a52/_packaging/PublicArtifactRepository/maven/v1' }
17+
}
18+
}
19+
20+
repositories{
21+
flatDir {
22+
dirs 'src/main/libs'
23+
}
24+
}
25+
26+
27+
apply plugin: 'kotlin-kapt'
28+
29+
dependencies {
30+
implementation("com.github.outsystems:oscore-android:1.2.0@aar")
31+
implementation("com.github.outsystems:oscordova-android:2.0.0@aar")
32+
implementation("com.github.outsystems:osbarcode-android:1.0.0@aar")
33+
34+
implementation 'androidx.appcompat:appcompat:1.4.1'
35+
implementation "androidx.activity:activity-ktx:1.4.0"
36+
37+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.0'
38+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3'
39+
40+
implementation 'com.google.zxing:core:3.4.1'
41+
implementation 'com.google.mlkit:barcode-scanning:17.2.0'
42+
implementation "androidx.camera:camera-camera2:1.0.2"
43+
implementation "androidx.camera:camera-lifecycle:1.0.2"
44+
implementation "androidx.camera:camera-view:1.0.0-alpha31"
45+
implementation "androidx.activity:activity-compose:1.4.0"
46+
implementation 'androidx.compose.material3:material3:1.0.0'
47+
implementation 'androidx.compose.material3:material3-window-size-class:1.0.0'
48+
}

0 commit comments

Comments
 (0)