Created
January 31, 2014 09:51
-
-
Save lele85/8729226 to your computer and use it in GitHub Desktop.
OPEN PDF
This file contains hidden or 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
| exports.open = function(f) { | |
| try { | |
| Ti.Android.currentActivity.startActivity(Ti.Android.createIntent({ | |
| action : Ti.Android.ACTION_VIEW, | |
| type : 'application/pdf', | |
| data : f.getNativePath() | |
| })); | |
| f = null; | |
| } catch (err) { | |
| f = null; | |
| var alertDialog = Titanium.UI.createAlertDialog({ | |
| title : 'Nessun lettore PDF', | |
| message : 'Nel tuo tablet non ci sono app per leggere i PDF, vuoi cercarne uno su Google Play Store?', | |
| buttonNames : ['Si', 'No'], | |
| cancel : 1 | |
| }); | |
| alertDialog.show(); | |
| alertDialog.addEventListener('click', function(evt) { | |
| if (evt.index == 0) { | |
| Ti.Platform.openURL('http://search?q=pdf'); | |
| } | |
| }); | |
| } | |
| f = null; | |
| }; |
This file contains hidden or 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 openPDF; | |
| var setPdfPath; | |
| var opened = false; | |
| if (OS_IOS) { | |
| var infoWebView = Ti.UI.createWebView( | |
| { | |
| top:"74dp", | |
| left:"0dp", | |
| width:Ti.UI.FILL, | |
| height:Ti.UI.FILL | |
| } | |
| ); | |
| setPdfPath = function(pdfPath){ | |
| infoWebView.setData(Titanium.Filesystem.getFile(pdfPath)); | |
| }; | |
| openPDF = function(parentView, onOpen, onClose){ | |
| if (opened===false) { | |
| opened = true; | |
| parentView.add(infoWebView); | |
| onOpen(); | |
| } else { | |
| opened = false; | |
| parentView.remove(infoWebView); | |
| onClose(); | |
| } | |
| }; | |
| } else { | |
| var f; | |
| setPdfPath = function(pdfPath){ | |
| f = Ti.Filesystem.getFile(pdfPath); | |
| }; | |
| openPDF = function() { | |
| require("AndroidOpenPdf").open(f); | |
| }; | |
| } | |
| exports.setPdfPath = setPdfPath; | |
| exports.openPDF = openPDF; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment