UNPKG

@titanium/barcode

Version:

⭐ Axway Amplify module for scanning barcodes with Appcelerator Titanium SDK

180 lines (94 loc) 8.45 kB
<h1>Ti.Barcode Module</h1> <h2>Description</h2> <p>Lets you process 1D/2D barcodes.</p> <h2>Getting Started</h2> <p>View the <a href="http://docs.appcelerator.com/titanium/latest/#!/guide/Using_Titanium_Modules">Using Titanium Modules</a> document for instructions on getting started with using this module in your application.</p> <h2>Warning when Updating to Barcode v1.5</h2> <p>With the 1.5 update to the Barcode Module, several breaking changes have been made. These changes were made to bring the iOS and Android modules in to full parity. When upgrading to 1.5, you will need to consider the following:</p> <ul><li>BREAKING CHANGE: iOS now uses event listeners instead of callbacks! Use Ti.Barcode.addEventListener(&#39;success&#39;, ...) instead of capture({ success: ...})!</li><li>BREAKING CHANGE: Android&#39;s contentType property is now an integer, instead of a string! Check out the example and documentation to find out more.</li><li>BREAKING CHANGE: All automatically parsed &quot;data&quot; keys will now be lower case. This ensures consistency across the API and ease of access.</li><li>BREAKING CHANGE: Android now properly fires the &quot;cancel&quot; event, as documented. It was firing the &quot;canceled&quot; event.</li><li>Ensure that you assign the module object that is returned from &quot;require(&#39;ti.barcode&#39;)&quot; to a variable or your event listeners may not receive the barcode events</li></ul> <h2>Accessing the Ti.Barcode Module</h2> <p>To access this module from JavaScript, you would do the following:</p> <p>&lt;pre&gt;var Barcode = require(&#39;ti.barcode&#39;);&lt;/pre&gt;</p> <h2>Functions</h2> <h3>capture([args])</h3> <p>Brings up the camera and begins the capture sequence for processing a barcode. Takes one optional argument, a dictionary containing any of the following properties:</p> <ul><li>animate[boolean]: Indicates if the device should animate between the current activity and the camera activity when the current activity is in a different orientation than the camera. Default is true.</li><li>showCancel[boolean]: Whether or not to include the default cancel button. Defaults to true.</li><li>showRectangle[boolean]: Whether or not to include the default rectangle around the scanning area. Defaults to true.</li><li>overlay[view]: The view to lay on top of the camera activity.</li><li>keepOpen[boolean]: Whether or not to keep the barcode scanner open after a barcode is recognized. Defaults to false. When set to true, &quot;success&quot; 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!</li><li>acceptedFormats[int[]]: An optional array of int constants detailing which barcode formats are accepted. Defaults to all formats. Check out the &quot;Barcode Format Constants&quot; section below to see the available int constants.</li><li>preventRotation[boolean]: Prevent the scanner from auto-rotating when the device is rotated. Default: true</li><li>frameWidth[int]: Width of the rectangle that is shown in the scanner</li><li>frameHeight[int]: Height of the rectangle that is shown in the scanner</li></ul> <h3>parse([args])</h3> <p>Parses a blob image for barcodes. Takes one required argument, a dictionary containing any of the following properties:</p> <ul><li>image[blob]: The image blob to parse for a barcode.</li><li>acceptedFormats[int[]]: An optional array of int constants detailing which barcode formats are accepted. Defaults to all formats. Check out the &quot;Barcode Format Constants&quot; section below to see the available int constants.</li></ul> <h3>cancel()</h3> <p>Cancels and closes the currently open capture window.</p> <h2>Events</h2> <p>Use Ti.Barcode.addEventListener() to process the following events that are sent from the module:</p> <h3>success</h3> <p>Sent upon a successful barcode scan. The event object contains the following fields:</p> <ul><li>format[string, Android only] : The format of the barcode</li><li>result[string] : The raw contents of the barcode</li><li>code[string, Android only] : The activity result code from the scanning activity. Use the result constants defined in the <a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Android-module">Ti.Android</a> namespace</li><li>contentType[int] : The type of barcode content. Use the constants defined in this module to determine which.</li><li>data[object]: The parsed fields associated with the contentType.</li></ul> <h3>error</h3> <p>Sent when an error occurs. The event object contains the following fields:</p> <ul><li>message[string] : The error message</li><li>code[string] : The activity result code from the scanning activity. Use the result constants defined in the <a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Android-module">Ti.Android</a> namespace</li></ul> <h3>cancel</h3> <p>Sent when the scanning process is canceled. The event object contains the following fields:</p> <ul><li>message[string] : The error message</li><li>code[string] : The activity result code from the scanning activity. Use the result constants defined in the <a href="http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Android-module">Ti.Android</a> namespace</li></ul> <h2>Properties</h2> <h3>allowRotation[boolean, defaults to false, iOS only]</h3> <p>Value that indicates if the barcode capture should analyze captured images in either portrait or landscape device orientation. (Warning: Analyzing both the captured image and the rotated version(s) of the image will increase the processing time of the capture.)</p> <ul><li>true: Captured images will be analyzed in both portrait and landscape orientation.</li><li>false [default]: Captured images will be analyzed using only the current device orientation.</li></ul> <h3>allowMenu[boolean, defaults to true, Android only]</h3> <p>Whether or not to allow the built-in ZXing menu to display.</p> <h3>allowInstructions[boolean, defaults to true, Android only]</h3> <p>Whether or not to display helpful instructions or a changelog when the app is updated.</p> <h3>displayedMessage[string]</h3> <p>Controls the message that is displayed to the end user when they are capturing a barcode.</p> <h3>useFrontCamera[boolean, defaults to false]</h3> <p>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 camera is available.</p> <h3>useLED[boolean, defaults to false]</h3> <p>Whether or not to use the LED when scanning barcodes (also known as the flashlight, torch, or some derivation thereof).</p> <h2>Barcode Result Type Constants</h2> <h3>URL[int]</h3> <p>Value representing URL content</p> <h3>SMS[int]</h3> <p>Value representing SMS content</p> <h3>TELEPHONE[int]</h3> <p>Value representing telephone number content</p> <h3>TEXT[int]</h3> <p>Value representing text content</p> <h3>CALENDAR[int]</h3> <p>Value representing date content</p> <h3>GEOLOCATION[int]</h3> <p>Value representing geolocation content</p> <h3>EMAIL[int]</h3> <p>Value representing an email address</p> <h3>CONTACT[int]</h3> <p>Value representing contact information (vcard or mecard)</p> <h3>BOOKMARK[int]</h3> <p>Value representing bookmark content</p> <h3>WIFI[int]</h3> <p>Value representing wifi connection settings</p> <h2>Barcode Format Constants</h2> <h3>FORMAT_NONE[int]</h3> <h3>FORMAT<em>QR</em>CODE[int]</h3> <h3>FORMAT<em>DATA</em>MATRIX[int]</h3> <h3>FORMAT<em>UPC</em>E[int]</h3> <h3>FORMAT<em>UPC</em>A[int]</h3> <h3>FORMAT<em>EAN</em>8[int]</h3> <h3>FORMAT<em>EAN</em>13[int]</h3> <h3>FORMAT<em>CODE</em>128[int]</h3> <h3>FORMAT<em>CODE</em>39[int]</h3> <h3>FORMAT_ITF[int]</h3> <h2>Usage</h2> <p>See example.</p> <h2>Author</h2> <p>Clint Tredway &amp; Dawson Toth</p> <h2>Module History</h2> <p>View the <a href="changelog.html">change log</a> for this module.</p> <h2>Feedback and Support</h2> <p>Please direct all questions, feedback, and concerns to <a href="mailto:info@appcelerator.com?subject=Android%20Barcode%20Module">info@appcelerator.com</a>.</p> <h2>License</h2> <p>Copyright(c) 2010-2013 by Appcelerator, Inc. All Rights Reserved. Please see the LICENSE file included in the distribution for further details.</p>