-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial functionality with click to scan barcode iOS/Android
- Loading branch information
1 parent
2a7347b
commit 2224537
Showing
91 changed files
with
2,930 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.0.1 | ||
|
||
* scanBarcode method that opens a camera views and exits once an item has been scanned or the user disimisses the scanner. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Amol Gangadhare | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/> | ||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/> | ||
<classpathentry kind="output" path="bin/default"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>flutter_scandit</name> | ||
<comment>Project flutter_scandit created by Buildship.</comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
arguments= | ||
auto.sync=false | ||
build.scans.enabled=false | ||
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.0-20191016123526+0000)) | ||
connection.project.dir=../example/android | ||
eclipse.preferences.version=1 | ||
gradle.user.home= | ||
java.home= | ||
jvm.arguments= | ||
offline.mode=false | ||
override.workspace.settings=true | ||
show.console.view=true | ||
show.executions.view=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
group 'za.co.palota.flutter_scandit' | ||
version '1.0' | ||
|
||
buildscript { | ||
repositories { | ||
google() | ||
jcenter() | ||
maven { url 'https://scandit.bintray.com/DataCapture' } | ||
} | ||
|
||
dependencies { | ||
classpath 'com.android.tools.build:gradle:3.2.1' | ||
} | ||
} | ||
|
||
rootProject.allprojects { | ||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
|
||
defaultConfig { | ||
minSdkVersion 19 | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
lintOptions { | ||
disable 'InvalidPackage' | ||
} | ||
dependencies { | ||
implementation "com.scandit.datacapture:core:6.1.0" | ||
implementation "com.scandit.datacapture:barcode:6.1.0" | ||
|
||
implementation "androidx.appcompat:appcompat:1.0.2" | ||
implementation "com.google.android.material:material:1.0.0" | ||
|
||
implementation "androidx.constraintlayout:constraintlayout:1.1.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
org.gradle.jvmargs=-Xmx1536M | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rootProject.name = 'flutter_scandit' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="za.co.palota.flutter_scandit"> | ||
<uses-permission android:name="android.permission.INTERNET"/> | ||
|
||
<application | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.AppCompat.NoActionBar"> | ||
|
||
<activity | ||
android:name=".BarcodeScanActivity" | ||
android:screenOrientation="sensor"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
</manifest> |
216 changes: 216 additions & 0 deletions
216
android/src/main/java/za/co/palota/flutter_scandit/BarcodeScanActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
package za.co.palota.flutter_scandit; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.app.AlertDialog; | ||
import com.scandit.datacapture.barcode.capture.*; | ||
import com.scandit.datacapture.barcode.data.Barcode; | ||
import com.scandit.datacapture.barcode.data.Symbology; | ||
import com.scandit.datacapture.barcode.ui.overlay.BarcodeCaptureOverlay; | ||
import com.scandit.datacapture.core.capture.DataCaptureContext; | ||
import com.scandit.datacapture.core.data.FrameData; | ||
import com.scandit.datacapture.core.source.Camera; | ||
import com.scandit.datacapture.core.source.FrameSourceState; | ||
import com.scandit.datacapture.core.ui.DataCaptureView; | ||
import com.scandit.datacapture.core.ui.viewfinder.RectangularViewfinder; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
|
||
public class BarcodeScanActivity | ||
extends CameraPermissionActivity implements BarcodeCaptureListener { | ||
public static final String BARCODE_ERROR = "error"; | ||
public static final String BARCODE_DATA = "data"; | ||
public static final String BARCODE_SYMBOLOGY = "symbology"; | ||
|
||
private DataCaptureContext dataCaptureContext; | ||
private BarcodeCapture barcodeCapture; | ||
private Camera camera; | ||
private DataCaptureView dataCaptureView; | ||
|
||
private AlertDialog dialog; | ||
|
||
private String licenseKey; | ||
private HashSet<Symbology> symbologies; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
Intent intent = getIntent(); | ||
this.licenseKey = intent.getStringExtra(FlutterScanditPlugin.LICENSE_KEY); | ||
ArrayList<String> passedSymbologies = intent.getStringArrayListExtra(FlutterScanditPlugin.SYMBOLOGIES_KEY); | ||
symbologies = new HashSet<>(); | ||
|
||
for(String symbologyName:passedSymbologies){ | ||
Symbology symbology = FlutterScanditPlugin.convertToSymbology(symbologyName); | ||
if(symbology != null){ | ||
symbologies.add(symbology); | ||
} | ||
} | ||
if(symbologies.isEmpty()){ | ||
symbologies.add(Symbology.EAN13_UPCA); // default | ||
} | ||
|
||
// Initialize and start the barcode recognition. | ||
initializeAndStartBarcodeScanning(); | ||
} | ||
|
||
private void finishWithError(String errorReason) { | ||
Intent data = new Intent(); | ||
data.putExtra(BARCODE_ERROR, errorReason); | ||
setResult(Activity.RESULT_CANCELED, data); | ||
finish(); | ||
} | ||
|
||
private void initializeAndStartBarcodeScanning() { | ||
// Create data capture context using your license key. | ||
dataCaptureContext = DataCaptureContext.forLicenseKey(this.licenseKey); | ||
|
||
// Use the default camera and set it as the frame source of the context. | ||
// The camera is off by default and must be turned on to start streaming frames to the data | ||
// capture context for recognition. | ||
// See resumeFrameSource and pauseFrameSource below. | ||
camera = Camera.getDefaultCamera(); | ||
if (camera != null) { | ||
// Use the recommended camera settings for the BarcodeCapture mode. | ||
camera.applySettings(BarcodeCapture.createRecommendedCameraSettings()); | ||
dataCaptureContext.setFrameSource(camera); | ||
} else { | ||
finishWithError("NO_CAMERA"); | ||
} | ||
|
||
// The barcode capturing process is configured through barcode capture settings | ||
// which are then applied to the barcode capture instance that manages barcode recognition. | ||
BarcodeCaptureSettings barcodeCaptureSettings = new BarcodeCaptureSettings(); | ||
|
||
// The settings instance initially has all types of barcodes (symbologies) disabled. | ||
// For the purpose of this sample we enable a very generous set of symbologies. | ||
// In your own app ensure that you only enable the symbologies that your app requires as | ||
// every additional enabled symbology has an impact on processing times. | ||
|
||
barcodeCaptureSettings.enableSymbologies(this.symbologies); | ||
|
||
// Some linear/1d barcode symbologies allow you to encode variable-length data. | ||
// By default, the Scandit Data Capture SDK only scans barcodes in a certain length range. | ||
// If your application requires scanning of one of these symbologies, and the length is | ||
// falling outside the default range, you may need to adjust the "active symbol counts" | ||
// for this symbology. This is shown in the following few lines of code for one of the | ||
// variable-length symbologies. | ||
SymbologySettings symbologySettings = | ||
barcodeCaptureSettings.getSymbologySettings(Symbology.CODE39); | ||
|
||
HashSet<Short> activeSymbolCounts = new HashSet<>( | ||
Arrays.asList(new Short[] { 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 })); | ||
|
||
symbologySettings.setActiveSymbolCounts(activeSymbolCounts); | ||
|
||
// Create new barcode capture mode with the settings from above. | ||
barcodeCapture = BarcodeCapture.forDataCaptureContext(dataCaptureContext, barcodeCaptureSettings); | ||
|
||
// Register self as a listener to get informed whenever a new barcode got recognized. | ||
barcodeCapture.addListener(this); | ||
|
||
// To visualize the on-going barcode capturing process on screen, setup a data capture view | ||
// that renders the camera preview. The view must be connected to the data capture context. | ||
dataCaptureView = DataCaptureView.newInstance(this, dataCaptureContext); | ||
|
||
// Add a barcode capture overlay to the data capture view to render the location of captured | ||
// barcodes on top of the video preview. | ||
// This is optional, but recommended for better visual feedback. | ||
BarcodeCaptureOverlay overlay = BarcodeCaptureOverlay.newInstance(barcodeCapture, dataCaptureView); | ||
overlay.setViewfinder(new RectangularViewfinder()); | ||
|
||
setContentView(dataCaptureView); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
pauseFrameSource(); | ||
super.onPause(); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
barcodeCapture.removeListener(this); | ||
dataCaptureContext.removeMode(barcodeCapture); | ||
super.onDestroy(); | ||
} | ||
|
||
private void pauseFrameSource() { | ||
// Switch camera off to stop streaming frames. | ||
// The camera is stopped asynchronously and will take some time to completely turn off. | ||
// Until it is completely stopped, it is still possible to receive further results, hence | ||
// it's a good idea to first disable barcode capture as well. | ||
barcodeCapture.setEnabled(false); | ||
camera.switchToDesiredState(FrameSourceState.OFF, null); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
|
||
// Check for camera permission and request it, if it hasn't yet been granted. | ||
// Once we have the permission the onCameraPermissionGranted() method will be called. | ||
requestCameraPermission(); | ||
} | ||
|
||
@Override | ||
public void onCameraPermissionGranted() { | ||
resumeFrameSource(); | ||
} | ||
|
||
@Override | ||
public void onCameraPermissionDenied() { | ||
finishWithError("CAMERA_PERMISSION_DENIED"); | ||
} | ||
|
||
private void resumeFrameSource() { | ||
dismissScannedCodesDialog(); | ||
|
||
// Switch camera on to start streaming frames. | ||
// The camera is started asynchronously and will take some time to completely turn on. | ||
barcodeCapture.setEnabled(true); | ||
camera.switchToDesiredState(FrameSourceState.ON, null); | ||
} | ||
|
||
private void dismissScannedCodesDialog() { | ||
if (dialog != null) { | ||
dialog.dismiss(); | ||
dialog = null; | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public void onBarcodeScanned( | ||
@NonNull BarcodeCapture barcodeCapture, | ||
@NonNull BarcodeCaptureSession session, | ||
@NonNull FrameData frameData | ||
) { | ||
if (session.getNewlyRecognizedBarcodes().isEmpty()) return; | ||
|
||
Barcode barcode = session.getNewlyRecognizedBarcodes().get(0); | ||
|
||
|
||
Intent data = new Intent(); | ||
data.putExtra(BARCODE_DATA, barcode.getData()); | ||
data.putExtra(BARCODE_SYMBOLOGY, barcode.getSymbology().name()); | ||
setResult(Activity.RESULT_OK, data); | ||
finish(); | ||
} | ||
|
||
|
||
@Override | ||
public void onSessionUpdated(@NonNull BarcodeCapture barcodeCapture, | ||
@NonNull BarcodeCaptureSession session, @NonNull FrameData data) {} | ||
|
||
@Override | ||
public void onObservationStarted(@NonNull BarcodeCapture barcodeCapture) {} | ||
|
||
@Override | ||
public void onObservationStopped(@NonNull BarcodeCapture barcodeCapture) {} | ||
} |
Oops, something went wrong.