1

I am creating a custom UI component where user can upload an image of a map and then user can specify certain locations and Display a pin. First upon image of the map loaded user will be able to pan and zoom to any position. for this I used following example which works like a charm. TouchImageView

Next part was to add a pin when it is long pressed on the image. For this I used an Absolute Layout over the map image and added an OnTouchListener and Returned false at the end for the touch listener on ImageView to work as well. I implemented the OnTouchListener As below

absoluteLayout.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, final MotionEvent event) {
            switch (event.getAction()){
                case MotionEvent.ACTION_DOWN:
                    count=-1;// reset count. Thredd will start as 0
                    released = false;// Touch long press is started
                    final Handler handler = new Handler();
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            while(!released){//Stop count if touch released
                                try {
                                    count++;// Count every 200 ms
                                    Thread.sleep(200);
                                    if(count>10){ //if pressed for 200*10= 2 seconds 
                                        released=true;

                                        handler.post(new Runnable() {
                                            @Override
                                            public void run() {
                                                addPin((int) event.getX(), (int) event.getY());//Calling the method to add the pin
                                            }
                                        });
                                    }
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                            }

                        }
                    }).start();
                    break;

                case MotionEvent.ACTION_UP:
                    released=true;// touch is released
                    break;
                case MotionEvent.ACTION_MOVE:
                    released=true; // touch is a movement therefore release long press 
                    break;
            }

            return false;
        }
    });

But the issue here is With case :"MotionEvent.ACTION_MOVE" it always make the long press released. But without it if user is trying to pan or zoom the imageView it will add a pin.

How can i detect if there is a movement in the touch and ignore when user is zooming or panning the map?

Thanks in advance.

SysClaude
  • 146
  • 2
  • 8

1 Answers1

0

You can specify a minimum amount of movement to be sure if it's an accidental movement or not, like it's explained here

Community
  • 1
  • 1
Jofre Mateu
  • 2,390
  • 15
  • 26