Skip to content

Instantly share code, notes, and snippets.

@andresamayadiaz
Created September 28, 2011 18:26
Show Gist options
  • Save andresamayadiaz/1248778 to your computer and use it in GitHub Desktop.
Save andresamayadiaz/1248778 to your computer and use it in GitHub Desktop.
Titanium Appcelerator remote PDF with ProgressBar
/*
If you want to open a remote PDF (by remote i mean you have an PDF URL) and want to show a progressbar downloading the file, and at the end show the PDF in a webview
*/
// INIT Create PDF View
mw.ui.CreatePDFView = function(_args){
var win = Ti.UI.createWindow({
title: _args.title
});
//alert("Open: "+_args.pdf);
var ind=Ti.UI.createProgressBar({
width:200,
height:50,
min:0,
max:1,
value:0,
style:Titanium.UI.iPhone.ProgressBarStyle.PLAIN,
top:10,
message:'Downloading',
font:{fontSize:12, fontWeight:'bold'},
color:'#888'
});
win.add(ind);
ind.show();
ind.value = 0;
c = Ti.Network.createHTTPClient();
c.setTimeout(10000);
c.onload = function(e)
{
// Web View
var webv = Ti.UI.createWebView({
data: this.responseData,
top: 0,
scalesPageToFit: true
});
ind.hide();
win.remove(ind);
win.add(webv);
f.close();
};
c.ondatastream = function(e)
{
ind.value = e.progress ;
ind.message = "Downloading (" + Math.round(e.progress*100) + "%)";
};
c.onerror = function(e)
{
Ti.UI.createAlertDialog({title:'ERROR', message:'Error: ' + e.error}).show();
};
c.open('GET',_args.pdf);
c.send();
return win;
}
// END Create PDF View
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment