Cacheing html, javascript, css with android webview - android-webview

I have done the following in my webviewSetting but the files are still not saved in the cache:
webView.getSettings().setCacheMode(WebSettings.LOAD_NORMAL);
webView.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);
String appCachePath = activity.getCacheDir().getAbsolutePath();
webView.getSettings().setAppCachePath(appCachePath + "/cache");
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAppCacheEnabled(true);
any ideas?

Related

Call tinyMCE windowManager.open with a percentage value for window width

The script below invokes an inline popup window from a tinyMCE editor. I need to convert the width to a percentage value instead of a pixel based value. Any ideas how?
(function() {
// Load plugin specific language pack
tinymce.PluginManager.requireLangPack('CustomCodes');
tinymce.create('tinymce.plugins.CustomCodes', {
/**
* Initializes the plugin, this will be executed after the plugin has been created.
* This call is done before the editor instance has finished it's initialization so use the onInit event
* of the editor instance to intercept that event.
*
* #param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
* #param {string} url Absolute URL to where the plugin is located.
*/
init : function(ed, url) {
// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceExample');
ed.addCommand('mceCustomCodes', function() {
ed.windowManager.open({
file : url + '/custom_post.php',
width : 1024 + ed.getLang('CustomCodes.delta_width', 0),
height : 600 + ed.getLang('CustomCodes.delta_height', 0),
inline : 1
}, {
plugin_url : url // Plugin absolute URL
});
});
You could messure the inner width of the iframe and assign a pixel value depending on your desired percentage of the width.

How to save a pdf file in iPhone memory and make it accessible by pdf file opener applications using titanium

i am new bie to titanium in my app i need to download and save a pdf file in iOS using titanium and the downloaded file can be accessible by third party pdf viewer applications.any help to achieve this thanks in advance.
1- Make sure your webservice returns a PDF file.
2- Use the FileSystem to manage your files
var xhr = Titanium.Network.createHTTPClient({
onload : function() {
var f = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, 'file.pdf');
f.write(this.responseData);
tmpFile = Ti.Filesystem.createTempFile();
var newPath = tmpFile.nativePath + "." + f.extension();
Ti.API.info("newPath: " + newPath);
tmpFile = Ti.Filesystem.getFile(newPath);
tmpFile.write(f.read());
},
timeout : 10000
});
xhr.open('GET', 'your webservice');
xhr.send();
Now you use a pdf viewer and open the PDF from the externalStorageDirectory
I tested on Android, it works !

Error while paginating html in UIWebView using css Multicolumns

Here is my Problem:
I'm currently writing an ebook reader in objective-c and want to use multicolumns to paginate my xhtml file in my webview.
Unfortunately when I add Multicolumns to my css, my html seems to be only 2 "pages" long, which is exactly the first two tags.
Does anyone know what I'm doing wrong?.
here is the code with which i inject the new settings into my css:
NSString *varMySheet = #"var mySheet = document.styleSheets[0];";
NSString *addCSSRule = #""
"function addCSSRule(selector, newRule) {"
"if (mySheet.addRule) {"
"mySheet.addRule(selector, newRule);" // For Internet Explorer
"} else {"
"ruleIndex = mySheet.cssRules.length;"
"mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);" // For Firefox, Chrome, etc.
"}" // endif mySheet.addRule
"}"; // end addCSSRule()
NSString *insertColumns = [NSString stringWithFormat:#"addCSSRule('div', 'height: 370px; -webkit-column-width: 320px');"];
[wv_reader stringByEvaluatingJavaScriptFromString:varMySheet];
[wv_reader stringByEvaluatingJavaScriptFromString:addCSSRule];
[wv_reader stringByEvaluatingJavaScriptFromString:insertColumns];
For scrolling i use the following code:
int i_scrollTo = ([AppState sharedInstance].i_myselectedPage -1) * wv_reader.frame.size.height;
[wv_reader stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"window.scrollTo(0,%d);", i_scrollTo]];
which works perfect if i don't set Multicolumns in my css.
I also tested, if my html is somehow cut off after adding multicolumns, but a NSLog of the content of the webview showed, that the whole ebook is loaded.
When getting the maximum scrollheight though i found out, that without columns it is 79061, and after inserting columns into my css it is reduced to 424 for some reason i don't know.
Can somebody please help me to fix this? I'm working on this problem for about a week now and couldn't find a solution.
Thx in advance.
Maverick
*UPDATE**
Scrolling horizontally doesn't work either, because my document.scrollWidth is stuck to the width of my Columns, which is pretty odd I think.
https://github.com/fedefrappi/AePubReader
Maybe this sample can help you ?

Uploading files with PhoneGap + iPhone

I understand that PhoneGap applications are largely (if not entirely) HTML5 + CSS + JavaScript. Natively, the iPhone doesn't provide controls to upload files.
Does PhoneGap provide any mechanisms that allow users to upload files? (images / video, in the case of the iPhone)
I know Titanium allows users to do this, but it's a different animal with its compiled Javascript and proprietary APIs. Thanks for your advice/input.
I believe you might be able to read the files using the PhoneGap API and the upload them using and AJAX post if the server application supported it.
The other option is to write a custom module/Plugin in PhoneGap that could specific to your needs.
Here are some Example Plugins
You can do an xmlhttprequest to the file on a local drive.
I'm not 100% sure if it will work on the iPhone, but webkit should support it.
function getImageBinaries(url) { //synchronous binary downloader for firefox2
var req = new XMLHttpRequest();
req.open("GET", url, false);
req.overrideMimeType('text/plain; charset=x-user-defined');
req.send("");
if (req.status != 200) {
return "";
}
var t = req.responseText || "" ;
var ff = [];
var mx = t.length;
var scc= String.fromCharCode;
for (var z = 0; z < mx; z++) {
ff[z] = scc(t.charCodeAt(z) & 255);
}
var b = ff.join("");
return b;
}
Succes,
Erik

Javascript render jpeg binary data from variable

How to render JPEG/PNG file data contained in Javascript variable? Is it possible ? What javascript libraries needed ? Browser in use is FF / IE.
Thanks
Modern browsers support inline images. So you could convert the binary data to a base64 encoded string and then append it to the DOM:
var img = document.createElement('img');
img.src = 'data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7';
img.width = '16';
img.height = '14';
document.body.appendChild(img);