Skip to content

Instantly share code, notes, and snippets.

@jonalter
Created February 6, 2012 23:19
Show Gist options
  • Select an option

  • Save jonalter/1755813 to your computer and use it in GitHub Desktop.

Select an option

Save jonalter/1755813 to your computer and use it in GitHub Desktop.
iOS: fake loading screen for barcode module
var Barcode = require('ti.barcode');
Barcode.allowRotation = false;
var barLoadWin = null;
 
Barcode.addEventListener('error', function(e) {
    Ti.API.info('ERROR called with barcode: ' + e);
    if(barLoadWin){
        barLoadWin.close();
    }
});
Barcode.addEventListener('cancel', function(e) {
    Ti.API.info('Cancel received');
    if(barLoadWin){
        barLoadWin.close();
    }
});
Barcode.addEventListener('success', function(e) {
    Ti.API.info('Success called with barcode: ' + e.result);
    if(barLoadWin){
        barLoadWin.close();
    }
});
 
var overlay = Ti.UI.createView({
    backgroundColor: 'transparent',
    top: 0, right: 0, bottom: 0, left: 0
});
 
var cancelButton = Ti.UI.createButton({
    title: 'Cancel', textAlign: 'center',
    color: '#000', backgroundColor: '#fff', style: 0,
    font: { fontWeight: 'bold', fontSize: 16 },
    borderColor: '#000', borderRadius: 10, borderWidth: 1,
    opacity: 0.5,
    width: 220, height: 45,
    bottom: 20
});
cancelButton.addEventListener('click', function() {
    Barcode.cancel();
});
overlay.add(cancelButton);
 
App.Barcode.init = function(){
// The barcode_loading.png is a screen shot of the barcode scanner, taken when it was open.
// Opening this window with this background image creates the illution that the scanner
// comes up before it actually does.
    barLoadWin = Ti.UI.createWindow({backgroundImage:'/barcode_loading.png'});
    barLoadWin.open();
     
    Barcode.capture({
        animate: false,
        overlay: overlay
    });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment