How to implement both pinch zoom and pan with multitouch? - android

First of all i should say my app is already has pinch zoom which works perfectly and it has pan feature too but this pan feature works with single touch and i want to make both work with multi touch. What i mean is if user make pinch gesture zoom work should be done and if user move both finger in same direction then pan work would be done. I have tried to use a threshold approach which measures the distance between fingers and compare the distance with previous distance and if the difference between distances is less than threshold it act as pan and if the difference is bigger than threshold then it acts as zoom. This approach kind of works but it is inconsistent. So i am here to ask for smarter and smoother way to make work this.
PS: My pinch zoom code is from here

The best approach that I can think of is by using the direction of movement. If the two fingers move in different directions, then activate only the zoom. But if they move in the same direction, pan and check for zoom based on the threshold. This should add some consistency.

Related

Setting boundaries for pinch-zoom in Maps view

For an app I'm working on the user needs to be able to zoom in and out using pinch gestures, but only within a certain boundary.
There are multiple "levels" on which users can see the map and there should be a settable zoom boundary for each of these.
We got this working partially by resetting the camera back to the limit if pinching has brought it outside of it's boundaries, but the user shouldn't be able to pinch out/in of the boundaries at all.
Here's a video of how it's working now:
https://www.youtube.com/watch?v=WfAle_M-i0k
And how it should work is that once the camera is at the zoomlevel-limit, zooming out further shouldn't be possible.
This is important because we'll be drawing a lot of objects on the screen and the app crashes when it's zoomed out too far.
We're using the default pinch-zoom that comes with
mMap.getUiSettings().setZoomGesturesEnabled(true);
Is there a way to disable further zooming in/out when the boundary has been reached?
I don't see any other way of doing this that implementing zoom controls by yourself, i.e. setting
mMap.getUiSettings().setZoomGesturesEnabled(false);
and adding buttons on top of your map with actions with zoomBy inside (with respect to your zoom boundaries kept somewhere).
You may also check lite mode.

What is the best way to display a map picture on Android?

I am currently trying to figure out which way is best to display a picture in an Android app. The picture will be a map and will be a big picture (3000x3000 pixels). I would like to add the ability to pinch zoom into the picture and move the image around the screen but not have the scale of the image changed. I have played around with a lot of solutions that when the image is moved it is auto re-sized. Is there a way of doing this? Thanks.
However I have used many libraries for loading large images but subsampling-scale-image-view is the best library I found and also it supports a variety of gesture support.
Gesture detection
One finger pan
Two finger pinch to zoom
Pan while zooming
Seamless switch between pan and zoom
Fling momentum after panning
Double tap to zoom in and out
Options to disable pan and/or zoom gestures
Supports interception of events using GestureDetector and OnTouchListener
Extend to add your own gestures
Njoy!

trouble creating a continuous zoom in (android)

i am trying to write an Application for android that zooms in AFTER the user FINISHED dragging or touching the screen (this means at motionEvent.ACTION_UP).
i want it to be continuous just like in a pinch zoom, but the problem is that pinch zooming is a continuous action and therefore create many events , what i am looking for is a SINGLE event (motionEvent.Action_up) that will cause continuous zooming.
Thanks in advance.
After MotionEvent.ACTION_UP you should set a timer which will repeatedly, and slowly, zoom over the designated area you decide (Instead of zooming according to future motion events, like in pinch zooming).

How to modify pan sensitivity in achartengine?

It is a simple question. Is there any way to modify the pan sensitivity to move an XYChart? Move it faster or "accelerate" the movement to scroll through it rapidly.
Thank you
The pan works in a "natural" way. This means it moves as much as you drag on the screen. So, you cannot move it faster or slower.

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.

Categories

Resources