Disable pan/zoom in com.google.android.maps.MapView - android

How can i disable the panning/zooming functionality of a MapView (not the zoom controls, i want a wholly static map)?
I've also noticed that touching the map doesn't seem to trigger the MapView onClickListener, could anyone elaborate why?

For version 2 of the Google Maps API for Android, this is the way:
map.getUiSettings().setScrollGesturesEnabled(false);

This is gauranteed to work
mapView.getMap().getUiSettings().setAllGesturesEnabled(false);

Use android:clickable="false" in your layout file.

Please use Overlay to get the tap event on the map
http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/Overlay.html

I had the same question and the following solution is the best one I could find and that fulfilled my requirements:
mapView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getPointerCount() > 1) {
return true;
}
return false;
}
});
As posted by Alexander Stolz here:
How to disable pinch in Android MapView
And here is the reason:
It does not disable clicking on the mapView completely - it only grabs & prevents two-finger gestures (for zooming you need two fingers) - tapping on the map (for instance on Overlays) still works.

this is the right way
#Override
public boolean dispatchTouchEvent(MotionEvent ev)
{
switch (ev.getAction()&MotionEvent.ACTION_MASK)
{
case (MotionEvent.ACTION_DOWN):
{
// do what you want
// you may scroll map where you want
// don't use 'break', the same in case pointer events;
//break;
return true;
}
}
// 'super' go to the mapView procedures and scroll map in own algorithm
return super.dispatchTouchEvent(ev);
}

on your onMapReady method, add these code lines
gMap.getUiSettings().setZoomGesturesEnabled(false);
to disable all the guesures
gMap.getUiSettings().setAllGesturesEnabled(false);
happy coding :)

Related

How to prevent multi-taps in android apps

I use onTouch as it is the best and more modifiable than for an instance onClick. It is a custom view that is being touched that I want to respond with action, and I have allready limited so you can't just touch and it does it over and over. Now I need it to limit the amount of simountanious taps.
EDIT:
#Override
public boolean onTouch(View v, MotionEvent event) {
lines++;
return false;
}
I have prevented constant action, but not the possibility to press with more than 1 finger, so that if you tap with more the rest of the fingers get ignored
There are several ways to do it.
best for you may be limit it inside in your overrided onTouch event.
if(event.getPointerCount() > 1) {
System.out.println("Multitouch detected!");
return true;
}
else
return super.onTouchEvent(event);
Another option is set attribute android:splitMotionEvents = false in your xml file.

Custom View, continues to pass on events?

I have a ListView. Inside the cells, I have a custom view. (You can draw in it.)
When drawing, I turn off scrolling of the list ..
theListView.setOnTouchListener(new View.OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_MOVE)
{
if ( STATE.weAreDrawoning )
{
return true;
// so, do not forward and hence do not scroll the list
}
else
{
return false;
}
}
return false;
}
});
That's fine. But strangely, up-down touching in the custom View, is still passed on to the list and makes it scroll.
public class AmazingCustomView extends View
{
blah
#Override
public boolean onTouchEvent(MotionEvent event)
{
blah
return true;
}
}
notice in the custom view onTouchEvent is returning true (I also tried false! :) )
but the motion events appear to be still passed on .. what gives??
Is there another "on .. something" I'm missing in the custom view? Sorry, new to Android and lame. Thanks!
PS, I tried turning on "clickable" on the xml of the custom view, didn't help :O
--
Worse ...
I've just realised ALL controls in the ListView, say buttons, still "pass on scrolling"
I fear the system I use above for turning off scrolling is just no good. :/
important...
For anyone googling to here. The only real way I've found to turn off scrolling on an android listView ...
danosipov.com/?p=604
(don't forget to separately turn off your pull-to-refresh)
You may need to override onInterceptTouchEvent. Its an odd function, documentation here: http://developer.android.com/reference/android/view/ViewGroup.html#onInterceptTouchEvent%28android.view.MotionEvent%29

Android - How to disable horizontal scroll in google mapview?

I am using google MapView in my application and set the zoom level to 2 so that the world map with continent names are visible. Now I want to disable horizontal scrolling. Can any one share some idea on how to do it ?
Just got an idea. Using MotionEvent.AXIS_* flags.
#Override
public boolean onTouch(View view, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_AXIS_...) {
// ...
}
return sper.onTouchEvent(event);
}
Look at AXIS_HSCROLL, AXIS_VSCROLL, AXIS_X, AXIS_Y, AXIS_Z: Documentation

Disable CoverFlow Scrolling until Popup Appears

I am using cover flow in my project and while display of cover flow on button click i am showing popup.
(Coverflow in android is the style to display images in line which is scrolled on touch as we generally see in media player and can be selected ;It's based on the Android Gallery widget and is used in the same way, with a ViewAdapter. My main aim when coding this coverflow widget was to create an easily re-usable component using the standard Android 2D libraries
reference :- http://www.inter-fuser.com/2010/01/android-coverflow-widget.html)
s
- now when popup is displayed i don't want my coverflow to
scroll/navigate on touch i.e i want to disable coverflow untill popup
is displayed
i have already tried all the code below but it is not help full to
disable coverflow.
coverFlow.clearFocus();
Popup.setFocusable(true);
coverFlow.setClickable(false);
coverFlow.setFocusable(false);
coverFlow.setEnabled(false);
coverFlow.setSelected(false);
can any one help me out in this matter ?
I don't know what source code of CoverFlow you are using. But you can custom it.
Extend the CoverFlow (which already extends Gallery, i think), override the onTouchEvent and onInterceptTouchEvent methods with return false if you don't want the CoverFlow scroll, and add the method to set this attribute.
The code maybe looks like :
#Override
public boolean onTouchEvent(MotionEvent event) {
if (this.enabled) {
return super.onTouchEvent(event);
}
return false;
}
#Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (this.enabled) {
return super.onInterceptTouchEvent(event);
}
return false;
}
public void setScrollEnabled(boolean enabled) {
this.enabled = enabled;
}
And then you can set the CoverFlow scroll or not by using setScrollEnabled method

google maps in android

I am a new user of google maps API in android OS. I have made a small application in which i am using google maps. I want to add a functionality that when i double click (multi touch) on a map the map should zoom in. IS there anybody who has an idea how to do this or if it is possible please provid a code example.
Thanks in advance.
BR,
SilentCoders
I've done something like this in an app using maps api. Although I did this in an overlay item, the principle should be the same.
You could try using TouchListener and GestureDetector to detect the touch events and such.
Note that this is not all actual working code, you need to adopt it so it fits into your implementation.
...
class MyDetector extends SimpleOnGestureListener {
#Override
public boolean onDoubleTap(MotionEvent event) {
mapView.getController().zoomInFixing((int) event.getX(), (int) event.getY());
return super.onDoubleTap(
}
}
// maybe do this in your init or something
GestureDetector gDetector = new GestureDetector(new MyDetector());
mapView.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
return gDetector.onTouchEvent(event);
}
});
Something like that "should" work :)

Categories

Resources