lon = temp3.split(",", -1)[1];\r
q = temp2;\r
\r
- Message msg = new Message();\r
+ Message msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_SET_DESTINATION.ordinal());\r
+\r
Bundle b = new Bundle();\r
- b.putInt("Callback", 3);\r
b.putString("lat", lat);\r
b.putString("lon", lon);\r
b.putString("q", q);\r
msg.setData(b);\r
- N_NavitGraphics.callback_handler.sendMessage(msg);\r
+ msg.sendToTarget();\r
}\r
else\r
{\r
{\r
case 1 :\r
// zoom in\r
- Message msg = new Message();\r
- Bundle b = new Bundle();\r
- b.putInt("Callback", 1);\r
- msg.setData(b);\r
- N_NavitGraphics.callback_handler.sendMessage(msg);\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
break;\r
case 2 :\r
// zoom out\r
- msg = new Message();\r
- b = new Bundle();\r
- b.putInt("Callback", 2);\r
- msg.setData(b);\r
- N_NavitGraphics.callback_handler.sendMessage(msg);\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
Navit.NavitDownloaderSecSelectMap_id);\r
break;\r
case 5 :\r
- // toggle the normal POI layers (to avoid double POIs) --> why is this double ???\r
- msg = new Message();\r
- b = new Bundle();\r
- b.putInt("Callback", 5);\r
+ // toggle the normal POI layers (to avoid double POIs)\r
+ Message msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CBL_CALL_CMD.ordinal());\r
+ Bundle b = new Bundle();\r
b.putString("cmd", "toggle_layer(\"POI Symbols\");");\r
msg.setData(b);\r
- N_NavitGraphics.callback_handler.sendMessage(msg);\r
-\r
- /*\r
- * // toggle the normal POI layers (to avoid double POIs)\r
- * msg = new Message();\r
- * b = new Bundle();\r
- * b.putInt("Callback", 5);\r
- * b.putString("cmd", "toggle_layer(\"POI Labels\");");\r
- * msg.setData(b);\r
- * N_NavitGraphics.callback_handler.sendMessage(msg);\r
- */\r
-\r
- // toggle full POI icons on/off --> why is this double ???\r
- msg = new Message();\r
+ msg.sendToTarget();\r
+\r
+ // toggle full POI icons on/off\r
+ msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CBL_CALL_CMD.ordinal());\r
b = new Bundle();\r
- b.putInt("Callback", 5);\r
b.putString("cmd", "toggle_layer(\"Android-POI-Icons-full\");");\r
msg.setData(b);\r
- N_NavitGraphics.callback_handler.sendMessage(msg);\r
-\r
- /*\r
- * // toggle full POI labels on/off\r
- * msg = new Message();\r
- * b = new Bundle();\r
- * b.putInt("Callback", 5);\r
- * b.putString("cmd", "toggle_layer(\"Android-POI-Labels-full\");");\r
- * msg.setData(b);\r
- * N_NavitGraphics.callback_handler.sendMessage(msg);\r
- */\r
+ msg.sendToTarget();\r
+\r
break;\r
case 6 :\r
// ok startup address search activity\r
+ Navit.NavitAddressResultList_foundItems\r
.get(destination_id).addr, Toast.LENGTH_LONG).show(); //TRANS\r
\r
- Message msg = new Message();\r
+ Message msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CBL_CALL_CMD.ordinal());\r
Bundle b = new Bundle();\r
- b.putInt("Callback", 3);\r
b.putString("lat", String.valueOf(Navit.NavitAddressResultList_foundItems\r
.get(destination_id).lat));\r
b.putString("lon", String.valueOf(Navit.NavitAddressResultList_foundItems\r
b.putString("q",\r
Navit.NavitAddressResultList_foundItems.get(destination_id).addr);\r
msg.setData(b);\r
- N_NavitGraphics.callback_handler.sendMessage(msg);\r
+ msg.sendToTarget();\r
}\r
catch (NumberFormatException e)\r
{\r
import android.graphics.Canvas;\r
import android.graphics.Color;\r
import android.graphics.Paint;\r
-import android.graphics.RectF;\r
import android.graphics.Paint.Style;\r
+import android.graphics.RectF;\r
import android.os.Bundle;\r
+import android.os.Handler;\r
import android.os.Message;\r
import android.view.MotionEvent;\r
import android.widget.ImageView;\r
\r
-public class NavitAndroidOverlay extends ImageView\r
+public class NavitAndroidOverlay extends ImageView implements Runnable\r
{\r
public Boolean draw_bubble = false;\r
public static Boolean confirmed_bubble = false;\r
- public long bubble_showing_since = 0L;\r
public static long bubble_max_showing_timespan = 8000L; // 8 secs.\r
\r
- public static BubbleThread bubble_thread = null;\r
-\r
- private class BubbleThread extends Thread\r
- {\r
- private Boolean running;\r
- private long bubble_showing_since = 0L;\r
- private NavitAndroidOverlay a_overlay = null;\r
-\r
- BubbleThread(NavitAndroidOverlay a_ov)\r
- {\r
- this.running = true;\r
- this.a_overlay = a_ov;\r
- this.bubble_showing_since = System.currentTimeMillis();\r
- //Log.e("Navit", "BubbleThread created");\r
- }\r
-\r
- public void stop_me()\r
- {\r
- this.running = false;\r
- }\r
-\r
- public void run()\r
- {\r
- //Log.e("Navit", "BubbleThread started");\r
- while (this.running)\r
- {\r
- if ((System.currentTimeMillis() - this.bubble_showing_since) > bubble_max_showing_timespan)\r
- {\r
- //Log.e("Navit", "BubbleThread: bubble displaying too long, hide it");\r
- // with invalidate we call the onDraw() function, that will take care of it\r
- this.a_overlay.postInvalidate();\r
- this.running = false;\r
- }\r
- else\r
- {\r
- try\r
- {\r
- Thread.sleep(50);\r
- }\r
- catch (InterruptedException e)\r
- {\r
- // e.printStackTrace();\r
- }\r
- }\r
- }\r
- //Log.e("Navit", "BubbleThread ended");\r
- }\r
- }\r
-\r
-\r
public static class NavitAndroidOverlayBubble\r
{\r
int x;\r
//Log.e("Navit", "NavitAndroidOverlay -> show_bubble");\r
if (!this.draw_bubble)\r
{\r
+ Handler handler = new Handler();\r
+ handler.postDelayed(this, bubble_max_showing_timespan);\r
NavitAndroidOverlay.confirmed_bubble = false;\r
this.draw_bubble = true;\r
- this.bubble_showing_since = System.currentTimeMillis();\r
- bubble_thread = new BubbleThread(this);\r
- bubble_thread.start();\r
-\r
- // test test DEBUG\r
- /*\r
- * Message msg = new Message();\r
- * Bundle b = new Bundle();\r
- * b.putInt("Callback", 4);\r
- * b.putInt("x", this.bubble_001.x);\r
- * b.putInt("y", this.bubble_001.y);\r
- * msg.setData(b);\r
- * Navit.N_NavitGraphics.callback_handler.sendMessage(msg);\r
- */\r
}\r
}\r
\r
return this.draw_bubble;\r
}\r
\r
- public void hide_bubble()\r
- {\r
- NavitAndroidOverlay.confirmed_bubble = false;\r
- this.draw_bubble = false;\r
- this.bubble_showing_since = 0L;\r
- try\r
- {\r
- bubble_thread.stop_me();\r
- // bubble_thread.stop();\r
- }\r
- catch (Exception e)\r
- {\r
-\r
- }\r
- //this.postInvalidate();\r
+ public void hide_bubble() {\r
+ confirmed_bubble = false;\r
+ draw_bubble = false;\r
+ Message msg = Message.obtain(Navit.N_NavitGraphics.callback_handler,\r
+ NavitGraphics.msg_type.CLB_REDRAW.ordinal());\r
+ msg.sendToTarget();\r
+ postInvalidate();\r
}\r
\r
public void set_bubble(NavitAndroidOverlayBubble b)\r
this.postInvalidate();\r
\r
// set destination\r
- Message msg = new Message();\r
+ Message msg = Message.obtain(Navit.N_NavitGraphics.callback_handler,\r
+ NavitGraphics.msg_type.CLB_SET_DISPLAY_DESTINATION.ordinal());\r
+\r
Bundle b = new Bundle();\r
- b.putInt("Callback", 4);\r
b.putInt("x", this.bubble_001.x);\r
b.putInt("y", this.bubble_001.y);\r
msg.setData(b);\r
- Navit.N_NavitGraphics.callback_handler.sendMessage(msg);\r
+ msg.sendToTarget();\r
+\r
// consume the event\r
return true;\r
}\r
}\r
\r
- // test if we touched the grey rectangle\r
- //\r
- // if ((x < 300) && (x > 10) && (y < 200) && (y > 10))\r
- // {\r
- // Log.e("Navit", "NavitAndroidOverlay -> onTouchEvent -> touch Rect!!");\r
- // return true;\r
- // }\r
- // else\r
- // {\r
- // return false;\r
- // }\r
-\r
// false -> we dont use this event, give it to other layers\r
return false;\r
}\r
\r
if (this.draw_bubble)\r
{\r
- if ((System.currentTimeMillis() - this.bubble_showing_since) > NavitAndroidOverlay.bubble_max_showing_timespan)\r
- {\r
- // bubble has been showing too log, hide it\r
- this.hide_bubble();\r
-\r
- // next lines are a hack, without it screen will not get updated anymore!\r
- // next lines are a hack, without it screen will not get updated anymore!\r
- // down\r
- Message msg = new Message();\r
- Bundle b = new Bundle();\r
- b.putInt("Callback", 21);\r
- b.putInt("x", 1);\r
- b.putInt("y", 1);\r
- msg.setData(b);\r
- Navit.N_NavitGraphics.callback_handler.sendMessage(msg);\r
-\r
- // move\r
- msg = new Message();\r
- b = new Bundle();\r
- b.putInt("Callback", 23);\r
- b.putInt("x", 1 + 10);\r
- b.putInt("y", 1);\r
- msg.setData(b);\r
- Navit.N_NavitGraphics.callback_handler.sendMessage(msg);\r
-\r
- // move\r
- msg = new Message();\r
- b = new Bundle();\r
- b.putInt("Callback", 23);\r
- b.putInt("x", 1 - 10);\r
- b.putInt("y", 1);\r
- msg.setData(b);\r
- Navit.N_NavitGraphics.callback_handler.sendMessage(msg);\r
-\r
- // up\r
- msg = new Message();\r
- b = new Bundle();\r
- b.putInt("Callback", 22);\r
- b.putInt("x", 1);\r
- b.putInt("y", 1);\r
- msg.setData(b);\r
- Navit.N_NavitGraphics.callback_handler.sendMessage(msg);\r
- // next lines are a hack, without it screen will not get updated anymore!\r
- // next lines are a hack, without it screen will not get updated anymore!\r
- }\r
- }\r
-\r
- if (this.draw_bubble)\r
- {\r
//Log.e("Navit", "NavitAndroidOverlay -> onDraw -> bubble");\r
\r
int dx = (int) ((20 / 1.5f) * draw_factor);\r
this.bubble_001.y + dy + inner_dy, bubble_paint);\r
\r
}\r
+ }\r
\r
- // // test, draw rectangles on top layer!\r
- // Paint paint = new Paint(0);\r
- // paint.setAntiAlias(false);\r
- // paint.setStyle(Style.STROKE);\r
- // paint.setColor(Color.GREEN);\r
- // c.drawRect(0 * draw_factor, 0 * draw_factor, 64 * draw_factor, 64 * draw_factor, paint);\r
- // paint.setColor(Color.RED);\r
- // c.drawRect(0 * draw_factor, (0 + 70) * draw_factor, 64 * draw_factor,\r
- // (64 + 70) * draw_factor, paint);\r
+ @Override\r
+ public void run() {\r
+ hide_bubble();\r
}\r
}\r
// 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 Handler timer_handler = new Handler();
public void SetCamera(int use_camera)
{
parent_graphics = parent;
}
+ static public enum msg_type {
+ CLB_ZOOM_IN, CLB_ZOOM_OUT, CLB_REDRAW, CLB_MOVE, CLB_BUTTON_UP, CLB_BUTTON_DOWN, CLB_SET_DESTINATION, CLB_SET_DISPLAY_DESTINATION, CBL_CALL_CMD
+ };
+
+ static public msg_type[] msg_values = msg_type.values();
+
public Handler callback_handler = new Handler()
{
public void handleMessage(Message msg)
{
- if (msg.getData().getInt("Callback") == 1)
+ switch (msg_values[msg.what])
{
- //Log.e("NavitGraphics","callback_handler -> handleMessage 1");
- //KeypressCallback(KeypressCallbackID, msg.getData()
- // .getString("s"));
+ case CLB_ZOOM_IN:
CallbackMessageChannel(1, "");
- }
- else if (msg.getData().getInt("Callback") == 2)
-
- {
+ break;
+ case CLB_ZOOM_OUT:
CallbackMessageChannel(2, "");
- }
- else if (msg.getData().getInt("Callback") == 3)
-
- {
+ break;
+ case CLB_MOVE:
+ MotionCallback(MotionCallbackID, msg.getData().getInt("x"), msg.getData().getInt("y"));
+ break;
+ case CLB_SET_DESTINATION:
String lat = msg.getData().getString("lat");
String lon = msg.getData().getString("lon");
String q = msg.getData().getString("q");
CallbackMessageChannel(3, lat + "#" + lon + "#" + q);
- }
- else if (msg.getData().getInt("Callback") == 4)
-
- {
+ break;
+ case CLB_SET_DISPLAY_DESTINATION:
int x = msg.getData().getInt("x");
int y = msg.getData().getInt("y");
CallbackMessageChannel(4, "" + x + "#" + y);
- }
- else if (msg.getData().getInt("Callback") == 5)
- {
+ break;
+ case CBL_CALL_CMD:
String cmd = msg.getData().getString("cmd");
CallbackMessageChannel(5, cmd);
- }
- else if (msg.getData().getInt("Callback") == 21)
- {
- //Log.e("NavitGraphics","callback_handler -> handleMessage 2");
- int x = msg.getData().getInt("x");
- int y = msg.getData().getInt("y");
- ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
- }
- else if (msg.getData().getInt("Callback") == 22)
- {
- //Log.e("NavitGraphics","callback_handler -> handleMessage 3");
- int x = msg.getData().getInt("x");
- int y = msg.getData().getInt("y");
- ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
- }
- else if (msg.getData().getInt("Callback") == 23)
- {
- //Log.e("NavitGraphics","callback_handler -> handleMessage 3");
- int x = msg.getData().getInt("x");
- int y = msg.getData().getInt("y");
- MotionCallback(MotionCallbackID, x, y);
+ break;
+ case CLB_BUTTON_UP:
+ ButtonCallback(ButtonCallbackID, 0, 1, msg.getData().getInt("x"), msg.getData().getInt("y")); // up
+ break;
+ case CLB_BUTTON_DOWN:
+ ButtonCallback(ButtonCallbackID, 1, 1, msg.getData().getInt("x"), msg.getData().getInt("y")); // down
+ break;
}
}
};
public native void SizeChangedCallback(int id, int x, int y);
+ public native void KeypressCallback(int id, String s);
+ public native int CallbackMessageChannel(int i, String s);
public native void ButtonCallback(int id, int pressed, int button, int x, int y);
public native void MotionCallback(int id, int x, int y);
- public native void KeypressCallback(int id, String s);
private Canvas draw_canvas;
private Bitmap draw_bitmap;
private int SizeChangedCallbackID, ButtonCallbackID, MotionCallbackID, KeypressCallbackID;
return ret;
}
- /**
- * generic message channel to C-code
- */
- public native int CallbackMessageChannel(int i, String s);
/**
* start a search on the map