Created
September 28, 2011 18:26
-
-
Save andresamayadiaz/1248778 to your computer and use it in GitHub Desktop.
Titanium Appcelerator remote PDF with ProgressBar
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
/* | |
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