Fix:android:Overhaul and fix touch handling (press, longpress, pitch-zoom), add conte...
authorrikky <rikky@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 31 Aug 2011 21:42:53 +0000 (21:42 +0000)
committerrikky <rikky@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 31 Aug 2011 21:42:53 +0000 (21:42 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@4736 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/android/src/org/navitproject/navit/Navit.java
navit/navit/android/src/org/navitproject/navit/NavitGraphics.java

index 03bf319..a6e2a62 100644 (file)
@@ -669,20 +669,12 @@ public class Navit extends Activity
                                // zoom in\r
                                Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_ZOOM_IN.ordinal()).sendToTarget();\r
                                // if we zoom, hide the bubble\r
-                               if (N_NavitGraphics.NavitAOverlay != null)\r
-                               {\r
-                                       N_NavitGraphics.NavitAOverlay.hide_bubble();\r
-                               }\r
                                Log.e("Navit", "onOptionsItemSelected -> zoom in");\r
                                break;\r
                        case 2 :\r
                                // zoom out\r
                                Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_ZOOM_OUT.ordinal()).sendToTarget();\r
                                // if we zoom, hide the bubble\r
-                               if (N_NavitGraphics.NavitAOverlay != null)\r
-                               {\r
-                                       N_NavitGraphics.NavitAOverlay.hide_bubble();\r
-                               }\r
                                Log.e("Navit", "onOptionsItemSelected -> zoom out");\r
                                break;\r
                        case 3 :\r
index 8c0a832..4a83e34 100644 (file)
 
 package org.navitproject.navit;
 
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 
 import org.navitproject.navit.Navit.Navit_Address_Result_Struct;
-import org.navitproject.navit.NavitAndroidOverlay.NavitAndroidOverlayBubble;
 
 import android.app.Activity;
+import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Paint;
 import android.graphics.Path;
 import android.graphics.PointF;
 import android.graphics.Rect;
-import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
 import android.util.FloatMath;
 import android.util.Log;
+import android.view.ContextMenu;
 import android.view.KeyEvent;
+import android.view.MenuItem;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.inputmethod.InputMethodManager;
@@ -47,37 +47,26 @@ import android.widget.RelativeLayout;
 
 public class NavitGraphics
 {
-       private NavitGraphics           parent_graphics;
-       private ArrayList<NavitGraphics>                                overlays                                                                                = new ArrayList<NavitGraphics>();
-       int                                                             bitmap_w;
-       int                                                             bitmap_h;
-       int                                                             pos_x;
-       int                                                             pos_y;
-       int                                                             pos_wraparound;
-       int                                                             overlay_disabled;
-       float                                                           trackball_x, trackball_y;
-       View                                                            view;
-       RelativeLayout                                  relativelayout;
-       NavitCamera                                             camera;
-       Activity                                                        activity;
-
-       public static Boolean           in_map                                                                          = false;
+       private NavitGraphics            parent_graphics;
+       private ArrayList<NavitGraphics> overlays          = new ArrayList<NavitGraphics>();
+       int                              bitmap_w;
+       int                              bitmap_h;
+       int                              pos_x;
+       int                              pos_y;
+       int                              pos_wraparound;
+       int                              overlay_disabled;
+       float                            trackball_x, trackball_y;
+       View                             view;
+       RelativeLayout                   relativelayout;
+       NavitCamera                      camera;
+       Activity                         activity;
+
+       public static Boolean            in_map            = false;
 
        // for menu key
-       private static long                     time_for_long_press                                             = 300L;
-       private static long                     interval_for_long_press                                 = 200L;
-
-       // for touch screen
-       private long                                    last_touch_on_screen                                            = 0L;
-       private static long                     long_press_on_screen_interval                   = 1500L;
-       private static float                    long_press_on_screen_max_distance       = 8f;
-
-       // Overlay View for Android
-       //
-       // here you can draw all the nice things you want
-       // and get touch events for it (without touching C-code)
-       public NavitAndroidOverlay      NavitAOverlay                                                           = null;
-       
+       private static long              time_for_long_press               = 300L;
+       private static long              interval_for_long_press           = 200L;
+
        private Handler timer_handler = new Handler();
 
        public void SetCamera(int use_camera)
@@ -91,869 +80,615 @@ public class NavitGraphics
                }
        }
 
