mirror of
https://github.com/wahyd4/BarcodeScanner.git
synced 2026-08-09 13:05:55 +10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12be23d657 | ||
|
|
12ecfd7f55 | ||
|
|
933525da37 | ||
|
|
7ad74807c3 | ||
|
|
4ed50488b6 | ||
|
|
91d7e9aa4a | ||
|
|
eab15a370a | ||
|
|
a7bf6fc2c0 | ||
|
|
7d831d83ed | ||
|
|
ec4de624ae | ||
|
|
ba3c96c386 | ||
|
|
24acf29896 | ||
|
|
a310fda2d7 | ||
|
|
8bf3cce073 | ||
|
|
2d8701634f | ||
|
|
7880bf7b5c | ||
|
|
12a31b76b0 | ||
|
|
a2857ba5f8 | ||
|
|
f046f651ce | ||
|
|
6ad6dafc11 | ||
|
|
14d63e35ac | ||
|
|
d901977064 |
@@ -1,12 +1,15 @@
|
|||||||
BarcodeScanner
|
BarcodeScanner
|
||||||
==============
|
==============
|
||||||
|
|
||||||
|
Added version that runs with windows mobile devices.
|
||||||
|
To run on those devices, the zxing.net library must be added to the project (Install as nuget packet - more information on http://www.nuget.org/packages/ZXing.Net)
|
||||||
|
|
||||||
|
Windows Phone currently only supports Scaning for codes, feel free to extend it that it can also encode.
|
||||||
|
|
||||||
Cross-platform BarcodeScanner for Cordova / PhoneGap.
|
Cross-platform BarcodeScanner for Cordova / PhoneGap.
|
||||||
|
|
||||||
Follows the [Cordova Plugin spec](https://github.com/apache/cordova-plugman/blob/master/plugin_spec.md), so that it works with [Plugman](https://github.com/apache/cordova-plugman).
|
Follows the [Cordova Plugin spec](https://github.com/apache/cordova-plugman/blob/master/plugin_spec.md), so that it works with [Plugman](https://github.com/apache/cordova-plugman).
|
||||||
|
|
||||||
This plugin leverages Cordova/PhoneGap's [require/define functionality used for plugins](http://simonmacdonald.blogspot.ca/2012/08/so-you-wanna-write-phonegap-200-android.html).
|
|
||||||
|
|
||||||
Note: the Android source for this project includes an Android Library Project.
|
Note: the Android source for this project includes an Android Library Project.
|
||||||
plugman currently doesn't support Library Project refs, so its been
|
plugman currently doesn't support Library Project refs, so its been
|
||||||
prebuilt as a jar library. Any updates to the Library Project should be
|
prebuilt as a jar library. Any updates to the Library Project should be
|
||||||
@@ -49,9 +52,7 @@ The following barcode types are currently supported:
|
|||||||
|
|
||||||
A full example could be:
|
A full example could be:
|
||||||
```
|
```
|
||||||
var scanner = cordova.require("cordova/plugin/BarcodeScanner");
|
cordova.plugins.barcodeScanner.scan(
|
||||||
|
|
||||||
scanner.scan(
|
|
||||||
function (result) {
|
function (result) {
|
||||||
alert("We got a barcode\n" +
|
alert("We got a barcode\n" +
|
||||||
"Result: " + result.text + "\n" +
|
"Result: " + result.text + "\n" +
|
||||||
@@ -65,7 +66,7 @@ A full example could be:
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Encoding a Barcode ##
|
## Encoding a Barcode ##
|
||||||
The plugin creates the object `window.plugins.barcodeScanner` with the method `encode(type, data, success, fail)`.
|
The plugin creates the object `cordova.plugins.barcodeScanner` with the method `encode(type, data, success, fail)`.
|
||||||
Supported encoding types:
|
Supported encoding types:
|
||||||
|
|
||||||
* TEXT_TYPE
|
* TEXT_TYPE
|
||||||
@@ -76,9 +77,7 @@ Supported encoding types:
|
|||||||
```
|
```
|
||||||
A full example could be:
|
A full example could be:
|
||||||
|
|
||||||
var scanner = cordova.require("cordova/plugin/BarcodeScanner");
|
cordova.plugins.barcodeScanner.encode(BarcodeScanner.Encode.TEXT_TYPE, "http://www.nytimes.com", function(success) {
|
||||||
|
|
||||||
scanner.encode(BarcodeScanner.Encode.TEXT_TYPE, "http://www.nytimes.com", function(success) {
|
|
||||||
alert("encode success: " + success);
|
alert("encode success: " + success);
|
||||||
}, function(fail) {
|
}, function(fail) {
|
||||||
alert("encoding failed: " + fail);
|
alert("encoding failed: " + fail);
|
||||||
|
|||||||
+35
-6
@@ -1,19 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?><plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
|
<?xml version="1.0" encoding="UTF-8"?><plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
id="com.phonegap.plugins.barcodescanner"
|
id="com.phonegap.plugins.barcodescanner"
|
||||||
version="0.7.0">
|
version="1.2.0">
|
||||||
|
|
||||||
<name>BarcodeScanner</name>
|
<name>BarcodeScanner</name>
|
||||||
|
|
||||||
<description>Scans Barcodes.</description>
|
<description>Scans Barcodes.</description>
|
||||||
|
<license>MIT</license>
|
||||||
|
|
||||||
<engines>
|
<engines>
|
||||||
<engine name="cordova" version=">=2.8.0" />
|
<engine name="cordova" version=">=3.0.0" />
|
||||||
</engines>
|
</engines>
|
||||||
|
|
||||||
|
<js-module src="www/barcodescanner.js" name="BarcodeScanner">
|
||||||
|
<clobbers target="cordova.plugins.barcodeScanner" />
|
||||||
|
</js-module>
|
||||||
|
|
||||||
<asset src="www/barcodescanner.js" target="barcodescanner.js" />
|
<asset src="www/barcodescanner.js" target="barcodescanner.js" />
|
||||||
|
|
||||||
<license>MIT</license>
|
|
||||||
|
|
||||||
<!-- ios -->
|
<!-- ios -->
|
||||||
<platform name="ios">
|
<platform name="ios">
|
||||||
@@ -28,14 +30,41 @@
|
|||||||
|
|
||||||
<header-file src="src/ios/zxing-all-in-one.h" />
|
<header-file src="src/ios/zxing-all-in-one.h" />
|
||||||
|
|
||||||
<source-file src="src/ios/CDVBarcodeScanner.mm" />
|
<source-file src="src/ios/CDVBarcodeScanner.mm" compiler-flags="-fno-objc-arc" />
|
||||||
<source-file src="src/ios/zxing-all-in-one.cpp" />
|
<source-file src="src/ios/zxing-all-in-one.cpp" />
|
||||||
|
|
||||||
<framework src="libiconv.dylib" />
|
<framework src="libiconv.dylib" />
|
||||||
<framework src="AVFoundation.framework" />
|
<framework src="AVFoundation.framework" />
|
||||||
<framework src="AssetsLibrary.framework" />
|
<framework src="AssetsLibrary.framework" />
|
||||||
<framework src="CoreVideo.framework" />
|
<framework src="CoreVideo.framework" />
|
||||||
|
<framework src="QuartzCore.framework" />
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
|
<platform name="wp7">
|
||||||
|
<config-file target="config.xml" parent="/*">
|
||||||
|
<feature name="BarcodeScanner">
|
||||||
|
<param name="wp-package" value="BarcodeScanner"/>
|
||||||
|
</feature>
|
||||||
|
</config-file>
|
||||||
|
|
||||||
|
<source-file src="src/wp/BarcodeScanner.cs" />
|
||||||
|
<source-file src="src/wp/BarcodeScannerResult.cs" />
|
||||||
|
<source-file src="src/wp/Scan.xaml.cs" />
|
||||||
|
<source-file src="src/wp/Scan.xaml" />
|
||||||
|
</platform>
|
||||||
|
|
||||||
|
<platform name="wp8">
|
||||||
|
<config-file target="config.xml" parent="/*">
|
||||||
|
<feature name="BarcodeScanner">
|
||||||
|
<param name="wp-package" value="BarcodeScanner"/>
|
||||||
|
</feature>
|
||||||
|
</config-file>
|
||||||
|
|
||||||
|
<source-file src="src/wp/BarcodeScanner.cs" />
|
||||||
|
<source-file src="src/wp/BarcodeScannerResult.cs" />
|
||||||
|
<source-file src="src/wp/Scan.xaml.cs" />
|
||||||
|
<source-file src="src/wp/Scan.xaml" />
|
||||||
|
</platform>
|
||||||
|
|
||||||
<!-- android -->
|
<!-- android -->
|
||||||
<platform name="android">
|
<platform name="android">
|
||||||
|
|||||||
@@ -1,216 +0,0 @@
|
|||||||
<?php
|
|
||||||
class PluginHelper {
|
|
||||||
public $basePath = 'src/android/LibraryProject/';
|
|
||||||
|
|
||||||
private function perror($msg)
|
|
||||||
{
|
|
||||||
file_put_contents('php://stderr', $msg, FILE_APPEND);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get contents of an XML file.
|
|
||||||
*
|
|
||||||
* @param string $xmlFilePath The XML file path relative to $this->basePath.
|
|
||||||
* @param string $parent Parent element from which to get children.
|
|
||||||
* @param array $options
|
|
||||||
* <li>ident - ident chanracters.
|
|
||||||
* <li>ignorePattern - pattern that will be matched to XML.
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getXml($xmlFilePath, $parent, $options=array())
|
|
||||||
{
|
|
||||||
if (!isset($options['indent']))
|
|
||||||
{
|
|
||||||
$options['indent'] = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
$contents = "";
|
|
||||||
$filePath = $this->basePath . $xmlFilePath;
|
|
||||||
if (!file_exists($filePath))
|
|
||||||
{
|
|
||||||
$this->perror("File $filePath does not exist");
|
|
||||||
return $contents;
|
|
||||||
}
|
|
||||||
|
|
||||||
$xml = file_get_contents($this->basePath . $xmlFilePath);
|
|
||||||
$document = new SimpleXMLElement($xml);
|
|
||||||
$els = $document->xpath($parent);
|
|
||||||
if (!empty($els))
|
|
||||||
{
|
|
||||||
$rootNode = $els[0];
|
|
||||||
foreach ($rootNode->children() as $child)
|
|
||||||
{
|
|
||||||
$childContent = $child->asXML();
|
|
||||||
if (isset($options['ignorePattern']) && preg_match($options['ignorePattern'], $childContent))
|
|
||||||
{
|
|
||||||
$this->perror("\nignored $childContent");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$contents .= "\n" . $options['indent'] . $childContent;
|
|
||||||
}
|
|
||||||
$contents = ltrim ($contents) . "\n";
|
|
||||||
return $contents;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->perror("Path $parent not found in $xmlFilePath");
|
|
||||||
return $contents;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate source-file tags to copy all resources from given dir.
|
|
||||||
*
|
|
||||||
* @param type $dir Dir path relative to $this->basePath.
|
|
||||||
* @param array $options
|
|
||||||
* <li>ident - ident chanracters.
|
|
||||||
*/
|
|
||||||
public function sourceFiles($dir, $options=array())
|
|
||||||
{
|
|
||||||
//ob_end_clean();
|
|
||||||
|
|
||||||
if (!isset($options['indent']))
|
|
||||||
{
|
|
||||||
$options['indent'] = "";
|
|
||||||
}
|
|
||||||
$path = $this->basePath . $dir;
|
|
||||||
|
|
||||||
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
|
|
||||||
while($it->valid())
|
|
||||||
{
|
|
||||||
if (!$it->isDot())
|
|
||||||
{
|
|
||||||
$filename = strtr($it->key(), '\\', '/');
|
|
||||||
if (isset($options['ignorePattern']) && preg_match($options['ignorePattern'], $filename))
|
|
||||||
{
|
|
||||||
$this->perror("\nignored $filename");
|
|
||||||
$it->next();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$targetDir = preg_replace('#.+LibraryProject/(.+?)/[^/]+$#', '$1', $filename);
|
|
||||||
echo "\n{$options['indent']}<source-file src=\"$filename\" target-dir=\"$targetDir\"/>";
|
|
||||||
}
|
|
||||||
$it->next();
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "\n";
|
|
||||||
//exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// init
|
|
||||||
$pluginHelper = new PluginHelper();
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
echo '<?xml version="1.0" encoding="UTF-8"?>';
|
|
||||||
?>
|
|
||||||
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
id="com.phonegap.plugins.barcodescanner"
|
|
||||||
version="0.5.3">
|
|
||||||
|
|
||||||
<name>BarcodeScanner</name>
|
|
||||||
|
|
||||||
<description>Scans Barcodes.</description>
|
|
||||||
|
|
||||||
<engines>
|
|
||||||
<engine name="cordova" version=">=2.0.0" />
|
|
||||||
</engines>
|
|
||||||
|
|
||||||
<asset src="www/barcodescanner.js" target="barcodescanner.js" />
|
|
||||||
|
|
||||||
<!-- ios -->
|
|
||||||
<platform name="ios">
|
|
||||||
<plugins-plist key="BarcodeScanner" string="CDVBarcodeScanner" />
|
|
||||||
|
|
||||||
<!-- Cordova >= 2.3 -->
|
|
||||||
<config-file target="config.xml" parent="plugins">
|
|
||||||
<plugin name="BarcodeScanner" value="CDVBarcodeScanner"/>
|
|
||||||
</config-file>
|
|
||||||
|
|
||||||
<resource-file src="src/ios/scannerOverlay.xib" />
|
|
||||||
|
|
||||||
<header-file src="src/ios/zxing-all-in-one.h" />
|
|
||||||
|
|
||||||
<source-file src="src/ios/CDVBarcodeScanner.mm" />
|
|
||||||
<source-file src="src/ios/zxing-all-in-one.cpp" />
|
|
||||||
|
|
||||||
<framework src="libiconv.dylib" />
|
|
||||||
<framework src="AVFoundation.framework" />
|
|
||||||
<framework src="AssetsLibrary.framework" />
|
|
||||||
<framework src="CoreVideo.framework" />
|
|
||||||
</platform>
|
|
||||||
|
|
||||||
<!-- android -->
|
|
||||||
<platform name="android">
|
|
||||||
|
|
||||||
<source-file src="src/android/com/phonegap/plugins/barcodescanner/BarcodeScanner.java" target-dir="src/com/phonegap/plugins/barcodescanner" />
|
|
||||||
<!--
|
|
||||||
<source-file src="R.java" target-dir="src/com/google/zxing/client/android" />
|
|
||||||
-->
|
|
||||||
|
|
||||||
<config-file target="res/xml/plugins.xml" parent="/plugins">
|
|
||||||
<plugin name="BarcodeScanner" value="com.phonegap.plugins.barcodescanner.BarcodeScanner"/>
|
|
||||||
</config-file>
|
|
||||||
|
|
||||||
<config-file target="res/xml/config.xml" parent="plugins">
|
|
||||||
<plugin name="BarcodeScanner" value="com.phonegap.plugins.barcodescanner.BarcodeScanner"/>
|
|
||||||
</config-file>
|
|
||||||
|
|
||||||
<config-file target="AndroidManifest.xml" parent="/manifest/application">
|
|
||||||
<activity
|
|
||||||
android:name="com.google.zxing.client.android.CaptureActivity"
|
|
||||||
android:screenOrientation="landscape"
|
|
||||||
android:clearTaskOnLaunch="true"
|
|
||||||
android:configChanges="orientation|keyboardHidden"
|
|
||||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
|
|
||||||
android:windowSoftInputMode="stateAlwaysHidden"
|
|
||||||
android:exported="false">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="com.phonegap.plugins.barcodescanner.SCAN"/>
|
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
<activity android:name="com.google.zxing.client.android.encode.EncodeActivity" android:label="@string/share_name">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="com.phonegap.plugins.barcodescanner.ENCODE"/>
|
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
<activity android:name="com.google.zxing.client.android.HelpActivity" android:label="@string/share_name">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.VIEW"/>
|
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
</config-file>
|
|
||||||
|
|
||||||
<config-file target="AndroidManifest.xml" parent="/manifest">
|
|
||||||
<uses-permission android:name="android.permission.CAMERA" />
|
|
||||||
<uses-permission android:name="android.permission.FLASHLIGHT" />
|
|
||||||
<!-- Not required to allow users to work around this -->
|
|
||||||
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
|
||||||
</config-file>
|
|
||||||
|
|
||||||
<source-file src="src/android/com.google.zxing.client.android.captureactivity.jar" target-dir="libs"/>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
LibraryProject/res/*.*
|
|
||||||
search: (src/android/LibraryProject/(.+?)/[^/]+)$
|
|
||||||
replace: <source-file src="$1" target-dir="$2"/>
|
|
||||||
-->
|
|
||||||
<?
|
|
||||||
$pluginHelper->sourceFiles("res", array('indent'=>"\t\t", 'ignorePattern' => '#values/strings.xml#'));
|
|
||||||
?>
|
|
||||||
|
|
||||||
<!-- plugman cannot merge - prepare manual merge -->
|
|
||||||
<config-file target="res/values/strings.xml" parent="/resources">
|
|
||||||
<?=$pluginHelper->getXml('res/values/strings.xml', "/resources", array('ignorePattern' => '/name="(app_name|menu_settings)"/', 'indent' => "\t\t\t"))?>
|
|
||||||
</config-file>
|
|
||||||
</platform>
|
|
||||||
</plugin>
|
|
||||||
<?php
|
|
||||||
$pluginText = ob_get_clean();
|
|
||||||
file_put_contents("plugin.xml", $pluginText);
|
|
||||||
?>
|
|
||||||
@@ -15,20 +15,5 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item android:id="@+id/menu_share"
|
<!-- removed nonfunctional menu - see file history to retrieve -->
|
||||||
android:title="@string/menu_share"
|
|
||||||
android:icon="@android:drawable/ic_menu_share"
|
|
||||||
android:orderInCategory="1"/>
|
|
||||||
<item android:id="@+id/menu_history"
|
|
||||||
android:title="@string/menu_history"
|
|
||||||
android:icon="@android:drawable/ic_menu_recent_history"
|
|
||||||
android:orderInCategory="2"/>
|
|
||||||
<item android:id="@+id/menu_settings"
|
|
||||||
android:title="@string/menu_settings"
|
|
||||||
android:icon="@android:drawable/ic_menu_preferences"
|
|
||||||
android:orderInCategory="3"/>
|
|
||||||
<item android:id="@+id/menu_help"
|
|
||||||
android:title="@string/menu_help"
|
|
||||||
android:icon="@android:drawable/ic_menu_help"
|
|
||||||
android:orderInCategory="4"/>
|
|
||||||
</menu>
|
</menu>
|
||||||
@@ -15,12 +15,5 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item android:id="@+id/menu_share"
|
<!-- removed nonfunctional menu - see file history to retrieve -->
|
||||||
android:title="@string/menu_share"
|
|
||||||
android:icon="@android:drawable/ic_menu_share"
|
|
||||||
android:orderInCategory="1"/>
|
|
||||||
<item android:id="@+id/menu_encode"
|
|
||||||
android:title="@string/menu_encode_vcard"
|
|
||||||
android:icon="@android:drawable/ic_menu_sort_alphabetically"
|
|
||||||
android:orderInCategory="2"/>
|
|
||||||
</menu>
|
</menu>
|
||||||
@@ -81,6 +81,7 @@ Workflow for creating and building example project with the plugin:
|
|||||||
3. Install the plugin (current dir. being "hello"):
|
3. Install the plugin (current dir. being "hello"):
|
||||||
```
|
```
|
||||||
plugman --plugins_dir plugins --plugin com.phonegap.plugins.barcodescanner --platform android --project platforms\android
|
plugman --plugins_dir plugins --plugin com.phonegap.plugins.barcodescanner --platform android --project platforms\android
|
||||||
|
plugman install --plugins_dir plugins --plugin com.phonegap.plugins.barcodescanner --platform android --project platforms\android
|
||||||
```
|
```
|
||||||
|
|
||||||
Note. To manually remove plugin you need to re-create plugins\android.json (and remove changes done by the plugin - you can simply remove whole platform as described in first step and re-create).
|
Note. To manually remove plugin you need to re-create plugins\android.json (and remove changes done by the plugin - you can simply remove whole platform as described in first step and re-create).
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
#import <AVFoundation/AVFoundation.h>
|
#import <AVFoundation/AVFoundation.h>
|
||||||
#import <AssetsLibrary/AssetsLibrary.h>
|
#import <AssetsLibrary/AssetsLibrary.h>
|
||||||
|
#import <AudioToolbox/AudioToolbox.h>
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// use the all-in-one version of zxing that we built
|
// use the all-in-one version of zxing that we built
|
||||||
@@ -46,8 +47,8 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@interface CDVBarcodeScanner : CDVPlugin {}
|
@interface CDVBarcodeScanner : CDVPlugin {}
|
||||||
- (NSString*)isScanNotPossible;
|
- (NSString*)isScanNotPossible;
|
||||||
- (void)scan:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
|
- (void)scan:(CDVInvokedUrlCommand*)command;
|
||||||
- (void)encode:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
|
- (void)encode:(CDVInvokedUrlCommand*)command;
|
||||||
- (void)returnSuccess:(NSString*)scannedText format:(NSString*)format cancelled:(BOOL)cancelled callback:(NSString*)callback;
|
- (void)returnSuccess:(NSString*)scannedText format:(NSString*)format cancelled:(BOOL)cancelled callback:(NSString*)callback;
|
||||||
- (void)returnError:(NSString*)message callback:(NSString*)callback;
|
- (void)returnError:(NSString*)message callback:(NSString*)callback;
|
||||||
@end
|
@end
|
||||||
@@ -120,18 +121,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
- (void)scan:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
|
- (void)scan:(CDVInvokedUrlCommand*)command {
|
||||||
CDVbcsProcessor* processor;
|
CDVbcsProcessor* processor;
|
||||||
NSString* callback;
|
NSString* callback;
|
||||||
NSString* capabilityError;
|
NSString* capabilityError;
|
||||||
|
|
||||||
callback = [arguments objectAtIndex:0];
|
callback = command.callbackId;
|
||||||
|
|
||||||
// We allow the user to define an alternate xib file for loading the overlay.
|
// We allow the user to define an alternate xib file for loading the overlay.
|
||||||
NSString *overlayXib = nil;
|
NSString *overlayXib = nil;
|
||||||
if ( [arguments count] == 2 )
|
if ( [command.arguments count] >= 1 )
|
||||||
{
|
{
|
||||||
overlayXib = [arguments objectAtIndex:1];
|
overlayXib = [command.arguments objectAtIndex:0];
|
||||||
}
|
}
|
||||||
|
|
||||||
capabilityError = [self isScanNotPossible];
|
capabilityError = [self isScanNotPossible];
|
||||||
@@ -152,8 +153,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
- (void)encode:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
|
- (void)encode:(CDVInvokedUrlCommand*)command {
|
||||||
[self returnError:@"encode function not supported" callback:[arguments objectAtIndex:0]];
|
[self returnError:@"encode function not supported" callback:command.callbackId];
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@@ -205,6 +206,8 @@
|
|||||||
@synthesize is2D = _is2D;
|
@synthesize is2D = _is2D;
|
||||||
@synthesize capturing = _capturing;
|
@synthesize capturing = _capturing;
|
||||||
|
|
||||||
|
SystemSoundID _soundFileObject;
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
- (id)initWithPlugin:(CDVBarcodeScanner*)plugin
|
- (id)initWithPlugin:(CDVBarcodeScanner*)plugin
|
||||||
callback:(NSString*)callback
|
callback:(NSString*)callback
|
||||||
@@ -222,6 +225,9 @@ parentViewController:(UIViewController*)parentViewController
|
|||||||
self.is2D = YES;
|
self.is2D = YES;
|
||||||
self.capturing = NO;
|
self.capturing = NO;
|
||||||
|
|
||||||
|
CFURLRef soundFileURLRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("CDVBarcodeScanner.bundle/beep"), CFSTR ("caf"), NULL);
|
||||||
|
AudioServicesCreateSystemSoundID(soundFileURLRef, &_soundFileObject);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,6 +243,9 @@ parentViewController:(UIViewController*)parentViewController
|
|||||||
|
|
||||||
self.capturing = NO;
|
self.capturing = NO;
|
||||||
|
|
||||||
|
AudioServicesRemoveSystemSoundCompletion(_soundFileObject);
|
||||||
|
AudioServicesDisposeSystemSoundID(_soundFileObject);
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,6 +290,9 @@ parentViewController:(UIViewController*)parentViewController
|
|||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
- (void)barcodeScanSucceeded:(NSString*)text format:(NSString*)format {
|
- (void)barcodeScanSucceeded:(NSString*)text format:(NSString*)format {
|
||||||
[self barcodeScanDone];
|
[self barcodeScanDone];
|
||||||
|
|
||||||
|
AudioServicesPlaySystemSound(_soundFileObject);
|
||||||
|
|
||||||
[self.plugin returnSuccess:text format:format cancelled:FALSE callback:self.callback];
|
[self.plugin returnSuccess:text format:format cancelled:FALSE callback:self.callback];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,7 +332,9 @@ parentViewController:(UIViewController*)parentViewController
|
|||||||
output.alwaysDiscardsLateVideoFrames = YES;
|
output.alwaysDiscardsLateVideoFrames = YES;
|
||||||
output.videoSettings = videoOutputSettings;
|
output.videoSettings = videoOutputSettings;
|
||||||
|
|
||||||
[output setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
|
dispatch_queue_t queue = dispatch_queue_create("CDVBarcodeScanner", NULL);
|
||||||
|
[output setSampleBufferDelegate:self queue:queue];
|
||||||
|
dispatch_release(queue);
|
||||||
|
|
||||||
if (![captureSession canSetSessionPreset:AVCaptureSessionPresetMedium]) {
|
if (![captureSession canSetSessionPreset:AVCaptureSessionPresetMedium]) {
|
||||||
return @"unable to preset medium quality video capture";
|
return @"unable to preset medium quality video capture";
|
||||||
@@ -416,7 +430,13 @@ parentViewController:(UIViewController*)parentViewController
|
|||||||
const char* cString = resultText->getText().c_str();
|
const char* cString = resultText->getText().c_str();
|
||||||
NSString* resultString = [[[NSString alloc] initWithCString:cString encoding:NSUTF8StringEncoding] autorelease];
|
NSString* resultString = [[[NSString alloc] initWithCString:cString encoding:NSUTF8StringEncoding] autorelease];
|
||||||
|
|
||||||
[self barcodeScanSucceeded:resultString format:format];
|
NSMethodSignature *sig = [self methodSignatureForSelector:@selector(barcodeScanSucceeded:format:)];
|
||||||
|
NSInvocation *invoke = [NSInvocation invocationWithMethodSignature:sig];
|
||||||
|
[invoke setTarget:self];
|
||||||
|
[invoke setSelector:@selector(barcodeScanSucceeded:format:)];
|
||||||
|
[invoke setArgument:&resultString atIndex:2];
|
||||||
|
[invoke setArgument:&format atIndex:3];
|
||||||
|
[invoke performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:YES];
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (zxing::ReaderException &rex) {
|
catch (zxing::ReaderException &rex) {
|
||||||
|
|||||||
@@ -1940,7 +1940,7 @@ GreyscaleLuminanceSource::GreyscaleLuminanceSource(unsigned char* greyData, int
|
|||||||
|
|
||||||
unsigned char* GreyscaleLuminanceSource::getRow(int y, unsigned char* row) {
|
unsigned char* GreyscaleLuminanceSource::getRow(int y, unsigned char* row) {
|
||||||
if (y < 0 || y >= this->getHeight()) {
|
if (y < 0 || y >= this->getHeight()) {
|
||||||
throw IllegalArgumentException("Requested row is outside the image: " + y);
|
throw IllegalArgumentException("Requested row is outside the image.");
|
||||||
}
|
}
|
||||||
int width = getWidth();
|
int width = getWidth();
|
||||||
// TODO(flyashi): determine if row has enough size.
|
// TODO(flyashi): determine if row has enough size.
|
||||||
@@ -2017,7 +2017,7 @@ GreyscaleRotatedLuminanceSource::GreyscaleRotatedLuminanceSource(unsigned char*
|
|||||||
// The API asks for rows, but we're rotated, so we return columns.
|
// The API asks for rows, but we're rotated, so we return columns.
|
||||||
unsigned char* GreyscaleRotatedLuminanceSource::getRow(int y, unsigned char* row) {
|
unsigned char* GreyscaleRotatedLuminanceSource::getRow(int y, unsigned char* row) {
|
||||||
if (y < 0 || y >= getHeight()) {
|
if (y < 0 || y >= getHeight()) {
|
||||||
throw IllegalArgumentException("Requested row is outside the image: " + y);
|
throw IllegalArgumentException("Requested row is outside the image");
|
||||||
}
|
}
|
||||||
int width = getWidth();
|
int width = getWidth();
|
||||||
if (row == NULL) {
|
if (row == NULL) {
|
||||||
@@ -10309,7 +10309,7 @@ namespace {
|
|||||||
int secondThirdBytes = bits.readBits(16);
|
int secondThirdBytes = bits.readBits(16);
|
||||||
return ((firstByte & 0x1F) << 16) | secondThirdBytes;
|
return ((firstByte & 0x1F) << 16) | secondThirdBytes;
|
||||||
}
|
}
|
||||||
throw IllegalArgumentException("Bad ECI bits starting with byte " + firstByte);
|
throw IllegalArgumentException("Bad ECI bits starting with byte ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
using BarcodeScanner;
|
||||||
|
using Microsoft.Phone.Controls;
|
||||||
|
using System;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using WPCordovaClassLib.Cordova;
|
||||||
|
using WPCordovaClassLib.Cordova.Commands;
|
||||||
|
using WPCordovaClassLib.Cordova.JSON;
|
||||||
|
|
||||||
|
namespace Cordova.Extension.Commands
|
||||||
|
{
|
||||||
|
public class BarcodeScanner : BaseCommand
|
||||||
|
{
|
||||||
|
private PhoneApplicationFrame currentRootVisual;
|
||||||
|
|
||||||
|
public void scan(string options)
|
||||||
|
{
|
||||||
|
Deployment.Current.Dispatcher.BeginInvoke(() =>
|
||||||
|
{
|
||||||
|
currentRootVisual = Application.Current.RootVisual as PhoneApplicationFrame;
|
||||||
|
currentRootVisual.Navigated += OnFrameNavigated;
|
||||||
|
currentRootVisual.Navigate(new Uri("/Plugins/com.phonegap.plugins.barcodescanner/Scan.xaml", UriKind.Relative));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnFrameNavigated(object sender, NavigationEventArgs e)
|
||||||
|
{
|
||||||
|
var scanPage = e.Content as Scan;
|
||||||
|
if (scanPage != null)
|
||||||
|
{
|
||||||
|
scanPage.BarcodeScannerPlugin = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnScanFailed(string error)
|
||||||
|
{
|
||||||
|
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, error));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnScanSucceeded(BarcodeScannerResult scanResult)
|
||||||
|
{
|
||||||
|
var resultString = JsonHelper.Serialize(scanResult);
|
||||||
|
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, resultString));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BarcodeScanner
|
||||||
|
{
|
||||||
|
public class BarcodeScannerResult
|
||||||
|
{
|
||||||
|
public string format
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string text
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<phone:PhoneApplicationPage
|
||||||
|
x:Class="BarcodeScanner.Scan"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
|
||||||
|
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
FontFamily="{StaticResource PhoneFontFamilyNormal}"
|
||||||
|
FontSize="{StaticResource PhoneFontSizeNormal}"
|
||||||
|
Foreground="{StaticResource PhoneForegroundBrush}"
|
||||||
|
SupportedOrientations="Portrait" Orientation="Portrait"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
shell:SystemTray.IsVisible="True">
|
||||||
|
|
||||||
|
<!--LayoutRoot is the root grid where all page content is placed-->
|
||||||
|
<Grid x:Name="LayoutRoot" Background="Transparent">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
<RowDefinition Height="100" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<Canvas x:Name="viewfinderCanvas">
|
||||||
|
|
||||||
|
<!--Camera viewfinder -->
|
||||||
|
<Canvas.Background>
|
||||||
|
<VideoBrush x:Name="viewfinderBrush">
|
||||||
|
<VideoBrush.RelativeTransform>
|
||||||
|
<CompositeTransform
|
||||||
|
x:Name="viewfinderTransform"
|
||||||
|
CenterX="0.5"
|
||||||
|
CenterY="0.5"
|
||||||
|
Rotation="90"/>
|
||||||
|
</VideoBrush.RelativeTransform>
|
||||||
|
</VideoBrush>
|
||||||
|
</Canvas.Background>
|
||||||
|
</Canvas>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
</phone:PhoneApplicationPage>
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using Microsoft.Phone.Controls;
|
||||||
|
using Microsoft.Phone.Shell;
|
||||||
|
using Microsoft.Devices;
|
||||||
|
using System.Windows.Threading;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using ZXing;
|
||||||
|
|
||||||
|
namespace BarcodeScanner
|
||||||
|
{
|
||||||
|
public partial class Scan : PhoneApplicationPage
|
||||||
|
{
|
||||||
|
private PhotoCamera phoneCamera;
|
||||||
|
private IBarcodeReader barcodeReader;
|
||||||
|
private DispatcherTimer scanTimer;
|
||||||
|
private WriteableBitmap previewBuffer;
|
||||||
|
|
||||||
|
private string scannedCode = string.Empty;
|
||||||
|
|
||||||
|
private bool scanSucceeded;
|
||||||
|
|
||||||
|
public Scan()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cordova.Extension.Commands.BarcodeScanner BarcodeScannerPlugin
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
|
||||||
|
{
|
||||||
|
// Initialize the camera object
|
||||||
|
phoneCamera = new PhotoCamera();
|
||||||
|
phoneCamera.Initialized += OnCameraInitialized;
|
||||||
|
|
||||||
|
CameraButtons.ShutterKeyHalfPressed += OnCameraButtonShutterKeyHalfPressed;
|
||||||
|
|
||||||
|
//Display the camera feed in the UI
|
||||||
|
viewfinderBrush.SetSource(phoneCamera);
|
||||||
|
|
||||||
|
|
||||||
|
// This timer will be used to scan the camera buffer every 250ms and scan for any barcodes
|
||||||
|
scanTimer = new DispatcherTimer();
|
||||||
|
scanTimer.Interval = TimeSpan.FromMilliseconds(250);
|
||||||
|
scanTimer.Tick += (o, arg) => ScanForBarcode();
|
||||||
|
|
||||||
|
base.OnNavigatedTo(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCameraButtonShutterKeyHalfPressed(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
phoneCamera.Focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
|
||||||
|
{
|
||||||
|
scanTimer.Stop();
|
||||||
|
|
||||||
|
if (phoneCamera != null)
|
||||||
|
{
|
||||||
|
phoneCamera.Dispose();
|
||||||
|
phoneCamera.Initialized -= OnCameraInitialized;
|
||||||
|
CameraButtons.ShutterKeyHalfPressed -= OnCameraButtonShutterKeyHalfPressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!scanSucceeded)
|
||||||
|
{
|
||||||
|
BarcodeScannerPlugin.OnScanFailed("Cancelled by user");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnCameraInitialized(object sender, Microsoft.Devices.CameraOperationCompletedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Succeeded)
|
||||||
|
{
|
||||||
|
this.Dispatcher.BeginInvoke(delegate()
|
||||||
|
{
|
||||||
|
phoneCamera.FlashMode = FlashMode.Off;
|
||||||
|
previewBuffer = new WriteableBitmap((int)phoneCamera.PreviewResolution.Width, (int)phoneCamera.PreviewResolution.Height);
|
||||||
|
|
||||||
|
barcodeReader = new BarcodeReader();
|
||||||
|
|
||||||
|
// By default, BarcodeReader will scan every supported barcode type
|
||||||
|
// If we want to limit the type of barcodes our app can read,
|
||||||
|
// we can do it by adding each format to this list object
|
||||||
|
|
||||||
|
//var supportedBarcodeFormats = new List<BarcodeFormat>();
|
||||||
|
//supportedBarcodeFormats.Add(BarcodeFormat.QR_CODE);
|
||||||
|
//supportedBarcodeFormats.Add(BarcodeFormat.DATA_MATRIX);
|
||||||
|
//_bcReader.PossibleFormats = supportedBarcodeFormats;
|
||||||
|
|
||||||
|
barcodeReader.Options.TryHarder = true;
|
||||||
|
|
||||||
|
barcodeReader.ResultFound += OnBarcodeResultFound;
|
||||||
|
scanTimer.Start();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Dispatcher.BeginInvoke(() =>
|
||||||
|
{
|
||||||
|
BarcodeScannerPlugin.OnScanFailed("Unable to initialize the camera");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnBarcodeResultFound(Result obj)
|
||||||
|
{
|
||||||
|
if (BarcodeIsValid(obj.Text))
|
||||||
|
{
|
||||||
|
var barcodeScannerResult = new BarcodeScannerResult();
|
||||||
|
barcodeScannerResult.format = obj.BarcodeFormat.ToString();
|
||||||
|
barcodeScannerResult.text = obj.Text;
|
||||||
|
scanSucceeded = true;
|
||||||
|
|
||||||
|
BarcodeScannerPlugin.OnScanSucceeded(barcodeScannerResult);
|
||||||
|
NavigationService.GoBack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool BarcodeIsValid(string barcode)
|
||||||
|
{
|
||||||
|
if (barcode.Equals(scannedCode))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ScanForBarcode()
|
||||||
|
{
|
||||||
|
//grab a camera snapshot
|
||||||
|
phoneCamera.GetPreviewBufferArgb32(previewBuffer.Pixels);
|
||||||
|
previewBuffer.Invalidate();
|
||||||
|
|
||||||
|
//scan the captured snapshot for barcodes
|
||||||
|
//if a barcode is found, the ResultFound event will fire
|
||||||
|
barcodeReader.Decode(previewBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
-5
@@ -6,10 +6,7 @@
|
|||||||
* Copyright (c) 2011, IBM Corporation
|
* Copyright (c) 2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var ScannerLoader = function (require, exports, module) {
|
||||||
cordova.define("cordova/plugin/BarcodeScanner",
|
|
||||||
|
|
||||||
function (require, exports, module) {
|
|
||||||
|
|
||||||
var exec = require("cordova/exec");
|
var exec = require("cordova/exec");
|
||||||
|
|
||||||
@@ -88,4 +85,13 @@ cordova.define("cordova/plugin/BarcodeScanner",
|
|||||||
|
|
||||||
var barcodeScanner = new BarcodeScanner();
|
var barcodeScanner = new BarcodeScanner();
|
||||||
module.exports = barcodeScanner;
|
module.exports = barcodeScanner;
|
||||||
});
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ScannerLoader(require, exports, module);
|
||||||
|
|
||||||
|
cordova.define("cordova/plugin/BarcodeScanner", ScannerLoader);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user