Skip to content

Commit

Permalink
Merge pull request #89 from m1ga/example
Browse files Browse the repository at this point in the history
Android: Update zxing core library; Fix example
  • Loading branch information
garymathews authored Dec 17, 2018
2 parents 13f75ee + 26e7cf5 commit 086a659
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 24 deletions.
27 changes: 15 additions & 12 deletions android/documentation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ the iOS and Android modules in to full parity. When upgrading to 1.5, you will n

- BREAKING CHANGE: iOS now uses event listeners instead of callbacks! Use Ti.Barcode.addEventListener('success', ...) instead of capture({ success: ...})!
- BREAKING CHANGE: Android's contentType property is now an integer, instead of a string! Check out the example and documentation to find out more.
- BREAKING CHANGE: All automatically parsed "data" keys will now be lower case. This ensures consistency across the API and ease of access.
- BREAKING CHANGE: All automatically parsed "data" keys will now be lower case. This ensures consistency across the API and ease of access.
- BREAKING CHANGE: Android now properly fires the "cancel" event, as documented. It was firing the "canceled" event.
- Ensure that you assign the module object that is returned from "require('ti.barcode')" to a variable or your event listeners may not receive the barcode events

Expand All @@ -34,13 +34,16 @@ containing any of the following properties:
* showRectangle[boolean]: Whether or not to include the default rectangle around the scanning area. Defaults to true.
* overlay[view]: The view to lay on top of the camera activity.
* keepOpen[boolean]: Whether or not to keep the barcode scanner open after a barcode is recognized. Defaults to false. When set to true, "success" will fire once every time a barcode is recognized, up to two times per second. As such, it can fire multiple times for a single barcode!
* acceptedFormats[int[]]: An optional array of int constants detailing which barcode formats are accepted. Defaults to all formats. Check out the "Barcode Format Constants" section below to see the available int constants.
* acceptedFormats[int[]]: An optional array of int constants detailing which barcode formats are accepted. Defaults to all formats. Check out the "Barcode Format Constants" section below to see the available int constants.
* preventRotation[boolean]: Prevent the scanner from auto-rotating when the device is rotated. Default: true
* frameWidth[int]: Width of the rectangle that is shown in the scanner
* frameHeight[int]: Height of the rectangle that is shown in the scanner

### parse([args])
Parses a blob image for barcodes. Takes one required argument, a dictionary containing any of the following properties:

* image[blob]: The image blob to parse for a barcode.
* acceptedFormats[int[]]: An optional array of int constants detailing which barcode formats are accepted. Defaults to all formats. Check out the "Barcode Format Constants" section below to see the available int constants.
* acceptedFormats[int[]]: An optional array of int constants detailing which barcode formats are accepted. Defaults to all formats. Check out the "Barcode Format Constants" section below to see the available int constants.

### cancel()
Cancels and closes the currently open capture window.
Expand All @@ -51,23 +54,23 @@ Use Ti.Barcode.addEventListener() to process the following events that are sent
### success
Sent upon a successful barcode scan. The event object contains the following fields:

* format[string, Android only] : The format of the barcode
* result[string] : The raw contents of the barcode
* code[string, Android only] : The activity result code from the scanning activity. Use the result constants defined in the [Ti.Android][] namespace
* format[string, Android only] : The format of the barcode
* result[string] : The raw contents of the barcode
* code[string, Android only] : The activity result code from the scanning activity. Use the result constants defined in the [Ti.Android][] namespace
* contentType[int] : The type of barcode content. Use the constants defined in this module to determine which.
* data[object]: The parsed fields associated with the contentType.

### error
Sent when an error occurs. The event object contains the following fields:

* message[string] : The error message
* code[string] : The activity result code from the scanning activity. Use the result constants defined in the [Ti.Android][] namespace
* message[string] : The error message
* code[string] : The activity result code from the scanning activity. Use the result constants defined in the [Ti.Android][] namespace

### cancel
Sent when the scanning process is canceled. The event object contains the following fields:

* message[string] : The error message
* code[string] : The activity result code from the scanning activity. Use the result constants defined in the [Ti.Android][] namespace
* message[string] : The error message
* code[string] : The activity result code from the scanning activity. Use the result constants defined in the [Ti.Android][] namespace

## Properties

Expand All @@ -87,7 +90,7 @@ Whether or not to display helpful instructions or a changelog when the app is up

### displayedMessage[string]
Controls the message that is displayed to the end user when they are capturing a barcode.

