RE: [android-developers] Long press on the Google map secret?
Date: Sun, 17 Jun 2012 05:56:11 -0700 From: entre...@gmail.com To: android-developers@googlegroups.com Subject: Re: [android-developers] Long press on the Google map secret? Please, see my code. I speak that method onLongClick does not work. why does not code work, i can not understand public class MainItemizedOverlay extends ItemizedOverlay implements OnLongClickListener{ private ArrayList mOverlayItems; public MainItemizedOverlay(Drawable defaultMarker) { super(boundCenterBottom(defaultMarker));mOverlayItems = new ArrayList(); populate(); } public void addNewItem(GeoPoint location, String markerText, String snippet) { mOverlayItems.add(new OverlayItem(location, markerText, markerText)); populate(); } public void removeItem(int index) { mOverlayItems.remove(index);populate(); } @Override protected OverlayItem createItem(int index) { return mOverlayItems.get(index);} @Override public int size() { return mOverlayItems.size();} @Override public boolean onTouchEvent(MotionEvent event, MapView mapView) { switch (event.getAction()) {case MotionEvent.ACTION_DOWN: Log.i(MainMap.TAG, "Work"); break; case MotionEvent.ACTION_MOVE: Log.i(MainMap.TAG, "Work"); break; case MotionEvent.ACTION_UP: Log.i(MainMap.TAG, "Work"); break; case MotionEvent.ACTION_CANCEL: Log.i(MainMap.TAG, "Work"); break; default:break; } return super.onTouchEvent(event, mapView); } public boolean onLongClick(View v) {Log.i(MainMap.TAG, "Do not Work!! Why");return true;}} воскресенье, 17 июня 2012 г., 7:34:10 UTC+3 пользователь Ibrahim написал:There is a method called onlongClick listener ...apply that method... it may help you.. On 16 June 2012 21:01, Andrei wrote: Hello. For several days now can't find a solution how to handle a long press on Google map. I found a few detours: 1) Add GestureDetector as an overlay on the map 2) Do the calculation and determine a long time. But I don't understand why is not working OnLongClickListener if I ask for mapView, or define it in the class inherited from the ItemizedOverlay. Method onTouch works fine, but why didn't it work onLongClick -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Long press on the Google map secret?
Thank, but i this saw. I think this method does not correct. Engineers tell in what direction think :) воскресенье, 17 июня 2012 г., 18:51:36 UTC+3 пользователь Ralph Bergmann написал: > > here the link :-) > > > http://www.kind-kristiansen.no/2011/android-handling-longpresslongclick-on-map-revisited/ > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Long press on the Google map secret?
here the link :-) http://www.kind-kristiansen.no/2011/android-handling-longpresslongclick-on-map-revisited/ -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Long press on the Google map secret?
try this: import java.util.Timer; import java.util.TimerTask; import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapView; public class MyLongpressMapView extends MapView { public interface OnLongpressListener { public void onLongpress(MapView view, GeoPoint longpressLocation); } /** * Time in ms before the OnLongpressListener is triggered. */ static final int LONGPRESS_THRESHOLD = 500; /** * Keep a record of the center of the map, to know if the map * has been panned. */ private GeoPoint lastMapCenter; private Timer longpressTimer = new Timer(); private MyLongpressMapView.OnLongpressListener longpressListener; private float offset; public MyLongpressMapView(Context context, String apiKey) { super(context, apiKey); } public MyLongpressMapView(Context context, AttributeSet attrs) { super(context, attrs); this.offset = context.getResources().getDimension(R.dimen.tabbar_height); } public MyLongpressMapView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public void setOnLongpressListener(MyLongpressMapView.OnLongpressListener listener) { this.longpressListener = listener; } /** * This method is called every time user touches the map, * drags a finger on the map, or removes finger from the map. */ @Override public boolean onTouchEvent(MotionEvent event) { handleLongpress(event); return super.onTouchEvent(event); } /** * This method takes MotionEvents and decides whether or not * a longpress has been detected. This is the meat of the * OnLongpressListener. * The Timer class executes a TimerTask after a given time, * and we start the timer when a finger touches the screen. * We then listen for map movements or the finger being * removed from the screen. If any of these events occur * before the TimerTask is executed, it gets cancelled. Else * the listener is fired. * * @param event */ private void handleLongpress(final MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { this.longpressTimer = new Timer(); this.longpressTimer.schedule(new TimerTask() { @Override public void run() { final GeoPoint longpressLocation = getProjection() .fromPixels((int) event.getX(), (int) (event.getY() - MyLongpressMapView.this.offset)); if (MyLongpressMapView.this.longpressListener != null) { MyLongpressMapView.this.longpressListener.onLongpress(MyLongpressMapView.this, longpressLocation); } } }, LONGPRESS_THRESHOLD); this.lastMapCenter = getMapCenter(); } if (event.getAction() == MotionEvent.ACTION_MOVE) { if (!getMapCenter().equals(this.lastMapCenter)) { this.longpressTimer.cancel(); } this.lastMapCenter = getMapCenter(); } if (event.getAction() == MotionEvent.ACTION_UP) { this.longpressTimer.cancel(); } if (event.getPointerCount() > 1) { this.longpressTimer.cancel(); } } } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Long press on the Google map secret?
There is a method called onlongClick listener ...apply that method... it may help you.. On 16 June 2012 21:01, Andrei wrote: > Hello. > For several days now can't find a solution how to handle a long press on > Google map. > I found a few detours: > 1) Add GestureDetector as an overlay on the map > 2) Do the calculation and determine a long time. > But I don't understand why is not working OnLongClickListener if I ask for > mapView, or define it in the class inherited from the > ItemizedOverlay. Method onTouch works fine, but why didn't it > work onLongClick > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en