Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 11    Views: 535

chrspe
Android Fan
Profile
Posts: 95
Reg: Jan 07, 2012
Buffalo, WY
5,400
05/14/12 01:34 PM (13 years ago)

HTML5 localStorage database cache

It was really bugging me that I could use local storage in the Native browser but not webview (customhtml/text) I was able to write and get from localStorage on my Droid X: Add to eclipse on the customHTML.java page, this turns localStorage on- String packageName = "com.yourpackagename"; WebSettings settings = webView.getSettings(); settings.setJavaScriptEnabled(true); settings.setDatabaseEnabled(true); settings.setDatabasePath("/data/data/"+packageName+"/databases"); settings.setDomStorageEnabled(true); Here is a simple localStorage example I just pasted on a customHTML/ text page- <!doctype html> <html> <head> <title>Local Storage Test</title> <script> function save() { var fieldValue = document.getElementById('textfield').value; localStorage.setItem('text', fieldValue); } function load() { var storedValue = localStorage.getItem('text'); if(storedValue) { document.getElementById('textfield').value = storedValue; } } </script> </head> <body onLoad="load()"> <input type="text" id="textfield" /> <input type="button" value="save" onclick="save()" /> </body> </html> Enter something in the text box, click save, close the program and re-open and it is in the box!
 
chrspe
Android Fan
Profile
Posts: 95
Reg: Jan 07, 2012
Buffalo, WY
5,400
like
05/14/12 01:38 PM (13 years ago)
Once you have built the sample app in Eclipse with the 6 settings, you can use the customHTML/text box to paste in other localStorage scripts to try them out without having to re-build.
 
Fred@mySkylla com
Android Fan
Profile
Posts: 5259
Reg: Oct 03, 2011
location unknow...
62,560
like
05/14/12 01:50 PM (13 years ago)
This could be big. Nice. Fred
 
Fred@mySkylla com
Android Fan
Profile
Posts: 5259
Reg: Oct 03, 2011
location unknow...
62,560
like
05/14/12 01:52 PM (13 years ago)
How would you do this with just the HTML? Fred
 
chrspe
Android Fan
Profile
Posts: 95
Reg: Jan 07, 2012
Buffalo, WY
5,400
like
05/14/12 01:58 PM (13 years ago)
I haven't found a way to set the settings via html alone, only html and changing some things in eclipse. I am wondering out loud... that if there is a change in eclipse that we make over and over (like I do for setting initial scale and getting rid of the spinner) can we just modify the plugin and never have to make the changes again? The latest BTU videos opened up a whole new world in my thinking cap. So far tests with the local storage where the code opens a 2nd page or reloads on save- the next page is always black. Working on that next.
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
05/14/12 02:01 PM (13 years ago)
This IS huge! Great stuff! Mark
 
ceerup
Code is Art
Profile
Posts: 1033
Reg: Oct 10, 2011
New York City
16,380
like
05/14/12 02:03 PM (13 years ago)
very nice
 
chrspe
Android Fan
Profile
Posts: 95
Reg: Jan 07, 2012
Buffalo, WY
5,400
like
05/14/12 02:06 PM (13 years ago)
..
 
Fred@mySkylla com
Android Fan
Profile
Posts: 5259
Reg: Oct 03, 2011
location unknow...
62,560
like
05/14/12 02:11 PM (13 years ago)
If the modification is to a file that doesn't contain app specific info, say the package name, then you could drag and stop the modified file, say the customURL.xml file from a previous project to the new project replacing the file. Fred
 
Fred@mySkylla com
Android Fan
Profile
Posts: 5259
Reg: Oct 03, 2011
location unknow...
62,560
like
05/14/12 02:13 PM (13 years ago)
If you're self hosting you can modify the file in the plugin, rezip, then upload to Control Panel. Fred
 
chrspe
Android Fan
Profile
Posts: 95
Reg: Jan 07, 2012
Buffalo, WY
5,400
like
05/14/12 02:32 PM (13 years ago)
Here is a good piece of code for the local storage that lets you add, remove, clear and get from local storage. It's in my public google drive as storage.txt. Just copy the text into customHTML/text https://docs.google.com/open?id=0B4Ok1QURYbE3aGFnbk5sV3lTZm8
 
chrspe
Android Fan
Profile
Posts: 95
Reg: Jan 07, 2012
Buffalo, WY
5,400
like
05/15/12 03:19 PM (13 years ago)
Added another script example that works here: https://docs.google.com/open?id=0B4Ok1QURYbE3aGFnbk5sV3lTZm8 It is urlsetting.html Paste it in custom HTML/text. This will give a text box to enter a url. Save then refresh and there is a new link to that url. What I have been trying to do with this is be able to have a settings page, click on it and you get a page like this with some forms to fill in (like the url). Then take another page and draw data from that page, in my case, I want a new page to open up with that stored url. The use of that is for a tutorial I am making. The person using that tutorial would be able to place a link to their mobile website on the settings page and open it up in a webview to see how it looks without having to compile an app.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.