### useFrontCamera[boolean, defaults to false]
Controls whether or not the front camera on the device will be used to capture barcodes. On Android, this requires API
level 9 (Android OS 2.3) or higher. If no front camera is available, this will gracefully fall back to utilize whatever
Expand Down Expand Up @@ -157,4 +160,4 @@ Please direct all questions, feedback, and concerns to [[email protected]](m
## License
Copyright(c) 2010-2013 by Appcelerator, Inc. All Rights Reserved. Please see the LICENSE file included in the distribution for further details.

[Ti.Android]: http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Android-module
[Ti.Android]: http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Android-module
2 changes: 1 addition & 1 deletion android/example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Barcode.allowMenu = false;
Barcode.allowInstructions = false;
Barcode.useLED = true;

var isiOS = Ti.Platform.osname === 'iphone' || Ti.Platform.osname === 'android';
var isAndroid = Ti.Platform.osname === 'android';
var isiOS = !isAndroid;

var window = Ti.UI.createWindow({
backgroundColor: 'white'
Expand Down
Binary file removed android/lib/core-3.3.1-SNAPSHOT.jar
Binary file not shown.
Binary file added android/lib/core-3.3.3.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 4.0.1
version: 4.0.2
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86
description: Lets you process 1D/2D barcodes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private void resume(){

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

if (prefs.getBoolean(PreferencesActivity.KEY_DISABLE_AUTO_ORIENTATION, true)) {
if (prefs.getBoolean(PreferencesActivity.KEY_DISABLE_AUTO_ORIENTATION, true) && intent.getBooleanExtra(Intents.Scan.PREVENT_ROTATION, true)) {
setRequestedOrientation(getCurrentOrientation());
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
Expand Down
1 change: 1 addition & 0 deletions android/src/com/google/zxing/client/android/Intents.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static final class Scan {
public static final String ALLOW_MENU = "ALLOW_MENU";
public static final String ALLOW_INSTRUCTIONS = "ALLOW_INSTRUCTIONS";
public static final String SHOW_INFO_TEXT = "SHOW_INFO_TEXT";
public static final String PREVENT_ROTATION = "PREVENT_ROTATION";
public static TiViewProxy overlayProxy = null;

/**
Expand Down
11 changes: 6 additions & 5 deletions android/src/ti/barcode/BarcodeModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ public void capture(@Kroll.argument(optional = true) HashMap args) {
_instance = this;

Intent intent = new Intent(Intents.Scan.ACTION);

if (args != null) {
KrollDict argsDict = new KrollDict(args);

// [MOD-233] Turn off default animation if requested. It is on by default.
boolean animate = argsDict.optBoolean("animate", true);
if (!animate) {
Expand Down Expand Up @@ -296,10 +296,11 @@ public void capture(@Kroll.argument(optional = true) HashMap args) {

intent.putExtra(Intents.Scan.SHOW_RECTANGLE, argsDict.optBoolean("showRectangle", true));
intent.putExtra(Intents.Scan.KEEP_OPEN, argsDict.optBoolean("keepOpen", false));

frameWidth = argsDict.optInt("frameWidth", 0);
frameHeight = argsDict.optInt("frameHeight",0);
intent.putExtra(Intents.Scan.SHOW_INFO_TEXT, argsDict.optBoolean("showInfoText", false));
intent.putExtra(Intents.Scan.PREVENT_ROTATION, argsDict.optBoolean("preventRotation", true));
} else {

Intents.Scan.overlayProxy = null;
intent.putExtra(Intents.Scan.SHOW_RECTANGLE, true);
intent.putExtra(Intents.Scan.KEEP_OPEN, false);
Expand Down Expand Up @@ -375,7 +376,7 @@ public void onResult(Activity activity, int requestCode, int resultCode, Intent
e.printStackTrace();
processFailed(resultCode);
}

if (!keepOpen) {
_instance = null;
}
Expand Down
6 changes: 3 additions & 3 deletions android/timodule.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<ti:module xmlns:ti="http://ti.appcelerator.org" xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Similar to tiapp.xml, but contains module/platform specific configuration in <iphone> and <android>/<android:manifest> sections -->
<property name="android.javac.target">1.7</property>
<property name="android.javac.source">1.7</property>
<property name="android.javac.target">1.7</property>
<property name="android.javac.source">1.7</property>
<android>
<manifest>
<application>
<activity android:name="com.google.zxing.client.android.CaptureActivity"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="fullSensor"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
Expand Down
2 changes: 1 addition & 1 deletion ios/example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Barcode.allowMenu = false;
Barcode.allowInstructions = false;
Barcode.useLED = true;

var isiOS = Ti.Platform.osname === 'iphone' || Ti.Platform.osname === 'android';
var isAndroid = Ti.Platform.osname === 'android';
var isiOS = !isAndroid;

var window = Ti.UI.createWindow({
backgroundColor: 'white'
Expand Down

0 comments on commit 086a659

Please sign in to comment.