Android WebView Zoom out limited - android

I am using a WebView in Android. After loading a webpage I would like to use the on-screen Zoom out control. After one or two clicks it becomes grayed and no longer allows me to zoom out any further. When I call the zoomOut() function in code, it also does not zoom out any further.
What is limiting how much I can zoom out. I would expect to be able to zoom out much further than I am allowed - to the point of making the page too small to read. But, zoom out is disabled well before I reach this level of zoom.
Any help is greatly appreciated.
Thanks,
Barry.

You should probably do this myWebView.getSettings().setUseWideViewPort(true)
You'll then see that you can zoom out farther than what you usually see on default settings.

Take a look at WebView.setInitialScale(...) - I'm not sure if it will help you with what you want but setting it to 50, for example, will scale the WebView to 50% of its normal size. I think that will allow you to zoom in and then out again to the (initial) smaller size.

Hey Barry
The built in range for that zoomin and zoomout function is starts from 0.8 something that is the minimum value after this if you
will call the zoomout function it will return the false value and
maximum value for zoomin is upto 4.0 ,So these zoomin and zoomout
functions are of boolean type Like for a zoomin function wverytime you
call zoomin function it multiply with some factor and return true if
further zoomin is possible and whenever it reaches to the last point
that is 4.0 so it will return false and after that it will not zoom
in.

Related

How to disable automatic zoom on scale change in Android's webview?

I've got a webview with following settings:
WebSettings s = getSettings();
s.setAllowFileAccess(true);
s.setSupportZoom(false);
s.setBuiltInZoomControls(false);
s.setDisplayZoomControls(false);
s.setDomStorageEnabled(true);
s.setJavaScriptCanOpenWindowsAutomatically(true);
s.setUseWideViewPort(true);
s.setLoadWithOverviewMode(true);
In my app, I allow the user to change between two modes of the page which is displayed: fit screen & zoomed.
To do that, I change the scale of the page using javascript.
It all worked great, but a new requirement came along: always allow the user to use pinch to zoom, nevermind the mode they view the page with.
So I have changed these two settings:
s.setSupportZoom(true);
s.setBuiltInZoomControls(true);
And voila, the user can use pinch to zoom.
Now, I have two places where I scale the page:
javascript where I change the content scale
java where I allow user to zoom in on the webview
This means, that when user switches to fit screen mode, I have to zoom out the webview. It took me a moment to figure out, since there's only zoomOut() method, which zooms out "a little bit", but fortunately it returns a boolean to indicate success or failure, so a simple:
while(webview.zoomOut()) {}
does the trick. The webpage is properly zoomed out and scaled.
There is, however, a VERY frustrating side effect: when changing to the fit screen mode, the webview suddenly zooms in a little bit. It is done with animation and lasts for about 500ms. It's done automatically, I don't have any code which would do that.
So the effect is: page zooms out to fit the screen immediately and zooms in by a little margin within 500ms.
I have removed my zoomOut code and didn't use the pinch to zoom in my tests, but the webview would still zoom in a bit after I change the content scale inside javascript.
The only way to remove this effect is to setSupportZoom(false) which disables pinch to zoom.
Did anyone came across a similar issue and know how to disable this automatic zoom in?
Thank you
s.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
try this !!

Pinch-To-Zoom feature for TiledScrollView

I used https://github.com/ened/Android-Tiling-ScrollView library to display large tiled image. Everything is working fine. Only problem is that, I want to zoom only particular part which I touched(pinch-to-zoom as in Google map). Now, its always display tiles from beginning for all zoom levels irrespective of where I touched. Sometimes, it takes me near where I want to zoom but its not perfect as sometimes it takes me to different part. Following code does moving logic
mScroller.startScroll(getScrollX(), getScrollY(), newOffsetX, newOffsetY);
First 2 parameters indicate start scroll offset and last 2 indicates destination points to where scroll ends. I tried different combinations for last 2 parameters but ran out of luck.
If it's a ImageView, I would have done
canvas.translate(x, y);
to Zoom particular part but unfortunately its not ImageView. Even though I applied ImageView zoom logic as in https://github.com/jasonpolites/gesture-imageview to tile Zoom but had no luck.
Suggestions or clues are greatly appreciated.
Thanks.
Got a very nice library for custom mapView with almost all the features of google map. Its here.

