Created
March 26, 2013 20:06
-
-
Save rblalock/5248713 to your computer and use it in GitHub Desktop.
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
var RedLaser = require('ti.redlaser'); | |
var win = Ti.UI.createWindow({ | |
backgroundColor: "#eee" | |
}); | |
var startScanningBtn = Ti.UI.createButton({ | |
width: "50%", | |
height: 50, | |
title: "Start Scanning" | |
}); | |
var overlayWrapper = Ti.UI.createView(); | |
var target = Ti.UI.createView({ | |
borderColor: "red", | |
width: 250, | |
height: 175 | |
}); | |
var close = Ti.UI.createButton({ | |
title: "Close", | |
width: "50%", | |
height: 50, | |
bottom: 10 | |
}); | |
overlayWrapper.add( target ); | |
overlayWrapper.add( close ); | |
win.add( startScanningBtn ); | |
close.addEventListener("click", function() { | |
RedLaser.doneScanning(); | |
}); | |
startScanningBtn.addEventListener("click", function() { | |
RedLaser.startScanning({ | |
overlay: overlayWrapper | |
}); | |
}); | |
RedLaser.addEventListener("scannerStatusUpdated", function(_event) { | |
Ti.API.info(_event.foundBarcodes); | |
if(_event.foundBarcodes.length > 0) { | |
RedLaser.doneScanning(); | |
Ti.API.info( _event.foundBarcodes[0].barcodeTypeString ); | |
Ti.API.info( _event.foundBarcodes[0].barcodeExtendedString ); | |
Ti.API.info( _event.foundBarcodes[0].barcodeExtendedString ); | |
alert( _event.foundBarcodes[0].barcodeString ); | |
} | |
}); | |
RedLaser.addEventListener('scannerActivated', function() { | |
Ti.API.info('scannerActivated event received.'); | |
// All barcode types are enabled by default. Here we turn off most of them | |
// to improve performance. | |
RedLaser.scanSticky = false; | |
RedLaser.scanCodabar = false; | |
RedLaser.scanCode39 = false; | |
RedLaser.scanCode93 = false; | |
RedLaser.scanDataMatrix = false; | |
RedLaser.scanEan2 = false; | |
RedLaser.scanEan5 = false; | |
RedLaser.scanEan8 = false; | |
RedLaser.scanITF = false; | |
RedLaser.scanRSS14 = false; | |
RedLaser.scanSticky = false; | |
}); | |
RedLaser.addEventListener('backButtonPressed', function (e) { | |
RedLaser.doneScanning(); | |
}); | |
RedLaser.addEventListener('enabledBarcodeTypesChanged', function() { | |
Ti.API.info('enabledBarcodeTypesChanged event received.'); | |
}); | |
RedLaser.addEventListener('cameraError', function(e) { | |
Ti.API.info('cameraError event received. Code: ' + e.errorCode); | |
}); | |
RedLaser.doneScanning(); | |
// Test Constants | |
Ti.API.info('BARCODE_TYPE_CODABAR:' + RedLaser.BARCODE_TYPE_CODABAR); | |
Ti.API.info('BARCODE_TYPE_CODE128:' + RedLaser.BARCODE_TYPE_CODE128); | |
Ti.API.info('BARCODE_TYPE_CODE39:' + RedLaser.BARCODE_TYPE_CODE39); | |
Ti.API.info('BARCODE_TYPE_CODE93:' + RedLaser.BARCODE_TYPE_CODE93); | |
Ti.API.info('BARCODE_TYPE_DATAMATRIX:' + RedLaser.BARCODE_TYPE_DATAMATRIX); | |
Ti.API.info('BARCODE_TYPE_EAN13:' + RedLaser.BARCODE_TYPE_EAN13); | |
Ti.API.info('BARCODE_TYPE_EAN2:' + RedLaser.BARCODE_TYPE_EAN2); | |
Ti.API.info('BARCODE_TYPE_EAN5:' + RedLaser.BARCODE_TYPE_EAN5); | |
Ti.API.info('BARCODE_TYPE_EAN8:' + RedLaser.BARCODE_TYPE_EAN8); | |
Ti.API.info('BARCODE_TYPE_ITF:' + RedLaser.BARCODE_TYPE_ITF); | |
Ti.API.info('BARCODE_TYPE_NONE:' + RedLaser.BARCODE_TYPE_NONE); | |
Ti.API.info('BARCODE_TYPE_QRCODE:' + RedLaser.BARCODE_TYPE_QRCODE); | |
Ti.API.info('BARCODE_TYPE_RSS14:' + RedLaser.BARCODE_TYPE_RSS14); | |
Ti.API.info('BARCODE_TYPE_STICKY:' + RedLaser.BARCODE_TYPE_STICKY); | |
Ti.API.info('BARCODE_TYPE_UPCE:' + RedLaser.BARCODE_TYPE_UPCE); | |
Ti.API.info('STATUS_API_LEVEL_TOO_LOW:' + RedLaser.STATUS_API_LEVEL_TOO_LOW); | |
Ti.API.info('STATUS_EVAL_MODE_READY:' + RedLaser.STATUS_EVAL_MODE_READY); | |
Ti.API.info('STATUS_LICENSED_MODE_READY:' + RedLaser.STATUS_LICENSED_MODE_READY); | |
Ti.API.info('STATUS_MISSING_OS_LIBS:' + RedLaser.STATUS_MISSING_OS_LIBS); | |
Ti.API.info('STATUS_NO_CAMERA:' + RedLaser.STATUS_NO_CAMERA); | |
Ti.API.info('STATUS_BAD_LICENSE:' + RedLaser.STATUS_BAD_LICENSE); | |
Ti.API.info('STATUS_SCAN_LIMIT_REACHED:' + RedLaser.STATUS_SCAN_LIMIT_REACHED); | |
Ti.API.info('STATUS_MISSING_PERMISSIONS:' + RedLaser.STATUS_MISSING_PERMISSIONS); | |
Ti.API.info('STATUS_UNKNOWN_STATE:' + RedLaser.STATUS_UNKNOWN_STATE); | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment