loading html 5 application with page transition

Put your problem here if it does not fit any of the other categories.

loading html 5 application with page transition

Postby shailaja » Wed Feb 15, 2012 7:59 am

I am developing an android application, that should open html 5 file when it launches. What I did is

I saved the complete html application under Assets folder.

By passing the path of html file am able to load it from my android application in a web view.

when html pages are loading, page transition is missing. Pages are loading without animation.

Following is the code which i used

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  TextSize t = WebSettings.TextSize.SMALLEST;
  2.         mWebView = (WebView) findViewById(R.id.webview);
  3.             mWebView.getSettings().setJavaScriptEnabled(true);
  4.             mWebView.getSettings().setTextSize(t);
  5.             mWebView.getSettings().setLoadWithOverviewMode(true);
  6.             mWebView.getSettings().setUseWideViewPort(true);
  7.             mWebView.setInitialScale(25);
  8.             mWebView.getSettings().setBuiltInZoomControls(true);
  9.             mWebView.getSettings().setSupportZoom(true);
  10.             mWebView.getSettings().enableSmoothTransition();
  11.             mWebView.getLayoutAnimation();
  12.             mWebView.getSettings().setDomStorageEnabled(true);
  13.             mWebView.loadUrl("file:///android_asset/mobile/index.html");
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


After using this code also there is no animation shown my html pages while loading. Can any one aware about this, please let me know how to give animation effect.

Thanks
shailaja
shailaja
Developer
Developer
 
Posts: 40
Joined: Fri Aug 06, 2010 8:00 am

Top

Re: loading html 5 application with page transition

Postby Phyll » Wed Feb 15, 2012 1:10 pm

Hi Shailaja,

Here's what one of the docs says about WebView:

By default, a WebView provides no browser-like widgets, does not enable JavaScript and errors will be ignored. If your goal is only to display some HTML as a part of your UI, this is probably fine; the user won't need to interact with the web page beyond reading it, and the web page won't need to interact with the user. If you actually want a fully blown web browser, then you probably want to invoke the Browser application with your URL rather than show it with a WebView.

This doesn't sound very encouraging. Could using the standard browser be an alternative for this job?

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: loading html 5 application with page transition

Postby shailaja » Wed Feb 15, 2012 1:55 pm

Hi phyll,

Thanks to your suggestion.

Now i changed my approach to run html5 application using external browser from webview, as webview is not supporting all html features.

I followed
https://github.com/commonsguy/cw-advand ... ider/Files
link to run html file from external browser. I tried to open html file instead of pdf file in this sample. In fileprovider class i replaced pdf with my html file which i want to open. And the changes in my activity as follows

Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
browserIntent.setData(Uri.parse(FileProvider.CONTENT_URI+ "index.html"));
browserIntent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
startActivity(browserIntent);
Now am able to open external browser and I can see only googling page with my path.

Could you please help me to give correct path to parse and to open my html in that external browser.

Thanks
Shailaja
shailaja
Developer
Developer
 
Posts: 40
Joined: Fri Aug 06, 2010 8:00 am

Re: loading html 5 application with page transition

Postby Phyll » Wed Feb 15, 2012 10:29 pm

Hi shailaja,

I don't think I would create a content provider unless I was thinking about sharing it with other apps. I think I would just copy the file (which is what that does anyway) and then use it from there. If it was important I would delete it when I was done otherwise just leave it there and not have to copy it again.

I guess I would use something like this to copy the file from assets temporarily into the file system:

Code: Select all
    private void copyFromAssets(String fromFile, String toFile) { //if toFile empty this will
         InputStream ips;                                          //make it same as fromFile
         String toTemp = toFile;
         if (toTemp.length() == 0) toTemp = fromFile;
      try {
         ips = this.getAssets().open(fromFile);

             String outFileName = dataPath + "/" + toTemp;
             OutputStream ops = new FileOutputStream(outFileName);
             byte[] buffer = new byte[1024];
             int length;
             while ((length = ips.read(buffer))>0){
                ops.write(buffer, 0, length);
                 }//while
             ops.flush();
             ops.close();
             ips.close();
          } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
              }//catched
          }//copy from assets


Then something like this to pass it to the default browser:

Code: Select all
                Intent intent = new Intent();
                intent.setAction(android.content.Intent.ACTION_VIEW);
                Uri uri = Uri.fromFile(new File(dataPath+"/"+myHtmlFile"));
                  intent.setDataAndType(uri, "text/html");
                try {
                   startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                      
                        }//catched


Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: loading html 5 application with page transition

Postby shailaja » Fri Feb 17, 2012 6:15 am

hi phyll,

Thanks for your valuable reply.
As you said creating and using content provider is not correct way to do my requirement.
I done it without usnig any content providers.
What i did is
1. copied a zip file for my html 5 application folder under assets.
2. created a file in sdcard
3. unzip the html folder and assigned it to file in sdcard
4. called the browser intent by passing that file's path as url.
And now am able to see the output in external browser.
My current requirement is
If the html 5 application folder got changes in it, the zip file under assets needs to change according to updates on html app. For that what my doubts are
1. Is it possible to change the zip folder according to updates on html 5 app with android code?
2. If possible, for that what i need to do?

Please let me know the way to do it.

Thanks
shailaja
shailaja
Developer
Developer
 
Posts: 40
Joined: Fri Aug 06, 2010 8:00 am

Re: loading html 5 application with page transition

Postby Phyll » Fri Feb 17, 2012 12:42 pm

Hi shailaja,

You cannot write to the application folders on a normal phone. Perhaps a rooted phone would allow it. Generally the regular files that are part of your apk are zipped except for assets but they are part of your app and protected from reading and writing as normal files.

You should create a way to update such files from the internet so that either the program or the user can initiate an update when one is necessary. Not too hard if you have a website.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 15 guests