-       public static SensorThread      touch_sensor_thread     = null;
+       private class NavitView extends View implements Runnable, MenuItem.OnMenuItemClickListener{
+               int               touch_mode = NONE;
+               float             oldDist    = 0;
+               static final int  NONE       = 0;
+               static final int  DRAG       = 1;
+               static final int  ZOOM       = 2;
+               static final int  PRESSED    = 3;
 
-       private class SensorThread extends Thread
-       {
-               private Boolean                                 running;
-               private long                                            last_down_action        = 0L;
-               private Boolean                                 is_still_pressing;
-               private View                                            v                                               = null;
-               private float                                           x;
-               private float                                           y;
-
-               SensorThread(long last_touch, View v, NavitAndroidOverlay n_ov, float x, float y)
-               {
-                       this.x = x;
-                       this.y = y;
-                       this.running = true;
-                       this.v = v;
-                       this.is_still_pressing = true;
-                       last_down_action = System.currentTimeMillis();
-                       Log.e("NavitGraphics", "SensorThread created");
+               Method eventGetX = null;
+               Method eventGetY = null;
+               
+               public PointF    mPressedPosition = null;
+               
+               public NavitView(Context context) {
+                       super(context);
+                       try
+                       {
+                               eventGetX = android.view.MotionEvent.class.getMethod("getX", int.class);
+                               eventGetY = android.view.MotionEvent.class.getMethod("getY", int.class);
+                       }
+                       catch (Exception e)
+                       {
+                               Log.e("NavitGraphics", "Multitouch zoom not supported");
+                       }
                }
 
-               public void stop_me()
-               {
-                       this.running = false;
+               @Override
+               protected void onCreateContextMenu(ContextMenu menu) {
+                       super.onCreateContextMenu(menu);
+                       
+                       menu.setHeaderTitle("Position...");
+                       menu.add(1, 1, NONE, Navit.get_text("drive here")).setOnMenuItemClickListener(this);
+                       menu.add(1, 2, NONE, Navit.get_text("Add to contacts")).setOnMenuItemClickListener(this);
                }
 
-               public void run()
+               @Override
+               public boolean onMenuItemClick(MenuItem item) {
+                       switch(item.getItemId()) {
+                       case 1:
+                               Message msg = Message.obtain(callback_handler, msg_type.CLB_SET_DISPLAY_DESTINATION.ordinal()
+                                  , (int)mPressedPosition.x, (int)mPressedPosition.y);
+                               msg.sendToTarget();
+                               break;
+                       case 2:
+                               break;
+                       }
+                       return false;
+               }
+               
+               @Override
+               protected void onDraw(Canvas canvas)
                {
-                       Log.e("NavitGraphics", "SensorThread started");
-                       while (this.running)
+                       super.onDraw(canvas);
+                       canvas.drawBitmap(draw_bitmap, pos_x, pos_y, null);
+                       if (overlay_disabled == 0)
                        {
-                               if ((System.currentTimeMillis() - this.last_down_action) > long_press_on_screen_interval)
+                               //Log.e("NavitGraphics", "view -> onDraw 1");
+                               // assume we ARE in map view mode!
+                               in_map = true;
+
+                               Object overlays_array[];
+                               overlays_array = overlays.toArray();
+                               for (Object overlay : overlays_array)
                                {
-                                       // ok, we have counted a long press on screen
-                                       // do stuff and then stop this thread
-                                       Log.e("NavitGraphics", "SensorThread: LONG PRESS");
-                                       try
-                                       {
-                                               // find the class, to get the method "do_longpress_action"
-                                               // and then call the method
-                                               Class<? extends View> cls = this.v.getClass();
-                                               //Log.e("NavitGraphics", "c=" + String.valueOf(cls));
-                                               Class<?> partypes[] = new Class[2];
-                                               partypes[0] = Float.TYPE;
-                                               partypes[1] = Float.TYPE;
-                                               Method meth = cls.getMethod("do_longpress_action", partypes);
-                                               View methobj = this.v;
-                                               Object arglist[] = new Object[2];
-                                               arglist[0] = new Float(this.x);
-                                               arglist[1] = new Float(this.y);
-                                               meth.invoke(methobj, arglist);
-                                       }
-                                       catch (Throwable e)
+                                       //Log.e("NavitGraphics","view -> onDraw 2");
+
+                                       NavitGraphics overlay_graphics = (NavitGraphics) overlay;
+                                       if (overlay_graphics.overlay_disabled == 0)
                                        {
-                                               System.err.println(e);
-                                       }
+                                               //Log.e("NavitGraphics","view -> onDraw 3");
 
-                                       this.running = false;
-                               }
-                               else if (!this.is_still_pressing)
-                               {
-                                       Log.e("NavitGraphics", "SensorThread: stopped pressing");
-                                       this.running = false;
+                                               int x = overlay_graphics.pos_x;
+                                               int y = overlay_graphics.pos_y;
+                                               if (overlay_graphics.pos_wraparound != 0 && x < 0) x += bitmap_w;
+                                               if (overlay_graphics.pos_wraparound != 0 && y < 0) y += bitmap_h;
+                                               canvas.drawBitmap(overlay_graphics.draw_bitmap, x, y, null);
+                                       }
                                }
-                               else
+                       }
+                       else
+                       {
+                               if (Navit.show_soft_keyboard)
                                {
-                                       // Log.e("NavitGraphics", "SensorThread running");
-                                       try
+                                       if (Navit.mgr != null)
                                        {
-                                               Thread.sleep(50);
-                                       }
-                                       catch (InterruptedException e)
-                                       {
-                                               // e.printStackTrace();
+                                               //Log.e("NavitGraphics", "view -> SHOW SoftInput");
+                                               //Log.e("NavitGraphics", "view mgr=" + String.valueOf(Navit.mgr));
+                                               Navit.mgr.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);
+                                               Navit.show_soft_keyboard_now_showing = true;
+                                               // clear the variable now, keyboard will stay on screen until backbutton pressed
+                                               Navit.show_soft_keyboard = false;
                                        }
                                }
                        }
-                       Log.e("NavitGraphics", "SensorThread ended");
                }
-       }
 
+               @Override
+               protected void onSizeChanged(int w, int h, int oldw, int oldh)
+               {
+                       Log.e("Navit", "NavitGraphics -> onSizeChanged pixels x=" + w + " pixels y=" + h);
+                       Log.e("Navit", "NavitGraphics -> onSizeChanged density=" + Navit.metrics.density);
+                       Log.e("Navit", "NavitGraphics -> onSizeChanged scaledDensity="
+                                       + Navit.metrics.scaledDensity);
+                       super.onSizeChanged(w, h, oldw, oldh);
+                       draw_bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
+                       draw_canvas = new Canvas(draw_bitmap);
+                       bitmap_w = w;
+                       bitmap_h = h;
+                       SizeChangedCallback(SizeChangedCallbackID, w, h);
+               }
 
-       public NavitGraphics(Activity activity, NavitGraphics parent, int x, int y, int w, int h,
-                       int alpha, int wraparound, int use_camera)
-       {
-               if (parent == null)
+               public void do_longpress_action()
                {
-                       this.activity = activity;
-                       view = new View(activity)
+                       Log.e("NavitGraphics", "do_longpress_action enter");
+                       
+                       activity.openContextMenu(this);
+               }
+
+               private int getActionField(String fieldname, Object obj)
+               {
+                       int ret_value = -999;
+                       try
                        {
-                               int                                     touch_mode      = NONE;
-                               float                                   oldDist         = 0;
-                               PointF                          touch_now       = new PointF(0, 0);
-                               PointF                          touch_start     = new PointF(0, 0);
-                               PointF                          touch_prev      = new PointF(0, 0);
-                               static final int        NONE                    = 0;
-                               static final int        DRAG                    = 1;
-                               static final int        ZOOM                    = 2;
-                               static final int        PRESS                   = 3;
-
-                               @Override
-                               protected void onDraw(Canvas canvas)
+                               java.lang.reflect.Field field = android.view.MotionEvent.class.getField(fieldname);
+                               try
                                {
-                                       super.onDraw(canvas);
-                                       canvas.drawBitmap(draw_bitmap, pos_x, pos_y, null);
-                                       if (overlay_disabled == 0)
-                                       {
-                                               //Log.e("NavitGraphics", "view -> onDraw 1");
-                                               // assume we ARE in map view mode!
-                                               in_map = true;
+                                       ret_value = field.getInt(obj);
+                               }
+                               catch (Exception e)
+                               {
+                                       e.printStackTrace();
+                               }
+                       }
+                       catch (NoSuchFieldException ex) {}
 
-                                               Object overlays_array[];
-                                               overlays_array = overlays.toArray();
-                                               for (Object overlay : overlays_array)
-                                               {
-                                                       //Log.e("NavitGraphics","view -> onDraw 2");
+                       return ret_value;
+               }
+               
+               @Override
+               public boolean onTouchEvent(MotionEvent event)
+               {
+                       //Log.e("NavitGraphics", "onTouchEvent");
+                       super.onTouchEvent(event);
+                       int x = (int) event.getX();
+                       int y = (int) event.getY();
 
-                                                       NavitGraphics overlay_graphics = (NavitGraphics) overlay;
-                                                       if (overlay_graphics.overlay_disabled == 0)
-                                                       {
-                                                               //Log.e("NavitGraphics","view -> onDraw 3");
+                       int _ACTION_POINTER_UP_ = getActionField("ACTION_POINTER_UP", event);
+                       int _ACTION_POINTER_DOWN_ = getActionField("ACTION_POINTER_DOWN", event);
+                       int _ACTION_MASK_ = getActionField("ACTION_MASK", event);
 
-                                                               int x = overlay_graphics.pos_x;
-                                                               int y = overlay_graphics.pos_y;
-                                                               if (overlay_graphics.pos_wraparound != 0 && x < 0) x += bitmap_w;
-                                                               if (overlay_graphics.pos_wraparound != 0 && y < 0) y += bitmap_h;
-                                                               canvas.drawBitmap(overlay_graphics.draw_bitmap, x, y, null);
-                                                       }
-                                               }
-                                       }
-                                       else
-                                       {
-                                               if (Navit.show_soft_keyboard)
-                                               {
-                                                       if (Navit.mgr != null)
-                                                       {
-                                                               //Log.e("NavitGraphics", "view -> SHOW SoftInput");
-                                                               //Log.e("NavitGraphics", "view mgr=" + String.valueOf(Navit.mgr));
-                                                               Navit.mgr.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);
-                                                               Navit.show_soft_keyboard_now_showing = true;
-                                                               // clear the variable now, keyboard will stay on screen until backbutton pressed
-                                                               Navit.show_soft_keyboard = false;
-                                                       }
-                                               }
-                                       }
-                               }
+                       int switch_value = event.getAction();
+                       if (_ACTION_MASK_ != -999)
+                       {
+                               switch_value = (event.getAction() & _ACTION_MASK_);
+                       }
 
-                               @Override
-                               protected void onSizeChanged(int w, int h, int oldw, int oldh)
-                               {
-                                       Log.e("Navit", "NavitGraphics -> onSizeChanged pixels x=" + w + " pixels y=" + h);
-                                       Log.e("Navit", "NavitGraphics -> onSizeChanged density=" + Navit.metrics.density);
-                                       Log.e("Navit", "NavitGraphics -> onSizeChanged scaledDensity="
-                                                       + Navit.metrics.scaledDensity);
-                                       super.onSizeChanged(w, h, oldw, oldh);
-                                       draw_bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
-                                       draw_canvas = new Canvas(draw_bitmap);
-                                       bitmap_w = w;
-                                       bitmap_h = h;
-                                       SizeChangedCallback(SizeChangedCallbackID, w, h);
-                               }
+                       if (switch_value == MotionEvent.ACTION_DOWN)
+                       {
+                               ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
+                               touch_mode = PRESSED;
+                               mPressedPosition = new PointF(x, y);
+                               postDelayed(this, time_for_long_press);
+                       }
+                       else if ((switch_value == MotionEvent.ACTION_UP) || (switch_value == _ACTION_POINTER_UP_))
+                       {
+                               Log.e("NavitGraphics", "ACTION_UP");
 
-                               public void do_longpress_action(float x, float y)
+                               if ( touch_mode == DRAG )
                                {
-                                       if (!NavitAndroidOverlay.confirmed_bubble)
-                                       {
-                                               Log.e("NavitGraphics", "do_longpress_action enter");
-                                               NavitAndroidOverlayBubble b = new NavitAndroidOverlayBubble();
-                                               b.x = (int) x;
-                                               b.y = (int) y;
-                                               NavitAOverlay.set_bubble(b);
-                                               NavitAOverlay.show_bubble();
-                                               this.postInvalidate();
-                                               NavitAOverlay.invalidate();
-                                       }
-                               }
+                                       Log.e("NavitGraphics", "onTouch move");
 
-                               @Override
-                               public boolean onTouchEvent(MotionEvent event)
+                                       MotionCallback(MotionCallbackID, x, y);
+                                       ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
+                               }
+                               else if (touch_mode == ZOOM)
                                {
-                                       PointF touch_now2 = null;
-                                       PointF touch_start2 = null;
-
-                                       //Log.e("NavitGraphics", "onTouchEvent");
-
-                                       super.onTouchEvent(event);
-                                       int x = (int) event.getX();
-                                       int y = (int) event.getY();
+                                       //Log.e("NavitGraphics", "onTouch zoom");
 
-                                       int _ACTION_POINTER_UP_ = -999;
-                                       int _ACTION_POINTER_DOWN_ = -999;
-                                       int _ACTION_MASK_ = -999;
-                                       try
+                                       float newDist = spacing(getFloatValue(event, 0), getFloatValue(event, 1));
+                                       float scale = 0;
+                                       if (newDist > 10f)
                                        {
-                                               java.lang.reflect.Field field = android.view.MotionEvent.class
-                                                               .getField("ACTION_POINTER_UP");
-                                               try
-                                               {
-                                                       _ACTION_POINTER_UP_ = field.getInt(event);
-                                               }
-                                               catch (IllegalArgumentException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
-                                               catch (IllegalAccessException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
+                                               scale = newDist / oldDist;
                                        }
-                                       catch (NoSuchFieldException ex)
-                                       {
 
-                                       }
-                                       try
-                                       {
-                                               java.lang.reflect.Field field = android.view.MotionEvent.class
-                                                               .getField("ACTION_POINTER_DOWN");
-                                               try
-                                               {
-                                                       _ACTION_POINTER_DOWN_ = field.getInt(event);
-                                               }
-                                               catch (IllegalArgumentException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
-                                               catch (IllegalAccessException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
-                                       }
-                                       catch (NoSuchFieldException ex)
+                                       if (scale > 1.3)
                                        {
+                                               // zoom in
+                                               CallbackMessageChannel(1, "");
 
+                                               // next lines are a hack, without it screen will not get updated anymore!
+                                               ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
+                                               MotionCallback(MotionCallbackID, x + 15, y);
+                                               MotionCallback(MotionCallbackID, x - 15, y);
+                                               ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
+                                               this.postInvalidate();
+
+                                               //Log.e("NavitGraphics", "onTouch zoom in");
                                        }
-                                       try
-                                       {
-                                               java.lang.reflect.Field field = android.view.MotionEvent.class
-                                                               .getField("ACTION_MASK");
-                                               try
-                                               {
-                                                       _ACTION_MASK_ = field.getInt(event);
-                                               }
-                                               catch (IllegalArgumentException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
-                                               catch (IllegalAccessException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
-                                       }
-                                       catch (NoSuchFieldException ex)
+                                       else if (scale < 0.8)
                                        {
+                                               // zoom out    
+                                               CallbackMessageChannel(2, "");
 
-                                       }
+                                               // next lines are a hack, without it screen will not get updated anymore!
+                                               ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
+                                               MotionCallback(MotionCallbackID, x + 15, y);
+                                               MotionCallback(MotionCallbackID, x - 15, y);
+                                               ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
+                                               this.postInvalidate();
 
-                                       // calculate value
-                                       int switch_value = event.getAction();;
-                                       if (_ACTION_MASK_ != -999)
-                                       {
-                                               switch_value = (event.getAction() & _ACTION_MASK_);
+                                               //Log.e("NavitGraphics", "onTouch zoom out");
                                        }
-                                       //Log.e("NavitGraphics", "switch_value=" + switch_value);
-                                       //Log.e("NavitGraphics", "_ACTION_MASK_=" + _ACTION_MASK_);
-                                       // calculate value
+                               }
+                               else if (touch_mode == PRESSED)
+                               {
+                                       ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
+                               }
+                               touch_mode = NONE;
+                       }
+                       else if (switch_value == MotionEvent.ACTION_MOVE)
+                       {
+                               //Log.e("NavitGraphics", "ACTION_MOVE");
 
-                                       if (switch_value == MotionEvent.ACTION_DOWN)
+                               if (touch_mode == DRAG)
+                               {
+                                       MotionCallback(MotionCallbackID, x, y);
+                               }
+                               else if (touch_mode == ZOOM)
+                               {
+                                       float newDist = spacing(getFloatValue(event, 0), getFloatValue(event, 1));
+                                       float scale = newDist / oldDist;
+                                       Log.e("NavitGraphics", "New scale = " + scale);
+                                       if (scale > 1.2)
                                        {
-                                               this.touch_now.set(event.getX(), event.getY());
-                                               this.touch_start.set(event.getX(), event.getY());
-                                               this.touch_prev.set(event.getX(), event.getY());
-                                               //Log.e("NavitGraphics", "ACTION_DOWN");
-
-                                               if (in_map)
-                                               {
-                                                       // remember last press on screen time
-                                                       last_touch_on_screen = System.currentTimeMillis();
-                                                       touch_sensor_thread = new SensorThread(last_touch_on_screen, this,
-                                                                       NavitAOverlay, this.touch_now.x, this.touch_now.y);
-                                                       touch_sensor_thread.start();
-                                               }
+                                               // zoom in
+                                               CallbackMessageChannel(1, "");
+                                               oldDist = newDist;
 
+                                               // next lines are a hack, without it screen will not get updated anymore!
                                                ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
-                                               touch_mode = DRAG;
+                                               MotionCallback(MotionCallbackID, x + 15, y);
+                                               MotionCallback(MotionCallbackID, x - 15, y);
+                                               ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
+                                               this.postInvalidate();
 
+                                               //Log.e("NavitGraphics", "onTouch zoom in");
                                        }
-                                       else if ((switch_value == MotionEvent.ACTION_UP)
-                                                       || (switch_value == _ACTION_POINTER_UP_))
+                                       else if (scale < 0.8)
                                        {
-                                               this.touch_now.set(event.getX(), event.getY());
-                                               touch_now2 = touch_now;
-                                               touch_start2 = touch_start;
-                                               Log.e("NavitGraphics", "ACTION_UP");
-
-                                               Log.e("NavitGraphics", "xxxxxxxxxx");
-                                               try
-                                               {
-                                                       Log.e("NavitGraphics", "yyyyyyyyyyyyyy");
-                                                       //touch_sensor_thread.down();
-                                                       touch_sensor_thread.stop_me();
-                                                       // touch_sensor_thread.stop();
-                                               }
-                                               catch (Exception e)
-                                               {
-
-                                               }
-
-                                               if ((touch_mode == DRAG)
-                                                               && (spacing(touch_start2, touch_now2) < long_press_on_screen_max_distance))
-                                               {
-                                                       // just a single press down
-                                                       touch_mode = PRESS;
-
-                                                       try
-                                                       {
-                                                               //touch_sensor_thread.down();
-                                                               touch_sensor_thread.stop_me();
-                                                               // touch_sensor_thread.stop();
-                                                       }
-                                                       catch (Exception e)
-                                                       {
-
-                                                       }
-
-                                                       // was is a long press? or normal quick touch?
-                                                       if ((in_map)
-                                                                       && ((System.currentTimeMillis() - last_touch_on_screen) > long_press_on_screen_interval))
-                                                       {
-                                                               Log.e("NavitGraphics", "onTouch up (LONG PRESS)");
-                                                               do_longpress_action(touch_now.x, touch_now.y);
-                                                       }
-                                                       else
-                                                       {
-                                                               Log.e("NavitGraphics", "onTouch up (quick touch)");
-                                                               ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
-                                                       }
-                                                       touch_mode = NONE;
-                                               }
-                                               else
-                                               {
-                                                       if (touch_mode == DRAG)
-                                                       {
-                                                               touch_now2 = touch_now;
-                                                               touch_start2 = touch_start;
-
-                                                               Log.e("NavitGraphics", "onTouch move");
-
-                                                               try
-                                                               {
-                                                                       //touch_sensor_thread.down();
-                                                                       touch_sensor_thread.stop_me();
-                                                                       // touch_sensor_thread.stop();
-                                                               }
-                                                               catch (Exception e)
-                                                               {
+                                               oldDist = newDist;
+                                               // zoom out    
+                                               CallbackMessageChannel(2, "");
 
-                                                               }
+                                               // next lines are a hack, without it screen will not get updated anymore!
+                                               ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
+                                               MotionCallback(MotionCallbackID, x + 15, y);
+                                               MotionCallback(MotionCallbackID, x - 15, y);
+                                               ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
+                                               this.postInvalidate();
 
-                                                               // if we drag, hide the bubble
-                                                               NavitAOverlay.hide_bubble();
+                                               //Log.e("NavitGraphics", "onTouch zoom out");
+                                       }
+                               }
+                               else if (touch_mode == PRESSED)
+                               {
+                                       Log.e("NavitGraphics", "Start drag mode");
+                                       if ( spacing(mPressedPosition, new PointF(event.getX(),  event.getY()))  > 20f)
+                                               touch_mode = DRAG;
+                               }
+                       }
+                       else if (switch_value == _ACTION_POINTER_DOWN_)
+                       {
+                               //Log.e("NavitGraphics", "ACTION_POINTER_DOWN");
+                               oldDist = spacing(getFloatValue(event, 0), getFloatValue(event, 1));
+                               if (oldDist > 2f)
+                               {
+                                       touch_mode = ZOOM;
+                                       
+                                       //Log.e("NavitGraphics", "--> zoom");
+                               }
+                       }
+                       return true;
+               }
 
-                                                               MotionCallback(MotionCallbackID, x, y);
-                                                               ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
+               private float spacing(PointF a, PointF b)
+               {
+                       float x = a.x - b.x;
+                       float y = a.y - b.y;
+                       return FloatMath.sqrt(x * x + y * y);
+               }
 
-                                                               touch_mode = NONE;
-                                                       }
-                                                       else
-                                                       {
-                                                               if (touch_mode == ZOOM)
-                                                               {
-                                                                       // end of "pinch zoom" move
-
-                                                                       //Log.e("NavitGraphics", "onTouch zoom");
-
-                                                                       float newDist = spacing(event);
-                                                                       float scale = 0;
-                                                                       if (newDist > 10f)
-                                                                       {
-                                                                               scale = newDist / oldDist;
-                                                                       }
-
-                                                                       if (scale > 1.3)
-                                                                       {
-                                                                               // zoom in
-                                                                               CallbackMessageChannel(1, "");
-
-                                                                               // next lines are a hack, without it screen will not get updated anymore!
-                                                                               ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
-                                                                               MotionCallback(MotionCallbackID, x + 15, y);
-                                                                               MotionCallback(MotionCallbackID, x - 15, y);
-                                                                               ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
-                                                                               this.postInvalidate();
-
-                                                                               //Log.e("NavitGraphics", "onTouch zoom in");
-                                                                       }
-                                                                       else if (scale < 0.8)
-                                                                       {
-                                                                               // zoom out    
-                                                                               CallbackMessageChannel(2, "");
-
-                                                                               // next lines are a hack, without it screen will not get updated anymore!
-                                                                               ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
-                                                                               MotionCallback(MotionCallbackID, x + 15, y);
-                                                                               MotionCallback(MotionCallbackID, x - 15, y);
-                                                                               ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
-                                                                               this.postInvalidate();
-
-                                                                               //Log.e("NavitGraphics", "onTouch zoom out");
-                                                                       }
-                                                                       touch_mode = NONE;
-                                                               }
-                                                               else
-                                                               {
-                                                                       Log.d("NavitGraphics", "touch_mode=NONE (END of ZOOM part 2)");
-                                                                       touch_mode = NONE;
-                                                               }
-                                                       }
-                                               }
-                                       }
-                                       else if (switch_value == MotionEvent.ACTION_MOVE)
+               private PointF getFloatValue(Object instance, Object argument)
+               {
+                       PointF pos = new PointF(0,0); 
+                       
+                       if (eventGetX != null && eventGetY != null)
+                       {
+                               try
+                               {
+                                       Float x = (java.lang.Float) eventGetX.invoke(instance, argument);
+                                       Float y = (java.lang.Float) eventGetY.invoke(instance, argument);
+                                       pos.set(x.floatValue(), y.floatValue());
+                                       
+                               }
+                               catch (Exception e){}
+                       }
+                       return pos;
+               }
+               
+               @Override
+               public boolean onKeyDown(int keyCode, KeyEvent event)
+               {
+                       int i;
+                       String s = null;
+                       boolean handled = true;
+                       i = event.getUnicodeChar();
+                       //Log.e("NavitGraphics", "onKeyDown " + keyCode + " " + i);
+                       // Log.e("NavitGraphics","Unicode "+event.getUnicodeChar());
+                       if (i == 0)
+                       {
+                               if (keyCode == android.view.KeyEvent.KEYCODE_DEL)
+                               {
+                                       s = java.lang.String.valueOf((char) 8);
+                               }
+                               else if (keyCode == android.view.KeyEvent.KEYCODE_MENU)
+                               {
+                                       if (!in_map)
                                        {
-                                               //Log.e("NavitGraphics", "ACTION_MOVE");
-
-                                               if (touch_mode == DRAG)
+                                               // if last menukeypress is less than 0.2 seconds away then count longpress
+                                               if ((System.currentTimeMillis() - Navit.last_pressed_menu_key) < interval_for_long_press)
                                                {
-                                                       this.touch_now.set(event.getX(), event.getY());
-                                                       touch_now2 = touch_now;
-                                                       touch_start2 = touch_start;
-                                                       this.touch_prev.set(event.getX(), event.getY());
-
-                                                       try
-                                                       {
-                                                               //touch_sensor_thread.down();
-                                                               touch_sensor_thread.stop_me();
-                                                               // touch_sensor_thread.stop();
-                                                       }
-                                                       catch (Exception e)
-                                                       {
-
-                                                       }
+                                                       Navit.time_pressed_menu_key = Navit.time_pressed_menu_key
+                                                                       + (System.currentTimeMillis() - Navit.last_pressed_menu_key);
+                                                       //Log.e("NavitGraphics", "press time=" + Navit.time_pressed_menu_key);
 
-                                                       if ((in_map)
-                                                                       && (spacing(touch_start2, touch_now2) < long_press_on_screen_max_distance))
+                                                       // on long press let softkeyboard popup
+                                                       if (Navit.time_pressed_menu_key > time_for_long_press)
                                                        {
-                                                               // is it a still ongoing long press?
-                                                               if ((System.currentTimeMillis() - last_touch_on_screen) > long_press_on_screen_interval)
-                                                               {
-                                                                       Log.e("NavitGraphics", "onTouch up (LONG PRESS)");
-                                                                       do_longpress_action(touch_now.x, touch_now.y);
-                                                               }
-                                                       }
-                                                       else
-                                                       {
-                                                               //Log.e("NavitGraphics", "onTouch move2");
-                                                               MotionCallback(MotionCallbackID, x, y);
+                                                               //Log.e("NavitGraphics", "long press menu key!!");
+                                                               Navit.show_soft_keyboard = true;
+                                                               Navit.time_pressed_menu_key = 0L;
+                                                               // need to draw to get the keyboard showing
+                                                               this.postInvalidate();
                                                        }
                                                }
-                                               else if (touch_mode == ZOOM)
+                                               else
                                                {
-                                                       this.touch_now.set(event.getX(), event.getY());
-                                                       this.touch_prev.set(event.getX(), event.getY());
-
-                                                       //Log.e("NavitGraphics", "zoom 2");
+                                                       Navit.time_pressed_menu_key = 0L;
                                                }
+                                               Navit.last_pressed_menu_key = System.currentTimeMillis();
+                                               // if in menu view:
+                                               // use as OK (Enter) key
+                                               s = java.lang.String.valueOf((char) 13);
+                                               handled = true;
+                                               // dont use menu key here (use it in onKeyUp)
+                                               return handled;
                                        }
-                                       else if (switch_value == _ACTION_POINTER_DOWN_)
+                                       else
                                        {
-                                               //Log.e("NavitGraphics", "ACTION_POINTER_DOWN");
-
-                                               oldDist = spacing(event);
-                                               if (oldDist > 10f)
-                                               {
-                                                       touch_mode = ZOOM;
-                                                       //Log.e("NavitGraphics", "--> zoom");
-                                               }
+                                               // if on map view:
+                                               // volume UP
+                                               //s = java.lang.String.valueOf((char) 1);
+                                               handled = false;
+                                               return handled;
                                        }
-                                       return true;
                                }
-
-                               private float spacing(PointF a, PointF b)
+                               else if (keyCode == android.view.KeyEvent.KEYCODE_SEARCH)
                                {
-                                       float x = a.x - b.x;
-                                       float y = a.y - b.y;
-                                       return FloatMath.sqrt(x * x + y * y);
+                                       s = java.lang.String.valueOf((char) 19);
                                }
-
-                               public float spacing(MotionEvent event)
+                               else if (keyCode == android.view.KeyEvent.KEYCODE_BACK)
+                               {
+                                       //Log.e("NavitGraphics", "KEYCODE_BACK down");
+                                       s = java.lang.String.valueOf((char) 27);
+                               }
+                               else if (keyCode == android.view.KeyEvent.KEYCODE_CALL)
+                               {
+                                       s = java.lang.String.valueOf((char) 3);
+                               }
+                               else if (keyCode == android.view.KeyEvent.KEYCODE_VOLUME_UP)
                                {
-                                       float x;
-                                       float y;
-                                       java.lang.Object instance = event;
-                                       java.lang.Object arg0 = (int) 0;
-                                       java.lang.Object arg1 = (int) 1;
-                                       try
+                                       if (!in_map)
                                        {
-                                               Method m_getX = android.view.MotionEvent.class.getMethod("getX", int.class);
-                                               Method m_getY = android.view.MotionEvent.class.getMethod("getY", int.class);
-                                               float y0 = 0;
-                                               try
-                                               {
-                                                       Float xxxx = (java.lang.Float) m_getY.invoke(instance, arg0);
-                                                       y0 = xxxx.floatValue();
-                                               }
-                                               catch (IllegalArgumentException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
-                                               catch (IllegalAccessException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
-                                               catch (InvocationTargetException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
-
-                                               float y1 = 0;
-                                               try
-                                               {
-                                                       Float xxxx = (java.lang.Float) m_getY.invoke(instance, arg1);
-                                                       y1 = xxxx.floatValue();
-                                               }
-                                               catch (IllegalArgumentException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
-                                               catch (IllegalAccessException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
-                                               catch (InvocationTargetException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
-
-                                               float x0 = 0;
-                                               try
-                                               {
-                                                       Float xxxx = (java.lang.Float) m_getX.invoke(instance, arg0);
-                                                       x0 = xxxx.floatValue();
-                                               }
-                                               catch (IllegalArgumentException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
-                                               catch (IllegalAccessException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
-                                               catch (InvocationTargetException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
-                                               float x1 = 0;
-                                               try
-                                               {
-                                                       Float xxxx = (java.lang.Float) m_getX.invoke(instance, arg1);
-                                                       x1 = xxxx.floatValue();
-                                               }
-                                               catch (IllegalArgumentException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
-                                               catch (IllegalAccessException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
-                                               catch (InvocationTargetException e)
-                                               {
-                                                       e.printStackTrace();
-                                               }
-                                               //.invoke(instance, arg) - m_getX.invoke(instance, arg);
-                                               x = x0 - x1;
-                                               y = y0 - y1;
+                                               // if in menu view:
+                                               // use as UP key
+                                               s = java.lang.String.valueOf((char) 16);
+                                               handled = true;
                                        }
-                                       catch (NoSuchMethodException ex)
+                                       else
                                        {
-                                               x = 0;
-                                               y = 0;
+                                               // if on map view:
+                                               // volume UP
+                                               //s = java.lang.String.valueOf((char) 21);
+                                               handled = false;
+                                               return handled;
                                        }
-                                       return FloatMath.sqrt(x * x + y * y);
                                }
-
-                               @Override
-                               public boolean onKeyDown(int keyCode, KeyEvent event)
+                               else if (keyCode == android.view.KeyEvent.KEYCODE_VOLUME_DOWN)
                                {
-                                       int i;
-                                       String s = null;
-                                       boolean handled = true;
-                                       i = event.getUnicodeChar();
-                                       //Log.e("NavitGraphics", "onKeyDown " + keyCode + " " + i);
-                                       // Log.e("NavitGraphics","Unicode "+event.getUnicodeChar());
-                                       if (i == 0)
+                                       if (!in_map)
                                        {
-                                               if (keyCode == android.view.KeyEvent.KEYCODE_DEL)
-                                               {
-                                                       s = java.lang.String.valueOf((char) 8);
-                                               }
-                                               else if (keyCode == android.view.KeyEvent.KEYCODE_MENU)
-                                               {
-                                                       if (!in_map)
-                                                       {
-                                                               // if last menukeypress is less than 0.2 seconds away then count longpress
-                                                               if ((System.currentTimeMillis() - Navit.last_pressed_menu_key) < interval_for_long_press)
-                                                               {
-                                                                       Navit.time_pressed_menu_key = Navit.time_pressed_menu_key
-                                                                                       + (System.currentTimeMillis() - Navit.last_pressed_menu_key);
-                                                                       //Log.e("NavitGraphics", "press time=" + Navit.time_pressed_menu_key);
-
-                                                                       // on long press let softkeyboard popup
-                                                                       if (Navit.time_pressed_menu_key > time_for_long_press)
-                                                                       {
-                                                                               //Log.e("NavitGraphics", "long press menu key!!");
-                                                                               Navit.show_soft_keyboard = true;
-                                                                               Navit.time_pressed_menu_key = 0L;
-                                                                               // need to draw to get the keyboard showing
-                                                                               this.postInvalidate();
-                                                                       }
-                                                               }
-                                                               else
-                                                               {
-                                                                       Navit.time_pressed_menu_key = 0L;
-                                                               }
-                                                               Navit.last_pressed_menu_key = System.currentTimeMillis();
-                                                               // if in menu view:
-                                                               // use as OK (Enter) key
-                                                               s = java.lang.String.valueOf((char) 13);
-                                                               handled = true;
-                                                               // dont use menu key here (use it in onKeyUp)
-                                                               return handled;
-                                                       }
-                                                       else
-                                                       {
-                                                               // if on map view:
-                                                               // volume UP
-                                                               //s = java.lang.String.valueOf((char) 1);
-                                                               handled = false;
-                                                               return handled;
-                                                       }
-                                               }
-                                               else if (keyCode == android.view.KeyEvent.KEYCODE_SEARCH)
-                                               {
-                                                       s = java.lang.String.valueOf((char) 19);
-                                               }
-                                               else if (keyCode == android.view.KeyEvent.KEYCODE_BACK)
-                                               {
-                                                       //Log.e("NavitGraphics", "KEYCODE_BACK down");
-                                                       s = java.lang.String.valueOf((char) 27);
-                                               }
-                                               else if (keyCode == android.view.KeyEvent.KEYCODE_CALL)
-                                               {
-                                                       s = java.lang.String.valueOf((char) 3);
-                                               }
-                                               else if (keyCode == android.view.KeyEvent.KEYCODE_VOLUME_UP)
-                                               {
-                                                       if (!in_map)
-                                                       {
-                                                               // if in menu view:
-                                                               // use as UP key
-                                                               s = java.lang.String.valueOf((char) 16);
-                                                               handled = true;
-                                                       }
-                                                       else
-                                                       {
-                                                               // if on map view:
-                                                               // volume UP
-                                                               //s = java.lang.String.valueOf((char) 21);
-                                                               handled = false;
-                                                               return handled;
-                                                       }
-                                               }
-                                               else if (keyCode == android.view.KeyEvent.KEYCODE_VOLUME_DOWN)
-                                               {
-                                                       if (!in_map)
-                                                       {
-                                                               // if in menu view:
-                                                               // use as DOWN key
-                                                               s = java.lang.String.valueOf((char) 14);
-                                                               handled = true;
-                                                       }
-                                                       else
-                                                       {
-                                                               // if on map view:
-                                                               // volume DOWN
-                                                               //s = java.lang.String.valueOf((char) 4);
-                                                               handled = false;
-                                                               return handled;
-                                                       }
-                                               }
-                                               else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_CENTER)
-                                               {
-                                                       s = java.lang.String.valueOf((char) 13);
-                                               }
-                                               else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_DOWN)
-                                               {
-                                                       s = java.lang.String.valueOf((char) 16);
-                                               }
-                                               else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_LEFT)
-                                               {
-                                                       s = java.lang.String.valueOf((char) 2);
-                                               }
-                                               else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_RIGHT)
-                                               {
-                                                       s = java.lang.String.valueOf((char) 6);
-                                               }
-                                               else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_UP)
-                                               {
-                                                       s = java.lang.String.valueOf((char) 14);
-                                               }
+                                               // if in menu view:
+                                               // use as DOWN key
+                                               s = java.lang.String.valueOf((char) 14);
+                                               handled = true;
                                        }
-                                       else if (i == 10)
+                                       else
                                        {
-                                               s = java.lang.String.valueOf((char) 13);
+                                               // if on map view:
+                                               // volume DOWN
+                                               //s = java.lang.String.valueOf((char) 4);
+                                               handled = false;
+                                               return handled;
                                        }
-                                       else
+                               }
+                               else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_CENTER)
+                               {
+                                       s = java.lang.String.valueOf((char) 13);
+                               }
+                               else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_DOWN)
+                               {
+                                       s = java.lang.String.valueOf((char) 16);
+                               }
+                               else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_LEFT)
+                               {
+                                       s = java.lang.String.valueOf((char) 2);
+                               }
+                               else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_RIGHT)
+                               {
+                                       s = java.lang.String.valueOf((char) 6);
+                               }
+                               else if (keyCode == android.view.KeyEvent.KEYCODE_DPAD_UP)
+                               {
+                                       s = java.lang.String.valueOf((char) 14);
+                               }
+                       }
+                       else if (i == 10)
+                       {
+                               s = java.lang.String.valueOf((char) 13);
+                       }
+                       else
+                       {
+                               s = java.lang.String.valueOf((char) i);
+                       }
+                       if (s != null)
+                       {
+                               KeypressCallback(KeypressCallbackID, s);
+                       }
+                       return handled;
+               }
+
+               @Override
+               public boolean onKeyUp(int keyCode, KeyEvent event)
+               {
+                       //Log.e("NavitGraphics", "onKeyUp " + keyCode);
+
+                       int i;
+                       String s = null;
+                       boolean handled = true;
+                       i = event.getUnicodeChar();
+
+                       if (i == 0)
+                       {
+                               if (keyCode == android.view.KeyEvent.KEYCODE_VOLUME_UP)
+                               {
+                                       if (!in_map)
                                        {
-                                               s = java.lang.String.valueOf((char) i);
+                                               //s = java.lang.String.valueOf((char) 16);
+                                               handled = true;
+                                               return handled;
                                        }
-                                       if (s != null)
+                                       else
                                        {
-                                               KeypressCallback(KeypressCallbackID, s);
+                                               //s = java.lang.String.valueOf((char) 21);
+                                               handled = false;
+                                               return handled;
                                        }
-                                       return handled;
                                }
-
-                               @Override
-                               public boolean onKeyUp(int keyCode, KeyEvent event)
+                               else if (keyCode == android.view.KeyEvent.KEYCODE_VOLUME_DOWN)
                                {
-                                       //Log.e("NavitGraphics", "onKeyUp " + keyCode);
-
-                                       int i;
-                                       String s = null;
-                                       boolean handled = true;
-                                       i = event.getUnicodeChar();
-
-                                       if (i == 0)
+                                       if (!in_map)
                                        {
-                                               if (keyCode == android.view.KeyEvent.KEYCODE_VOLUME_UP)
-                                               {
-                                                       if (!in_map)
-                                                       {
-                                                               //s = java.lang.String.valueOf((char) 16);
-                                                               handled = true;
-                                                               return handled;
-                                                       }
-                                                       else
-                                                       {
-                                                               //s = java.lang.String.valueOf((char) 21);
-                                                               handled = false;
-                                                               return handled;
-                                                       }
-                                               }
-                                               else if (keyCode == android.view.KeyEvent.KEYCODE_VOLUME_DOWN)
-                                               {
-                                                       if (!in_map)
-                                                       {
-                                                               //s = java.lang.String.valueOf((char) 14);
-                                                               handled = true;
-                                                               return handled;
-                                                       }
-                                                       else
-                                                       {
-                                                               //s = java.lang.String.valueOf((char) 4);
-                                                               handled = false;
-                                                               return handled;
-                                                       }
-                                               }
-                                               else if (keyCode == android.view.KeyEvent.KEYCODE_BACK)
-                                               {
-                                                       if (Navit.show_soft_keyboard_now_showing)
-                                                       {
-                                                               Navit.show_soft_keyboard_now_showing = false;
-                                                       }
-                                                       //Log.e("NavitGraphics", "KEYCODE_BACK up");
-                                                       //s = java.lang.String.valueOf((char) 27);
-                                                       handled = true;
-                                                       return handled;
-                                               }
-                                               else if (keyCode == android.view.KeyEvent.KEYCODE_MENU)
-                                               {
-                                                       if (!in_map)
-                                                       {
-                                                               if (Navit.show_soft_keyboard_now_showing)
-                                                               {
-                                                                       // if soft keyboard showing on screen, dont use menu button as select key
-                                                               }
-                                                               else
-                                                               {
-                                                                       // if in menu view:
-                                                                       // use as OK (Enter) key
-                                                                       s = java.lang.String.valueOf((char) 13);
-                                                                       handled = true;
-                                                               }
-                                                       }
-                                                       else
-                                                       {
-                                                               // if on map view:
-                                                               // volume UP
-                                                               //s = java.lang.String.valueOf((char) 1);
-                                                               handled = false;
-                                                               return handled;
-                                                       }
-                                               }
+                                               //s = java.lang.String.valueOf((char) 14);
+                                               handled = true;
+                                               return handled;
                                        }
-                                       if (s != null)
+                                       else
                                        {
-                                               KeypressCallback(KeypressCallbackID, s);
+                                               //s = java.lang.String.valueOf((char) 4);
+                                               handled = false;
+                                               return handled;
                                        }
-                                       return handled;
-
                                }
-
-                               @Override
-                               public boolean onTrackballEvent(MotionEvent event)
+                               else if (keyCode == android.view.KeyEvent.KEYCODE_BACK)
                                {
-                                       //Log.e("NavitGraphics", "onTrackball " + event.getAction() + " " + event.getX() + " "
-                                       //              + event.getY());
-                                       String s = null;
-                                       if (event.getAction() == android.view.MotionEvent.ACTION_DOWN)
+                                       if (Navit.show_soft_keyboard_now_showing)
                                        {
-                                               s = java.lang.String.valueOf((char) 13);
+                                               Navit.show_soft_keyboard_now_showing = false;
                                        }
-                                       if (event.getAction() == android.view.MotionEvent.ACTION_MOVE)
+                                       //Log.e("NavitGraphics", "KEYCODE_BACK up");
+                                       //s = java.lang.String.valueOf((char) 27);
+                                       handled = true;
+                                       return handled;
+                               }
+                               else if (keyCode == android.view.KeyEvent.KEYCODE_MENU)
+                               {
+                                       if (!in_map)
                                        {
-                                               trackball_x += event.getX();
-                                               trackball_y += event.getY();
-                                               //Log.e("NavitGraphics", "trackball " + trackball_x + " " + trackball_y);
-                                               if (trackball_x <= -1)
+                                               if (Navit.show_soft_keyboard_now_showing)
                                                {
-                                                       s = java.lang.String.valueOf((char) 2);
-                                                       trackball_x += 1;
+                                                       // if soft keyboard showing on screen, dont use menu button as select key
                                                }
-                                               if (trackball_x >= 1)
-                                               {
-                                                       s = java.lang.String.valueOf((char) 6);
-                                                       trackball_x -= 1;
-                                               }
-                                               if (trackball_y <= -1)
-                                               {
-                                                       s = java.lang.String.valueOf((char) 16);
-                                                       trackball_y += 1;
-                                               }
-                                               if (trackball_y >= 1)
+                                               else
                                                {
-                                                       s = java.lang.String.valueOf((char) 14);
-                                                       trackball_y -= 1;
+                                                       // if in menu view:
+                                                       // use as OK (Enter) key
+                                                       s = java.lang.String.valueOf((char) 13);
+                                                       handled = true;
                                                }
                                        }
-                                       if (s != null)
+                                       else
                                        {
-                                               KeypressCallback(KeypressCallbackID, s);
+                                               // if on map view:
+                                               // volume UP
+                                               //s = java.lang.String.valueOf((char) 1);
+                                               handled = false;
+                                               return handled;
                                        }
-                                       return true;
                                }
-                               @Override
-                               protected void onFocusChanged(boolean gainFocus, int direction,
-                                               Rect previouslyFocusedRect)
+                       }
+                       if (s != null)
+                       {
+                               KeypressCallback(KeypressCallbackID, s);
+                       }
+                       return handled;
+
+               }
+
+               @Override
+               public boolean onTrackballEvent(MotionEvent event)
+               {
+                       //Log.e("NavitGraphics", "onTrackball " + event.getAction() + " " + event.getX() + " "
+                       //              + event.getY());
+                       String s = null;
+                       if (event.getAction() == android.view.MotionEvent.ACTION_DOWN)
+                       {
+                               s = java.lang.String.valueOf((char) 13);
+                       }
+                       if (event.getAction() == android.view.MotionEvent.ACTION_MOVE)
+                       {
+                               trackball_x += event.getX();
+                               trackball_y += event.getY();
+                               //Log.e("NavitGraphics", "trackball " + trackball_x + " " + trackball_y);
+                               if (trackball_x <= -1)
+                               {
+                                       s = java.lang.String.valueOf((char) 2);
+                                       trackball_x += 1;
+                               }
+                               if (trackball_x >= 1)
+                               {
+                                       s = java.lang.String.valueOf((char) 6);
+                                       trackball_x -= 1;
+                               }
+                               if (trackball_y <= -1)
                                {
-                                       super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
-                                       //Log.e("NavitGraphics", "FocusChange " + gainFocus);
+                                       s = java.lang.String.valueOf((char) 16);
+                                       trackball_y += 1;
                                }
-                       };
+                               if (trackball_y >= 1)
+                               {
+                                       s = java.lang.String.valueOf((char) 14);
+                                       trackball_y -= 1;
+                               }
+                       }
+                       if (s != null)
+                       {
+                               KeypressCallback(KeypressCallbackID, s);
+                       }
+                       return true;
+               }
+               @Override
+               protected void onFocusChanged(boolean gainFocus, int direction,
+                               Rect previouslyFocusedRect)
+               {
+                       super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
+                       //Log.e("NavitGraphics", "FocusChange " + gainFocus);
+               }
+
+               @Override
+               public void run() {
+                       if (in_map && touch_mode == PRESSED)
+                       {
+                               do_longpress_action();
+                               touch_mode = NONE;
+                       }
+               }
+               
+       }
+       
+       public NavitGraphics(final Activity activity, NavitGraphics parent, int x, int y, int w, int h,
+                       int alpha, int wraparound, int use_camera)
+       {
+               if (parent == null)
+               {
+                       this.activity = activity;
+                       view = new NavitView(activity);
+                       //activity.registerForContextMenu(view);
+                       view.setClickable(false);
                        view.setFocusable(true);
                        view.setFocusableInTouchMode(true);
                        view.setKeepScreenOn(true);
@@ -964,16 +699,6 @@ public class NavitGraphics
                        }
                        relativelayout.addView(view);
 
-                       // android overlay
-                       Log.e("Navit", "create android overlay");
-                       NavitAOverlay = new NavitAndroidOverlay(relativelayout.getContext());
-                       RelativeLayout.LayoutParams NavitAOverlay_lp = new RelativeLayout.LayoutParams(
-                                       RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
-                       relativelayout.addView(NavitAOverlay, NavitAOverlay_lp);
-                       NavitAOverlay.bringToFront();
-                       NavitAOverlay.invalidate();
-                       // android overlay
-
                        activity.setContentView(relativelayout);
                        view.requestFocus();
                }
@@ -1019,8 +744,8 @@ public class NavitGraphics
                                        CallbackMessageChannel(3, lat + "#" + lon + "#" + q);
                                        break;
                                case CLB_SET_DISPLAY_DESTINATION:
-                                       int x = msg.getData().getInt("x");
-                                       int y = msg.getData().getInt("y");
+                                       int x = msg.arg1;
+                                       int y = msg.arg2;
                                        CallbackMessageChannel(4, "" + x + "#" + y);
                                        break;
                                case CBL_CALL_CMD:
@@ -1162,18 +887,13 @@ public class NavitGraphics
        }
        protected void overlay_disable(int disable)
        {
-               //Log.e("NavitGraphics","overlay_disable");
+               Log.e("NavitGraphics","overlay_disable: " + disable + "Parent: " + (parent_graphics != null));
                // assume we are NOT in map view mode!
-               in_map = false;
-
-               // check if overlay has been initialized yet
-               if (NavitAOverlay != null)
-               {
-                       NavitAOverlay.hide_bubble();
-               }
-
+               if (parent_graphics == null)
+                       in_map = (disable==0);
                overlay_disabled = disable;
        }
+
        protected void overlay_resize(int x, int y, int w, int h, int alpha, int wraparond)
        {
                //Log.e("NavitGraphics","overlay_resize");