Skip to content

Instantly share code, notes, and snippets.

@dawsontoth
Created September 7, 2011 14:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dawsontoth/1200648 to your computer and use it in GitHub Desktop.
Save dawsontoth/1200648 to your computer and use it in GitHub Desktop.
QR Codes in Titanium Mobile
/**
* Creates an image view using Google's QR Code generator.
* @param text The text to be encoded in the QR code
* @param size The size of the QR code; Possible Sizes: 100x100, 150x150, 200x200, 250x250, 300x300, 350x350, 400x400, 500x500
*/
function createQRCodeImageView(text, size) {
var url = 'http://chart.apis.google.com/chart?cht=qr&chs=' + size + '&chl=' + encodeURI(text) + '&chld=H|0';
var width = size.split('x')[0], height = size.split('x')[1];
if (Ti.Android) {
width += 'dp';
height += 'dp';
}
return Ti.UI.createImageView({
image: url, width: width, height: height
});
}
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
win.add(createQRCodeImageView('Hello, world!', '150x150'));
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment