From: rikky Date: Sat, 20 Aug 2011 22:47:31 +0000 (+0000) Subject: Fix:Android:Cleanup X-Git-Tag: navit-0.5.0.5194svn~506 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3287026626afdecf4b51289a99fd174f60df629a;p=profile%2Fivi%2Fnavit.git Fix:Android:Cleanup git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@4689 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- diff --git a/navit/navit/android/src/org/navitproject/navit/Navit.java b/navit/navit/android/src/org/navitproject/navit/Navit.java index b2c3b72..1042aa8 100644 --- a/navit/navit/android/src/org/navitproject/navit/Navit.java +++ b/navit/navit/android/src/org/navitproject/navit/Navit.java @@ -601,14 +601,14 @@ public class Navit extends Activity implements Handler.Callback lon = temp3.split(",", -1)[1]; q = temp2; - Message msg = new Message(); + Message msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_SET_DESTINATION.ordinal()); + Bundle b = new Bundle(); - b.putInt("Callback", 3); b.putString("lat", lat); b.putString("lon", lon); b.putString("q", q); msg.setData(b); - N_NavitGraphics.callback_handler.sendMessage(msg); + msg.sendToTarget(); } else { @@ -744,11 +744,7 @@ public class Navit extends Activity implements Handler.Callback { case 1 : // zoom in - Message msg = new Message(); - Bundle b = new Bundle(); - b.putInt("Callback", 1); - msg.setData(b); - N_NavitGraphics.callback_handler.sendMessage(msg); + Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_ZOOM_IN.ordinal()).sendToTarget(); // if we zoom, hide the bubble if (N_NavitGraphics.NavitAOverlay != null) { @@ -758,11 +754,7 @@ public class Navit extends Activity implements Handler.Callback break; case 2 : // zoom out - msg = new Message(); - b = new Bundle(); - b.putInt("Callback", 2); - msg.setData(b); - N_NavitGraphics.callback_handler.sendMessage(msg); + Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_ZOOM_OUT.ordinal()).sendToTarget(); // if we zoom, hide the bubble if (N_NavitGraphics.NavitAOverlay != null) { @@ -785,41 +777,20 @@ public class Navit extends Activity implements Handler.Callback Navit.NavitDownloaderSecSelectMap_id); break; case 5 : - // toggle the normal POI layers (to avoid double POIs) --> why is this double ??? - msg = new Message(); - b = new Bundle(); - b.putInt("Callback", 5); + // toggle the normal POI layers (to avoid double POIs) + Message msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CBL_CALL_CMD.ordinal()); + Bundle b = new Bundle(); b.putString("cmd", "toggle_layer(\"POI Symbols\");"); msg.setData(b); - N_NavitGraphics.callback_handler.sendMessage(msg); - - /* - * // toggle the normal POI layers (to avoid double POIs) - * msg = new Message(); - * b = new Bundle(); - * b.putInt("Callback", 5); - * b.putString("cmd", "toggle_layer(\"POI Labels\");"); - * msg.setData(b); - * N_NavitGraphics.callback_handler.sendMessage(msg); - */ - - // toggle full POI icons on/off --> why is this double ??? - msg = new Message(); + msg.sendToTarget(); + + // toggle full POI icons on/off + msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CBL_CALL_CMD.ordinal()); b = new Bundle(); - b.putInt("Callback", 5); b.putString("cmd", "toggle_layer(\"Android-POI-Icons-full\");"); msg.setData(b); - N_NavitGraphics.callback_handler.sendMessage(msg); - - /* - * // toggle full POI labels on/off - * msg = new Message(); - * b = new Bundle(); - * b.putInt("Callback", 5); - * b.putString("cmd", "toggle_layer(\"Android-POI-Labels-full\");"); - * msg.setData(b); - * N_NavitGraphics.callback_handler.sendMessage(msg); - */ + msg.sendToTarget(); + break; case 6 : // ok startup address search activity @@ -964,9 +935,8 @@ public class Navit extends Activity implements Handler.Callback + Navit.NavitAddressResultList_foundItems .get(destination_id).addr, Toast.LENGTH_LONG).show(); //TRANS - Message msg = new Message(); + Message msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CBL_CALL_CMD.ordinal()); Bundle b = new Bundle(); - b.putInt("Callback", 3); b.putString("lat", String.valueOf(Navit.NavitAddressResultList_foundItems .get(destination_id).lat)); b.putString("lon", String.valueOf(Navit.NavitAddressResultList_foundItems @@ -974,7 +944,7 @@ public class Navit extends Activity implements Handler.Callback b.putString("q", Navit.NavitAddressResultList_foundItems.get(destination_id).addr); msg.setData(b); - N_NavitGraphics.callback_handler.sendMessage(msg); + msg.sendToTarget(); } catch (NumberFormatException e) { diff --git a/navit/navit/android/src/org/navitproject/navit/NavitAndroidOverlay.java b/navit/navit/android/src/org/navitproject/navit/NavitAndroidOverlay.java index e7c7c10..169ff5e 100644 --- a/navit/navit/android/src/org/navitproject/navit/NavitAndroidOverlay.java +++ b/navit/navit/android/src/org/navitproject/navit/NavitAndroidOverlay.java @@ -23,70 +23,20 @@ import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; -import android.graphics.RectF; import android.graphics.Paint.Style; +import android.graphics.RectF; import android.os.Bundle; +import android.os.Handler; import android.os.Message; import android.view.MotionEvent; import android.widget.ImageView; -public class NavitAndroidOverlay extends ImageView +public class NavitAndroidOverlay extends ImageView implements Runnable { public Boolean draw_bubble = false; public static Boolean confirmed_bubble = false; - public long bubble_showing_since = 0L; public static long bubble_max_showing_timespan = 8000L; // 8 secs. - public static BubbleThread bubble_thread = null; - - private class BubbleThread extends Thread - { - private Boolean running; - private long bubble_showing_since = 0L; - private NavitAndroidOverlay a_overlay = null; - - BubbleThread(NavitAndroidOverlay a_ov) - { - this.running = true; - this.a_overlay = a_ov; - this.bubble_showing_since = System.currentTimeMillis(); - //Log.e("Navit", "BubbleThread created"); - } - - public void stop_me() - { - this.running = false; - } - - public void run() - { - //Log.e("Navit", "BubbleThread started"); - while (this.running) - { - if ((System.currentTimeMillis() - this.bubble_showing_since) > bubble_max_showing_timespan) - { - //Log.e("Navit", "BubbleThread: bubble displaying too long, hide it"); - // with invalidate we call the onDraw() function, that will take care of it - this.a_overlay.postInvalidate(); - this.running = false; - } - else - { - try - { - Thread.sleep(50); - } - catch (InterruptedException e) - { - // e.printStackTrace(); - } - } - } - //Log.e("Navit", "BubbleThread ended"); - } - } - - public static class NavitAndroidOverlayBubble { int x; @@ -106,22 +56,10 @@ public class NavitAndroidOverlay extends ImageView //Log.e("Navit", "NavitAndroidOverlay -> show_bubble"); if (!this.draw_bubble) { + Handler handler = new Handler(); + handler.postDelayed(this, bubble_max_showing_timespan); NavitAndroidOverlay.confirmed_bubble = false; this.draw_bubble = true; - this.bubble_showing_since = System.currentTimeMillis(); - bubble_thread = new BubbleThread(this); - bubble_thread.start(); - - // test test DEBUG - /* - * Message msg = new Message(); - * Bundle b = new Bundle(); - * b.putInt("Callback", 4); - * b.putInt("x", this.bubble_001.x); - * b.putInt("y", this.bubble_001.y); - * msg.setData(b); - * Navit.N_NavitGraphics.callback_handler.sendMessage(msg); - */ } } @@ -130,21 +68,13 @@ public class NavitAndroidOverlay extends ImageView return this.draw_bubble; } - public void hide_bubble() - { - NavitAndroidOverlay.confirmed_bubble = false; - this.draw_bubble = false; - this.bubble_showing_since = 0L; - try - { - bubble_thread.stop_me(); - // bubble_thread.stop(); - } - catch (Exception e) - { - - } - //this.postInvalidate(); + public void hide_bubble() { + confirmed_bubble = false; + draw_bubble = false; + Message msg = Message.obtain(Navit.N_NavitGraphics.callback_handler, + NavitGraphics.msg_type.CLB_REDRAW.ordinal()); + msg.sendToTarget(); + postInvalidate(); } public void set_bubble(NavitAndroidOverlayBubble b) @@ -191,30 +121,20 @@ public class NavitAndroidOverlay extends ImageView this.postInvalidate(); // set destination - Message msg = new Message(); + Message msg = Message.obtain(Navit.N_NavitGraphics.callback_handler, + NavitGraphics.msg_type.CLB_SET_DISPLAY_DESTINATION.ordinal()); + Bundle b = new Bundle(); - b.putInt("Callback", 4); b.putInt("x", this.bubble_001.x); b.putInt("y", this.bubble_001.y); msg.setData(b); - Navit.N_NavitGraphics.callback_handler.sendMessage(msg); + msg.sendToTarget(); + // consume the event return true; } } - // test if we touched the grey rectangle - // - // if ((x < 300) && (x > 10) && (y < 200) && (y > 10)) - // { - // Log.e("Navit", "NavitAndroidOverlay -> onTouchEvent -> touch Rect!!"); - // return true; - // } - // else - // { - // return false; - // } - // false -> we dont use this event, give it to other layers return false; } @@ -240,55 +160,6 @@ public class NavitAndroidOverlay extends ImageView if (this.draw_bubble) { - if ((System.currentTimeMillis() - this.bubble_showing_since) > NavitAndroidOverlay.bubble_max_showing_timespan) - { - // bubble has been showing too log, hide it - this.hide_bubble(); - - // next lines are a hack, without it screen will not get updated anymore! - // next lines are a hack, without it screen will not get updated anymore! - // down - Message msg = new Message(); - Bundle b = new Bundle(); - b.putInt("Callback", 21); - b.putInt("x", 1); - b.putInt("y", 1); - msg.setData(b); - Navit.N_NavitGraphics.callback_handler.sendMessage(msg); - - // move - msg = new Message(); - b = new Bundle(); - b.putInt("Callback", 23); - b.putInt("x", 1 + 10); - b.putInt("y", 1); - msg.setData(b); - Navit.N_NavitGraphics.callback_handler.sendMessage(msg); - - // move - msg = new Message(); - b = new Bundle(); - b.putInt("Callback", 23); - b.putInt("x", 1 - 10); - b.putInt("y", 1); - msg.setData(b); - Navit.N_NavitGraphics.callback_handler.sendMessage(msg); - - // up - msg = new Message(); - b = new Bundle(); - b.putInt("Callback", 22); - b.putInt("x", 1); - b.putInt("y", 1); - msg.setData(b); - Navit.N_NavitGraphics.callback_handler.sendMessage(msg); - // next lines are a hack, without it screen will not get updated anymore! - // next lines are a hack, without it screen will not get updated anymore! - } - } - - if (this.draw_bubble) - { //Log.e("Navit", "NavitAndroidOverlay -> onDraw -> bubble"); int dx = (int) ((20 / 1.5f) * draw_factor); @@ -360,15 +231,10 @@ public class NavitAndroidOverlay extends ImageView this.bubble_001.y + dy + inner_dy, bubble_paint); } + } - // // test, draw rectangles on top layer! - // Paint paint = new Paint(0); - // paint.setAntiAlias(false); - // paint.setStyle(Style.STROKE); - // paint.setColor(Color.GREEN); - // c.drawRect(0 * draw_factor, 0 * draw_factor, 64 * draw_factor, 64 * draw_factor, paint); - // paint.setColor(Color.RED); - // c.drawRect(0 * draw_factor, (0 + 70) * draw_factor, 64 * draw_factor, - // (64 + 70) * draw_factor, paint); + @Override + public void run() { + hide_bubble(); } } diff --git a/navit/navit/android/src/org/navitproject/navit/NavitGraphics.java b/navit/navit/android/src/org/navitproject/navit/NavitGraphics.java index 544e184..1a44536 100644 --- a/navit/navit/android/src/org/navitproject/navit/NavitGraphics.java +++ b/navit/navit/android/src/org/navitproject/navit/NavitGraphics.java @@ -77,6 +77,8 @@ public class NavitGraphics // 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) { @@ -989,70 +991,57 @@ public class NavitGraphics 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; @@ -1199,10 +1188,6 @@ public class NavitGraphics return ret; } - /** - * generic message channel to C-code - */ - public native int CallbackMessageChannel(int i, String s); /** * start a search on the map