how can i override default pinch zoom in osmdroid?

I m using Osmdroid to create an offline map
Now, i want to implement my own pinch to zoom functionality for offline maps
When user uses pinch, i would like to zoom in/ zoom out to only a particular zoom level and not increment/ decrement zoom level by 1
Is there a way to do it? how can i go about this ?
P.S : yes, there are zoom controls, but i would like to make zooming feature more intuitive
Thanks
I dealt with a similar question here, and provided the code for custom functionality on pinch. So basically, expanding on what I had in the answer, just basically do:
int currentZoomLevel = mOsmv.getController().getZoomLevel();
if (currentZoomLevel < (mOsmv.getControler().getMaxZoomLevel()) - 2)
mOsmv.getController().setZoomLevel(currentZoomLevel + 2);
That is just an example of increasing the zoom level by 2, instead of just 1. I also wrote the code above from memory, so I'm not 100% sure if you call getController() to get the current and maximum zoom level, but I'm pretty sure that's it. mOsmv, just in case you don't get it, is an instance of the osmdroid map.
I think the way to do this will be to extend MapView.
Overriding setZoomLevel looks like one option but I don't think it will work. As I belive the code needs to be writen in a this.setZoomLevel style which it is not consistantly doing.
I think you should be able to override selectObject which looks like the place where a pinch trigers a call setZoomLevel
You will need to check the source code to see how to make the nessasary modifications

In game scrolling and zooming

I'm in the process of developing an android game. I have an activity that has a custom class that extends the view and where everything is drawn. Everything works fine and I have implemented a way to draw levels and it looks good.
The problem that I have is that the levels are clearly too big for just 1 screen and re-designing them is not an option as it affects the user experience. The only solution that I see is making the screen scrollable so that you can move around the rendered stuff and zooming. What I'm looking for is double tapping anywhere to zoom in and out and scrolling to move around the map.
What I need help with is how to do this. I know how to detect that the user has scrolled or double tapped but I don't know what I should do to actually zoom in and out and scroll (if a scroll is detected).
I have been looking around and saw some very simple tutorials but all of them deal with zooming in/out of an image which is not what I need. My level is rendered using many different bitmaps so I know I need to redraw all of them when updating the screen (zoom or scroll).
Is my case the same as having a single image. When it comes to scrolling I think what need to be done is calculating how much the screen is "moved" then update the and redraw the view bitmaps with the new scaled coordinates, is this correct? What about zooming?
Any help would be much appreciated. Thanks
Zooming should be easy once you have detected where you are currently at (zoom level i.e.)
image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);
Something like that should help you zoom out/in on the image. When the zoom levels cross a certain level, you can consider swapping out an image that is more detailed that the one you are currently rendering.

Get actual image coordinates of image in Android webview onTouch event

I'm loading floor plans into an Android application. I need the user to be able to identify problem areas on the floor plan with a single click. My thought process is to identify the click action, reload the html of the webview adding my marker asset to it at the specified location.
I've loaded the image into a webview to take advantage of zoom capabilities. I can get the X,Y coordinates of the webview where the click occurred, but I can't figure out how to get the current zoom level. Also, I'm not sure what math will be required to translate the X,Y,scale to actual pixel coordinates.
Is the webview the right view for me to use?
EDIT:
Using the link suggested below, I got the zoom functionality working. I still can't figure out how to place a drawable marker on top of the TouchImageView, much less get the coordinates that were actually touched on the image.
For your zoom question as well as coor, How can I get zoom functionality for images? should help you
The accepted answer does use a WebView, but the other answer uses a better approach for enabling zoom. It also provides the necessary math required for translating your X and Y coordinates into usable points.

Categories

Resources