Loading and zooming images through webview

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

Loading and zooming images through webview

Postby alejo » Sat Jan 22, 2011 12:39 pm

hello,

I wanted to load an image from the internet, save it to the sd card and then use it through webview, since it would automatically add the zooming and scrolling tools.

Unfortunatelly, I haven't been able to use any of the tutorials available on the net for this... eclipse always ends up giving me unsolvable errors which I can't deal with.

My last attempt was using this code, but it's all filled with errors from "mContentView... till the end"

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Test extends Activity {
  2.         /* Using WebView to display the full-screen image */
  3.         WebView full = (WebView)findViewById(R.id.webview);
  4.         /* Set up the Zoom controls */
  5.         FrameLayout mContentView = (FrameLayout) getWindow().
  6.         getDecorView().findViewById(android.R.id.content);
  7.         final View zoom = this.full.getZoomControls();
  8.         mContentView.addView (zoom, ZOOM_PARAMS);
  9.         zoom.setVisibility(View.VISIBLE);
  10.         /* Create a new Html that contains the full-screen image */
  11.         String html = new String();
  12.         html = ("<html><center><img src=""+fileName+""></html>" );
  13.         /* Finally, display the content using WebView */
  14.         full.loadDataWithBaseURL("file:///sdcard/data/data/com.youproject.example/",
  15. html,
  16. "text/html",
  17. "utf-8",
  18. "");
  19. }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Any suggestion?
I've already tried a dozen of tutorials, with little success. The only one which I got working crashes on samsung devices (tested on a galaxy S and a nexus S).
alejo
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Mar 31, 2010 9:08 am

Top

Re: Loading and zooming images through webview

Postby jiqqaman » Fri Jan 28, 2011 9:16 am

this is working on my end you may need to change setContentView to your view and also the webView

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Test extends Activity{
  2. WebView wb;
  3. private static final FrameLayout.LayoutParams ZOOM_PARAMS =
  4.         new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
  5.         ViewGroup.LayoutParams.WRAP_CONTENT,Gravity.BOTTOM);
  6.  
  7. @Override
  8.         protected void onCreate(Bundle savedInstanceState) {
  9.                 super.onCreate(savedInstanceState);
  10.                 setContentView (R.layout.main);
  11.                 wb = (WebView) findViewById (R.id.WebView01);
  12.                 FrameLayout mContentView = (FrameLayout) getWindow().
  13.  
  14.             getDecorView().findViewById(android.R.id.content);
  15.  
  16.             final View zoom = this.wb.getZoomControls();
  17.             mContentView.addView(zoom, ZOOM_PARAMS);
  18.             zoom.setVisibility(View.VISIBLE);
  19.            
  20.                 wb.loadUrl("file:///android_asset/myhtml.html");
  21.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
jiqqaman
Freshman
Freshman
 
Posts: 6
Joined: Sat Sep 25, 2010 12:23 am

Re: Loading and zooming images through webview

Postby alejo » Fri Jan 28, 2011 5:19 pm

Thank you for your help!! It's working right now...

My next step will be to try to write it to sdcard and load it with webview... I've seen some code written with a similar purpose, so I'll try to make an hybrid from both
alejo
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Mar 31, 2010 9:08 am

Re: Loading and zooming images through webview

Postby alejo » Sun Mar 06, 2011 6:53 pm

I finally solved it... or, at least, most of it.
alejo
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Mar 31, 2010 9:08 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Alexa [Bot], Google [Bot], MSNbot Media and 17 guests