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).
Related
I need to build a screen with map of a theater, and user can interact with zoom in/out and choose seats on map.
When user touch on a seat, the icon of seat is changed.
Is there some lib/component to build my own map with touch areas? Or some good idea to use Android API to solve this problem?
Thanks.
You should take a look at the SurfaceView API.
It provides you with an easy to use abstraction for drawing on a canvas. You can use it to render your theater image and intercept touch events on it. However, zoom in and zoom out are not supported out of the box, so you should implement them separately.
Another thing you can do is show your image in an ImageView and use scaling to implement the zoom in/zoom out, but then intercepting the exact touch position can get a little tricky.
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.
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!
The KitKat SDK supports a new type of scale gesture called quick scale. Instead of requiring two fingers to pinch zoom, the user can doubletap and swipe to scale a view. You can see this in action in the Chrome and Maps apps.
Both Chrome and Maps differentiate between a doubletap (which zooms into the relevant content area, as before) and a doubletap-swipe (which allows you to scale arbitrarily with one finger).
Under the hood, the ScaleGestureDetector uses a GestureDetector to detect doubletaps and start looking for the corresponding swipe.
My question is how to mimic Chrome and Maps, detecting both doubletaps and this doubletap-swipe gesture but not both at the same time. That is, I'd like to differentiate between a normal doubletap (no swipe) and a doubletap-swipe.
I have both a GestureDetector and a ScaleGestureDetector being fed all touch events on my view. Currently, both GestureListener.onDoubleTap() and ScaleGestureListener.onScaleBegin() fire when I do a doubletap-swipe. onDoubleTap() gets fired first, so there's no way cancel handling events in the ScaleGestureListener.
I see two possible solutions, neither of which is very clean:
Copy the ScaleGestureDetector from the Android source and add a new callback to the ScaleGestureListener interface for something like onDoubleTapConfirmed() (doubletap, no swipe).
Add a small delay to onDoubleTap() so we handle the event X milliseconds after it gets triggered. If onScaleBegin() gets fired before the delay is up, cancel handling the onDoubleTap() event and start handling the scale instead.
What's the best way to handle this?
A bit late to this party, but the quick scale is more like an unfinished double tap on which the second tap turns into a drag, something like:
tap down, tap up, tap down, move
It seems your interpretation of quick scale is:
tap down, tap up, tap down, tap up, tap down, move
Which makes your problem a lot easier if you only register a plain double tap on the second action down. When the second action up happens, you just need to figure out whether a drag has happened during the second tap cycle. In case the gesture recognizers don't work for you, you can do that manually by checking against getScaledTouchSlop.
Also, copying the ScaleGestureDetector is probably not as bad as you think - github is littered with "compat" projects that are basically backports of features in newer SDK versions.
I am looking for an optimized way of implementing Pinch Zoom feature on my GirdView containing images. Why optimized? Because playing with Bitmaps any day gifts me with Out of Memory exception. Till date I have implemented the handling of Multitouch on screen by using switch (event.getAction() & MotionEvent.ACTION_MASK)
in my onTouch event and getting to the case of "MotionEvent.ACTION_MOVE".
Further I have been rebuilding the grid by calling the Adapter again and again on every case of pinch zoom in or out but one or the other moment I get out of memory exception.
Also I have tracked the intensity of pinch by taking the difference of coordinates between the old touch point and new touch point (using the trigonometry formulae: [(x2-x1)^2 +(y2-y2)^2]^1/2 ).
To summarize I am looking for help/suggestions on two points:
1) The way I have been tracking the intensity of Pinch Zoom in/out, is this a correct way?
2) What will be an optimized way of rebuilding the grid after the detection of pinch zoom in/out.
Thanks.
Extend the grid view and make your own class, make a custom grid view and set the gesturelistener in that gridview and it will work out(if u need it in version > android 2.1) , i think...!!!!!!