altosdroid: Select tracker by clicking on map
[fw/altos] / altoslib / AltosMap.java
index adf52ab9469d0be1405a4295a201b92fe7dca718..8d12a18094007c7cbf30b555c1a52acf49598227 100644 (file)
@@ -391,6 +391,10 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
 
        AltosPointInt   drag_start;
 
+       boolean         dragged;
+
+       static final double drag_far = 20;
+
        private void drag(int x, int y) {
                if (drag_start == null)
                        return;
@@ -398,6 +402,11 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                int dx = x - drag_start.x;
                int dy = y - drag_start.y;
 
+               double distance = Math.hypot(dx, dy);
+
+               if (distance > drag_far)
+                       dragged = true;
+
                if (transform == null) {
                        debug("Transform not set in drag\n");
                        return;
@@ -410,6 +419,12 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
 
        private void drag_start(int x, int y) {
                drag_start = new AltosPointInt(x, y);
+               dragged = false;
+       }
+
+       private void drag_stop(int x, int y) {
+               if (!dragged)
+                       map_interface.select_object (transform.screen_lat_lon(new AltosPointInt(x,y)));
        }
 
        private void line_start(int x, int y) {
@@ -442,6 +457,12 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                        line(x, y);
        }
 
+       public void touch_stop(int x, int y, boolean is_drag) {
+               notice_user_input();
+               if (is_drag)
+                       drag_stop(x, y);
+       }
+
        public AltosMap(AltosMapInterface map_interface) {
                this.map_interface = map_interface;
                cache = new AltosMapCache(map_interface);