0

I have different implementation for panning and on double click of google map.I have implemented the panning functionality with the help of this link.

But the issue is when user double click on map the updation on map occurs twice as the action_up event gets fired twice.

My requirement is to not do any thing on double tap as well as a little touch of map should also work as panning of map (the reason of updation of map in Action_up event).

halfer
  • 19,824
  • 17
  • 99
  • 186
JAPS
  • 250
  • 4
  • 15

1 Answers1

0

Your question is kind of unclear but I think what you want is to prevent double clicks from updating your map twice.

Using the code you provided (from the link), to prevent double clicks to update the map twice you can use this code:

public  class TouchableWrapper extends FrameLayout {

    // Map updates only when click has been done 250 Milliseconds  after the last one
    private long lastClicked;
    private static final long CLICK_DELAY = 250L;

    private long lastTouched = 0;
    private static final long SCROLL_TIME = 200L; // 200 Milliseconds, but you can adjust that to your liking
    private UpdateMapAfterUserInterection updateMapAfterUserInterection;

    public TouchableWrapper(Context context) {
        super(context);
        // Force the host activity to implement the UpdateMapAfterUserInterection Interface
        try {
            updateMapAfterUserInterection = (ActivityMapv2) context;
        } catch (ClassCastException e) {
            throw new ClassCastException(context.toString() + " must implement UpdateMapAfterUserInterection");
        }
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                lastTouched = SystemClock.uptimeMillis();
                break;
            case MotionEvent.ACTION_UP:
                final long now = SystemClock.uptimeMillis();
                if (now - lastTouched > SCROLL_TIME) {
                    if (lastClicked == 0 || ( now - lastClicked  > CLICK_DELAY)) {
                        // Update the map
                        updateMapAfterUserInterection.onUpdateMapAfterUserInterection();
                        lastClicked = now;
                    }
                }
                break;
        }
        return super.dispatchTouchEvent(ev);
    }

    // Map Activity must implement this interface
    public interface UpdateMapAfterUserInterection {
        public void onUpdateMapAfterUserInterection();
    }

}

Explanation:

This saves the time of last UP motion. Then when the next one happens it checks if 250 Milliseconds have passed, if not the update is skipped.

If however you want to prevent double clicks from updating your map at all, you will need to delay the whole update in a specific amount of time. During that time you check for any additional clicks, if they happen, you cancel the update of the map.

Simas
  • 43,548
  • 10
  • 88
  • 116
  • hey thanks so much but its some how not working!! :( Actually if I pann the map very fast map does not get updatedwith my data i.e if (now - lastTouched > SCROLL_TIME) {} this condition becomes false also double click is sending request twice – JAPS Aug 13 '14 at 11:33
  • @JAPS You can try increasing the CLICK_DELAY if double click is still updating twice. – Simas Aug 13 '14 at 11:36
  • oh yes trying to do so :) – JAPS Aug 13 '14 at 11:39