/[zanavi_public1]/navit/navit/android/src/com/zoffcc/applications/zanavi/NavitGraphics.java
ZANavi

Contents of /navit/navit/android/src/com/zoffcc/applications/zanavi/NavitGraphics.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (11 years, 1 month ago) by zoff99
File size: 157242 byte(s)
new map version, lots of fixes and experimental new features
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011 - 2012 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 /**
21 * Navit, a modular navigation system.
22 * Copyright (C) 2005-2008 Navit Team
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * version 2 as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the
35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36 * Boston, MA 02110-1301, USA.
37 */
38
39 package com.zoffcc.applications.zanavi;
40
41 import java.util.ArrayList;
42 import java.util.concurrent.LinkedBlockingQueue;
43
44 import android.app.Activity;
45 import android.graphics.Bitmap;
46 import android.graphics.BitmapFactory;
47 import android.graphics.Camera;
48 import android.graphics.Canvas;
49 import android.graphics.Color;
50 import android.graphics.DashPathEffect;
51 import android.graphics.Matrix;
52 import android.graphics.Paint;
53 import android.graphics.Paint.Style;
54 import android.graphics.Path;
55 import android.graphics.PointF;
56 import android.graphics.Rect;
57 import android.os.Bundle;
58 import android.os.Debug;
59 import android.os.Handler;
60 import android.os.Message;
61 import android.util.FloatMath;
62 import android.util.Log;
63 import android.view.Gravity;
64 import android.view.KeyEvent;
65 import android.view.MotionEvent;
66 import android.view.View;
67 import android.widget.RelativeLayout;
68 import android.widget.ScrollView;
69 import android.widget.TextView;
70
71 import com.zoffcc.applications.zanavi.Navit.Navit_Address_Result_Struct;
72 import com.zoffcc.applications.zanavi.NavitAndroidOverlay.NavitAndroidOverlayBubble;
73
74 public class NavitGraphics
75 {
76 private int parent_num;
77 //private ArrayList overlays = new ArrayList();
78
79 static Canvas draw_canvas_s;
80 static Bitmap draw_bitmap_s;
81 static Canvas draw_canvas_screen_s;
82 static Bitmap draw_bitmap_screen_s;
83 static Canvas draw_canvas_screen_s2;
84 static Bitmap draw_bitmap_screen_s2;
85 static View view_s;
86 static int dl_thread_cur = 0;
87 static int dl_thread_max = 1;
88 static DrawLinesThread[] dl_thread = new DrawLinesThread[dl_thread_max];
89 static Boolean draw_map_one_shot = false;
90 static Boolean draw_reset_factors = false;
91
92 static Camera camera = new Camera();
93 static Matrix cam_m = new Matrix();
94 static float strech_factor_3d_map = 2.0f;
95 static int rotate_3d_map_angle = 61;
96
97 private Canvas draw_canvas;
98 private Bitmap draw_bitmap;
99 private Canvas draw_canvas_screen;
100 private Bitmap draw_bitmap_screen;
101 private Canvas draw_canvas_screen2;
102 private Bitmap draw_bitmap_screen2;
103
104 public final int map_bg_color = Color.parseColor("#FEF9EE");
105
106 public final static DashPathEffect dashed_map_lines__high = new DashPathEffect(new float[] { 4, 2 }, 1);
107 public final static DashPathEffect dashed_map_lines__low = new DashPathEffect(new float[] { 15, 11 }, 1);
108 public final static DashPathEffect dashed_map_lines__no_dash = null;
109
110 public final static DashPathEffect h001 = new DashPathEffect(new float[] { 6, 3 }, 1);
111 public final static DashPathEffect l001 = new DashPathEffect(new float[] { 6, 3 }, 1);
112 public final static DashPathEffect h002 = new DashPathEffect(new float[] { 6, 3 }, 1);
113 public final static DashPathEffect l002 = new DashPathEffect(new float[] { 6, 3 }, 1);
114 public final static DashPathEffect h003 = new DashPathEffect(new float[] { 6, 3 }, 1);
115 public final static DashPathEffect l003 = new DashPathEffect(new float[] { 6, 3 }, 1);
116 public final static DashPathEffect h004 = new DashPathEffect(new float[] { 6, 3 }, 1);
117 public final static DashPathEffect l004 = new DashPathEffect(new float[] { 6, 3 }, 1);
118 public final static DashPathEffect h005 = new DashPathEffect(new float[] { 6, 3 }, 1);
119 public final static DashPathEffect l005 = new DashPathEffect(new float[] { 6, 3 }, 1);
120 public final static DashPathEffect h006 = new DashPathEffect(new float[] { 6, 3 }, 1);
121 public final static DashPathEffect l006 = new DashPathEffect(new float[] { 6, 3 }, 1);
122 public final static DashPathEffect h007 = new DashPathEffect(new float[] { 6, 3 }, 1);
123 public final static DashPathEffect l007 = new DashPathEffect(new float[] { 7, 2 }, 1);
124
125 public static Paint paint_for_map_display = new Paint();
126 public static Paint paint_sky_day = new Paint();
127 public static Paint paint_sky_night = new Paint();
128 public static Paint paint_sky_night_stars = new Paint();
129 public static Paint paint_sky_twilight1 = new Paint();
130 public static Paint paint_sky_twilight2 = new Paint();
131 public static Paint paint_sky_twilight3 = new Paint();
132
133 public static final int max_stars = 7;
134 public static float[] stars_x = new float[max_stars + 1];
135 public static float[] stars_y = new float[max_stars + 1];
136 public static int[] stars_size = new int[max_stars + 1];
137
138 public final static DashPathEffect[] dashes__low = { null, l001, l002, l003, l004, l005, l006, l007 };
139 public final static DashPathEffect[] dashes__high = { null, h001, h002, h003, h004, h005, h006, h007 };
140
141 public static int navit_route_status = 0;
142
143 public final float BIGMAP_FACTOR = (10465f / 2f) * 0.8f;
144
145 public static long last_paint_OSD = 0;
146
147 public static Boolean wait_for_redraw_map = false;
148
149 public static Boolean MAP_DISPLAY_OFF = false;
150
151 public static int mCanvasWidth = 1;
152 public static int mCanvasHeight = 1;
153
154 public static final Boolean DEBUG_TOUCH = false;
155 public static Boolean ZOOM_MODE_ACTIVE = false;
156 public static float ZOOM_MODE_SCALE = 1.0f;
157 public static Boolean DRAG_MODE_ACTIVE = false;
158
159 public static float Global_Map_Zoomfactor = 1.0f;
160 public static float Global_Map_Rotationangle = 0;
161 public static int Global_Map_TransX = 0;
162 public static int Global_Map_TransY = 0;
163 public static Boolean Global_SmoothDrawing_stop = false;
164 public static Boolean Global_onTouch_fingerdown = false;
165
166 public static float draw_factor = 1.0f;
167
168 public static String debug_line_1 = "";
169 public static String debug_line_2 = "";
170 public static String debug_line_3 = "";
171 public static String debug_line_4 = "";
172
173 public static final int DRAW_ONEWAY_ARROWS_AT_ORDER = 13;
174 public static final int DRAW_DETAIL_DASHES_AT_ORDER = 13;
175 public static final int DRAW_MORE_DETAILS_AT_ORDER = 9;
176 public static final int DRAW_MORE_DETAILS_TUNNEL_BRIDGES_AT_ORDER = 8;
177
178 public static long[] OverlayDrawThread_cancel_drawing_timeout__options = { 300L, 900L, 2100L, 20000L }; // 900L normal, 300L short, 2100L long
179 public static int[] OverlayDrawThread_cancel_thread_sleep_time__options = { 100, 200, 400, 400 };
180 public static long[] OverlayDrawThread_cancel_thread_timeout__options = { 3000L, 3000L, 3000L, 22000L };
181
182 public static long OverlayDrawThread_cancel_drawing_timeout = OverlayDrawThread_cancel_drawing_timeout__options[1];
183 public static int OverlayDrawThread_cancel_thread_sleep_time = OverlayDrawThread_cancel_thread_sleep_time__options[1];
184 public static long OverlayDrawThread_cancel_thread_timeout = OverlayDrawThread_cancel_thread_timeout__options[1];
185
186 int loc_dot_x = 0;
187 int loc_dot_y = 0;
188 int loc_dot_x2 = 0;
189 int loc_dot_y2 = 0;
190 int loc_1_x = 0;
191 int loc_1_y = 0;
192 int loc_2_x = 0;
193 int loc_2_y = 0;
194 Boolean loc_12_valid = false;
195 Boolean loc_dot_valid = false;
196 int gr_type = 0; // 0 -> dummy, 1 -> map
197
198 int bitmap_w;
199 int bitmap_h;
200 int pos_x;
201 int pos_y;
202 //
203 int vehicle_speed = 0;
204 int vehicle_pos_x = 0;
205 int vehicle_pos_y = 0;
206 int vehicle_direction = 0;
207 int vehicle_pos_x_delta = 0;
208 int vehicle_pos_y_delta = 0;
209 int vehicle_direction_delta = 0;
210 // drag pos
211 public static int d_pos_x_old = -1;
212 public static int d_pos_y_old = -1;
213 // drag post
214 int pos_wraparound;
215 // int overlay_disabled;
216 float trackball_x, trackball_y;
217 View view;
218 RelativeLayout relativelayout;
219 // --obsolote --- // NavitCamera camera;
220 Activity activity;
221
222 private Bitmap bigmap_bitmap_temp = null;
223 private Matrix matrix_oneway_arrows = null;
224 private float wsave_003 = 0f;
225 private float wsave_004 = 0f;
226 private Boolean b_paint_antialias = true;
227 private Path b_paint_path = new Path();
228
229 public static Boolean in_map = true; // always in map mode, now
230
231 // for menu key
232 private static long time_for_long_press = 300L;
233 private static long interval_for_long_press = 200L;
234
235 // for touch screen
236 private long last_touch_on_screen = 0L;
237 private static long long_press_on_screen_interval = 1000L;
238 private static float long_press_on_screen_max_distance = 8f;
239
240 // Overlay View for Android
241 //
242 // here you can draw all the nice things you want
243 // and get touch events for it (without touching C-code)
244 public NavitAndroidOverlay NavitAOverlay = null;
245 public static NavitAndroidOverlay NavitAOverlay_s = null;
246 private NavitOSDJava NavitAOSDJava = null;
247 public static NavitOSDJava NavitAOSDJava_ = null;
248 private TextView NavitMsgTv = null;
249 public static TextView NavitMsgTv_ = null;
250 public ZANaviBusySpinner busyspinner = null;
251 public static ZANaviBusySpinner busyspinner_ = null;
252 public ZANaviBusyText busyspinnertext = null;
253 public static ZANaviBusyText busyspinnertext_ = null;
254
255 private TextView NavitMsgTv2 = null;
256 public static TextView NavitMsgTv2_ = null;
257
258 public static NavitGlobalMap NavitGlobalMap_ = null;
259
260 public void SetCamera(int use_camera)
261 {
262 // ------ obsolete
263
264 /*
265 * if (use_camera != 0 && camera == null)
266 * {
267 * // activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
268 * camera = new NavitCamera(activity);
269 * relativelayout.addView(camera);
270 * relativelayout.bringChildToFront(view);
271 * }
272 */
273 }
274
275 public static SensorThread touch_sensor_thread = null;
276
277 private class SensorThread extends Thread
278 {
279 private Boolean running;
280 private long last_down_action = 0L;
281 private Boolean is_still_pressing;
282 //private View v = null;
283 //private NavitAndroidOverlay n_overlay = null;
284 private float prev_x;
285 private float prev_y;
286 private float x;
287 private float y;
288
289 SensorThread(long last_touch, float x, float y)
290 {
291 this.prev_x = x;
292 this.prev_y = y;
293 this.x = x;
294 this.y = y;
295 this.running = true;
296 //this.n_overlay = n_ov;
297 //this.v = v;
298 this.is_still_pressing = true;
299 last_down_action = System.currentTimeMillis();
300 if (DEBUG_TOUCH) Log.e("NavitGraphics", "SensorThread created");
301 }
302
303 public void down()
304 {
305 this.is_still_pressing = true;
306 }
307
308 // public void up()
309 // {
310 // this.is_still_pressing=false;
311 // }
312
313 public void stop_me()
314 {
315 this.running = false;
316 }
317
318 public void run()
319 {
320 if (DEBUG_TOUCH) Log.e("NavitGraphics", "SensorThread started");
321 while (this.running)
322 {
323 if ((System.currentTimeMillis() - this.last_down_action) > long_press_on_screen_interval)
324 {
325 // ok, we have counted a long press on screen
326 // do stuff and then stop this thread
327 if (DEBUG_TOUCH) Log.e("NavitGraphics", "SensorThread: LONG PRESS");
328 try
329 {
330 if (this.running)
331 {
332 if (!NavitAndroidOverlay.confirmed_bubble)
333 {
334 //Log.e("NavitGraphics", "do_longpress_action enter");
335 NavitAndroidOverlayBubble b = new NavitAndroidOverlayBubble();
336 b.x = (int) this.x;
337 b.y = (int) this.y;
338 NavitAOverlay.set_bubble(b);
339 NavitAOverlay.show_bubble();
340 copy_map_buffer();
341 //System.out.println("invalidate 009");
342 Navit.NG__map_main.view.postInvalidate();
343 //System.out.println("invalidate 010");
344 NavitAOverlay.postInvalidate();
345 }
346 }
347 // this is called!!! yes really!! via REFLECT (make it better, later)
348 // find the class, to get the method "do_longpress_action"
349 // and then call the method
350
351 // Class cls = this.v.getClass();
352 // //Log.e("NavitGraphics", "c=" + String.valueOf(cls));
353 // Class partypes[] = new Class[2];
354 // partypes[0] = Float.TYPE;
355 // partypes[1] = Float.TYPE;
356 // Method meth = cls.getMethod("do_longpress_action", partypes);
357 // View methobj = this.v;
358 // Object arglist[] = new Object[2];
359 // arglist[0] = new Float(this.x);
360 // arglist[1] = new Float(this.y);
361
362 //if (running)
363 //{
364 //Object retobj = meth.invoke(methobj, arglist);
365 //}
366 }
367 // catch (Throwable e)
368 catch (Exception e)
369 {
370 System.err.println(e);
371 }
372 this.running = false;
373 }
374 else if (!this.is_still_pressing)
375 {
376 if (DEBUG_TOUCH) Log.e("NavitGraphics", "SensorThread: stopped pressing");
377 this.running = false;
378 }
379 else
380 {
381 // Log.e("NavitGraphics", "SensorThread running");
382 try
383 {
384 Thread.sleep(50);
385 }
386 catch (InterruptedException e)
387 {
388 // e.printStackTrace();
389 }
390 }
391 }
392 if (DEBUG_TOUCH) Log.e("NavitGraphics", "SensorThread ended");
393 }
394 }
395
396 // public static OverlayDrawThread overlay_draw_thread = null;
397
398 public static class OverlayDrawThread extends Thread
399 {
400 private Boolean running = true;
401 private Boolean redraw = false;
402 private long start_timestamp = 0L;
403
404 OverlayDrawThread()
405 {
406 // Log.e("NavitGraphics", "OverlayDrawThread created");
407 start_timestamp = System.currentTimeMillis();
408 }
409
410 public void run()
411 {
412 this.running = true;
413 this.redraw = true;
414
415 // start_timestamp = System.currentTimeMillis();
416 // Log.e("NavitGraphics", "OverlayDrawThread starting"+start_timestamp);
417
418 while (this.running)
419 {
420
421 if (System.currentTimeMillis() > (start_timestamp + OverlayDrawThread_cancel_drawing_timeout))
422 {
423 // after xxx milliseconds of delay, stop drawing the map!
424 // most likely the device is too slow, or there are too much items to draw
425 try
426 {
427 //Log.e("NavitGraphics", "## stop map drawing x1: NOW ##" + System.currentTimeMillis());
428 //***NavitGraphics.CallbackMessageChannel(50, "");
429 //Message msg = new Message();
430 //Bundle b = new Bundle();
431 //b.putInt("Callback", 50);
432 //msg.setData(b);
433 //callback_handler.sendMessage(msg);
434 //Log.e("NavitGraphics", "## stop map drawing x2: NOW ##" + System.currentTimeMillis());
435 this.running = false;
436 break;
437 }
438 catch (Exception e)
439 {
440 e.printStackTrace();
441 }
442 }
443
444 if (System.currentTimeMillis() > (start_timestamp + OverlayDrawThread_cancel_thread_timeout))
445 {
446 // just to be safe, stop after 5 seconds
447 this.running = false;
448 }
449
450 //Log.e("NavitGraphics", "OverlayDrawThread running");
451 if (this.redraw)
452 {
453 // Log.e("NavitGraphics", "OverlayDrawThread -> redraw");
454 try
455 {
456 //NavitAOverlay_s.invalidate();
457 Message msg = Navit.Navit_progress_h.obtainMessage();
458 Bundle b = new Bundle();
459 msg.what = 16;
460 msg.setData(b);
461 Navit.Navit_progress_h.sendMessage(msg);
462 }
463 catch (Exception e)
464 {
465 e.printStackTrace();
466 }
467
468 //this.redraw = false;
469 }
470
471 try
472 {
473 Thread.sleep(OverlayDrawThread_cancel_thread_sleep_time);
474 }
475 catch (InterruptedException e)
476 {
477 e.printStackTrace();
478 }
479 }
480
481 //Log.e("NavitGraphics", "OverlayDrawThread finished");
482 }
483
484 public void redraw_overlay()
485 {
486 //Log.e("NavitGraphics", "OverlayDrawThread set redraw");
487 this.redraw = true;
488 }
489
490 public void stop_me()
491 {
492 this.running = false;
493 }
494
495 public void stop_redraw()
496 {
497 this.redraw = false;
498 }
499 }
500
501 public NavitGraphics(Activity activity, int parent, int x, int y, int w, int h, int alpha, int wraparound, int use_camera)
502 {
503 if (parent == 0)
504 {
505 this.gr_type = 1;
506
507 this.activity = activity;
508 view = new View(activity)
509 {
510 int touch_mode = NONE;
511 float oldDist = 0;
512 PointF touch_now = new PointF(0, 0);
513 PointF touch_now_center = new PointF(0, 0);
514 PointF touch_start = new PointF(0, 0);
515 PointF touch_prev = new PointF(0, 0);
516 static final int NONE = 0;
517 static final int DRAG = 1;
518 static final int ZOOM = 2;
519 static final int PRESS = 3;
520
521 @Override
522 protected void onDraw(Canvas canvas)
523 {
524 //System.out.println("*******DRAW INIT******* " + gr_type);
525 super.onDraw(canvas);
526
527 if (!MAP_DISPLAY_OFF)
528 {
529 if (draw_reset_factors)
530 {
531 //System.out.println("DO__DRAW:Java:reset factors");
532 draw_reset_factors = false;
533 pos_x = 0;
534 pos_y = 0;
535 ZOOM_MODE_ACTIVE = false;
536 ZOOM_MODE_SCALE = 1.0f;
537 }
538
539 //System.out.println("DO__DRAW:Java:onDraw:draw bitmap to SCREEN");
540 //System.out.println("DO__DRAW:Java:onDraw:gzf=" + Global_Map_Zoomfactor + " scale=" + ZOOM_MODE_SCALE);
541 //System.out.println("DO__DRAW:Java:onDraw:gx=" + Global_Map_TransX + " pos_x=" + pos_x);
542 //System.out.println("DO__DRAW:Java:onDraw:gy=" + Global_Map_TransY + " pos_y=" + pos_y);
543
544 if (Navit.PREF_show_3d_map)
545 {
546 draw_canvas_screen2.save();
547 if ((ZOOM_MODE_ACTIVE) || (Global_Map_Zoomfactor != 1.0f))
548 {
549 draw_canvas_screen2.scale(ZOOM_MODE_SCALE * Global_Map_Zoomfactor, ZOOM_MODE_SCALE * Global_Map_Zoomfactor, Global_Map_TransX + this.touch_now_center.x, Global_Map_TransY + this.touch_now_center.y);
550 }
551 else if (Global_Map_Rotationangle != 0.0f)
552 {
553 draw_canvas_screen2.rotate(Global_Map_Rotationangle, Navit.NG__vehicle.vehicle_pos_x, Navit.NG__vehicle.vehicle_pos_y);
554 }
555 draw_canvas_screen2.translate(Global_Map_TransX + pos_x, Global_Map_TransY + pos_y);
556 draw_canvas_screen2.drawColor(map_bg_color); // fill with yellow-ish bg color
557 // draw the bitmap in the offscreen buffer (offset 30 pixels to center!!)
558 draw_canvas_screen2.drawBitmap(draw_bitmap_screen, 0, 0, paint_for_map_display);
559 canvas.save();
560 canvas.drawColor(map_bg_color); // fill with yellow-ish bg color
561
562 // 3D modus -----------------
563 canvas.concat(cam_m);
564 // 3D modus -----------------
565
566 // draw bitmap to screen
567 canvas.drawBitmap(draw_bitmap_screen2, 0, 0, paint_for_map_display);
568
569 // ------ DEBUG -------
570 // ------ DEBUG -------
571 // Paint paint79 = new Paint();
572 // paint79.setColor(Color.MAGENTA);
573 // paint79.setStrokeWidth(16);
574 // paint79.setStyle(Style.STROKE);
575 // // float y_point = (bitmap_h - (bitmap_h * 0.7f));
576 // float y_point = bitmap_h * 0.7f;
577 // canvas.drawLine(bitmap_w / 2, y_point - 20, bitmap_w / 2, y_point + 20, paint79);
578 // canvas.drawLine(bitmap_w / 2 - 100, y_point, bitmap_w / 2 + 100, y_point, paint79);
579 //
580 // Paint paint78 = new Paint();
581 // paint78.setColor(Color.RED);
582 // paint78.setStrokeWidth(20);
583 // paint78.setStyle(Style.STROKE);
584 // canvas.drawRect(30, 30, this.getWidth() - 30, this.getHeight() - 30, paint78);
585 // ------ DEBUG -------
586 // ------ DEBUG -------
587
588 canvas.restore();
589 draw_canvas_screen2.restore();
590
591 float h_scaled = this.getHeight() * 0.27f;
592 if (Navit.is_night)
593 {
594 if (Navit.is_twilight)
595 {
596 // draw twilight
597 // elevation -> -0.83 to -10.00
598 float a = h_scaled / 10f * (float) (-Navit.elevation);
599 float b = h_scaled / 10f * (float) ((-Navit.elevation / 2f) + 5);
600 canvas.drawRect(0, 0, this.getWidth(), a, paint_sky_twilight1);
601 canvas.drawRect(0, a, this.getWidth(), b, paint_sky_twilight2);
602 canvas.drawRect(0, b, this.getWidth(), h_scaled, paint_sky_twilight3);
603 }
604 else
605 {
606 // draw sky - at night
607 canvas.drawRect(0, 0, this.getWidth(), h_scaled, paint_sky_night);
608 // stars
609 canvas.drawCircle(NavitGraphics.stars_x[0] * this.getWidth(), NavitGraphics.stars_y[0] * h_scaled, NavitGraphics.stars_size[0], paint_sky_night_stars);
610 canvas.drawCircle(NavitGraphics.stars_x[1] * this.getWidth(), NavitGraphics.stars_y[1] * h_scaled, NavitGraphics.stars_size[1], paint_sky_night_stars);
611 canvas.drawCircle(NavitGraphics.stars_x[2] * this.getWidth(), NavitGraphics.stars_y[2] * h_scaled, NavitGraphics.stars_size[2], paint_sky_night_stars);
612 canvas.drawCircle(NavitGraphics.stars_x[3] * this.getWidth(), NavitGraphics.stars_y[3] * h_scaled, NavitGraphics.stars_size[3], paint_sky_night_stars);
613 canvas.drawCircle(NavitGraphics.stars_x[4] * this.getWidth(), NavitGraphics.stars_y[4] * h_scaled, NavitGraphics.stars_size[4], paint_sky_night_stars);
614 canvas.drawCircle(NavitGraphics.stars_x[5] * this.getWidth(), NavitGraphics.stars_y[5] * h_scaled, NavitGraphics.stars_size[5], paint_sky_night_stars);
615 canvas.drawCircle(NavitGraphics.stars_x[6] * this.getWidth(), NavitGraphics.stars_y[6] * h_scaled, NavitGraphics.stars_size[6], paint_sky_night_stars);
616 canvas.drawCircle(NavitGraphics.stars_x[7] * this.getWidth(), NavitGraphics.stars_y[7] * h_scaled, NavitGraphics.stars_size[7], paint_sky_night_stars);
617 }
618 }
619 else
620 {
621 // draw sky - at day
622 canvas.drawRect(0, 0, this.getWidth(), h_scaled, paint_sky_day);
623 }
624 }
625 else
626 {
627 canvas.save();
628 if ((ZOOM_MODE_ACTIVE) || (Global_Map_Zoomfactor != 1.0f))
629 {
630 canvas.scale(ZOOM_MODE_SCALE * Global_Map_Zoomfactor, ZOOM_MODE_SCALE * Global_Map_Zoomfactor, Global_Map_TransX + this.touch_now_center.x, Global_Map_TransY + this.touch_now_center.y);
631 }
632 else if (Global_Map_Rotationangle != 0.0f)
633 {
634 canvas.rotate(Global_Map_Rotationangle, Navit.NG__vehicle.vehicle_pos_x, Navit.NG__vehicle.vehicle_pos_y);
635 }
636 canvas.translate(Global_Map_TransX + pos_x, Global_Map_TransY + pos_y);
637 canvas.drawColor(map_bg_color); // fill with yellow-ish bg color
638 // draw bitmap to screen
639 canvas.drawBitmap(draw_bitmap_screen, 0, 0, paint_for_map_display);
640 canvas.restore();
641 }
642 }
643 }
644
645 @Override
646 protected void onSizeChanged(int w, int h, int oldw, int oldh)
647 {
648 mCanvasWidth = w;
649 mCanvasHeight = h;
650
651 //Log.e("Navit", "NavitGraphics -> onSizeChanged pixels x=" + w + " pixels y=" + h);
652 //Log.e("Navit", "NavitGraphics -> onSizeChanged dpi=" + Navit.metrics.densityDpi);
653 //Log.e("Navit", "NavitGraphics -> onSizeChanged density=" + Navit.metrics.density);
654 //Log.e("Navit", "NavitGraphics -> onSizeChanged scaledDensity=" + Navit.metrics.scaledDensity);
655 super.onSizeChanged(w, h, oldw, oldh);
656 if (draw_bitmap != null)
657 {
658 // try to avoid out of memory errors
659 draw_bitmap.recycle();
660 draw_bitmap = null;
661 }
662
663 if (draw_bitmap_screen != null)
664 {
665 // try to avoid out of memory errors
666 draw_bitmap_screen.recycle();
667 draw_bitmap_screen = null;
668 }
669
670 if (draw_bitmap_screen2 != null)
671 {
672 // try to avoid out of memory errors
673 draw_bitmap_screen2.recycle();
674 draw_bitmap_screen2 = null;
675 }
676
677 try
678 {
679 draw_bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
680 }
681 catch (OutOfMemoryError e)
682 {
683 int usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
684 String usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
685 System.out.println("" + usedMegsString);
686 System.out.println("@@@@@@@@ out of VM Memory @@@@@@@@");
687 draw_bitmap = null;
688 draw_canvas = null;
689 System.gc();
690 System.gc();
691 usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
692 usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
693 System.out.println("" + usedMegsString);
694 // try again
695 draw_bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
696 }
697
698 try
699 {
700 draw_bitmap_screen = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
701 }
702 catch (OutOfMemoryError e)
703 {
704 int usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
705 String usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
706 System.out.println("" + usedMegsString);
707 System.out.println("@@@@@@@@ out of VM Memory @@@@@@@@");
708 draw_bitmap_screen = null;
709 draw_canvas_screen = null;
710 System.gc();
711 System.gc();
712 usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
713 usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
714 System.out.println("" + usedMegsString);
715 // try again
716 draw_bitmap_screen = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
717 }
718
719 try
720 {
721 draw_bitmap_screen2 = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
722 }
723 catch (OutOfMemoryError e)
724 {
725 int usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
726 String usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
727 System.out.println("" + usedMegsString);
728 System.out.println("@@@@@@@@ out of VM Memory @@@@@@@@");
729 draw_bitmap_screen2 = null;
730 draw_canvas_screen2 = null;
731 System.gc();
732 System.gc();
733 usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
734 usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
735 System.out.println("" + usedMegsString);
736 // try again
737 draw_bitmap_screen2 = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
738 }
739
740 draw_canvas = new Canvas(draw_bitmap);
741 draw_canvas_screen = new Canvas(draw_bitmap_screen);
742 draw_canvas_screen2 = new Canvas(draw_bitmap_screen2);
743 if (gr_type == 1)
744 {
745 //System.out.println("*map*gra*");
746 draw_bitmap_s = draw_bitmap;
747 draw_canvas_s = draw_canvas;
748 draw_bitmap_screen_s = draw_bitmap_screen;
749 draw_canvas_screen_s = draw_canvas_screen;
750 draw_bitmap_screen_s2 = draw_bitmap_screen2;
751 draw_canvas_screen_s2 = draw_canvas_screen2;
752 }
753 bitmap_w = w;
754 bitmap_h = h;
755 SizeChangedCallback(w, h);
756
757 // 3D modus -----------------
758 NavitGraphics.camera.save();
759 //NavitGraphics.camera.translate(0, 0, 40);
760 NavitGraphics.camera.rotateX(rotate_3d_map_angle);
761 NavitGraphics.camera.getMatrix(NavitGraphics.cam_m);
762 NavitGraphics.camera.restore();
763 // C-Code: (50 + offset) * height / 100 // offset = 30%
764 //float y_point = (bitmap_h - (bitmap_h * 0.7f));
765 float y_offset = 0; // 20
766 float y_point = bitmap_h * 0.7f;
767 NavitGraphics.cam_m.preTranslate(-bitmap_w / 2, -y_offset - y_point);
768 NavitGraphics.cam_m.postTranslate(bitmap_w / 2, y_offset + y_point);
769 NavitGraphics.cam_m.postScale(strech_factor_3d_map, strech_factor_3d_map, bitmap_w / 2, y_offset + y_point);
770 //NavitGraphics.cam_m.postTranslate(0, 50);
771 // 3D modus -----------------
772
773 draw_factor = 1.0f;
774 if (Navit.my_display_density.compareTo("mdpi") == 0)
775 {
776 draw_factor = 1.0f;
777 }
778 else if (Navit.my_display_density.compareTo("ldpi") == 0)
779 {
780 draw_factor = 0.7f;
781 }
782 else if (Navit.my_display_density.compareTo("hdpi") == 0)
783 {
784 draw_factor = 1.5f;
785 }
786
787 if (Navit.first_ever_startup)
788 {
789 Navit.first_ever_startup = false;
790 //System.out.println("");
791 //System.out.println("*** Zoom out FULL (#startup#) ***");
792 //System.out.println("");
793 Message msg = new Message();
794 Bundle b = new Bundle();
795 b.putInt("Callback", 8);
796 msg.setData(b);
797 callback_handler.sendMessage(msg);
798 }
799 }
800
801 @Override
802 public boolean onTouchEvent(MotionEvent event)
803 {
804 PointF touch_now2 = null;
805 PointF touch_start2 = null;
806 PointF touch_prev2 = null;
807 PointF touch_last_load_tiles2 = null;
808
809 if (DEBUG_TOUCH) Log.e("NavitGraphics", "onTouchEvent");
810 if (DEBUG_TOUCH) Log.e("NavitGraphics", "systime1:" + System.currentTimeMillis());
811 if (DEBUG_TOUCH) Log.e("NavitGraphics", "eventtime1:" + event.getEventTime());
812
813 super.onTouchEvent(event);
814 int action = event.getAction();
815 int x = (int) event.getX();
816 int y = (int) event.getY();
817
818 int _ACTION_POINTER_UP_ = MotionEvent.ACTION_POINTER_UP;
819 int _ACTION_POINTER_DOWN_ = MotionEvent.ACTION_POINTER_DOWN;
820 int _ACTION_MASK_ = MotionEvent.ACTION_MASK;
821
822 // calculate value
823 int switch_value = (event.getAction() & _ACTION_MASK_);
824 if (DEBUG_TOUCH) Log.e("NavitGraphics", "switch_value=" + switch_value);
825 if (DEBUG_TOUCH) Log.e("NavitGraphics", "_ACTION_MASK_=" + _ACTION_MASK_);
826 // calculate value
827
828 if (DEBUG_TOUCH) Log.e("NavitGraphics", "event x=" + event.getX() + " y=" + event.getY());
829
830 if (switch_value == MotionEvent.ACTION_DOWN)
831 {
832 Global_onTouch_fingerdown = true;
833
834 this.touch_now.set(event.getX(), event.getY());
835 this.touch_start.set(event.getX(), event.getY());
836 this.touch_prev.set(event.getX(), event.getY());
837 if (DEBUG_TOUCH) Log.e("NavitGraphics", "ACTION_DOWN start");
838 //System.out.println("DO__DRAW:Java:ACTION DOWN start");
839
840 d_pos_x_old = pos_x;
841 d_pos_y_old = pos_y;
842 //Log.e("NavitGraphics", "pos_x=" + pos_x);
843 //Log.e("NavitGraphics", "pos_y=" + pos_y);
844
845 // cancel previous map drawing
846 //System.out.println("DO__DRAW:Java:cancel map drawing");
847 // CallbackMessageChannel(50, "");
848 CallbackMessageChannelReal(50, "");
849
850 if (in_map)
851 {
852 if (!NavitAOverlay.get_show_bubble())
853 {
854 if (DEBUG_TOUCH) Log.e("NavitGraphics", "hide bubble X1");
855 NavitAOverlay.hide_bubble();
856 // remember last press on screen time
857 last_touch_on_screen = event.getEventTime(); // System.currentTimeMillis();
858 touch_sensor_thread = new SensorThread(last_touch_on_screen, this.touch_now.x, this.touch_now.y);
859 touch_sensor_thread.start();
860 }
861 }
862
863 wait_for_redraw_map = true;
864 if (DEBUG_TOUCH) System.out.println("wait_for_redraw_map=true");
865
866 // down
867 // Message msg = new Message();
868 // Bundle b = new Bundle();
869 // b.putInt("Callback", 21);
870 // b.putInt("x", x);
871 // b.putInt("y", y);
872 // msg.setData(b);
873 // callback_handler.sendMessage(msg);
874 // ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
875
876 // wait_for_redraw_map = false;
877
878 touch_mode = DRAG;
879
880 if (DEBUG_TOUCH) Log.e("NavitGraphics", "ACTION_DOWN end");
881
882 // hold all map drawing -----------
883 Message msg = new Message();
884 Bundle b = new Bundle();
885 b.putInt("Callback", 69);
886 msg.setData(b);
887 try
888 {
889 callback_handler.sendMessage(msg);
890 }
891 catch (Exception e)
892 {
893 }
894 // hold all map drawing -----------
895
896 //System.out.println("DO__DRAW:Java:ACTION DOWN end");
897
898 }
899 else if ((switch_value == MotionEvent.ACTION_UP) || (switch_value == _ACTION_POINTER_UP_))
900 {
901 this.touch_now.set(event.getX(), event.getY());
902 touch_now2 = touch_now;
903 touch_start2 = touch_start;
904
905 //System.out.println("DO__DRAW:Java:ACTION UP start");
906
907 if (DEBUG_TOUCH) Log.e("NavitGraphics", "ACTION_UP start");
908 if (DEBUG_TOUCH) Log.e("NavitGraphics", "xxxxxxxxxx");
909 try
910 {
911 if (DEBUG_TOUCH) Log.e("NavitGraphics", "sensor thread stop X1");
912 //touch_sensor_thread.down();
913 touch_sensor_thread.stop_me();
914 // touch_sensor_thread.stop();
915 }
916 catch (Exception e)
917 {
918
919 }
920 // if it was a real longpress, dont hide the bubble
921 long real_event_time = event.getEventTime();
922 // long real_event_time = System.currentTimeMillis();
923 if ((in_map) && ((real_event_time - last_touch_on_screen) > long_press_on_screen_interval))
924 {
925 // real long press
926 }
927 else
928 {
929 if (DEBUG_TOUCH) Log.e("NavitGraphics", "hide bubble 1");
930 NavitAOverlay.hide_bubble();
931 }
932
933 if ((touch_mode == DRAG) && (spacing(touch_start2, touch_now2) < long_press_on_screen_max_distance))
934 {
935 // just a single press down
936 touch_mode = PRESS;
937
938 try
939 {
940 if (DEBUG_TOUCH) Log.e("NavitGraphics", "touch_sensor_thread.stop 1");
941 //touch_sensor_thread.down();
942 touch_sensor_thread.stop_me();
943 // touch_sensor_thread.stop();
944 }
945 catch (Exception e)
946 {
947
948 }
949
950 // was it a long press? or normal quick touch?
951 //if ((in_map) && ((System.currentTimeMillis() - last_touch_on_screen) > long_press_on_screen_interval))
952 //{
953 // Log.e("NavitGraphics", "onTouch up (LONG PRESS 1)");
954 // do_longpress_action(touch_now.x, touch_now.y);
955 //}
956 //else
957 //{
958 //Log.e("NavitGraphics", "onTouch up (quick touch)");
959 //wait_for_redraw_map = true;
960 //System.out.println("wait_for_redraw_map=true 2");
961
962 //*ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
963
964 // quick touch --> here we could repeat the last spoken direction ...
965 // quick touch --> here we could repeat the last spoken direction ...
966 // quick touch --> here we could repeat the last spoken direction ...
967 // quick touch --> here we could repeat the last spoken direction ...
968 // quick touch --> here we could repeat the last spoken direction ...
969 // quick touch --> here we could repeat the last spoken direction ...
970 // quick touch --> here we could repeat the last spoken direction ...
971 // quick touch --> here we could repeat the last spoken direction ...
972
973 if (DEBUG_TOUCH) System.out.println("wait_for_redraw_map=false 9");
974 NavitGraphics.wait_for_redraw_map = false;
975 try
976 {
977 if (DEBUG_TOUCH) Log.e("NavitGraphics", "overlay thread stop X1");
978 //NavitAndroidOverlay.overlay_draw_thread1.stop_redraw();
979 //NavitAndroidOverlay.overlay_draw_thread1.stop_me();
980 //NavitAndroidOverlay.overlay_draw_thread1 = null;
981 }
982 catch (Exception e)
983 {
984 //e.printStackTrace();
985 }
986 try
987 {
988 //System.out.println("invalidate 011");
989 NavitAOverlay_s.postInvalidate();
990 }
991 catch (Exception e)
992 {
993 e.printStackTrace();
994 }
995 //}
996 touch_mode = NONE;
997 }
998 else
999 {
1000 if (touch_mode == DRAG)
1001 {
1002 touch_now2 = touch_now;
1003 touch_start2 = touch_start;
1004
1005 if (DEBUG_TOUCH) Log.e("NavitGraphics", "onTouch move");
1006
1007 try
1008 {
1009 if (DEBUG_TOUCH) Log.e("NavitGraphics", "sensor thread stop X2");
1010 //touch_sensor_thread.down();
1011 touch_sensor_thread.stop_me();
1012 // touch_sensor_thread.stop();
1013 }
1014 catch (Exception e)
1015 {
1016
1017 }
1018
1019 // if we drag, hide the bubble --> NO !!
1020 // NavitAOverlay.hide_bubble();
1021
1022 // wait_for_redraw_map = true;
1023 //System.out.println("wait_for_redraw_map=true 3");
1024
1025 // DRAG ----------- new END --------------
1026 // DRAG ----------- new END --------------
1027 // DRAG ----------- new END --------------
1028 // this.touch_start
1029 // this.touch_now
1030 //pos_x = (int) (this.touch_now.x - this.touch_start.x);
1031 //pos_y = (int) (this.touch_now.y - this.touch_start.y);
1032
1033 // pos_x = d_pos_x_old; // wait for redraw !!
1034 // pos_y = d_pos_y_old; // wait for redraw !!
1035
1036 // ??? // ButtonCallback(1, 1, (int) this.touch_start.x, (int) this.touch_start.y); // down
1037 //this.invalidate();
1038 //this.postInvalidate();
1039 // DRAG ----------- new END --------------
1040 // DRAG ----------- new END --------------
1041 // DRAG ----------- new END --------------
1042
1043 // allow all map drawing -----------
1044 Message msg2 = new Message();
1045 Bundle b2 = new Bundle();
1046 b2.putInt("Callback", 70);
1047 msg2.setData(b2);
1048 try
1049 {
1050 callback_handler.sendMessage(msg2);
1051 }
1052 catch (Exception e)
1053 {
1054 }
1055
1056 // MotionCallback(x, y);
1057
1058 //System.out.println("DO__DRAW:Java:motion call back JAVA -START-");
1059 // -- new call --
1060 // if (dl_thread[0] != null)
1061 // {
1062 // dl_thread[0].motion_callback((int) this.touch_start.x, (int) this.touch_start.y, (int) this.touch_now.x, (int) this.touch_now.y);
1063 // }
1064 // -- old call --
1065 MotionCallback((int) this.touch_start.x, (int) this.touch_start.y, (int) this.touch_now.x, (int) this.touch_now.y);
1066 //System.out.println("DO__DRAW:Java:motion call back JAVA --END--");
1067
1068 //msg2 = new Message();
1069 //b2 = new Bundle();
1070 //b2.putInt("Callback", 23);
1071 //b2.putInt("x",(int) this.touch_start.x);
1072 //b2.putInt("y",(int) this.touch_start.y);
1073 //b2.putInt("x2",(int) this.touch_now.x);
1074 //b2.putInt("y2",(int) this.touch_now.y);
1075 //msg2.setData(b2);
1076 //try
1077 //{
1078 // callback_handler.sendMessage(msg2);
1079 //}
1080 //catch (Exception e)
1081 //{
1082 //}
1083
1084 // ??? // ButtonCallback(0, 1, x, y); // up
1085
1086 if (!Navit.PREF_follow_gps)
1087 {
1088 Navit.cwthr.CallbackGeoCalc2(1, 0, mCanvasWidth / 2, mCanvasHeight / 2);
1089 }
1090
1091 // try
1092 // {
1093 // // try to show current location/streetname
1094 // Message msg1 = new Message();
1095 // Bundle b1 = new Bundle();
1096 // b1.putInt("Callback", 9901);
1097 // msg1.setData(b1);
1098 // NavitGraphics.callback_handler_s.sendMessage(msg1);
1099 // }
1100 // catch (Exception e)
1101 // {
1102 //
1103 // }
1104
1105 touch_mode = NONE;
1106 }
1107 else
1108 {
1109 if (touch_mode == ZOOM)
1110 {
1111 // end of "pinch zoom" move
1112 // ZOOM_MODE_ACTIVE = false; // wait for redraw !!
1113 // ZOOM_MODE_SCALE = 1.0f; // wait for redraw !!
1114
1115 if (DEBUG_TOUCH) Log.e("NavitGraphics", "onTouch zoom");
1116
1117 float newDist = spacing(event);
1118 float scale = 1.0f;
1119 if (newDist > 10f)
1120 {
1121 scale = newDist / oldDist;
1122 }
1123
1124 if (scale > 1.05)
1125 {
1126 wait_for_redraw_map = true;
1127 if (DEBUG_TOUCH) System.out.println("wait_for_redraw_map=true 4");
1128
1129 try
1130 {
1131 if (DEBUG_TOUCH) Log.e("NavitGraphics", "sensor thread stop X3");
1132 //touch_sensor_thread.down();
1133 touch_sensor_thread.stop_me();
1134 // touch_sensor_thread.stop();
1135 }
1136 catch (Exception e)
1137 {
1138
1139 }
1140 if (DEBUG_TOUCH) Log.e("NavitGraphics", "hide bubble 2");
1141 // if we drag, hide the bubble
1142 NavitAOverlay.hide_bubble();
1143
1144 // zoom in
1145 if (scale < 0.2f)
1146 {
1147 scale = 0.2f;
1148 }
1149 else if (scale > 5)
1150 {
1151 scale = 5;
1152 }
1153
1154 // pos_x = d_pos_x_old; // wait for redraw !!
1155 // pos_y = d_pos_y_old; // wait for redraw !!
1156
1157 Message msg = new Message();
1158 Bundle b = new Bundle();
1159 b.putInt("Callback", 61);
1160 //System.out.println("sc1:" + Navit.GlobalScaleLevel);
1161 Navit.GlobalScaleLevel = (int) (Navit.GlobalScaleLevel / scale);
1162 //System.out.println("sc1.1:" + Navit.GlobalScaleLevel);
1163
1164 this.touch_now_center = calc_center(event);
1165 b.putString("s", (int) this.touch_now_center.x + "#" + (int) this.touch_now_center.y + "#" + Integer.toString(Navit.GlobalScaleLevel));
1166 msg.setData(b);
1167 try
1168 {
1169 callback_handler.sendMessage(msg);
1170 //System.out.println("touch: set zoom(in) level: " + Navit.GlobalScaleLevel);
1171 }
1172 catch (Exception e)
1173 {
1174 }
1175
1176 // next lines are a hack, without it screen will not get updated anymore!
1177 //*ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
1178 //*MotionCallback(MotionCallbackID, x + 15, y);
1179 //*MotionCallback(MotionCallbackID, x - 15, y);
1180 //*ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
1181 //*this.postInvalidate();
1182
1183 try
1184 {
1185 if (DEBUG_TOUCH) Log.e("NavitGraphics", "sensor thread stop X4");
1186 //touch_sensor_thread.down();
1187 touch_sensor_thread.stop_me();
1188 // touch_sensor_thread.stop();
1189 }
1190 catch (Exception e)
1191 {
1192
1193 }
1194 // if we drag, hide the bubble
1195 if (DEBUG_TOUCH) Log.e("NavitGraphics", "hide bubble X3");
1196 NavitAOverlay.hide_bubble();
1197
1198 if (DEBUG_TOUCH) Log.e("NavitGraphics", "onTouch zoom in");
1199 }
1200 else if (scale < 0.95)
1201 {
1202 wait_for_redraw_map = true;
1203 if (DEBUG_TOUCH) System.out.println("wait_for_redraw_map=true 5");
1204
1205 try
1206 {
1207 if (DEBUG_TOUCH) Log.e("NavitGraphics", "sensor thread stop X5");
1208 //touch_sensor_thread.down();
1209 touch_sensor_thread.stop_me();
1210 // touch_sensor_thread.stop();
1211 }
1212 catch (Exception e)
1213 {
1214
1215 }
1216 if (DEBUG_TOUCH) Log.e("NavitGraphics", "hide bubble 3");
1217 // if we drag, hide the bubble
1218 NavitAOverlay.hide_bubble();
1219
1220 // zoom out
1221
1222 if (scale < 0.2f)
1223 {
1224 scale = 0.2f;
1225 }
1226 else if (scale > 6)
1227 {
1228 scale = 6;
1229 }
1230
1231 // pos_x = d_pos_x_old; // wait for redraw !!
1232 // pos_y = d_pos_y_old; // wait for redraw !!
1233
1234 Message msg = new Message();
1235 Bundle b = new Bundle();
1236 b.putInt("Callback", 61);
1237 //System.out.println("sc2:" + Navit.GlobalScaleLevel);
1238 Navit.GlobalScaleLevel = (int) (Navit.GlobalScaleLevel / scale);
1239 if (Navit.GlobalScaleLevel < 2)
1240 {
1241 Navit.GlobalScaleLevel = 2;
1242 }
1243 //System.out.println("sc2.1:" + Navit.GlobalScaleLevel);
1244 this.touch_now_center = calc_center(event);
1245 b.putString("s", (int) this.touch_now_center.x + "#" + (int) this.touch_now_center.y + "#" + Integer.toString(Navit.GlobalScaleLevel));
1246 msg.setData(b);
1247 try
1248 {
1249 callback_handler.sendMessage(msg);
1250 //System.out.println("touch: set zoom(out) level: " + Navit.GlobalScaleLevel);
1251 }
1252 catch (Exception e)
1253 {
1254 }
1255
1256 // next lines are a hack, without it screen will not get updated anymore!
1257 //*ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
1258 //*MotionCallback(MotionCallbackID, x + 15, y);
1259 //*MotionCallback(MotionCallbackID, x - 15, y);
1260 //*ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
1261 //*this.postInvalidate();
1262
1263 try
1264 {
1265 if (DEBUG_TOUCH) Log.e("NavitGraphics", "sensor thread stop X6");
1266 //touch_sensor_thread.down();
1267 touch_sensor_thread.stop_me();
1268 // touch_sensor_thread.stop();
1269 }
1270 catch (Exception e)
1271 {
1272
1273 }
1274 if (DEBUG_TOUCH) Log.e("NavitGraphics", "hide bubble 4");
1275 // if we drag, hide the bubble
1276 NavitAOverlay.hide_bubble();
1277
1278 if (DEBUG_TOUCH) Log.e("NavitGraphics", "onTouch zoom out");
1279 }
1280 else
1281 {
1282 // pos_x = d_pos_x_old; // wait for redraw !!
1283 // pos_y = d_pos_y_old; // wait for redraw !!
1284
1285 // move was not zoom-out OR zoom-in
1286 // so just ignore and remove any pending stuff
1287 if (DEBUG_TOUCH) System.out.println("wait_for_redraw_map=false 10");
1288 NavitGraphics.wait_for_redraw_map = false;
1289 try
1290 {
1291 if (DEBUG_TOUCH) Log.e("NavitGraphics", "overlay thread stop X10");
1292 //NavitAndroidOverlay.overlay_draw_thread1.stop_redraw();
1293 //NavitAndroidOverlay.overlay_draw_thread1.stop_me();
1294 //NavitAndroidOverlay.overlay_draw_thread1 = null;
1295 }
1296 catch (Exception e)
1297 {
1298 //e.printStackTrace();
1299 }
1300 try
1301 {
1302 //System.out.println("invalidate 012");
1303 NavitAOverlay_s.postInvalidate();
1304 }
1305 catch (Exception e)
1306 {
1307 e.printStackTrace();
1308 }
1309 }
1310 touch_mode = NONE;
1311 }
1312 else
1313 {
1314 if (DEBUG_TOUCH) Log.d("NavitGraphics", "touch_mode=NONE (END of ZOOM part 2)");
1315 touch_mode = NONE;
1316 }
1317 }
1318 }
1319
1320 //Log.e("NavitGraphics", "pos_x=" + pos_x);
1321 //Log.e("NavitGraphics", "pos_y=" + pos_y);
1322 //Log.e("NavitGraphics", "d_pos_x_old=" + d_pos_x_old);
1323 //Log.e("NavitGraphics", "d_pos_y_old=" + d_pos_y_old);
1324
1325 // on final "UP" action, always reset the display center
1326 if (switch_value == MotionEvent.ACTION_UP)
1327 {
1328 // pos_x = d_pos_x_old; // wait for redraw !!
1329 // pos_y = d_pos_y_old; // wait for redraw !!
1330
1331 //Log.e("NavitGraphics", "DO__DRAW:Java:Final Up action");
1332 //copy_backwards_map_buffer();
1333 //draw_reset_factors = true;
1334 //this.invalidate();
1335
1336 //System.out.println("DO__DRAW:Java:xchange global factors");
1337 Global_Map_TransX = Global_Map_TransX + pos_x;
1338 Global_Map_TransY = Global_Map_TransY + pos_y;
1339 Global_Map_Rotationangle = 0f;
1340 Global_Map_Zoomfactor = Global_Map_Zoomfactor * ZOOM_MODE_SCALE;
1341
1342 //System.out.println("DO__DRAW:Java:reset local factors");
1343 pos_x = 0;
1344 pos_y = 0;
1345 ZOOM_MODE_ACTIVE = false;
1346 ZOOM_MODE_SCALE = 1.0f;
1347
1348 try
1349 {
1350 if (DEBUG_TOUCH) Log.e("NavitGraphics", "sensor thread stop final88");
1351 touch_sensor_thread.stop_me();
1352 }
1353 catch (Exception e)
1354 {
1355
1356 }
1357
1358 Global_onTouch_fingerdown = false;
1359
1360 // allow all map drawing -----------
1361 Message msg2 = new Message();
1362 Bundle b2 = new Bundle();
1363 b2.putInt("Callback", 70);
1364 msg2.setData(b2);
1365 try
1366 {
1367 callback_handler.sendMessage(msg2);
1368 }
1369 catch (Exception e)
1370 {
1371 }
1372 // allow all map drawing -----------
1373 }
1374
1375 //System.out.println("DO__DRAW:Java:ACTION UP end");
1376
1377 }
1378 else if (switch_value == MotionEvent.ACTION_MOVE)
1379 {
1380 //System.out.println("DO__DRAW:Java:ACTION MOVE start");
1381
1382 if (DEBUG_TOUCH) Log.e("NavitGraphics", "ACTION_MOVE");
1383
1384 if (touch_mode == DRAG)
1385 {
1386 if (DEBUG_TOUCH) Log.e("NavitGraphics", "mode = DRAG");
1387
1388 this.touch_now.set(event.getX(), event.getY());
1389 touch_now2 = touch_now;
1390 touch_start2 = touch_start;
1391 touch_prev2 = touch_prev;
1392 this.touch_prev.set(event.getX(), event.getY());
1393
1394 // try
1395 // {
1396 // //touch_sensor_thread.down();
1397 // touch_sensor_thread.stop_me();
1398 // // touch_sensor_thread.stop();
1399 // }
1400 // catch (Exception e)
1401 // {
1402 //
1403 // }
1404
1405 if (DEBUG_TOUCH) Log.e("NavitGraphics", "systime2:" + System.currentTimeMillis());
1406 if (DEBUG_TOUCH) Log.e("NavitGraphics", "eventtime2:" + event.getEventTime());
1407 if (DEBUG_TOUCH) Log.e("NavitGraphics", "last touch screen:" + last_touch_on_screen);
1408 // if ((System.currentTimeMillis() - last_touch_on_screen) > long_press_on_screen_interval)
1409 // {
1410 // Log.e("NavitGraphics", "onTouch up (LONG PRESS 2) ***** 11 *****");
1411 // // do_longpress_action(touch_now.x, touch_now.y);
1412 // }
1413
1414 if ((in_map) && (spacing(touch_start2, touch_now2) < long_press_on_screen_max_distance))
1415 {
1416 // now its still a PRESS, because we have not moved around too much!
1417
1418 if (DEBUG_TOUCH) Log.e("NavitGraphics", "in move: still a PRESS action");
1419
1420 // is it a still ongoing long press?
1421 if ((System.currentTimeMillis() - last_touch_on_screen) > long_press_on_screen_interval)
1422 {
1423 if (DEBUG_TOUCH) Log.e("NavitGraphics", "onTouch up (LONG PRESS 2) ***** 22 *****");
1424 // do_longpress_action(touch_now.x, touch_now.y);
1425 }
1426 }
1427 else
1428 {
1429 if (DEBUG_TOUCH) Log.e("NavitGraphics", "onTouch move2");
1430 // MotionCallback(MotionCallbackID, x, y);
1431 // DRAG ----------- new --------------
1432 // DRAG ----------- new --------------
1433 // DRAG ----------- new --------------
1434
1435 try
1436 {
1437 if (DEBUG_TOUCH) Log.e("NavitGraphics", "sensor thread stop X6");
1438 //touch_sensor_thread.down();
1439 touch_sensor_thread.stop_me();
1440 // touch_sensor_thread.stop();
1441 }
1442 catch (Exception e)
1443 {
1444
1445 }
1446
1447 pos_x = (int) (this.touch_now.x - this.touch_start.x);
1448 pos_y = (int) (this.touch_now.y - this.touch_start.y);
1449 //**dl_thread[dl_thread_cur].add_lines2(null, null, 0, 0, 98);
1450 //draw_map_one_shot = true;
1451 //copy_map_buffer();
1452 //System.out.println("invalidate 013");
1453 this.invalidate();
1454 // this.postInvalidate();
1455 // DRAG ----------- new --------------
1456 // DRAG ----------- new --------------
1457 // DRAG ----------- new --------------
1458
1459 }
1460 }
1461 else if (touch_mode == ZOOM)
1462 {
1463 this.touch_now.set(event.getX(), event.getY());
1464 this.touch_prev.set(event.getX(), event.getY());
1465
1466 if (DEBUG_TOUCH) Log.e("NavitGraphics", "zoom 2");
1467
1468 if (DEBUG_TOUCH) Log.e("NavitGraphics", "hide bubble 73");
1469 NavitAOverlay.hide_bubble();
1470 try
1471 {
1472 if (DEBUG_TOUCH) Log.e("NavitGraphics", "touch_sensor_thread.stop 73");
1473 touch_sensor_thread.stop_me();
1474 }
1475 catch (Exception e)
1476 {
1477 }
1478 if (DEBUG_TOUCH) Log.e("NavitGraphics", "hide bubble 74");
1479 NavitAOverlay.hide_bubble();
1480
1481 // were are in the middle of a zooming action here ----------
1482 // were are in the middle of a zooming action here ----------
1483
1484 this.touch_now_center = calc_center(event);
1485 float newDist = spacing(event);
1486 float scale = 1.0f;
1487 try
1488 {
1489 scale = newDist / oldDist;
1490 }
1491 catch (Exception ee)
1492 {
1493
1494 }
1495
1496 if (scale != 0)
1497 {
1498 ZOOM_MODE_SCALE = scale;
1499 }
1500 else
1501 {
1502 ZOOM_MODE_SCALE = 1.0f;
1503 }
1504
1505 ZOOM_MODE_ACTIVE = true;
1506 //**dl_thread[dl_thread_cur].add_lines2(null, null, 0, 0, 98);
1507 //draw_map_one_shot = true;
1508 //copy_map_buffer();
1509 //System.out.println("invalidate 014");
1510 this.invalidate();
1511 // Log.e("NavitGraphics", "x:" + this.touch_now.x + " y:" + this.touch_now.y);
1512 // were are in the middle of a zooming action here ----------
1513 // were are in the middle of a zooming action here ----------
1514 }
1515
1516 //System.out.println("DO__DRAW:Java:ACTION MOVE end");
1517
1518 }
1519 else if (switch_value == _ACTION_POINTER_DOWN_)
1520 {
1521 //System.out.println("DO__DRAW:Java:ACTION POINTER DOWN start");
1522 if (DEBUG_TOUCH) Log.e("NavitGraphics", "ACTION_POINTER_DOWN");
1523
1524 oldDist = spacing(event);
1525 if (oldDist > 10f)
1526 {
1527 touch_mode = ZOOM;
1528 if (DEBUG_TOUCH) Log.e("NavitGraphics", "--> zoom");
1529 // zoom action starts here --------
1530 // zoom action starts here --------
1531 // zoom action starts here --------
1532 // zoom action starts here --------
1533 }
1534
1535 //System.out.println("DO__DRAW:Java:ACTION POINTER DOWN end");
1536
1537 }
1538 return true;
1539 }
1540
1541 private float spacing(PointF a, PointF b)
1542 {
1543 float x = a.x - b.x;
1544 float y = a.y - b.y;
1545 return FloatMath.sqrt(x * x + y * y);
1546 }
1547
1548 public PointF calc_center(MotionEvent event)
1549 {
1550 //float x;
1551 //float y;
1552 PointF ret = new PointF(0, 0);
1553 try
1554 {
1555 float y0 = 0;
1556 float y1 = 0;
1557 float x0 = 0;
1558 float x1 = 0;
1559
1560 x0 = event.getX(0);
1561 y0 = event.getY(0);
1562 try
1563 {
1564 x1 = event.getX(1);
1565 y1 = event.getY(1);
1566 }
1567 catch (Exception ex)
1568 {
1569 ex.printStackTrace();
1570 }
1571 ret.x = x0 - ((x0 - x1) / 2);
1572 ret.y = y0 - ((y0 - y1) / 2);
1573 }
1574 catch (Exception ex)
1575 {
1576 ex.printStackTrace();
1577 ret.x = event.getX(0);
1578 ret.y = event.getY(0);
1579 }
1580 return ret;
1581 }
1582
1583 public float spacing(MotionEvent event)
1584 {
1585 float x;
1586 float y;
1587 try
1588 {
1589 float y0 = 0;
1590 float y1 = 0;
1591 float x0 = 0;
1592 float x1 = 0;
1593
1594 x0 = event.getX(0);
1595 y0 = event.getY(0);
1596 try
1597 {
1598 x1 = event.getX(1);
1599 y1 = event.getY(1);
1600 }
1601 catch (Exception ex)
1602 {
1603 ex.printStackTrace();
1604 }
1605 x = x0 - x1;
1606 y = y0 - y1;
1607 }
1608 catch (Exception ex)
1609 {
1610 ex.printStackTrace();
1611 x = 0;
1612 y = 0;
1613 }
1614 return FloatMath.sqrt(x * x + y * y);
1615 }
1616
1617 @Override
1618 public boolean onKeyDown(int keyCode, KeyEvent event)
1619 {
1620 if (keyCode == KeyEvent.KEYCODE_BACK)
1621 {
1622 // override back button, so it does NOT quit the application
1623 return true;
1624 }
1625 return super.onKeyDown(keyCode, event);
1626 }
1627
1628 @Override
1629 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect)
1630 {
1631 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
1632 //Log.e("NavitGraphics", "FocusChange " + gainFocus);
1633 }
1634 };
1635
1636 view.setFocusable(true);
1637 view.setFocusableInTouchMode(true);
1638 view.setKeepScreenOn(true);
1639 relativelayout = new RelativeLayout(activity);
1640
1641 if (this.gr_type == 1)
1642 {
1643 view_s = view;
1644 }
1645
1646 //if (use_camera != 0)
1647 //{
1648 // SetCamera(use_camera);
1649 //}
1650 relativelayout.addView(view);
1651
1652 // vehicle view
1653 RelativeLayout.LayoutParams NavitVehicleGraph_lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
1654 relativelayout.addView(Navit.NG__vehicle.view, NavitVehicleGraph_lp);
1655 Navit.NG__vehicle.view.bringToFront();
1656 Navit.NG__vehicle.view.postInvalidate();
1657 // vehicle view
1658
1659 // android overlay
1660 //Log.e("Navit", "create android overlay");
1661 NavitAOverlay = new NavitAndroidOverlay(relativelayout.getContext());
1662 NavitAOverlay_s = NavitAOverlay;
1663 RelativeLayout.LayoutParams NavitAOverlay_lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
1664 relativelayout.addView(NavitAOverlay, NavitAOverlay_lp);
1665 NavitAOverlay.bringToFront();
1666 NavitAOverlay.postInvalidate();
1667 // android overlay
1668
1669 // android OSDJava
1670 //Log.e("Navit", "create android OSDJava");
1671 NavitAOSDJava = new NavitOSDJava(relativelayout.getContext());
1672 NavitAOSDJava_ = NavitAOSDJava;
1673 RelativeLayout.LayoutParams NavitAOSDJava_lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
1674 relativelayout.addView(NavitAOSDJava, NavitAOSDJava_lp);
1675 NavitAOSDJava.bringToFront();
1676 NavitAOSDJava.postInvalidate();
1677 // android OSDJava
1678
1679 // android Messages TextView
1680 //Log.e("Navit", "create android Messages TextView");
1681 NavitMsgTv = new TextView(relativelayout.getContext());
1682 NavitMsgTv_ = NavitMsgTv;
1683 RelativeLayout.LayoutParams NavitMsgTv_lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
1684 // NavitMsgTv_lp.height = 50;
1685 NavitMsgTv_lp.leftMargin = 120;
1686 // NavitMsgTv.setHeight(10);
1687 int tc = Color.argb(125, 0, 0, 0); // half transparent black
1688 NavitMsgTv.setBackgroundColor(tc);
1689 NavitMsgTv.setLines(4);
1690 NavitMsgTv.setTextSize(12);
1691 NavitMsgTv.setTextColor(Color.argb(255, 200, 200, 200)); // almost white
1692 relativelayout.addView(NavitMsgTv, NavitMsgTv_lp);
1693 NavitMsgTv.bringToFront();
1694 NavitMsgTv.postInvalidate();
1695 // android Messages TextView
1696
1697 // android Speech Messages TextView
1698 //Log.e("Navit", "create android Speech Messages TextView");
1699 NavitMsgTv2 = new TextView(relativelayout.getContext());
1700 NavitMsgTv2_ = NavitMsgTv2;
1701 RelativeLayout.LayoutParams NavitMsgTv_lp2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
1702 NavitMsgTv_lp2.leftMargin = 10;
1703 NavitMsgTv_lp2.rightMargin = 10;
1704 int tc2 = Color.argb(125, 0, 0, 0); // half transparent black
1705 NavitMsgTv2.setBackgroundColor(tc2);
1706 NavitMsgTv2.setTextSize(15);
1707 NavitMsgTv2.setTextColor(Color.argb(255, 200, 200, 200)); // almost white
1708
1709 ScrollView sc = new ScrollView(relativelayout.getContext());
1710 RelativeLayout.LayoutParams NavitMsgTv_lp3 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
1711 sc.addView(NavitMsgTv2, NavitMsgTv_lp2);
1712 sc.setFadingEdgeLength(20);
1713 sc.setScrollbarFadingEnabled(true);
1714 sc.setHorizontalScrollBarEnabled(true);
1715 sc.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
1716 NavitMsgTv2.setGravity(Gravity.BOTTOM);
1717 relativelayout.addView(sc, NavitMsgTv_lp3);
1718
1719 NavitMsgTv2.bringToFront();
1720 NavitMsgTv2.postInvalidate();
1721 NavitMsgTv2.setEnabled(false);
1722 NavitMsgTv2.setVisibility(View.GONE);
1723 // android Speech Messages TextView
1724
1725 // busy spinner view on top of everything
1726 ZANaviBusySpinner busyspinner = new ZANaviBusySpinner(relativelayout.getContext());
1727 busyspinner_ = busyspinner;
1728 RelativeLayout.LayoutParams ZANaviBusySpinner_lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
1729 relativelayout.addView(busyspinner, ZANaviBusySpinner_lp);
1730 busyspinner.bringToFront();
1731 busyspinner.postInvalidate();
1732 busyspinner.setVisibility(View.INVISIBLE);
1733
1734 ZANaviBusyText busyspinnertext = new ZANaviBusyText(relativelayout.getContext());
1735 busyspinnertext_ = busyspinnertext;
1736 RelativeLayout.LayoutParams ZANaviBusyText_lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
1737 relativelayout.addView(busyspinnertext, ZANaviBusyText_lp);
1738 busyspinnertext.bringToFront();
1739 busyspinnertext.postInvalidate();
1740 busyspinnertext.setVisibility(View.INVISIBLE);
1741 // busy spinner view on top of everything
1742
1743 // big map overlay
1744 // NavitGlobalMap_ = new NavitGlobalMap(relativelayout.getContext());
1745 // RelativeLayout.LayoutParams NavitGlobalMap_lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
1746 // relativelayout.addView(NavitGlobalMap_, NavitGlobalMap_lp);
1747 // NavitGlobalMap_.bringToFront();
1748 // NavitGlobalMap_.invalidate();
1749 // big map overlay
1750
1751 activity.setContentView(relativelayout);
1752 view.requestFocus();
1753 }
1754 // parent == 0 ---------------
1755 else
1756 // parent == 1 ---------------
1757 {
1758 if (draw_bitmap != null)
1759 {
1760 // try to avoid out of memory errors
1761 draw_bitmap.recycle();
1762 }
1763
1764 try
1765 {
1766 draw_bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
1767 }
1768 catch (OutOfMemoryError e)
1769 {
1770 int usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
1771 String usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
1772 System.out.println("" + usedMegsString);
1773 System.out.println("@@@@@@@@ out of VM Memory @@@@@@@@");
1774 System.gc();
1775 usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
1776 usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
1777 System.out.println("" + usedMegsString);
1778 // try again
1779 draw_bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
1780 }
1781
1782 bitmap_w = w;
1783 bitmap_h = h;
1784 pos_x = x;
1785 pos_y = y;
1786 pos_wraparound = wraparound;
1787 draw_canvas = new Canvas(draw_bitmap);
1788
1789 this.activity = activity;
1790 view = new View(activity)
1791 {
1792 protected void onDraw(Canvas canvas)
1793 {
1794 //System.out.println("V.Draw x");
1795 //System.out.println("V.Draw x="+NG__vehicle.vehicle_pos_x+" y="+NG__vehicle.vehicle_pos_y);
1796 //System.out.println("V.Draw d=" + Navit.nav_arrow_stopped.getDensity());
1797 //System.out.println("V.Draw w=" + Navit.nav_arrow_stopped.getWidth());
1798 //System.out.println("V.Draw h=" + Navit.nav_arrow_stopped.getHeight());
1799 super.onDraw(canvas);
1800
1801 if (!NavitGraphics.MAP_DISPLAY_OFF)
1802 {
1803 if (Navit.NG__vehicle.vehicle_speed < 3)
1804 {
1805 canvas.drawBitmap(Navit.nav_arrow_stopped, Navit.NG__vehicle.vehicle_pos_x - Navit.nav_arrow_stopped.getWidth() / 2, Navit.NG__vehicle.vehicle_pos_y - Navit.nav_arrow_stopped.getHeight() / 2, null);
1806 }
1807 else
1808 {
1809 if (Navit.NG__vehicle.vehicle_direction != 0)
1810 {
1811 canvas.save();
1812 // rotate nav icon if needed
1813 canvas.rotate(Navit.NG__vehicle.vehicle_direction, Navit.NG__vehicle.vehicle_pos_x, Navit.NG__vehicle.vehicle_pos_y);
1814 }
1815 // offset shadow x+2 , y+8
1816 canvas.drawBitmap(Navit.nav_arrow_moving_shadow, 2 + Navit.NG__vehicle.vehicle_pos_x - Navit.nav_arrow_moving.getWidth() / 2, 8 + Navit.NG__vehicle.vehicle_pos_y - Navit.nav_arrow_moving.getHeight() / 2, null);
1817 canvas.drawBitmap(Navit.nav_arrow_moving, Navit.NG__vehicle.vehicle_pos_x - Navit.nav_arrow_moving.getWidth() / 2, Navit.NG__vehicle.vehicle_pos_y - Navit.nav_arrow_moving.getHeight() / 2, null);
1818 if (Navit.NG__vehicle.vehicle_direction != 0)
1819 {
1820 canvas.restore();
1821 }
1822 }
1823
1824 // paint the sweep spot of the vehicle position!!
1825 // Paint paint22 = new Paint();
1826 // paint22.setStyle(Paint.Style.FILL);
1827 // paint22.setStrokeWidth(0);
1828 // paint22.setColor(Color.RED);
1829 // canvas.drawCircle(Navit.NG__vehicle.vehicle_pos_x, Navit.NG__vehicle.vehicle_pos_y, 5, paint22);
1830 // paint the sweep spot of the vehicle position!!
1831 }
1832 }
1833
1834 @Override
1835 protected void onSizeChanged(int w, int h, int oldw, int oldh)
1836 {
1837 System.out.println("new width=" + w + " new height=" + h);
1838 }
1839 };
1840
1841 } // END IF: parent == 1 ---------------
1842
1843 parent_num = parent;
1844 }
1845
1846 public Handler callback_handler = new Handler()
1847 {
1848 public void handleMessage(Message msg)
1849 {
1850 if (msg.getData().getInt("Callback") == 1)
1851 {
1852 // zoom in
1853 CallbackMessageChannel(1, "");
1854 }
1855 else if (msg.getData().getInt("Callback") == 2)
1856 {
1857 // zoom out
1858 CallbackMessageChannel(2, "");
1859 }
1860 else if (msg.getData().getInt("Callback") == 3)
1861 {
1862 // get values
1863 String lat = msg.getData().getString("lat");
1864 String lon = msg.getData().getString("lon");
1865 String q = msg.getData().getString("q");
1866 // set routing target to lat,lon
1867 CallbackMessageChannel(3, lat + "#" + lon + "#" + q);
1868 }
1869 else if (msg.getData().getInt("Callback") == 48)
1870 {
1871 // get values
1872 String lat = msg.getData().getString("lat");
1873 String lon = msg.getData().getString("lon");
1874 String q = msg.getData().getString("q");
1875 // append to routing, add waypoint at lat,lon
1876 CallbackMessageChannel(48, lat + "#" + lon + "#" + q);
1877 }
1878 else if (msg.getData().getInt("Callback") == 4)
1879 {
1880 // set routing target to pixel x,y
1881 int x = msg.getData().getInt("x");
1882 int y = msg.getData().getInt("y");
1883
1884 CallbackMessageChannel(4, "" + x + "#" + y);
1885 try
1886 {
1887 Navit.follow_button_on();
1888 }
1889 catch (Exception e2)
1890 {
1891 e2.printStackTrace();
1892 }
1893 }
1894 else if (msg.getData().getInt("Callback") == 49)
1895 {
1896 // set routing target to pixel x,y
1897 int x = msg.getData().getInt("x");
1898 int y = msg.getData().getInt("y");
1899
1900 CallbackMessageChannel(49, "" + x + "#" + y);
1901 try
1902 {
1903 Navit.follow_button_on();
1904 }
1905 catch (Exception e2)
1906 {
1907 e2.printStackTrace();
1908 }
1909 }
1910 else if (msg.getData().getInt("Callback") == 5)
1911 {
1912 String cmd = msg.getData().getString("cmd");
1913 CallbackMessageChannel(5, cmd);
1914 }
1915 else if (msg.getData().getInt("Callback") == 7)
1916 {
1917 CallbackMessageChannel(7, "");
1918 }
1919 else if ((msg.getData().getInt("Callback") > 7) && (msg.getData().getInt("Callback") < 21))
1920 {
1921 CallbackMessageChannel(msg.getData().getInt("Callback"), "");
1922 }
1923 else if (msg.getData().getInt("Callback") == 21)
1924 {
1925 int x = msg.getData().getInt("x");
1926 int y = msg.getData().getInt("y");
1927 // ??? // ButtonCallback(1, 1, x, y); // down
1928 }
1929 else if (msg.getData().getInt("Callback") == 22)
1930 {
1931 int x = msg.getData().getInt("x");
1932 int y = msg.getData().getInt("y");
1933 // ??? // ButtonCallback(0, 1, x, y); // up
1934 }
1935 else if (msg.getData().getInt("Callback") == 23)
1936 {
1937 int x = msg.getData().getInt("x");
1938 int y = msg.getData().getInt("y");
1939 int x2 = msg.getData().getInt("x2");
1940 int y2 = msg.getData().getInt("y2");
1941 MotionCallback(x, y, x2, y2);
1942 }
1943 else if (msg.getData().getInt("Callback") == 24)
1944 {
1945 try
1946 {
1947 NavitGraphics.NavitMsgTv_.setVisibility(View.VISIBLE);
1948 }
1949 catch (Exception e)
1950 {
1951
1952 }
1953 }
1954 else if (msg.getData().getInt("Callback") == 25)
1955 {
1956 try
1957 {
1958 NavitGraphics.NavitMsgTv_.setVisibility(View.INVISIBLE);
1959 }
1960 catch (Exception e)
1961 {
1962
1963 }
1964 }
1965 else if (msg.getData().getInt("Callback") == 30)
1966 {
1967 // 2D
1968 // String s = msg.getData().getString("s");
1969 CallbackMessageChannel(30, "");
1970 }
1971 else if (msg.getData().getInt("Callback") == 31)
1972 {
1973 // 3D
1974 // String s = msg.getData().getString("s");
1975 CallbackMessageChannel(31, "");
1976 }
1977 else if (msg.getData().getInt("Callback") == 32)
1978 {
1979 // switch to specific 3D pitch
1980 String s = msg.getData().getString("s");
1981 CallbackMessageChannel(32, s);
1982 }
1983 else if (msg.getData().getInt("Callback") == 33)
1984 {
1985 // zoom to specific zoomlevel
1986 String s = msg.getData().getString("s");
1987 CallbackMessageChannel(33, s);
1988 }
1989 else if (msg.getData().getInt("Callback") == 34)
1990 {
1991 // announcer voice OFF
1992 CallbackMessageChannel(34, "");
1993 }
1994 else if (msg.getData().getInt("Callback") == 35)
1995 {
1996 // announcer voice ON
1997 CallbackMessageChannel(35, "");
1998 }
1999 else if (msg.getData().getInt("Callback") == 36)
2000 {
2001 // switch "Lock on road" ON
2002 CallbackMessageChannel(36, "");
2003 }
2004 else if (msg.getData().getInt("Callback") == 37)
2005 {
2006 // switch "Lock on road" OFF
2007 CallbackMessageChannel(37, "");
2008 }
2009 else if (msg.getData().getInt("Callback") == 38)
2010 {
2011 // switch "Northing" ON
2012 CallbackMessageChannel(38, "");
2013 }
2014 else if (msg.getData().getInt("Callback") == 39)
2015 {
2016 // switch "Northing" OFF
2017 CallbackMessageChannel(39, "");
2018 }
2019 else if (msg.getData().getInt("Callback") == 40)
2020 {
2021 // switch "Map follows Vehicle" ON
2022 CallbackMessageChannel(40, "");
2023 }
2024 else if (msg.getData().getInt("Callback") == 41)
2025 {
2026 // switch "Map follows Vehicle" OFF
2027 CallbackMessageChannel(41, "");
2028 }
2029 else if (msg.getData().getInt("Callback") == 42)
2030 {
2031 // routing mode "highways"
2032 CallbackMessageChannel(42, "");
2033 }
2034 else if (msg.getData().getInt("Callback") == 43)
2035 {
2036 // routing mode "normal roads"
2037 CallbackMessageChannel(43, "");
2038 }
2039 else if (msg.getData().getInt("Callback") == 44)
2040 {
2041 // show duplicates in search results
2042 CallbackMessageChannel(44, "");
2043 }
2044 else if (msg.getData().getInt("Callback") == 45)
2045 {
2046 // filter duplicates in search results
2047 CallbackMessageChannel(45, "");
2048 }
2049 else if (msg.getData().getInt("Callback") == 46)
2050 {
2051 // stop searching and show results found until now
2052 CallbackMessageChannel(46, "");
2053 }
2054 else if (msg.getData().getInt("Callback") == 47)
2055 {
2056 // change maps data dir
2057 String s = msg.getData().getString("s");
2058 CallbackMessageChannel(47, s);
2059 }
2060 else if (msg.getData().getInt("Callback") == 50)
2061 {
2062 // we request to stop drawing the map
2063 CallbackMessageChannel(50, "");
2064 }
2065 else if (msg.getData().getInt("Callback") == 51)
2066 {
2067 // set position to pixel x,y
2068 int x = msg.getData().getInt("x");
2069 int y = msg.getData().getInt("y");
2070 CallbackMessageChannel(51, "" + x + "#" + y);
2071 }
2072 else if (msg.getData().getInt("Callback") == 52)
2073 {
2074 // switch to demo vehicle
2075 String s = msg.getData().getString("s");
2076 CallbackMessageChannel(52, s);
2077 }
2078 else if (msg.getData().getInt("Callback") == 53)
2079 {
2080 // dont speak streetnames
2081 CallbackMessageChannel(53, "");
2082 }
2083 else if (msg.getData().getInt("Callback") == 54)
2084 {
2085 // speak streetnames
2086 CallbackMessageChannel(54, "");
2087 }
2088 else if (msg.getData().getInt("Callback") == 55)
2089 {
2090 // set cache size for (map-)files
2091 String s = msg.getData().getString("s");
2092 CallbackMessageChannel(55, s);
2093 }
2094 // else if (msg.getData().getInt("Callback") == 56)
2095 // {
2096 // // draw polylines with/without circles at the end
2097 // String s = msg.getData().getString("s");
2098 // CallbackMessageChannel(56, s); // 0 -> draw circles, 1 -> DO NOT draw circles
2099 // }
2100 else if (msg.getData().getInt("Callback") == 57)
2101 {
2102 // keep drawing streets as if at "order" level xxx
2103 String s = msg.getData().getString("s");
2104 CallbackMessageChannel(57, s);
2105 }
2106 else if (msg.getData().getInt("Callback") == 58)
2107 {
2108 // street search radius factor (multiplier)
2109 String s = msg.getData().getString("s");
2110 CallbackMessageChannel(58, s);
2111 }
2112 else if (msg.getData().getInt("Callback") == 59)
2113 {
2114 // enable layer "name"
2115 String s = msg.getData().getString("s");
2116 CallbackMessageChannel(59, s);
2117 }
2118 else if (msg.getData().getInt("Callback") == 60)
2119 {
2120 // disable layer "name"
2121 String s = msg.getData().getString("s");
2122 CallbackMessageChannel(60, s);
2123 }
2124 else if (msg.getData().getInt("Callback") == 61)
2125 {
2126 // zoom to specific zoomlevel at given point as center
2127 // pixel-x#pixel-y#zoom-level
2128 String s = msg.getData().getString("s");
2129 CallbackMessageChannel(61, s);
2130 }
2131 else if (msg.getData().getInt("Callback") == 62)
2132 {
2133 // disable map drawing
2134 CallbackMessageChannel(62, "");
2135 }
2136 else if (msg.getData().getInt("Callback") == 63)
2137 {
2138 // enable map drawing
2139 CallbackMessageChannel(63, "");
2140 }
2141 else if (msg.getData().getInt("Callback") == 64)
2142 {
2143 // draw map
2144 CallbackMessageChannel(64, "");
2145 }
2146 else if (msg.getData().getInt("Callback") == 65)
2147 {
2148 // draw map async
2149 CallbackMessageChannel(65, "");
2150 }
2151 else if (msg.getData().getInt("Callback") == 66)
2152 {
2153 // enable "multipolygons"
2154 CallbackMessageChannel(66, "");
2155 }
2156 else if (msg.getData().getInt("Callback") == 67)
2157 {
2158 // disable "multipolygons"
2159 CallbackMessageChannel(67, "");
2160 }
2161 else if (msg.getData().getInt("Callback") == 68)
2162 {
2163 // shift "order" by this value (only for drawing objects)
2164 String s = msg.getData().getString("s");
2165 CallbackMessageChannel(68, s);
2166 }
2167 else if (msg.getData().getInt("Callback") == 69)
2168 {
2169 // stop drawing map
2170 CallbackMessageChannel(69, "");
2171 }
2172 else if (msg.getData().getInt("Callback") == 70)
2173 {
2174 // allow drawing map
2175 CallbackMessageChannel(70, "");
2176 }
2177 else if (msg.getData().getInt("Callback") == 71)
2178 {
2179 // activate/deactivate "route graph" display
2180 // 0 -> deactivate
2181 // 1 -> activate
2182 String s = msg.getData().getString("s");
2183 CallbackMessageChannel(71, s);
2184 }
2185 else if (msg.getData().getInt("Callback") == 72)
2186 {
2187 // update the route path and route graph (e.g. after setting new roadblocks)
2188 // does not update destinations!!!
2189 CallbackMessageChannel(72, "");
2190 }
2191 else if (msg.getData().getInt("Callback") == 73)
2192 {
2193 // update the route path and route graph (e.g. after setting new roadblocks)
2194 // this destroys the route graph and calcs everything totally new!
2195 CallbackMessageChannel(73, "");
2196 }
2197
2198 else if (msg.getData().getInt("Callback") == 74)
2199 {
2200 // allow demo vechile to move
2201 CallbackMessageChannel(74, "");
2202 }
2203 else if (msg.getData().getInt("Callback") == 75)
2204 {
2205 // stop demo vechile
2206 CallbackMessageChannel(75, "");
2207 }
2208 else if (msg.getData().getInt("Callback") == 76)
2209 {
2210 // show route rectangles
2211 CallbackMessageChannel(76, "");
2212 }
2213 else if (msg.getData().getInt("Callback") == 77)
2214 {
2215 // do not show route rectangles
2216 CallbackMessageChannel(77, "");
2217 }
2218 else if (msg.getData().getInt("Callback") == 78)
2219 {
2220 // shift layout "order" values
2221 String s = msg.getData().getString("s");
2222 CallbackMessageChannel(78, s);
2223 }
2224 else if (msg.getData().getInt("Callback") == 79)
2225 {
2226 // set traffic light delay/cost
2227 String s = msg.getData().getString("s");
2228 CallbackMessageChannel(79, s);
2229 }
2230 }
2231 };
2232
2233 public static native void TimeoutCallback(int del, int id);
2234
2235 public static native void SizeChangedCallbackReal(int w, int h);
2236
2237 public static void SizeChangedCallback(int w, int h)
2238 {
2239 Navit.cwthr.SizeChangedCallback(w, h);
2240 }
2241
2242 // public native void ButtonCallback(int pressed, int button, int x, int y);
2243
2244 public static native void MotionCallbackReal(int x1, int y1, int x2, int y2);
2245
2246 public static void MotionCallback(int x1, int y1, int x2, int y2)
2247 {
2248 Navit.cwthr.MotionCallback(x1, y1, x2, y2);
2249 }
2250
2251 // public native void KeypressCallback(String s);
2252
2253 // private int SizeChangedCallbackID, ButtonCallbackID, MotionCallbackID, KeypressCallbackID;
2254
2255 // private int count;
2256 /*
2257 * public void setSizeChangedCallback(int id)
2258 * {
2259 * SizeChangedCallbackID = id;
2260 * }
2261 */
2262
2263 /*
2264 * public void setButtonCallback(int id)
2265 * {
2266 * ButtonCallbackID = id;
2267 * }
2268 */
2269
2270 /*
2271 * public void setMotionCallback(int id)
2272 * {
2273 * MotionCallbackID = id;
2274 * Navit.setMotionCallback(id, this);
2275 * }
2276 */
2277
2278 /*
2279 * public void setKeypressCallback(int id)
2280 * {
2281 * KeypressCallbackID = id;
2282 * // set callback id also in main intent (for menus)
2283 * Navit.setKeypressCallback(id, this);
2284 * }
2285 */
2286
2287 public void NavitSetGrObj()
2288 {
2289 // set the (static) graphics object (this is bad, please fix me!!)
2290 // **disabled** Navit.N_NavitGraphics = this;
2291 }
2292
2293 protected void draw_polyline(Paint paint, int c[])
2294 {
2295 // Log.e("NavitGraphics","draw_polyline");
2296 paint.setStyle(Paint.Style.STROKE);
2297 b_paint_antialias = paint.isAntiAlias();
2298 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
2299 //paint.setStrokeWidth(0);
2300 b_paint_path.reset();
2301 b_paint_path.moveTo(c[0], c[1]);
2302 for (int i = 2; i < c.length; i += 2)
2303 {
2304 b_paint_path.lineTo(c[i], c[i + 1]);
2305 }
2306 //global_path.close();
2307 draw_canvas.drawPath(b_paint_path, paint);
2308 paint.setAntiAlias(b_paint_antialias);
2309 //paint.setPathEffect(dashed_map_lines__no_dash);
2310 }
2311
2312 protected void draw_polyline2__NEW(Paint paint, int c[], int order, int oneway)
2313 {
2314 if (dl_thread[0] == null)
2315 {
2316 int ii = 0;
2317 for (ii = 0; ii < NavitGraphics.dl_thread_max; ii++)
2318 {
2319 NavitGraphics.dl_thread[ii] = new NavitGraphics.DrawLinesThread(ii);
2320 NavitGraphics.dl_thread[ii].start();
2321 }
2322 }
2323
2324 if (dl_thread_cur + 1 < dl_thread_max)
2325 {
2326 dl_thread_cur++;
2327 }
2328 else
2329 {
2330 dl_thread_cur = 0;
2331 }
2332 dl_thread[dl_thread_cur].add_lines3(paint, c, order, oneway);
2333 }
2334
2335 static void draw_polyline2_threads(Paint paint, int c[], int order, int oneway)
2336 {
2337 if (!Navit.PREF_gui_oneway_arrows)
2338 {
2339 return;
2340 }
2341
2342 // line less than 44px -> dont draw arrow!
2343 int len = (c[0] - c[2]) * (c[1] - c[3]);
2344 if (len < 0)
2345 {
2346 len = -len;
2347 }
2348 if (len > (2000))
2349 {
2350 paint.setStyle(Paint.Style.STROKE);
2351 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
2352
2353 // create matrix for the manipulation
2354 Matrix matrix_oneway_arrows2 = new Matrix();
2355
2356 int middle_x = c[0] + (int) ((c[2] - c[0]) / 2);
2357 int middle_y = c[1] + (int) ((c[3] - c[1]) / 2);
2358 double d_x = ((c[2] - c[0]) / 6);
2359 double d_y = ((c[3] - c[1]) / 6);
2360 int angle = (int) (Math.toDegrees(Math.atan2(d_y, d_x)));
2361 // System.out.println("arrow angle=" + angle);
2362 matrix_oneway_arrows2.postTranslate(-Navit.oneway_arrow.getWidth() / 2, -Navit.oneway_arrow.getHeight() / 2);
2363
2364 if (oneway == 1)
2365 {
2366 // rotate the Bitmap
2367 matrix_oneway_arrows2.postRotate(angle);
2368 }
2369 else if (oneway == 2)
2370 {
2371 // rotate the Bitmap
2372 matrix_oneway_arrows2.postRotate(angle + 180);
2373 }
2374
2375 if (oneway > 0)
2376 {
2377 if (c.length == 4)
2378 {
2379 matrix_oneway_arrows2.postTranslate(middle_x, middle_y);
2380 draw_canvas_s.drawBitmap(Navit.oneway_arrow, matrix_oneway_arrows2, paint);
2381 }
2382 }
2383 else
2384 {
2385 return;
2386 }
2387 }
2388 }
2389
2390 protected void draw_polyline2(Paint paint, int c[], int order, int oneway)
2391 {
2392 // Log.e("NavitGraphics", "draw_polyline2 count=" + c.length);
2393 if (!Navit.PREF_gui_oneway_arrows)
2394 {
2395 return;
2396 }
2397
2398 // Boolean normal = false;
2399 // Matrix matrix = null;
2400
2401 // this gets already checked in c-source!!
2402 //if (order > DRAW_ONEWAY_ARROWS_AT_ORDER)
2403 //{
2404
2405 // line less than 44px -> dont draw arrow!
2406 int len = (c[0] - c[2]) * (c[1] - c[3]);
2407 if (len < 0)
2408 {
2409 len = -len;
2410 }
2411
2412 if (len > (1600))
2413 {
2414 paint.setStyle(Paint.Style.STROKE);
2415 b_paint_antialias = paint.isAntiAlias();
2416 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
2417
2418 // create matrix for the manipulation
2419 matrix_oneway_arrows = new Matrix();
2420
2421 // calc this in c-code !! will be much faster!!
2422 // calc this in c-code !! will be much faster!!
2423 // calc this in c-code !! will be much faster!!
2424 double d_x = ((c[2] - c[0]));
2425 double d_y = ((c[3] - c[1]));
2426 int middle_x = c[0] + (int) (d_x / 6);
2427 int middle_y = c[1] + (int) (d_y / 6);
2428 int angle = (int) (Math.toDegrees(Math.atan2(d_y, d_x)));
2429 // calc this in c-code !! will be much faster!!
2430 // calc this in c-code !! will be much faster!!
2431 // calc this in c-code !! will be much faster!!
2432
2433 // System.out.println("arrow angle=" + angle);
2434 matrix_oneway_arrows.postTranslate(-Navit.oneway_arrow.getWidth() / 2, -Navit.oneway_arrow.getHeight() / 2);
2435
2436 //System.out.println("order=" + order);
2437 // resize the Bitmap
2438 if (order > 16)
2439 {
2440 matrix_oneway_arrows.postScale(4.5f, 4.5f);
2441 }
2442 else if (order > 14)
2443 {
2444 matrix_oneway_arrows.postScale(1.5f, 1.5f);
2445 }
2446
2447 if (oneway == 1)
2448 {
2449 // rotate the Bitmap
2450 matrix_oneway_arrows.postRotate(angle);
2451 }
2452 else if (oneway == 2)
2453 {
2454 // rotate the Bitmap
2455 matrix_oneway_arrows.postRotate(angle + 180);
2456 }
2457
2458 if (oneway > 0)
2459 {
2460 if (c.length == 4)
2461 {
2462 matrix_oneway_arrows.postTranslate(middle_x, middle_y);
2463 draw_canvas.drawBitmap(Navit.oneway_arrow, matrix_oneway_arrows, paint);
2464 }
2465
2466 paint.setAntiAlias(b_paint_antialias);
2467
2468 }
2469 else
2470 {
2471 // normal = true;
2472 return;
2473 }
2474 }
2475 //}
2476 //else
2477 //{
2478 // // normal = true;
2479 // // draw nothing, just return!
2480 // return;
2481 //}
2482
2483 //paint.setPathEffect(dashed_map_lines__no_dash);
2484 }
2485
2486 public static class draw_object
2487 {
2488 int type;
2489 Paint paint;
2490
2491 // -- 99 - "ready" signal
2492 // -- 0 -- normal line
2493 int[] c;
2494 int order;
2495 int width;
2496 // -- 2 -- tunnel/bridge line
2497 int line_type;
2498
2499 // -- 1 -- text
2500 int x;
2501 int y;
2502 String text;
2503 int size;
2504 int dx;
2505 int dy;
2506 }
2507
2508 public static class DrawLinesThread extends Thread
2509 {
2510 private Boolean running;
2511 private Boolean start_drawing;
2512 private final LinkedBlockingQueue<draw_object> queue = new LinkedBlockingQueue<draw_object>();
2513
2514 int i = 0;
2515 private draw_object l2;
2516 int thread_num;
2517 int counter = 0;
2518
2519 int m_x;
2520 int m_y;
2521 int m_x2;
2522 int m_y2;
2523 Boolean m_c = false;
2524
2525 DrawLinesThread(int thread_num)
2526 {
2527 this.thread_num = thread_num;
2528 this.running = true;
2529 this.start_drawing = false;
2530 }
2531
2532 public void motion_callback(int x, int y, int x2, int y2)
2533 {
2534 m_x = x;
2535 m_y = y;
2536 m_x2 = x2;
2537 m_y2 = y2;
2538 m_c = true;
2539 }
2540
2541 public void add_text(Paint paint, int x, int y, String text, int size, int dx, int dy)
2542 {
2543 draw_object l = new draw_object();
2544 l.type = 1; // text
2545 l.x = x;
2546 l.y = y;
2547 l.text = text;
2548 l.size = size;
2549 l.dx = dx;
2550 l.dy = dy;
2551 // -- paint --
2552 l.paint = new Paint();
2553 l.paint.setColor(paint.getColor());
2554 l.paint.setAlpha(paint.getAlpha());
2555 l.paint.setTypeface(paint.getTypeface());
2556 // l.paint.setPathEffect(paint.getPathEffect());
2557 // -- paint --
2558 queue.offer(l);
2559 }
2560
2561 public void add_lines(Paint paint, int c[], int order, int width)
2562 {
2563 draw_object l = new draw_object();
2564 l.type = 0; // line
2565 l.c = c;
2566 // -- paint --
2567 l.paint = new Paint();
2568 l.paint.setColor(paint.getColor());
2569 l.paint.setAlpha(paint.getAlpha());
2570 l.paint.setPathEffect(paint.getPathEffect());
2571 // -- paint --
2572 l.order = order;
2573 l.width = width;
2574 queue.offer(l);
2575 }
2576
2577 public void add_lines3(Paint paint, int c[], int order, int oneway)
2578 {
2579 draw_object l = new draw_object();
2580 l.type = 3; // line (one way arrows)
2581 l.c = c;
2582 // -- paint --
2583 l.paint = new Paint();
2584 l.paint.setColor(paint.getColor());
2585 l.paint.setAlpha(paint.getAlpha());
2586 l.paint.setPathEffect(paint.getPathEffect());
2587 // -- paint --
2588 l.order = order;
2589 l.width = oneway; // misuse this field here!!
2590 queue.offer(l);
2591 }
2592
2593 public void add_lines2(Paint paint, int c[], int order, int width, int line_type)
2594 {
2595 draw_object l = new draw_object();
2596
2597 if (line_type == 98)
2598 {
2599 // clear queue
2600 queue.clear();
2601 // stop drawing
2602 start_drawing = false;
2603 // and wake up from sleeping
2604 this.interrupt();
2605 return;
2606 }
2607 if (line_type == 97)
2608 {
2609 // start drawing from queue
2610 //System.out.println("start drawing");
2611 start_drawing = true;
2612 // and wake up from sleeping
2613 this.interrupt();
2614 return;
2615 }
2616 else if (line_type > 90)
2617 {
2618 l.type = line_type; // "***" signal
2619 }
2620 else
2621 {
2622 l.type = 2; // bridge/tunnel line
2623 l.c = c;
2624 l.line_type = line_type;
2625 // -- paint --
2626 l.paint = new Paint();
2627 l.paint.setColor(paint.getColor());
2628 l.paint.setAlpha(paint.getAlpha());
2629 l.paint.setPathEffect(paint.getPathEffect());
2630 // -- paint --
2631 l.order = order;
2632 l.width = width;
2633 }
2634 queue.offer(l);
2635 }
2636
2637 public void stop_me()
2638 {
2639 this.running = false;
2640 }
2641
2642 public void run()
2643 {
2644 while (this.running)
2645 {
2646
2647 if (m_c)
2648 {
2649 NavitGraphics.MotionCallback(m_x, m_y, m_x2, m_y2);
2650 m_c = false;
2651 }
2652
2653 counter = 0;
2654 // while ((start_drawing) && (queue.size() > 0))
2655 while (queue.size() > 0)
2656 {
2657 // if (counter > 20000)
2658 // {
2659 // // give a breather
2660 // try
2661 // {
2662 // Thread.sleep(10);
2663 // }
2664 // catch (InterruptedException e)
2665 // {
2666 // // e.printStackTrace();
2667 // }
2668 // counter = 0;
2669 // }
2670
2671 try
2672 {
2673 // blocking call
2674 l2 = queue.take();
2675 // non-blocking call
2676 // l2 = queue.poll();
2677 if (l2 != null)
2678 {
2679 switch (l2.type)
2680 {
2681 case 0:
2682 draw_polyline3_threads(l2.paint, l2.c, l2.order, l2.width);
2683 counter++;
2684 break;
2685 case 1:
2686 draw_text_threads(l2.paint, l2.x, l2.y, l2.text, l2.size, l2.dx, l2.dy);
2687 counter++;
2688 break;
2689 case 2:
2690 draw_polyline4_threads(l2.paint, l2.c, l2.order, l2.width, l2.line_type);
2691 counter++;
2692 break;
2693 case 3:
2694 draw_polyline2_threads(l2.paint, l2.c, l2.order, l2.width);
2695 counter++;
2696 break;
2697 case 96:
2698 //System.out.println("refresh map (layers)");
2699 // draw_map_one_shot = true;
2700 //copy_map_buffer();
2701 //draw_reset_factors = true;
2702 //view_s.postInvalidate();
2703 break;
2704 case 99:
2705 //System.out.println("refresh map OLDOLD");
2706 // draw_map_one_shot = true;
2707 copy_map_buffer();
2708 draw_reset_factors = true;
2709 //System.out.println("invalidate 015");
2710 view_s.postInvalidate();
2711 try
2712 {
2713 Thread.sleep(800);
2714 }
2715 catch (InterruptedException e)
2716 {
2717 // e.printStackTrace();
2718 }
2719 break;
2720 }
2721 }
2722 }
2723 catch (Exception e)
2724 {
2725 // e.printStackTrace();
2726 // // System.out.println("" + this.thread_num + " *ERR*");
2727 }
2728 }
2729
2730 //if (counter > 0)
2731 //{
2732 // // System.out.println("" + this.thread_num + " counter=" + counter);
2733 // view_s.postInvalidate();
2734 //}
2735
2736 try
2737 {
2738 Thread.sleep(60);
2739 }
2740 catch (InterruptedException e)
2741 {
2742 // e.printStackTrace();
2743 }
2744 }
2745 }
2746 }
2747
2748 protected void draw_polyline3___NEW(Paint paint, int c[], int order, int width)
2749 {
2750 if (dl_thread[0] == null)
2751 {
2752 int ii = 0;
2753 for (ii = 0; ii < NavitGraphics.dl_thread_max; ii++)
2754 {
2755 NavitGraphics.dl_thread[ii] = new NavitGraphics.DrawLinesThread(ii);
2756 NavitGraphics.dl_thread[ii].start();
2757 }
2758 }
2759
2760 if (dl_thread_cur + 1 < dl_thread_max)
2761 {
2762 dl_thread_cur++;
2763 }
2764 else
2765 {
2766 dl_thread_cur = 0;
2767 }
2768 dl_thread[dl_thread_cur].add_lines(paint, c, order, width);
2769 }
2770
2771 static void draw_polyline3_threads(Paint paint, int c[], int order, int width)
2772 {
2773 // Log.e("NavitGraphics","draw_polyline3_threads");
2774 paint.setStyle(Paint.Style.STROKE);
2775 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
2776 paint.setStrokeWidth(width);
2777 // *******************
2778 // *******************
2779 // ****** paint.setColor(Color.RED);
2780 // *******************
2781 // *******************
2782
2783 if (order > DRAW_MORE_DETAILS_AT_ORDER)
2784 {
2785 paint.setStyle(Paint.Style.FILL);
2786 paint.setStrokeWidth(0);
2787 draw_canvas_s.drawCircle(c[0], c[1], (width / 2), paint);
2788 }
2789 for (int i = 2; i < c.length; i += 2)
2790 {
2791 if (order > DRAW_MORE_DETAILS_AT_ORDER)
2792 {
2793 paint.setStyle(Paint.Style.FILL);
2794 paint.setStrokeWidth(0);
2795 draw_canvas_s.drawCircle(c[i], c[i + 1], (width / 2), paint);
2796 paint.setStyle(Paint.Style.STROKE);
2797 paint.setStrokeWidth(width);
2798 }
2799 draw_canvas_s.drawLine(c[i - 2], c[i - 1], c[i], c[i + 1], paint);
2800 }
2801 }
2802
2803 // draw normal polylines -> this function gets called the most!! XX-thousand times
2804 // draw normal polylines -> this function gets called the most!! XX-thousand times
2805 // draw normal polylines -> this function gets called the most!! XX-thousand times
2806 protected void draw_polyline3(int c[], int order, int width, int dashes, int r, int g, int b, int a)
2807 {
2808
2809 Paint paint2 = new Paint();
2810 paint2.setARGB(a, r, g, b);
2811 set_dashes(paint2, dashes, order);
2812
2813 //Log.e("NavitGraphics","draw_polyline3");
2814 paint2.setStyle(Paint.Style.STROKE);
2815 //b_paint_antialias = paint.isAntiAlias();
2816 paint2.setAntiAlias(Navit.PREF_use_anti_aliasing);
2817 //wsave_003 = paint.getStrokeWidth();
2818 paint2.setStrokeWidth(width);
2819
2820 if (order > DRAW_MORE_DETAILS_AT_ORDER)
2821 {
2822 paint2.setStyle(Paint.Style.FILL);
2823 paint2.setStrokeWidth(0);
2824 draw_canvas.drawCircle(c[0], c[1], (width / 2), paint2);
2825 }
2826 for (int i = 2; i < c.length; i += 2)
2827 {
2828 if (order > DRAW_MORE_DETAILS_AT_ORDER)
2829 {
2830 //if (i < (c.length - 2))
2831 //{
2832 paint2.setStyle(Paint.Style.FILL);
2833 paint2.setStrokeWidth(0);
2834 draw_canvas.drawCircle(c[i], c[i + 1], (width / 2), paint2);
2835 //}
2836 paint2.setStyle(Paint.Style.STROKE);
2837 paint2.setStrokeWidth(width);
2838 }
2839 draw_canvas.drawLine(c[i - 2], c[i - 1], c[i], c[i + 1], paint2);
2840 }
2841 //paint.setAntiAlias(b_paint_antialias);
2842 //paint.setStrokeWidth(wsave_003);
2843 }
2844
2845 // draw normal polylines -> this function gets called the most!! XX-thousand times
2846 // draw normal polylines -> this function gets called the most!! XX-thousand times
2847 // draw normal polylines -> this function gets called the most!! XX-thousand times
2848
2849 protected void draw_polyline4(int c[], int order, int width, int type, int dashes, int r, int g, int b, int a)
2850 {
2851 // type:0 -> normal line
2852 // type:1 -> underground (tunnel)
2853 // type:2 -> bridge
2854
2855 if (type > 90)
2856 {
2857 if (type == 96)
2858 {
2859 //System.out.println("refresh map (layers)");
2860 // draw_map_one_shot = true;
2861 //copy_map_buffer();
2862 //draw_reset_factors = true;
2863 //view_s.postInvalidate();
2864 }
2865 else if (type == 99)
2866 {
2867 //System.out.println("refresh map");
2868 //// draw_map_one_shot = true;
2869 //copy_map_buffer();
2870 //draw_reset_factors = true;
2871 //view_s.postInvalidate();
2872 }
2873 else if (type == 95)
2874 {
2875 //System.out.println("cancel map");
2876 // draw_map_one_shot = true;
2877 //copy_backwards_map_buffer();
2878 //draw_reset_factors = true;
2879 //view_s.postInvalidate();
2880 }
2881 return;
2882 }
2883
2884 Paint paint2 = new Paint();
2885 paint2.setARGB(a, r, g, b);
2886 set_dashes(paint2, dashes, order);
2887
2888 //b_paint_antialias = paint.isAntiAlias();
2889 paint2.setAntiAlias(Navit.PREF_use_anti_aliasing);
2890 //wsave_004 = paint.getStrokeWidth();
2891
2892 if (order <= DRAW_MORE_DETAILS_TUNNEL_BRIDGES_AT_ORDER)
2893 {
2894 type = 0;
2895 }
2896
2897 if (type == 2)
2898 {
2899 // bridge
2900 //
2901 //int csave = paint.getColor();
2902 paint2.setAlpha(120); // 0 .. 255 // 255 -> no seethru
2903 paint2.setStyle(Paint.Style.STROKE);
2904 paint2.setStrokeWidth(width + 2);
2905 // paint.setColor(Color.BLACK);
2906 if (order > DRAW_DETAIL_DASHES_AT_ORDER)
2907 {
2908 paint2.setStrokeWidth(width + 4);
2909 }
2910 for (int i = 2; i < c.length; i += 2)
2911 {
2912 draw_canvas.drawLine(c[i - 2], c[i - 1], c[i], c[i + 1], paint2);
2913 }
2914 //paint.setColor(csave);
2915
2916 // -- circles --
2917 /*
2918 * paint.setAlpha(120);
2919 * paint.setStyle(Paint.Style.FILL);
2920 * paint.setStrokeWidth(0);
2921 * draw_canvas.drawCircle(c[0], c[1], (width / 2), paint);
2922 * for (int i = 2; i < c.length; i += 2)
2923 * {
2924 * paint.setStyle(Paint.Style.FILL);
2925 * paint.setStrokeWidth(0);
2926 * draw_canvas.drawCircle(c[i], c[i + 1], (width / 2), paint);
2927 * }
2928 */
2929 // -- circles --
2930 }
2931
2932 // ---------------------------------------
2933 paint2.setStyle(Paint.Style.STROKE);
2934 paint2.setStrokeWidth(width);
2935
2936 if (type == 1)
2937 {
2938 // tunnel
2939 paint2.setAlpha(70); // 0 .. 255 // 255 -> no seethru
2940 if (order > DRAW_DETAIL_DASHES_AT_ORDER)
2941 {
2942 paint2.setPathEffect(dashed_map_lines__low);
2943 }
2944 else
2945 {
2946 paint2.setPathEffect(dashed_map_lines__high);
2947 }
2948 }
2949 else if (type == 2)
2950 {
2951 // bridge
2952 paint2.setAlpha(70); // 0 .. 255 // 255 -> no seethru
2953 }
2954
2955 paint2.setStyle(Paint.Style.STROKE);
2956 paint2.setStrokeWidth(width);
2957 for (int i = 2; i < c.length; i += 2)
2958 {
2959 draw_canvas.drawLine(c[i - 2], c[i - 1], c[i], c[i + 1], paint2);
2960 }
2961
2962 //paint.setPathEffect(dashed_map_lines__no_dash);
2963 //paint.setAntiAlias(b_paint_antialias);
2964 //paint.setStrokeWidth(wsave_004);
2965 }
2966
2967 protected void draw_polyline4__NEW(Paint paint, int c[], int order, int width, int type)
2968 {
2969 if (dl_thread[0] == null)
2970 {
2971 int ii = 0;
2972 for (ii = 0; ii < NavitGraphics.dl_thread_max; ii++)
2973 {
2974 NavitGraphics.dl_thread[ii] = new NavitGraphics.DrawLinesThread(ii);
2975 NavitGraphics.dl_thread[ii].start();
2976 }
2977 }
2978
2979 if (dl_thread_cur + 1 < dl_thread_max)
2980 {
2981 dl_thread_cur++;
2982 }
2983 else
2984 {
2985 dl_thread_cur = 0;
2986 }
2987 dl_thread[dl_thread_cur].add_lines2(paint, c, order, width, type);
2988 }
2989
2990 // for bridge or tunnel this function is used
2991 static void draw_polyline4_threads(Paint paint, int c[], int order, int width, int type)
2992 {
2993 // type:0 -> normal line
2994 // type:1 -> underground (tunnel)
2995 // type:2 -> bridge
2996
2997 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
2998
2999 if (order <= DRAW_MORE_DETAILS_TUNNEL_BRIDGES_AT_ORDER)
3000 {
3001 type = 0;
3002 }
3003
3004 if (type == 2)
3005 {
3006 // bridge
3007 //
3008 //int csave = paint.getColor();
3009 paint.setAlpha(120); // 0 .. 255 // 255 -> no seethru
3010 paint.setStyle(Paint.Style.STROKE);
3011 paint.setStrokeWidth(width + 2);
3012 // paint.setColor(Color.BLACK);
3013 if (order > DRAW_DETAIL_DASHES_AT_ORDER)
3014 {
3015 paint.setStrokeWidth(width + 4);
3016 }
3017 for (int i = 2; i < c.length; i += 2)
3018 {
3019 draw_canvas_s.drawLine(c[i - 2], c[i - 1], c[i], c[i + 1], paint);
3020 }
3021 //paint.setColor(csave);
3022
3023 // -- circles --
3024 /*
3025 * paint.setAlpha(120);
3026 * paint.setStyle(Paint.Style.FILL);
3027 * paint.setStrokeWidth(0);
3028 * draw_canvas.drawCircle(c[0], c[1], (width / 2), paint);
3029 * for (int i = 2; i < c.length; i += 2)
3030 * {
3031 * paint.setStyle(Paint.Style.FILL);
3032 * paint.setStrokeWidth(0);
3033 * draw_canvas.drawCircle(c[i], c[i + 1], (width / 2), paint);
3034 * }
3035 */
3036 // -- circles --
3037 }
3038
3039 // ---------------------------------------
3040 paint.setStyle(Paint.Style.STROKE);
3041 paint.setStrokeWidth(width);
3042
3043 if (type == 1)
3044 {
3045 // tunnel
3046 paint.setAlpha(70); // 0 .. 255 // 255 -> no seethru
3047 if (order > DRAW_DETAIL_DASHES_AT_ORDER)
3048 {
3049 paint.setPathEffect(dashed_map_lines__low);
3050 }
3051 else
3052 {
3053 paint.setPathEffect(dashed_map_lines__high);
3054 }
3055 }
3056 else if (type == 2)
3057 {
3058 // bridge
3059 paint.setAlpha(70); // 0 .. 255 // 255 -> no seethru
3060 }
3061
3062 paint.setStyle(Paint.Style.STROKE);
3063 paint.setStrokeWidth(width);
3064 for (int i = 2; i < c.length; i += 2)
3065 {
3066 draw_canvas_s.drawLine(c[i - 2], c[i - 1], c[i], c[i + 1], paint);
3067 }
3068 }
3069
3070 // for bridge or tunnel this function is used
3071
3072 protected void set_dashes(Paint paint, int variant, int order)
3073 {
3074 if (variant == 0)
3075 {
3076 paint.setPathEffect(dashed_map_lines__no_dash);
3077 return;
3078 }
3079
3080 if (order > DRAW_DETAIL_DASHES_AT_ORDER)
3081 {
3082 paint.setPathEffect(dashes__low[variant]);
3083 }
3084 else
3085 {
3086 paint.setPathEffect(dashes__high[variant]);
3087 }
3088 }
3089
3090 protected void draw_polyline_dashed(Paint paint, int c[], int order, int oneway)
3091 {
3092 // emtpy dummy for C-Code
3093 }
3094
3095 protected void draw_polyline_dashed______UNUSED(Paint paint, int c[], int order, int oneway)
3096 {
3097 //
3098 //
3099 // !! this function is unsed now !!
3100 //
3101 //
3102
3103 paint.setStyle(Paint.Style.STROKE);
3104 b_paint_antialias = paint.isAntiAlias();
3105 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
3106
3107 Boolean normal = false;
3108
3109 // create matrix for the manipulation
3110 Matrix matrix = new Matrix();
3111
3112 int middle_x = c[0] + (int) ((c[2] - c[0]) / 2);
3113 int middle_y = c[1] + (int) ((c[3] - c[1]) / 2);
3114 double d_x = ((c[2] - c[0]) / 6);
3115 double d_y = ((c[3] - c[1]) / 6);
3116 int angle = (int) (Math.toDegrees(Math.atan2(d_y, d_x)));
3117 matrix.postTranslate(-Navit.oneway_arrow.getWidth() / 2, -Navit.oneway_arrow.getHeight() / 2);
3118
3119 if (order > DRAW_ONEWAY_ARROWS_AT_ORDER)
3120 {
3121 if (oneway == 1)
3122 {
3123 if (!Navit.PREF_gui_oneway_arrows)
3124 {
3125 return;
3126 }
3127 // rotate the Bitmap
3128 matrix.postRotate(angle);
3129 }
3130 else if (oneway == 2)
3131 {
3132 if (!Navit.PREF_gui_oneway_arrows)
3133 {
3134 return;
3135 }
3136 // rotate the Bitmap
3137 matrix.postRotate(angle + 180);
3138 }
3139
3140 if (oneway > 0)
3141 {
3142 if (c.length == 4)
3143 {
3144 matrix.postTranslate(middle_x, middle_y);
3145 draw_canvas.drawBitmap(Navit.oneway_arrow, matrix, paint);
3146 }
3147 }
3148 else
3149 {
3150 normal = true;
3151 }
3152 }
3153 else
3154 {
3155 normal = true;
3156 }
3157
3158 if (normal)
3159 {
3160 // normal line
3161 if (order > DRAW_DETAIL_DASHES_AT_ORDER)
3162 {
3163 paint.setPathEffect(dashed_map_lines__low);
3164 }
3165 else
3166 {
3167 paint.setPathEffect(dashed_map_lines__high);
3168 }
3169 b_paint_path.reset();
3170 b_paint_path.moveTo(c[0], c[1]);
3171 for (int i = 2; i < c.length; i += 2)
3172 {
3173 b_paint_path.lineTo(c[i], c[i + 1]);
3174 }
3175
3176 draw_canvas.drawPath(b_paint_path, paint);
3177 paint.setPathEffect(dashed_map_lines__no_dash);
3178 }
3179 paint.setAntiAlias(b_paint_antialias);
3180 }
3181
3182 protected void draw_polygon(Paint paint, int c[])
3183 {
3184 paint.setStyle(Paint.Style.FILL);
3185 b_paint_antialias = paint.isAntiAlias();
3186 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
3187 b_paint_path.reset();
3188 b_paint_path.moveTo(c[0], c[1]);
3189 for (int i = 2; i < c.length; i += 2)
3190 {
3191 b_paint_path.lineTo(c[i], c[i + 1]);
3192 }
3193 draw_canvas.drawPath(b_paint_path, paint);
3194 paint.setAntiAlias(b_paint_antialias);
3195 }
3196
3197 protected void draw_polygon2(Paint paint, int c[], int order, int oneway)
3198 {
3199 paint.setStyle(Paint.Style.FILL);
3200 b_paint_antialias = paint.isAntiAlias();
3201 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
3202 b_paint_path.reset();
3203 b_paint_path.moveTo(c[0], c[1]);
3204 for (int i = 2; i < c.length; i += 2)
3205 {
3206 b_paint_path.lineTo(c[i], c[i + 1]);
3207 }
3208
3209 if (order > DRAW_ONEWAY_ARROWS_AT_ORDER)
3210 {
3211 if (oneway == 1)
3212 {
3213 paint.setColor(Color.RED);
3214 if (!Navit.PREF_gui_oneway_arrows)
3215 {
3216 return;
3217 }
3218 }
3219 else if (oneway == 2)
3220 {
3221 paint.setColor(Color.BLUE);
3222 if (!Navit.PREF_gui_oneway_arrows)
3223 {
3224 return;
3225 }
3226 }
3227 }
3228
3229 draw_canvas.drawPath(b_paint_path, paint);
3230 paint.setAntiAlias(b_paint_antialias);
3231 }
3232
3233 protected void draw_rectangle(Paint paint, int x, int y, int w, int h)
3234 {
3235 //Log.e("NavitGraphics","draw_rectangle");
3236 Rect r = new Rect(x, y, x + w, y + h);
3237 paint.setStyle(Paint.Style.FILL);
3238 b_paint_antialias = paint.isAntiAlias();
3239 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
3240 //paint.setStrokeWidth(0);d
3241 draw_canvas.drawRect(r, paint);
3242 paint.setAntiAlias(b_paint_antialias);
3243 }
3244
3245 protected void draw_circle(Paint paint, int x, int y, int r)
3246 {
3247 // Log.e("NavitGraphics", "draw_circle " + x + " " + y + " " + r);
3248 // float fx = x;
3249 // float fy = y;
3250 // float fr = r / 2;
3251 paint.setStyle(Paint.Style.STROKE);
3252 b_paint_antialias = paint.isAntiAlias();
3253 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
3254 draw_canvas.drawCircle(x, y, r / 2, paint);
3255 paint.setAntiAlias(b_paint_antialias);
3256 }
3257
3258 protected void draw_text__NEW(Paint paint, int x, int y, String text, int size, int dx, int dy)
3259 {
3260 if (dl_thread[0] == null)
3261 {
3262 int ii = 0;
3263 for (ii = 0; ii < NavitGraphics.dl_thread_max; ii++)
3264 {
3265 NavitGraphics.dl_thread[ii] = new NavitGraphics.DrawLinesThread(ii);
3266 NavitGraphics.dl_thread[ii].start();
3267 }
3268 }
3269
3270 if (dl_thread_cur + 1 < dl_thread_max)
3271 {
3272 dl_thread_cur++;
3273 }
3274 else
3275 {
3276 dl_thread_cur = 0;
3277 }
3278
3279 // FONT ------------------
3280 // FONT ------------------
3281 if (Navit.PREF_use_custom_font == true)
3282 {
3283 if (paint.getTypeface() == null)
3284 {
3285 try
3286 {
3287 paint.setTypeface(Navit.NavitStreetnameFont);
3288 //System.out.println("Calling setTypeface");
3289 }
3290 catch (Exception e)
3291 {
3292 //e.printStackTrace();
3293 }
3294 }
3295 }
3296 else
3297 {
3298 if (paint.getTypeface() != null)
3299 {
3300 paint.setTypeface(null);
3301 }
3302 }
3303 // FONT ------------------
3304 // FONT ------------------
3305
3306 dl_thread[dl_thread_cur].add_text(paint, x, y, text, size, dx, dy);
3307 }
3308
3309 static void draw_text_threads(Paint paint, int x, int y, String text, int size, int dx, int dy)
3310 {
3311 // float fx = x;
3312 // float fy = y;
3313 //Log.e("NavitGraphics","Text size "+size + " vs " + paint.getTextSize());
3314 if (Navit.PREF_map_font_size != 2)
3315 {
3316 if (Navit.PREF_map_font_size == 3)
3317 {
3318 // large
3319 paint.setTextSize((int) ((size / 15) * 1.4));
3320 }
3321 else if (Navit.PREF_map_font_size == 4)
3322 {
3323 // extra large
3324 paint.setTextSize((int) ((size / 15) * 1.7));
3325 }
3326 else if (Navit.PREF_map_font_size == 5)
3327 {
3328 // extra large
3329 paint.setTextSize((int) ((size / 15) * 2.2));
3330 }
3331 else if (Navit.PREF_map_font_size == 1)
3332 {
3333 // small
3334 paint.setTextSize((int) ((size / 15) * 0.72));
3335 }
3336 else
3337 {
3338 // other? use normal size
3339 paint.setTextSize(size / 15);
3340 }
3341 }
3342 else
3343 {
3344 // normal size
3345 paint.setTextSize(size / 15);
3346 }
3347 paint.setStyle(Paint.Style.FILL);
3348 // FONT ------------------
3349 // FONT ------------------
3350 if (Navit.PREF_use_custom_font == true)
3351 {
3352 if (paint.getTypeface() == null)
3353 {
3354 try
3355 {
3356 paint.setTypeface(Navit.NavitStreetnameFont);
3357 //System.out.println("Calling setTypeface");
3358 }
3359 catch (Exception e)
3360 {
3361 //e.printStackTrace();
3362 }
3363 }
3364 }
3365 else
3366 {
3367 if (paint.getTypeface() != null)
3368 {
3369 paint.setTypeface(null);
3370 }
3371 }
3372 // FONT ------------------
3373 // FONT ------------------
3374 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
3375 if (dx == 0x10000 && dy == 0)
3376 {
3377 draw_canvas_s.drawText(text, x, y, paint);
3378 }
3379 else
3380 {
3381 Path b_paint_path_ = new Path();
3382 b_paint_path_.reset();
3383 b_paint_path_.moveTo(x, y);
3384 b_paint_path_.rLineTo(dx, dy);
3385 paint.setTextAlign(android.graphics.Paint.Align.LEFT);
3386 draw_canvas_s.drawTextOnPath(text, b_paint_path_, 0, 0, paint);
3387 }
3388 }
3389
3390 protected void draw_text(Paint paint, int x, int y, String text, int size, int dx, int dy)
3391 {
3392 // float fx = x;
3393 // float fy = y;
3394 //Log.e("NavitGraphics","Text size "+size + " vs " + paint.getTextSize());
3395 if (Navit.PREF_map_font_size != 2)
3396 {
3397 if (Navit.PREF_map_font_size == 3)
3398 {
3399 // large
3400 paint.setTextSize((int) ((size / 15) * 1.4));
3401 }
3402 else if (Navit.PREF_map_font_size == 4)
3403 {
3404 // extra large
3405 paint.setTextSize((int) ((size / 15) * 1.7));
3406 }
3407 else if (Navit.PREF_map_font_size == 5)
3408 {
3409 // extra large
3410 paint.setTextSize((int) ((size / 15) * 2.2));
3411 }
3412 else if (Navit.PREF_map_font_size == 1)
3413 {
3414 // small
3415 paint.setTextSize((int) ((size / 15) * 0.72));
3416 }
3417 else
3418 {
3419 // other? use normal size
3420 paint.setTextSize(size / 15);
3421 }
3422 }
3423 else
3424 {
3425 // normal size
3426 paint.setTextSize(size / 15);
3427 }
3428 paint.setStyle(Paint.Style.FILL);
3429 // FONT ------------------
3430 // FONT ------------------
3431 if (Navit.PREF_use_custom_font == true)
3432 {
3433 if (paint.getTypeface() == null)
3434 {
3435 try
3436 {
3437 paint.setTypeface(Navit.NavitStreetnameFont);
3438 //System.out.println("Calling setTypeface");
3439 }
3440 catch (Exception e)
3441 {
3442 //e.printStackTrace();
3443 }
3444 }
3445 }
3446 else
3447 {
3448 if (paint.getTypeface() != null)
3449 {
3450 paint.setTypeface(null);
3451 }
3452 }
3453 // FONT ------------------
3454 // FONT ------------------
3455 b_paint_antialias = paint.isAntiAlias();
3456 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
3457 if (dx == 0x10000 && dy == 0)
3458 {
3459 draw_canvas.drawText(text, x, y, paint);
3460 }
3461 else
3462 {
3463 b_paint_path.reset();
3464 b_paint_path.moveTo(x, y);
3465 b_paint_path.rLineTo(dx, dy);
3466 paint.setTextAlign(android.graphics.Paint.Align.LEFT);
3467 draw_canvas.drawTextOnPath(text, b_paint_path, 0, 0, paint);
3468 }
3469 paint.setAntiAlias(b_paint_antialias);
3470 }
3471
3472 protected void draw_image(Paint paint, int x, int y, Bitmap bitmap)
3473 {
3474 //Log.e("NavitGraphics","draw_image");
3475 // float fx = x;
3476 // float fy = y;
3477 draw_canvas.drawBitmap(bitmap, x, y, paint);
3478 }
3479
3480 protected void draw_bigmap(int yaw, int order, float clng, float clat, int x_, int y_, int mcx, int mcy, int px_, int py_, int valid)
3481 {
3482 if (Navit.bigmap_bitmap != null)
3483 {
3484 // input: x,y --> screen coords of lat=0,lng=0 point!!
3485 /*
3486 * int scx = (int) (draw_canvas.getWidth() / 2);
3487 * int scy = (int) (draw_canvas.getHeight() / 2);
3488 * int px = px_;
3489 * int py = py_;
3490 */
3491
3492 // calculate the scale
3493 float scaleWidth = 1;
3494 float scaleHeight = 1;
3495
3496 /*
3497 * if (order == -1)
3498 * {
3499 * scaleWidth = scaleHeight = 0.8f * (1.5f / draw_factor);
3500 * }
3501 * else if (order == -2)
3502 * {
3503 * scaleWidth = scaleHeight = (float) ((1 / 2f) * 0.8f) * (1.5f / draw_factor);
3504 * }
3505 */
3506
3507 //System.out.println("bigmap order:" + (long) (order * 100));
3508 scaleWidth = scaleHeight = BIGMAP_FACTOR / (float) order * (1.5f / draw_factor);
3509 //System.out.println("draw_factor:" + draw_factor);
3510
3511 if ((scaleWidth == 0) || (scaleHeight == 0))
3512 {
3513 //System.out.println(" " + scaleWidth + " " + scaleHeight + " " + order);
3514 return;
3515 }
3516
3517 if (valid == 1)
3518 {
3519 //System.out.println(" px " + px + " py " + py);
3520 }
3521
3522 // create a matrix for the manipulation
3523 Matrix matrix = new Matrix();
3524 int half_x = (int) (Navit.bigmap_bitmap.getWidth() / 2);
3525 int half_y = (int) (Navit.bigmap_bitmap.getHeight() / 2);
3526 matrix.setScale(scaleWidth, scaleHeight, half_x, half_y);
3527
3528 int usedMegs;
3529 String usedMegsString;
3530 // int usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
3531 // String usedMegsString = String.format("00 - Memory Used: %d MB", usedMegs);
3532 // System.out.println("" + usedMegsString);
3533
3534 // recreate the new Bitmap
3535 try
3536 {
3537 bigmap_bitmap_temp = Bitmap.createBitmap(Navit.bigmap_bitmap, 0, 0, Navit.bigmap_bitmap.getWidth(), Navit.bigmap_bitmap.getHeight(), matrix, true);
3538 }
3539 catch (OutOfMemoryError e)
3540 {
3541 usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
3542 usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
3543 System.out.println("" + usedMegsString);
3544 System.out.println("@@@@@@@@ out of VM Memory @@@@@@@@");
3545 System.gc();
3546 usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
3547 usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
3548 System.out.println("" + usedMegsString);
3549
3550 try
3551 {
3552 bigmap_bitmap_temp = Bitmap.createBitmap(Navit.bigmap_bitmap, 0, 0, Navit.bigmap_bitmap.getWidth(), Navit.bigmap_bitmap.getHeight(), matrix, true);
3553 }
3554 catch (OutOfMemoryError e2)
3555 {
3556 e2.printStackTrace();
3557 return;
3558 }
3559 }
3560
3561 if (bigmap_bitmap_temp == null)
3562 {
3563 return;
3564 }
3565 else
3566 {
3567 try
3568 {
3569 if (bigmap_bitmap_temp.getWidth() <= 0)
3570 {
3571 return;
3572 }
3573 else if (bigmap_bitmap_temp.getHeight() <= 0)
3574 {
3575 return;
3576 }
3577 }
3578 catch (Exception e)
3579 {
3580 e.printStackTrace();
3581 return;
3582 }
3583 }
3584 // usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
3585 // usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
3586 // System.out.println("" + usedMegsString);
3587
3588 float top = 85.2f;
3589 //float bottom = -85.2f;
3590 float left = -180f;
3591 //float right = 180f;
3592
3593 String left_top_on_screen_string = CallbackGeoCalc(2, top, left);
3594 String tmp[] = left_top_on_screen_string.split(":", 2);
3595 int pixel_top_left_x = Integer.parseInt(tmp[0]);
3596 int pixel_top_left_y = Integer.parseInt(tmp[1]);
3597
3598 //float p_karte_pixel_x;
3599 //float p_karte_pixel_y;
3600
3601 // pixel point of 0/0 geo coord
3602 /*
3603 * p_karte_pixel_x = bigmap_bitmap_temp.getWidth() / 2;
3604 * p_karte_pixel_y = bigmap_bitmap_temp.getHeight() / 2;
3605 */
3606
3607 /*
3608 * if (!loc_12_valid)
3609 * {
3610 * // initialize them the first time
3611 * loc_1_x = x_;
3612 * loc_1_y = y_;
3613 * loc_2_x = mcx;
3614 * loc_2_y = mcy;
3615 * loc_12_valid = true;
3616 * }
3617 *
3618 * if ((loc_1_x == x_) && (loc_1_y == y_))
3619 * {
3620 * p_karte_pixel_x = p_karte_pixel_x - (loc_2_x - mcx);
3621 * p_karte_pixel_y = p_karte_pixel_y - (loc_2_y - mcy);
3622 * // System.out.println("SSSSSSSS SSSSSSSS");
3623 * }
3624 * else
3625 * {
3626 * loc_2_x = mcx;
3627 * loc_2_y = mcy;
3628 * }
3629 *
3630 * loc_1_x = x_;
3631 * loc_1_y = y_;
3632 */
3633
3634 //int ssschx = (int) (x_ - p_karte_pixel_x);
3635 //int ssschy = (int) (y_ - p_karte_pixel_y);
3636
3637 // fill canvas with ocean color
3638 draw_canvas.drawColor(Color.parseColor("#82C8EA"));
3639
3640 //int green_dot_x = scx;
3641 //int green_dot_y = scy;
3642 loc_dot_valid = true;
3643
3644 //int rotation_point_x = scx;
3645 //int rotation_point_y = scy;
3646
3647 /*
3648 * if (valid == 1)
3649 * {
3650 * green_dot_x = px;
3651 * green_dot_y = py;
3652 *
3653 * rotation_point_x = px;
3654 * rotation_point_y = py;
3655 * }
3656 */
3657 //
3658 draw_canvas.save(); // SAVE
3659 //
3660 // *********** draw_canvas.translate(green_dot_x, green_dot_y);
3661 draw_canvas.translate(pixel_top_left_x, pixel_top_left_y);
3662 draw_canvas.rotate(yaw, 0, 0);
3663
3664 draw_canvas.drawBitmap(bigmap_bitmap_temp, 0, 0, null);
3665
3666 //
3667 draw_canvas.restore(); // RESTORE
3668 //
3669 bigmap_bitmap_temp.recycle();
3670 bigmap_bitmap_temp = null;
3671 }
3672 }
3673
3674 public static void send_osd_values(String id, String text1, String text2, String text3, int i1, int i2, int i3, int i4, float f1, float f2, float f3)
3675 {
3676 //System.out.println("NavitOSDJava:" + id + " " + text1 + " " + text2 + " " + text3 + " " + i1 + " " + i2 + " " + i3 + " " + i4 + " " + f1 + " " + f2 + " " + f3);
3677 //System.out.println("NavitOSDJava:" + last_paint_OSD);
3678 Boolean needed_value = false;
3679 try
3680 {
3681 if (id.equals("scale"))
3682 {
3683 if (text1 != null)
3684 {
3685 if (text1.equals("draw_rectangle1"))
3686 {
3687 Navit.OSD_scale.base = i1;
3688 }
3689 else if (text1.equals("draw_rectangle2"))
3690 {
3691 Navit.OSD_scale.scale_valid = true;
3692 Navit.OSD_scale.var = i1;
3693 }
3694 else if (text1.equals("draw_text"))
3695 {
3696 Navit.OSD_scale.scale_valid = true;
3697 Navit.OSD_scale.scale_text = text2;
3698 }
3699 }
3700 needed_value = true;
3701 }
3702 else if (id.equals("osd_text_draw"))
3703 {
3704 if ((text1 != null) && (text1.equals("draw_text")))
3705 {
3706 if ((text2 != null) && (text2.equals("navigation:nav_position:destination_time")))
3707 {
3708 // text3 = 20:38 --> ETA time (+1 means next day!)
3709 // System.out.println("destination_time:" + text3);
3710 Navit.OSD_route_001.arriving_time = text3;
3711 Navit.OSD_route_001.arriving_time_valid = true;
3712 needed_value = true;
3713 }
3714 else if ((text2 != null) && (text2.equals("navigation:nav_position:destination_length")))
3715 {
3716 // text3 = 575m -> driving distance to target
3717 // System.out.println("destination_length:" + text3);
3718 Navit.OSD_route_001.driving_distance_to_target = text3;
3719 Navit.OSD_route_001.driving_distance_to_target_valid = true;
3720 needed_value = true;
3721 }
3722 else if ((text2 != null) && (text2.length() > 10) && (text2.substring(0, 11).equals("navigation:")))
3723 {
3724 String[] tmp_string = text2.split(":", 3);
3725 if (tmp_string.length == 3)
3726 {
3727 if (tmp_string[2].equals("length"))
3728 {
3729 // "navigation:******:length"
3730 // text3 = 250m --> when to do the next turn
3731 //System.out.println("nextturn_distance:" + text3);
3732 Navit.OSD_nextturn.nextturn_distance = text3;
3733 Navit.OSD_nextturn.nextturn_distance_valid = true;
3734 // we need to paint the OSD in any case
3735 last_paint_OSD = -1;
3736 needed_value = true;
3737 }
3738 else if (tmp_string[2].equals("street_name_systematic"))
3739 {
3740 // "navigation:******:street_name_systematic"
3741 //System.out.println("nextturn_streetname_systematic:" + text3);
3742 Navit.OSD_nextturn.nextturn_streetname_systematic = text3;
3743 needed_value = true;
3744 }
3745 else if (tmp_string[2].equals("street_name"))
3746 {
3747 // "navigation:******:street_name"
3748 //System.out.println("nextturn_streetname:" + text3);
3749 Navit.OSD_nextturn.nextturn_streetname = text3;
3750 needed_value = true;
3751 }
3752 }
3753 }
3754 else if ((text2 != null) && (text2.length() > 8) && (text2.substring(0, 9).equals("tracking:")))
3755 {
3756 if (NavitGraphics.navit_route_status == 0)
3757 {
3758 if (text2.equals("tracking:street_name:"))
3759 {
3760 //System.out.println("t2" + text2 + text3);
3761 Navit.OSD_nextturn.nextturn_streetname = text3;
3762 last_paint_OSD = -1;
3763 needed_value = true;
3764 }
3765 else if (text2.equals("tracking:street_name_systematic:"))
3766 {
3767 //System.out.println("t1" + text2 + text3);
3768 Navit.OSD_nextturn.nextturn_streetname_systematic = text3;
3769 needed_value = true;
3770 }
3771 }
3772 }
3773 else
3774 {
3775 // Log.e("NavitOSDJava", "" + id + " " + text1 + " " + text2 + " " + text3 + " " + i1 + " " + i2 + " " + i3 + " " + i4 + " " + f1 + " " + f2 + " " + f3);
3776 }
3777 }
3778 }
3779 else if (id.equals("nav_next_turn"))
3780 {
3781 if ((text1 != null) && (text1.equals("draw_image1")))
3782 {
3783 //System.out.println("tttt222:" + text2);
3784 // text2 = res/drawable/xx.png
3785 if ((text2 == null) || (text2.equals("")))
3786 {
3787 Navit.OSD_nextturn.nextturn_image_valid = false;
3788 Navit.OSD_nextturn.nextturn_image.recycle();
3789 }
3790 if (!Navit.OSD_nextturn.nextturn_image_filename.equals(text2))
3791 {
3792 // only if image is different from current image
3793 Navit.OSD_nextturn.nextturn_image_filename = text2;
3794 Navit.OSD_nextturn.nextturn_image_filename_valid = true;
3795 if (Navit.OSD_nextturn.nextturn_image != null)
3796 {
3797 try
3798 {
3799 Navit.OSD_nextturn.nextturn_image.recycle();
3800 }
3801 catch (Exception e)
3802 {
3803 }
3804 }
3805 // System.out.println("load image: " + Navit.OSD_nextturn.nextturn_image_filename);
3806 String x = Navit.OSD_nextturn.nextturn_image_filename.substring(13).replace(".png", "");
3807 // System.out.println("load image: " + x);
3808 int ResId = Navit.res_.getIdentifier("com.zoffcc.applications.zanavi:drawable/" + x, null, null);
3809 // System.out.println("ResId: " + ResId);
3810 Navit.OSD_nextturn.nextturn_image = BitmapFactory.decodeResource(Navit.res_, ResId);
3811 Navit.OSD_nextturn.nextturn_image_valid = true;
3812 }
3813 }
3814 needed_value = true;
3815 }
3816 else if (id.equals("compass"))
3817 {
3818 if ((text1 != null) && (text1.equals("text_and_dst_angle")))
3819 {
3820 if ((text2 == null) || (text2.equals("")))
3821 {
3822 Navit.OSD_compass.direct_distance_to_target = "";
3823 Navit.OSD_compass.direct_distance_to_target_valid = false;
3824 }
3825 else
3826 {
3827 Navit.OSD_compass.direct_distance_to_target = text2;
3828 Navit.OSD_compass.direct_distance_to_target_valid = true;
3829 }
3830 try
3831 {
3832 // Navit.OSD_compass.angle_target = Float.parseFloat(text3);
3833 Navit.OSD_compass.angle_target = i1;
3834 Navit.OSD_compass.angle_target_valid = true;
3835 }
3836 catch (Exception e)
3837 {
3838 //e.printStackTrace();
3839 }
3840 needed_value = true;
3841 }
3842 else if ((text1 != null) && (text1.equals("direction")))
3843 {
3844 try
3845 {
3846 // Navit.OSD_compass.angle_north = Float.parseFloat(text2);
3847 Navit.OSD_compass.angle_north = i1;
3848 Navit.OSD_compass.angle_north_valid = true;
3849 needed_value = true;
3850 }
3851 catch (Exception e)
3852 {
3853 //e.printStackTrace();
3854
3855 }
3856 }
3857 }
3858 }
3859 catch (Exception x)
3860 {
3861 x.printStackTrace();
3862 }
3863
3864 if (!needed_value)
3865 {
3866 // we got values that we dont use
3867 //System.out.println("xx paint 0 xx");
3868 return;
3869 }
3870
3871 if (NavitGraphics.MAP_DISPLAY_OFF)
3872 {
3873 // paint only every 800ms
3874 if ((last_paint_OSD + 800) < System.currentTimeMillis())
3875 {
3876 try
3877 {
3878 last_paint_OSD = System.currentTimeMillis();
3879 //System.out.println("xx paint 1 xx");
3880 NavitOSDJava.draw_real();
3881 //NavitAOSDJava.postInvalidate();
3882 }
3883 catch (Exception r)
3884 {
3885 //r.printStackTrace();
3886 }
3887 }
3888 }
3889 else
3890 {
3891 // paint only every 600ms
3892 if ((last_paint_OSD + 1200) < System.currentTimeMillis())
3893 {
3894 try
3895 {
3896 last_paint_OSD = System.currentTimeMillis();
3897 //System.out.println("xx paint 2 xx");
3898 NavitOSDJava.draw_real();
3899 //NavitAOSDJava.postInvalidate();
3900 }
3901 catch (Exception r)
3902 {
3903 //r.printStackTrace();
3904 }
3905 }
3906 }
3907 }
3908
3909 static void copy_map_buffer()
3910 {
3911 // stop any smooth drawing/moving first!
3912 Global_SmoothDrawing_stop = true;
3913
3914 //System.out.println("DO__DRAW:Java:reset GLOBAL factors");
3915 Global_Map_TransX = 0;
3916 Global_Map_TransY = 0;
3917 Global_Map_Rotationangle = 0f;
3918 Global_Map_Zoomfactor = 1.0f;
3919 try
3920 {
3921 draw_canvas_screen_s.drawBitmap(draw_bitmap_s, 0, 0, null);
3922
3923 if (Navit.PREF_show_route_rects)
3924 {
3925 // --- draw debug route rects ----
3926 int i3 = 0;
3927 for (i3 = 0; i3 < route_rects.size(); i3++)
3928 {
3929 route_rect rr = route_rects.get(i3);
3930 Paint paint78 = new Paint();
3931 if (rr.order == -99)
3932 {
3933 // rectangle to just include all waypoints
3934 paint78.setColor(Color.RED);
3935 }
3936 else if (rr.order == 8)
3937 {
3938 // rectangle around every waypoint with low detail (order = 8)
3939 paint78.setColor(Color.GREEN);
3940 }
3941 else if (rr.order == 18)
3942 {
3943 // rectangle around every waypoint with high detail (order = 18)
3944 paint78.setColor(Color.MAGENTA);
3945 }
3946 else if (rr.order == 4)
3947 {
3948 // rectangles ??
3949 paint78.setColor(Color.BLUE);
3950 }
3951 else if (rr.order == 6)
3952 {
3953 // rectangles ??
3954 paint78.setColor(Color.CYAN);
3955 }
3956 else if (rr.order == 7)
3957 {
3958 // rectangles ??
3959 paint78.setColor(Color.YELLOW);
3960 }
3961
3962 paint78.setStrokeWidth(15);
3963 paint78.setStyle(Style.STROKE);
3964
3965 String left_top_on_screen_string = CallbackGeoCalc(11, rr.x1, rr.y1);
3966 String tmp[] = left_top_on_screen_string.split(":", 2);
3967 int xx1 = Integer.parseInt(tmp[0]);
3968 int yy1 = Integer.parseInt(tmp[1]);
3969 //System.out.println(" " + xx1 + "," + yy1);
3970
3971 left_top_on_screen_string = CallbackGeoCalc(11, rr.x2, rr.y2);
3972 tmp = left_top_on_screen_string.split(":", 2);
3973 int xx2 = Integer.parseInt(tmp[0]);
3974 int yy2 = Integer.parseInt(tmp[1]);
3975 //System.out.println(" " + xx2 + "," + yy2);
3976
3977 // draw the route rectanlge
3978 draw_canvas_screen_s.drawRect(xx1, yy1, xx2, yy2, paint78);
3979 }
3980 // --- draw debug route rects ----
3981 }
3982 }
3983 catch (Exception e)
3984 {
3985 // if screen is rotated, bitmaps are not valid, and this would crash
3986 // find a better solution later!!
3987 }
3988 }
3989
3990 static void copy_backwards_map_buffer()
3991 {
3992 // draw_canvas_screen_s.drawColor(Color.parseColor("#FEF9EE")); // fill with yellow-ish bg color
3993
3994 //if (ZOOM_MODE_ACTIVE)
3995 //{
3996 // draw_canvas_screen_s.save();
3997 // draw_canvas_screen_s.scale(ZOOM_MODE_SCALE, ZOOM_MODE_SCALE, touch_now_center.x, touch_now_center.y);
3998 //}
3999 //draw_canvas_screen_s.drawBitmap(draw_bitmap_screen_s, pos_x, pos_y, null);
4000 //if (ZOOM_MODE_ACTIVE)
4001 //{
4002 // draw_canvas_screen_s.restore();
4003 //}
4004 }
4005
4006 protected void draw_mode(int mode)
4007 {
4008 //Log.e("NavitGraphics", "draw_mode mode=" + mode + " parent_graphics=" + String.valueOf(parent_graphics));
4009
4010 if (mode == 1 || (mode == 0 && parent_num != 0))
4011 {
4012 draw_bitmap.eraseColor(0);
4013 }
4014
4015 //if ((parent_num != 0) && ((mode == 2) || (mode == 4)))
4016 //{
4017 // vehicle graphics overlay
4018 // copy_map_buffer();
4019 // Paint paint43 = new Paint();
4020 // paint43.setStyle(Paint.Style.STROKE);
4021 // paint43.setAntiAlias(Navit.PREF_use_anti_aliasing);
4022 // paint43.setStrokeWidth(12);
4023 // paint43.setColor(Color.RED);
4024 // draw_canvas.drawLine(0, 0, 50, 50, paint43);
4025 //}
4026
4027 }
4028
4029 protected void draw_drag(int x, int y)
4030 {
4031 // Log.e("NavitGraphics","draw_drag"+pos_x+" "+pos_y+" "+x+" "+y);
4032 pos_x = x;
4033 pos_y = y;
4034 }
4035
4036 protected void overlay_disable(int disable)
4037 {
4038 // UNUSED ------
4039
4040 //Log.e("NavitGraphics","overlay_disable");
4041 // assume we are NOT in map view mode!
4042 // -> always in map mode now !!!! # in_map = false;
4043
4044 // check if overlay has been initialized yet
4045 //if (NavitAOverlay != null)
4046 //{
4047 // NavitAOverlay.hide_bubble();
4048 //}
4049
4050 // overlay_disabled = disable;
4051 }
4052
4053 protected void overlay_resize(int x, int y, int w, int h, int alpha, int wraparond)
4054 {
4055 // UNUSED ------
4056
4057 //Log.e("NavitGraphics", "overlay_resize: " + x + "" + y + "" + w + "" + h);
4058 //pos_x = x;
4059 //pos_y = y;
4060 }
4061
4062 public static String getLocalizedString(String text)
4063 {
4064 String ret = CallbackLocalizedString(text);
4065 //Log.e("NavitGraphics", "callback_handler -> lozalized string=" + ret);
4066 return ret;
4067 }
4068
4069 static String __n_distance(int i)
4070 {
4071 String ret = "";
4072 if ((i > 0) && (i < 10))
4073 {
4074 ret = __get_distance(i, 0);
4075 }
4076 else
4077 {
4078 switch (i)
4079 {
4080 case 10:
4081 ret = "";
4082 break;
4083 case 11:
4084 ret = "soon";
4085 break;
4086 case 12:
4087 ret = "after %i roads";
4088 break;
4089 case 13:
4090 ret = "now";
4091 break;
4092 default:
4093 ret = "";
4094 }
4095 }
4096 return ret;
4097 }
4098
4099 static String __get_distance(int i, int is_length)
4100 {
4101 String ret = "";
4102
4103 if (is_length == 0)
4104 {
4105 switch (i)
4106 {
4107 case 1:
4108 ret = "in %d m";
4109 break;
4110 case 2:
4111 ret = "in %d feet";
4112 break;
4113 case 3:
4114 ret = "in %d meters";
4115 break;
4116 case 4:
4117 ret = "in %d.%d miles";
4118 break;
4119 case 5:
4120 ret = "in %d.%d kilometers";
4121 break;
4122 case 6:
4123 ret = "in one mile";
4124 break;
4125 case 7:
4126 ret = "in %d miles";
4127 break;
4128 case 8:
4129 ret = "in one kilometer";
4130 break;
4131 case 9:
4132 ret = "in %d kilometer";
4133 break;
4134 default:
4135 ret = "";
4136 }
4137 }
4138 else
4139 {
4140 switch (i)
4141 {
4142 case 1:
4143 ret = "%d m";
4144 break;
4145 case 2:
4146 ret = "%d feet";
4147 break;
4148 case 3:
4149 ret = "%d meters";
4150 break;
4151 case 4:
4152 ret = "%d.%d miles";
4153 break;
4154 case 5:
4155 ret = "%d.%d kilometers";
4156 break;
4157 case 6:
4158 ret = "one mile";
4159 break;
4160 case 7:
4161 ret = "%d miles";
4162 break;
4163 case 8:
4164 ret = "one kilometer";
4165 break;
4166 case 9:
4167 ret = "%d kilometer";
4168 break;
4169 default:
4170 ret = "";
4171 }
4172 }
4173
4174 return ret;
4175 }
4176
4177 static String __direction(int i)
4178 {
4179 String ret = "";
4180
4181 switch (i)
4182 {
4183 case 1:
4184 ret = "left";
4185 break;
4186 case 2:
4187 ret = "right";
4188 break;
4189 default:
4190 ret = "";
4191 }
4192
4193 return ret;
4194 }
4195
4196 static String __strength(int i)
4197 {
4198 String ret = "";
4199
4200 switch (i)
4201 {
4202 case 1:
4203 ret = "";
4204 break;
4205 case 2:
4206 ret = "slight ";
4207 break;
4208 case 3:
4209 ret = "hard ";
4210 break;
4211 case 4:
4212 ret = "really hard ";
4213 break;
4214 default:
4215 ret = "";
4216 }
4217
4218 return ret;
4219 }
4220
4221 static String __navigation_item_destination(int i)
4222 {
4223 String ret = "";
4224
4225 switch (i)
4226 {
4227 case 1:
4228 ret = "";
4229 break;
4230 case 2:
4231 ret = "exit";
4232 break;
4233 case 3:
4234 ret = "into the ramp";
4235 break;
4236 case 4:
4237 ret = "%sinto the street %s%s%s";
4238 break;
4239 case 5:
4240 ret = "%sinto the %s%s%s|male form";
4241 break;
4242 case 6:
4243 ret = "%sinto the %s%s%s|female form";
4244 break;
4245 case 7:
4246 ret = "%sinto the %s%s%s|neutral form";
4247 break;
4248 case 8:
4249 ret = "%sinto the %s";
4250 break;
4251 default:
4252 ret = "";
4253 }
4254
4255 return ret;
4256 }
4257
4258 public static void generate_all_speech_commands()
4259 {
4260
4261 try
4262 {
4263 NavitGraphics.NavitMsgTv2_.setVisibility(View.VISIBLE);
4264 NavitGraphics.NavitMsgTv2_.setEnabled(true);
4265 }
4266 catch (Exception e)
4267 {
4268 e.printStackTrace();
4269 }
4270
4271 String a = null;
4272 String b = null;
4273 String a1 = null;
4274 String b1 = null;
4275 String c = null;
4276 String c1 = null;
4277 String d = null;
4278 String d1 = null;
4279 int j;
4280 //
4281 //
4282 //
4283 a = "When possible, please turn around";
4284 a1 = CallbackLocalizedString(a);
4285 NavitGraphics.NavitMsgTv2_.append(a + "\n");
4286 NavitGraphics.NavitMsgTv2_.append(a1 + "\n");
4287 System.out.println(a);
4288 System.out.println(a1);
4289 //
4290 a = "Enter the roundabout soon";
4291 a1 = CallbackLocalizedString(a);
4292 NavitGraphics.NavitMsgTv2_.append(a + "\n");
4293 NavitGraphics.NavitMsgTv2_.append(a1 + "\n");
4294 System.out.println(a);
4295 System.out.println(a1);
4296 //
4297 a = "then you have reached your destination.";
4298 a1 = CallbackLocalizedString(a);
4299 NavitGraphics.NavitMsgTv2_.append(a + "\n");
4300 NavitGraphics.NavitMsgTv2_.append(a1 + "\n");
4301 System.out.println(a);
4302 System.out.println(a1);
4303 //
4304 a = "In %s, enter the roundabout";
4305 a1 = CallbackLocalizedString(a);
4306 for (j = 1; j < 10; j++)
4307 {
4308 if ((j == 4) || (j == 5))
4309 {
4310 b = __get_distance(j, 1);
4311 b1 = CallbackLocalizedString(b);
4312 c = String.format(b, 1, 4);
4313 c1 = String.format(b1, 1, 4);
4314 d = String.format(a, c);
4315 d1 = String.format(a1, c1);
4316 try
4317 {
4318 d = String.format(d, 3, 4, 5);
4319 }
4320 catch (Exception e)
4321 {
4322
4323 }
4324 try
4325 {
4326 d1 = String.format(d1, 3, 4, 5);
4327 }
4328 catch (Exception e)
4329 {
4330
4331 }
4332 NavitGraphics.NavitMsgTv2_.append(d + "\n");
4333 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
4334 System.out.println(d);
4335 System.out.println(d1);
4336 }
4337 else
4338 {
4339 b = __get_distance(j, 1);
4340 b1 = CallbackLocalizedString(b);
4341 c = String.format(b, 250);
4342 c1 = String.format(b1, 250);
4343 d = String.format(a, c);
4344 d1 = String.format(a1, c1);
4345 try
4346 {
4347 d = String.format(d, 3, 4, 5);
4348 }
4349 catch (Exception e)
4350 {
4351
4352 }
4353 try
4354 {
4355 d1 = String.format(d1, 3, 4, 5);
4356 }
4357 catch (Exception e)
4358 {
4359
4360 }
4361 NavitGraphics.NavitMsgTv2_.append(d + "\n");
4362 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
4363 System.out.println(d);
4364 System.out.println(d1);
4365 }
4366 }
4367 //
4368 a = "Follow the road for the next %s";
4369 a1 = CallbackLocalizedString(a);
4370 for (j = 1; j < 10; j++)
4371 {
4372 if ((j == 4) || (j == 5))
4373 {
4374 b = __get_distance(j, 1);
4375 b1 = CallbackLocalizedString(b);
4376 c = String.format(b, 1, 4);
4377 c1 = String.format(b1, 1, 4);
4378 d = String.format(a, c);
4379 d1 = String.format(a1, c1);
4380 try
4381 {
4382 d = String.format(d, 3, 4, 5);
4383 }
4384 catch (Exception e)
4385 {
4386
4387 }
4388 try
4389 {
4390 d1 = String.format(d1, 3, 4, 5);
4391 }
4392 catch (Exception e)
4393 {
4394
4395 }
4396 NavitGraphics.NavitMsgTv2_.append(d + "\n");
4397 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
4398 System.out.println(d);
4399 System.out.println(d1);
4400 }
4401 else
4402 {
4403 b = __get_distance(j, 1);
4404 b1 = CallbackLocalizedString(b);
4405 c = String.format(b, 250);
4406 c1 = String.format(b1, 250);
4407 d = String.format(a, c);
4408 d1 = String.format(a1, c1);
4409 try
4410 {
4411 d = String.format(d, 3, 4, 5);
4412 }
4413 catch (Exception e)
4414 {
4415
4416 }
4417 try
4418 {
4419 d1 = String.format(d1, 3, 4, 5);
4420 }
4421 catch (Exception e)
4422 {
4423
4424 }
4425 NavitGraphics.NavitMsgTv2_.append(d + "\n");
4426 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
4427 System.out.println(d);
4428 System.out.println(d1);
4429 }
4430 }
4431 //
4432 a = "Leave the roundabout at the %s";
4433 a1 = CallbackLocalizedString(a);
4434 b = String.format(a, "first exit");
4435 b1 = String.format(a1, CallbackLocalizedString("first exit"));
4436 NavitGraphics.NavitMsgTv2_.append(b + "\n");
4437 NavitGraphics.NavitMsgTv2_.append(b1 + "\n");
4438 System.out.println(b);
4439 System.out.println(b1);
4440 //
4441 a = "Leave the roundabout at the %s";
4442 a1 = CallbackLocalizedString(a);
4443 b = String.format(a, "third exit");
4444 b1 = String.format(a1, CallbackLocalizedString("third exit"));
4445 NavitGraphics.NavitMsgTv2_.append(b + "\n");
4446 NavitGraphics.NavitMsgTv2_.append(b1 + "\n");
4447 System.out.println(b);
4448 System.out.println(b1);
4449 //
4450 a = "then leave the roundabout at the %s";
4451 a1 = CallbackLocalizedString(a);
4452 b = String.format(a, "first exit");
4453 b1 = String.format(a1, CallbackLocalizedString("first exit"));
4454 NavitGraphics.NavitMsgTv2_.append(b + "\n");
4455 NavitGraphics.NavitMsgTv2_.append(b1 + "\n");
4456 System.out.println(b);
4457 System.out.println(b1);
4458 //
4459 a = "then leave the roundabout at the %s";
4460 a1 = CallbackLocalizedString(a);
4461 b = String.format(a, "third exit");
4462 b1 = String.format(a1, CallbackLocalizedString("third exit"));
4463 NavitGraphics.NavitMsgTv2_.append(b + "\n");
4464 NavitGraphics.NavitMsgTv2_.append(b1 + "\n");
4465 System.out.println(b);
4466 System.out.println(b1);
4467 //
4468 a = "Take the %1$s road to the %2$s";
4469 a1 = CallbackLocalizedString(a);
4470 b = String.format(a, "first", "left");
4471 b1 = String.format(a1, CallbackLocalizedString("first"), CallbackLocalizedString("left"));
4472 NavitGraphics.NavitMsgTv2_.append(b + "\n");
4473 NavitGraphics.NavitMsgTv2_.append(b1 + "\n");
4474 System.out.println(b);
4475 System.out.println(b1);
4476 //
4477 a = "Take the %1$s road to the %2$s";
4478 a1 = CallbackLocalizedString(a);
4479 b = String.format(a, "first", "right");
4480 b1 = String.format(a1, CallbackLocalizedString("first"), CallbackLocalizedString("right"));
4481 NavitGraphics.NavitMsgTv2_.append(b + "\n");
4482 NavitGraphics.NavitMsgTv2_.append(b1 + "\n");
4483 System.out.println(b);
4484 System.out.println(b1);
4485 //
4486 a = "Take the %1$s road to the %2$s";
4487 a1 = CallbackLocalizedString(a);
4488 b = String.format(a, "third", "left");
4489 b1 = String.format(a1, CallbackLocalizedString("third"), CallbackLocalizedString("left"));
4490 NavitGraphics.NavitMsgTv2_.append(b + "\n");
4491 NavitGraphics.NavitMsgTv2_.append(b1 + "\n");
4492 System.out.println(b);
4493 System.out.println(b1);
4494 //
4495 a = "Take the %1$s road to the %2$s";
4496 a1 = CallbackLocalizedString(a);
4497 b = String.format(a, "third", "right");
4498 b1 = String.format(a1, CallbackLocalizedString("third"), CallbackLocalizedString("right"));
4499 NavitGraphics.NavitMsgTv2_.append(b + "\n");
4500 NavitGraphics.NavitMsgTv2_.append(b1 + "\n");
4501 System.out.println(b);
4502 System.out.println(b1);
4503 //
4504 a = "You have reached your destination %s";
4505 a1 = CallbackLocalizedString(a);
4506 for (j = 1; j < 14; j++)
4507 {
4508 if (j == 10)
4509 {
4510 d = String.format(a, "");
4511 d1 = String.format(a1, "");
4512 try
4513 {
4514 d = String.format(d, 3, 4, 5);
4515 }
4516 catch (Exception e)
4517 {
4518
4519 }
4520 try
4521 {
4522 d1 = String.format(d1, 3, 4, 5);
4523 }
4524 catch (Exception e)
4525 {
4526
4527 }
4528 NavitGraphics.NavitMsgTv2_.append(d + "\n");
4529 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
4530 System.out.println(d + "\n");
4531 System.out.println(d1 + "\n");
4532 }
4533 else if (j == 12)
4534 {
4535 b = __n_distance(j);
4536 b1 = CallbackLocalizedString(b);
4537 c = b.replace("%i", "3");
4538 c1 = b1.replace("%i", "3");
4539 d = String.format(a, c);
4540 d1 = String.format(a1, c1);
4541 try
4542 {
4543 d = String.format(d, 3, 4, 5);
4544 }
4545 catch (Exception e)
4546 {
4547
4548 }
4549 try
4550 {
4551 d1 = String.format(d1, 3, 4, 5);
4552 }
4553 catch (Exception e)
4554 {
4555
4556 }
4557 NavitGraphics.NavitMsgTv2_.append(d + "\n");
4558 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
4559 System.out.println(d);
4560 System.out.println(d1);
4561 }
4562 else
4563 {
4564 b = __n_distance(j);
4565 b1 = CallbackLocalizedString(b);
4566 d = String.format(a, b);
4567 d1 = String.format(a1, b1);
4568 try
4569 {
4570 d = String.format(d, 3, 4, 5);
4571 }
4572 catch (Exception e)
4573 {
4574
4575 }
4576 try
4577 {
4578 d1 = String.format(d1, 3, 4, 5);
4579 }
4580 catch (Exception e)
4581 {
4582
4583 }
4584 NavitGraphics.NavitMsgTv2_.append(d + "\n");
4585 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
4586 System.out.println(d);
4587 System.out.println(d1);
4588 }
4589 }
4590 //
4591 a = "Turn %1$s%2$s %3$s%4$s";
4592 a1 = CallbackLocalizedString(a);
4593 String xx = null;
4594 String xx1 = null;
4595 String yy = null;
4596 String yy1 = null;
4597 for (j = 1; j < 5; j++)
4598 {
4599 if (j == 1)
4600 {
4601 b = __strength(j);
4602 b1 = "";
4603 }
4604 else
4605 {
4606 b = __strength(j);
4607 b1 = CallbackLocalizedString(b);
4608 }
4609
4610 for (int k = 1; k < 3; k++)
4611 {
4612 c = __direction(k);
4613 c1 = CallbackLocalizedString(c);
4614
4615 for (int m = 1; m < 14; m++)
4616 {
4617 if (m == 10)
4618 {
4619 xx = "";
4620 xx1 = "";
4621 }
4622 else if (m == 12)
4623 {
4624 String zz = __n_distance(m);
4625 String zz1 = CallbackLocalizedString(zz);
4626 xx = zz.replace("%i", "3");
4627 xx1 = zz1.replace("%i", "3");
4628 }
4629 else
4630 {
4631 xx = __n_distance(m);
4632 xx1 = CallbackLocalizedString(xx);
4633 }
4634
4635 for (int o = 1; o < 9; o++)
4636 {
4637 if (o == 2)
4638 {
4639 // leave out "exit"
4640 break;
4641 }
4642
4643 if (o == 1)
4644 {
4645 yy = __navigation_item_destination(o);
4646 yy1 = "";
4647 }
4648 else if (o == 4)
4649 {
4650 String zz;
4651 String zz1;
4652 zz = __navigation_item_destination(o);
4653 zz1 = CallbackLocalizedString(zz);
4654 yy = String.format(zz, " ", "somestreet", " ", "A23");
4655 yy1 = String.format(zz1, " ", "blablastrasse", " ", "A23");
4656 }
4657 else if ((o == 5) || (o == 6) || (o == 7))
4658 {
4659 String zz;
4660 String zz1;
4661 zz = __navigation_item_destination(o);
4662 zz1 = CallbackLocalizedString(zz);
4663 try
4664 {
4665 zz = zz.substring(0, zz.lastIndexOf("|"));
4666 }
4667 catch (Exception e)
4668 {
4669
4670 }
4671 try
4672 {
4673 zz1 = zz1.substring(0, zz1.lastIndexOf("|"));
4674 }
4675 catch (Exception e)
4676 {
4677
4678 }
4679 yy = String.format(zz, " ", "somestreet", " ", "A23");
4680 yy1 = String.format(zz1, " ", "blablastrasse", " ", "A23");
4681 }
4682 else if (o == 8)
4683 {
4684 String zz;
4685 String zz1;
4686 zz = __navigation_item_destination(o);
4687 zz1 = CallbackLocalizedString(zz);
4688 yy = String.format(zz, " ", "A23");
4689 yy1 = String.format(zz1, " ", "A23");
4690 }
4691 else
4692 {
4693 yy = __navigation_item_destination(o);
4694 yy1 = " " + CallbackLocalizedString(yy);
4695 yy = " " + yy;
4696 }
4697
4698 // apply parts
4699 d = String.format(a, b, c, xx, yy);
4700 d1 = String.format(a1, b1, c1, xx1, yy1);
4701 try
4702 {
4703 d = String.format(d, 3, 4, 5);
4704 }
4705 catch (Exception e)
4706 {
4707
4708 }
4709 try
4710 {
4711 d1 = String.format(d1, 3, 4, 5);
4712 }
4713 catch (Exception e)
4714 {
4715
4716 }
4717 NavitGraphics.NavitMsgTv2_.append(d + "\n");
4718 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
4719 System.out.println(d);
4720 System.out.println(d1);
4721 }
4722 }
4723 }
4724 }
4725 //
4726 a = "then turn %1$s%2$s %3$s%4$s";
4727 a1 = CallbackLocalizedString(a);
4728 xx = null;
4729 xx1 = null;
4730 yy = null;
4731 yy1 = null;
4732 for (j = 1; j < 5; j++)
4733 {
4734 if (j == 1)
4735 {
4736 b = __strength(j);
4737 b1 = "";
4738 }
4739 else
4740 {
4741 b = __strength(j);
4742 b1 = CallbackLocalizedString(b);
4743 }
4744
4745 for (int k = 1; k < 3; k++)
4746 {
4747 c = __direction(k);
4748 c1 = CallbackLocalizedString(c);
4749
4750 for (int m = 1; m < 14; m++)
4751 {
4752 if (m == 10)
4753 {
4754 xx = "";
4755 xx1 = "";
4756 }
4757 else if (m == 12)
4758 {
4759 String zz = __n_distance(m);
4760 String zz1 = CallbackLocalizedString(zz);
4761 xx = zz.replace("%i", "3");
4762 xx1 = zz1.replace("%i", "3");
4763 }
4764 else
4765 {
4766 xx = __n_distance(m);
4767 xx1 = CallbackLocalizedString(xx);
4768 }
4769
4770 for (int o = 1; o < 9; o++)
4771 {
4772 if (o == 2)
4773 {
4774 // leave out "exit"
4775 break;
4776 }
4777
4778 if (o == 1)
4779 {
4780 yy = __navigation_item_destination(o);
4781 yy1 = "";
4782 }
4783 else if (o == 4)
4784 {
4785 String zz;
4786 String zz1;
4787 zz = __navigation_item_destination(o);
4788 zz1 = CallbackLocalizedString(zz);
4789 yy = String.format(zz, " ", "somestreet", " ", "A23");
4790 yy1 = String.format(zz1, " ", "blablastrasse", " ", "A23");
4791 }
4792 else if ((o == 5) || (o == 6) || (o == 7))
4793 {
4794 String zz;
4795 String zz1;
4796 zz = __navigation_item_destination(o);
4797 zz1 = CallbackLocalizedString(zz);
4798 try
4799 {
4800 zz = zz.substring(0, zz.lastIndexOf("|"));
4801 }
4802 catch (Exception e)
4803 {
4804
4805 }
4806 try
4807 {
4808 zz1 = zz1.substring(0, zz1.lastIndexOf("|"));
4809 }
4810 catch (Exception e)
4811 {
4812
4813 }
4814 yy = String.format(zz, " ", "somestreet", " ", "A23");
4815 yy1 = String.format(zz1, " ", "blablastrasse", " ", "A23");
4816 }
4817 else if (o == 8)
4818 {
4819 String zz;
4820 String zz1;
4821 zz = __navigation_item_destination(o);
4822 zz1 = CallbackLocalizedString(zz);
4823 yy = String.format(zz, " ", "A23");
4824 yy1 = String.format(zz1, " ", "A23");
4825 }
4826 else
4827 {
4828 yy = __navigation_item_destination(o);
4829 yy1 = " " + CallbackLocalizedString(yy);
4830 yy = " " + yy;
4831 }
4832
4833 // apply parts
4834 d = String.format(a, b, c, xx, yy);
4835 d1 = String.format(a1, b1, c1, xx1, yy1);
4836 try
4837 {
4838 d = String.format(d, 3, 4, 5);
4839 }
4840 catch (Exception e)
4841 {
4842
4843 }
4844 try
4845 {
4846 d1 = String.format(d1, 3, 4, 5);
4847 }
4848 catch (Exception e)
4849 {
4850
4851 }
4852 NavitGraphics.NavitMsgTv2_.append(d + "\n");
4853 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
4854 System.out.println(d);
4855 System.out.println(d1);
4856 }
4857 }
4858 }
4859 }
4860 //
4861 //
4862 //
4863
4864 /*
4865 * speech commands:
4866 * ================
4867 *
4868 *
4869 * When possible, please turn around
4870 * Enter the roundabout soon
4871 * then you have reached your destination.
4872 *
4873 * In %s, enter the roundabout (get_distance(is_length=1))
4874 * Follow the road for the next %s (get_distance(is_length=1))
4875 *
4876 * Leave the roundabout at the %s (get_exit_count_str)
4877 * then leave the roundabout at the %s (get_exit_count_str)
4878 *
4879 * Take the %1$s road to the %2$s (get_count_str(),direction)
4880 * then take the %1$s road to the %2$s (get_count_str(),direction)
4881 *
4882 * Turn %1$s%2$s %3$s%4$s (strength,direction,distance,navigation_item_destination(" "))
4883 * then turn %1$s%2$s %3$s%4$s (strength,direction,distance,navigation_item_destination(" "))
4884 *
4885 * You have reached your destination %s (distance)
4886 *
4887 *
4888 *
4889 * distance:
4890 * ""
4891 * soon
4892 * get_distance(is_length=0)
4893 * after %i roads
4894 * now
4895 *
4896 *
4897 * direction:
4898 * left
4899 * right
4900 *
4901 * strength:
4902 * ""
4903 * slight
4904 * hard
4905 * really hard
4906 *
4907 * navigation_item_destination:
4908 * ============================
4909 * ""
4910 * (prefix)exit
4911 * (prefix)into the ramp
4912 * (prefix)into the street (streetname)(sep)(systematic streetname)
4913 * (prefix)into the (streetname)(sep)(systematic streetname) |male form %s%s%s
4914 * (prefix)into the (streetname)(sep)(systematic streetname) |female form %s%s%s
4915 * (prefix)into the (streetname)(sep)(systematic streetname) |neutral form %s%s%s
4916 * (prefix)into the (systematic streetname) %s
4917 *
4918 *
4919 *
4920 * get_count_str:
4921 * ==============
4922 * first
4923 * second
4924 * fifth
4925 *
4926 *
4927 * get_exit_count_str:
4928 * ===================
4929 * first exit
4930 * second exit
4931 * fifth exit
4932 *
4933 *
4934 *
4935 * get_distance:
4936 * =============
4937 * %d m (is_length 1)
4938 * in %d m
4939 * %d feet (is_length 1)
4940 * in %d feet
4941 * %d meters (is_length 1)
4942 * in %d meters
4943 * %d.%d miles (is_length 1)
4944 * in %d.%d miles
4945 * %d.%d kilometers (is_length 1)
4946 * in %d.%d kilometers
4947 * one mile,%d miles (is_length 1)
4948 * in one mile,in %d miles
4949 * one kilometer,%d kilometers (is_length 1)
4950 * in one kilometer,in %d kilometers
4951 */
4952
4953 }
4954
4955 /**
4956 * generic message channel to C-code
4957 */
4958 public static native void CallbackMessageChannelReal(int i, String s);
4959
4960 public static native int GetThreadId();
4961
4962 public static void CallbackMessageChannel(int i, String s)
4963 {
4964 Navit.cwthr.CallbackMessageChannel(i, s);
4965 }
4966
4967 /**
4968 * return search result from C-code
4969 */
4970 public void fillStringArray(String s)
4971 {
4972 //Log.e("NavitGraphics", "**** fillStringArray s=" + s);
4973 // deactivate the spinner
4974 // --> no we want to spin ** Navit.NavitAddressSearchSpinnerActive = false;
4975
4976 if (s.equals("D:D"))
4977 {
4978 // ok its a dummy, just move the percent bar
4979 // Log.e("NavitGraphics", "**** fillStringArray s=" + s);
4980 }
4981 else
4982 {
4983 try
4984 {
4985 // we hope its a real result value
4986 Navit.Navit_Address_Result_Struct tmp_addr = new Navit_Address_Result_Struct();
4987 String[] tmp_s = s.split(":");
4988 tmp_addr.result_type = tmp_s[0];
4989 tmp_addr.item_id = tmp_s[1];
4990
4991 if (Navit.use_index_search)
4992 {
4993 tmp_addr.lat = Integer.parseInt(tmp_s[2]);
4994 tmp_addr.lon = Integer.parseInt(tmp_s[3]);
4995 }
4996 else
4997 {
4998 tmp_addr.lat = Float.parseFloat(tmp_s[2]);
4999 tmp_addr.lon = Float.parseFloat(tmp_s[3]);
5000 }
5001 // the rest ist address
5002 tmp_addr.addr = s.substring(4 + tmp_s[0].length() + tmp_s[1].length() + tmp_s[2].length() + tmp_s[3].length(), s.length());
5003
5004 // String hash_id = tmp_addr.result_type + ":" + tmp_addr.lat + ":" + tmp_addr.lon + ":" + tmp_addr.addr;
5005 String hash_id = tmp_addr.result_type + ":" + tmp_addr.addr;
5006 //System.out.println("hash_id=" + hash_id);
5007 if ((!Navit.search_hide_duplicates) || (!Navit.Navit_Address_Result_double_index.contains(hash_id)))
5008 {
5009 Navit.NavitAddressResultList_foundItems.add(tmp_addr);
5010 Navit.Navit_Address_Result_double_index.add(hash_id);
5011 //System.out.println("*add*=" + hash_id);
5012
5013 if (tmp_addr.result_type.equals("TWN"))
5014 {
5015 Navit.search_results_towns++;
5016 }
5017 else if (tmp_addr.result_type.equals("STR"))
5018 {
5019 Navit.search_results_streets++;
5020 }
5021 else if (tmp_addr.result_type.equals("SHN"))
5022 {
5023 Navit.search_results_streets_hn++;
5024 }
5025
5026 Navit.NavitSearchresultBar_title = Navit.get_text("loading search results");
5027 Navit.NavitSearchresultBar_text = Navit.get_text("towns") + ":" + Navit.search_results_towns + " " + Navit.get_text("Streets") + ":" + Navit.search_results_streets + "/" + Navit.search_results_streets_hn;
5028
5029 // make the dialog move its bar ...
5030 // Bundle b = new Bundle();
5031 // b.putInt("dialog_num", Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE);
5032 // b.putInt("max", Navit.ADDRESS_RESULTS_DIALOG_MAX);
5033 // b.putInt("cur", Navit.NavitAddressResultList_foundItems.size() % (Navit.ADDRESS_RESULTS_DIALOG_MAX + 1));
5034 // b.putString("title", Navit.get_text("loading search results")); //TRANS
5035 // b.putString("text", Navit.get_text("towns") + ":" + Navit.search_results_towns + " " + Navit.get_text("Streets") + ":" + Navit.search_results_streets + "/" + Navit.search_results_streets_hn);
5036 // Navit.msg_to_msg_handler(b, 10);
5037 }
5038 //else
5039 //{
5040 // //System.out.println("double " + tmp_addr.addr);
5041 //}
5042 }
5043 catch (Exception e)
5044 {
5045
5046 }
5047 }
5048
5049 // always move the bar, so that the user knows app is still doing something (and has not crashed!)
5050 // Navit.NavitSearchresultBarIndex++;
5051 // if (Navit.NavitSearchresultBarIndex > Navit.ADDRESS_RESULTS_DIALOG_MAX)
5052 // {
5053 // Navit.NavitSearchresultBarIndex = 0;
5054 // }
5055 // make the dialog move its bar ...
5056 // Bundle b = new Bundle();
5057 // b.putInt("dialog_num", Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE);
5058 // b.putInt("max", Navit.ADDRESS_RESULTS_DIALOG_MAX);
5059 // b.putInt("cur", Navit.NavitSearchresultBarIndex);
5060 // b.putString("title", Navit.get_text("loading search results")); //TRANS
5061 // b.putString("text", Navit.get_text("towns") + ":" + Navit.search_results_towns + " " + Navit.get_text("Streets") + ":" + Navit.search_results_streets + "/" + Navit.search_results_streets_hn);
5062 // Navit.msg_to_msg_handler(b, 10);
5063 }
5064
5065 public void SearchResultList(int i, int partial_match, String text, String t_town, String t_hn, int flags, String country_iso2, String search_latlon, int search_radius)
5066 {
5067 CallbackSearchResultList(i, partial_match, text, t_town, t_hn, flags, country_iso2, search_latlon, search_radius);
5068 }
5069
5070 public native void CallbackSearchResultList(int i, int partial_match, String s, String s_town, String s_hn, int flags, String country_iso2, String search_latlon, int search_radius);
5071
5072 /**
5073 * get localized string
5074 */
5075 public static native String CallbackLocalizedString(String s);
5076
5077 //
5078 //
5079 //
5080 // get route_status value from C-lib
5081 /*
5082 *
5083 * 0 -> 1 -> 13 -> 5 -> 17 -> 5 ... 33 -> 5 -> 33 -> 5 ...
5084 *
5085 * route_status_no_destination=0, # 0 --> no dest. set
5086 * route_status_destination_set=1, # 1
5087 * route_status_not_found=1|2, # 3 --> no route to destination found / route blocked
5088 * route_status_building_path=1|4, # 5
5089 * route_status_building_graph=1|4|8, # 13
5090 * route_status_path_done_new=1|16, # 17 --> route found
5091 * route_status_path_done_incremental=1|32, # 33 --> route found
5092 */
5093 // now we get the value pushed from C automatically
5094 public static int CallbackDestinationValid2()
5095 {
5096 return NavitGraphics.navit_route_status;
5097 }
5098
5099 // call C-function to get value --> not used anymore now!!
5100 public static native int CallbackDestinationValid();
5101
5102 public static Handler callback_handler_s = new Handler()
5103 {
5104 public void handleMessage(Message msg)
5105 {
5106 if (msg.getData().getInt("Callback") == 18)
5107 {
5108 CallbackMessageChannel(18, "");
5109 }
5110 else if (msg.getData().getInt("Callback") == 47)
5111 {
5112 // get values
5113 String s = msg.getData().getString("s");
5114 // set routing target to lat,lon
5115 CallbackMessageChannel(47, s);
5116 }
5117 else if (msg.getData().getInt("Callback") == 55)
5118 {
5119 // set cache size for (map-)files
5120 String s = msg.getData().getString("s");
5121 CallbackMessageChannel(55, s);
5122 }
5123 else if (msg.getData().getInt("Callback") == 78)
5124 {
5125 // shift layout "order" values
5126 String s = msg.getData().getString("s");
5127 CallbackMessageChannel(78, s);
5128 }
5129 else if (msg.getData().getInt("Callback") == 79)
5130 {
5131 // set traffic light delay
5132 String s = msg.getData().getString("s");
5133 CallbackMessageChannel(79, s);
5134 }
5135 else if (msg.getData().getInt("Callback") == 9901)
5136 {
5137 // if follow mode is on, then dont show freeview streetname
5138 //if (!Navit.PREF_follow_gps)
5139 //{
5140 // Navit.cwthr.CallbackGeoCalc2(1, 0, mCanvasWidth / 2, mCanvasHeight / 2);
5141 //}
5142 }
5143 else if (msg.getData().getInt("Callback") == 98001)
5144 {
5145 int id = msg.getData().getInt("id");
5146 int i = msg.getData().getInt("i");
5147 return_generic_int_real(id, i);
5148 }
5149 else if (msg.getData().getInt("Callback") == 9001)
5150 {
5151 busyspinner_.setVisibility(View.INVISIBLE);
5152 busyspinnertext_.setVisibility(View.INVISIBLE);
5153 }
5154 else if (msg.getData().getInt("Callback") == 9002)
5155 {
5156 busyspinner_.setVisibility(View.VISIBLE);
5157 busyspinnertext_.setVisibility(View.VISIBLE);
5158 }
5159 }
5160 };
5161
5162 //
5163 //
5164 //
5165
5166 // i=1 -> pixel a,b (x,y) -> geo string "lat(float)#lng(float)"
5167 // i=2 -> geo a,b (lat,lng) -> pixel string "x(int)#y(int)"
5168 public static native String CallbackGeoCalc(int i, float a, float b);
5169
5170 public static void send_generic_text(int id, String text)
5171 {
5172 //System.out.println("send_generic_text");
5173
5174 if (id == 1)
5175 {
5176 // speech textblock
5177 if (NavitGraphics.NavitMsgTv2_.getVisibility() == View.VISIBLE)
5178 {
5179 NavitMsgTv2_.append("TEXT:" + text);
5180 }
5181 }
5182 }
5183
5184 public static void return_generic_int(int id, int i)
5185 {
5186 try
5187 {
5188 Message msg1 = new Message();
5189 Bundle b1 = new Bundle();
5190 b1.putInt("Callback", 98001);
5191 b1.putInt("id", id);
5192 b1.putInt("i", i);
5193 msg1.setData(b1);
5194 NavitGraphics.callback_handler_s.sendMessage(msg1);
5195 }
5196 catch (Exception e)
5197 {
5198 }
5199 }
5200
5201 public static void set_vehicle_values(int x, int y, int angle, int speed)
5202 {
5203 // stop any smooth drawing/moving first!
5204 //System.out.println("set vehicle pos...");
5205 //--> don't set here // Global_SmoothDrawing_stop = true;
5206 last_vehicle_position_timestamp = System.currentTimeMillis();
5207
5208 Navit.NG__vehicle.vehicle_speed = speed;
5209 Navit.NG__vehicle.vehicle_pos_x = x;
5210 Navit.NG__vehicle.vehicle_pos_y = y;
5211 Navit.NG__vehicle.vehicle_direction = angle;
5212 }
5213
5214 public static int ddx_last = 0;
5215 public static int ddy_last = 0;
5216 public static float dda_last = 0;
5217 public static float ddx = 0;
5218 public static float ddy = 0;
5219 public static float dda = 0f;
5220 public static long last_vehicle_position_timestamp = 0L;
5221 public static final int Vehicle_updates_interval = 1000; // normal android phone gives position every 1000ms (=1 sec)
5222 public static int Vehicle_smooth_moves_count = 3; // how many intermediate moves do we want to draw
5223 public static int Vehicle_smooth_move_delay = 180;
5224 public static final int max_turn_angle = 190;
5225
5226 public static void set_vehicle_values_delta(int dx, int dy, int dangle2)
5227 {
5228 Navit.NG__vehicle.vehicle_pos_x_delta = dx;
5229 Navit.NG__vehicle.vehicle_pos_y_delta = dy;
5230 int dangle = dangle2;
5231 if (dangle2 > max_turn_angle)
5232 {
5233 // try to turn the correct way, sometimes there seems to be errors!
5234 dangle = dangle2 - 360;
5235 }
5236 else if (dangle2 < -max_turn_angle)
5237 {
5238 // try to turn the correct way, sometimes there seems to be errors!
5239 dangle = dangle2 + 360;
5240 }
5241
5242 Navit.NG__vehicle.vehicle_direction_delta = dangle;
5243
5244 Global_SmoothDrawing_stop = false;
5245
5246 if (!Navit.PREF_use_smooth_drawing)
5247 {
5248 // disbaled via prefs
5249 return;
5250 }
5251
5252 //if (Navit.NG__vehicle.vehicle_speed < 3)
5253 //{
5254 // // too slow, dont use smooth moving
5255 // return;
5256 //}
5257
5258 if (Navit.NG__vehicle.vehicle_speed > 12)
5259 {
5260 Vehicle_smooth_moves_count = 4;
5261 Vehicle_smooth_move_delay = 210;
5262 }
5263 else
5264 {
5265 Vehicle_smooth_moves_count = 3;
5266 Vehicle_smooth_move_delay = 160;
5267 }
5268
5269 if (System.currentTimeMillis() > last_vehicle_position_timestamp + 2100L)
5270 {
5271 // last vehicle position was too long ago (2.1 secs ago, or longer)
5272 return;
5273 }
5274
5275 if (Global_onTouch_fingerdown)
5276 {
5277 // dont use smooth moving while user moves the map
5278 return;
5279 }
5280
5281 //System.out.println("angle1:dx=" + dx + " dy=" + dy + " da=" + dangle2);
5282 //System.out.println("angle2:dx=" + dx + " dy=" + dy + " da=" + dangle);
5283
5284 if ((Math.abs(dangle) < 2) && (Math.abs(dx) < 1) && (Math.abs(dy) < 1))
5285 {
5286 // the move is very small only
5287 return;
5288 }
5289
5290 dda = (float) dangle / (float) (Vehicle_smooth_moves_count);
5291 dda_last = dangle - (Vehicle_smooth_moves_count * dda);
5292
5293 ddx = dx / (float) (Vehicle_smooth_moves_count);
5294 ddy = dy / (float) (Vehicle_smooth_moves_count);
5295 ddx_last = dx - Vehicle_smooth_moves_count * ((int) ddx);
5296 ddy_last = dy - Vehicle_smooth_moves_count * ((int) ddy);
5297
5298 //System.out.println("angle:ddx=" + ddx + " ddy=" + ddy + " dda=" + dda);
5299 //System.out.println("angle:ddx_l=" + ddx_last + " ddy_l=" + ddy_last + " dda_l=" + dda_last);
5300
5301 // now move the map (to have smooth driving)
5302 //System.out.println("--set_vehicle_values_delta-- START");
5303 final Thread t = new Thread(new Runnable()
5304 {
5305 int cur_count = 0;
5306
5307 public void run()
5308 {
5309 for (cur_count = 0; cur_count < Vehicle_smooth_moves_count; cur_count++)
5310 {
5311 if (Global_SmoothDrawing_stop == false)
5312 {
5313 // dont delay the first smooth move!
5314 if (cur_count != 0)
5315 {
5316 try
5317 {
5318 Thread.sleep(Vehicle_smooth_move_delay);
5319 }
5320 catch (InterruptedException e)
5321 {
5322 // e.printStackTrace();
5323 }
5324 }
5325
5326 }
5327
5328 if (Global_SmoothDrawing_stop == false)
5329 {
5330 //System.out.println("smooth move #" + (cur_count + 1) + " delay=" + Vehicle_smooth_move_delay);
5331 if (cur_count == (Vehicle_smooth_moves_count - 1))
5332 {
5333 Global_Map_TransX = Global_Map_TransX - ddx_last;
5334 Global_Map_TransY = Global_Map_TransY - ddy_last;
5335 Global_Map_Rotationangle = Global_Map_Rotationangle - dda_last;
5336 }
5337 else
5338 {
5339 Global_Map_TransX = Global_Map_TransX - (int) (ddx);
5340 Global_Map_TransY = Global_Map_TransY - (int) (ddy);
5341 Global_Map_Rotationangle = Global_Map_Rotationangle - dda;
5342 }
5343 Navit.NG__map_main.view.postInvalidate();
5344 }
5345 }
5346 //System.out.println("--set_vehicle_values_delta-- SLEEP - END");
5347 }
5348 });
5349 t.start();
5350 //System.out.println("translate, rotate");
5351 //System.out.println("--set_vehicle_values_delta-- END");
5352 }
5353
5354 public static void return_generic_int_real(int id, int i)
5355 {
5356 //System.out.println("id=" + id + " i=" + i);
5357
5358 if (id == 1)
5359 {
5360 // id=1 -> route_status
5361 NavitGraphics.navit_route_status = i;
5362 if (i == 0)
5363 {
5364 ZANaviBusySpinner.active = false;
5365 ZANaviBusySpinner.cancelAnim();
5366 busyspinner_.setVisibility(View.INVISIBLE);
5367 busyspinnertext_.setVisibility(View.INVISIBLE);
5368 busyspinnertext_.setText("");
5369 Navit.set_debug_messages1("");
5370 // DEBUG: clear route rectangle list
5371 route_rects.clear();
5372 }
5373 else if (i == 1)
5374 {
5375 ZANaviBusySpinner.active = true;
5376 busyspinnertext_.setText(Navit.get_text("Destination set")); // TRANS
5377 busyspinner_.setVisibility(View.VISIBLE);
5378 busyspinnertext_.setVisibility(View.VISIBLE);
5379 //System.out.println("invalidate 017");
5380 busyspinner_.postInvalidate();
5381 Navit.set_debug_messages1("Destination set");
5382 }
5383 else if (i == 3)
5384 {
5385 ZANaviBusySpinner.active = true;
5386 ZANaviBusySpinner.cancelAnim();
5387 busyspinner_.setVisibility(View.VISIBLE);
5388 busyspinnertext_.setText(Navit.get_text("No route found / Route blocked")); // TRANS
5389 busyspinnertext_.setVisibility(View.VISIBLE);
5390 Navit.set_debug_messages1("No route found / Route blocked");
5391 }
5392 else if (i == 5)
5393 {
5394 // status "5" is now ignored in c-code!!!
5395 ZANaviBusySpinner.active = true;
5396 busyspinner_.setVisibility(View.VISIBLE);
5397 //System.out.println("invalidate 018");
5398 busyspinner_.postInvalidate();
5399 busyspinnertext_.setText(Navit.get_text("Building route path")); // TRANS
5400 busyspinnertext_.setVisibility(View.VISIBLE);
5401 Navit.set_debug_messages1("Building route path");
5402 }
5403 else if (i == 13)
5404 {
5405 ZANaviBusySpinner.active = true;
5406 busyspinner_.setVisibility(View.VISIBLE);
5407 //System.out.println("invalidate 019");
5408 busyspinner_.postInvalidate();
5409 busyspinnertext_.setText(Navit.get_text("Building route graph")); // TRANS
5410 busyspinnertext_.setVisibility(View.VISIBLE);
5411 Navit.set_debug_messages1("Building route graph");
5412 }
5413 else if (i == 17)
5414 {
5415 ZANaviBusySpinner.active = false;
5416 ZANaviBusySpinner.cancelAnim();
5417 busyspinner_.setVisibility(View.INVISIBLE);
5418 busyspinnertext_.setText("");
5419 busyspinnertext_.setVisibility(View.INVISIBLE);
5420 Navit.set_debug_messages1("Route found");
5421 }
5422 else if (i == 33)
5423 {
5424 ZANaviBusySpinner.active = false;
5425 ZANaviBusySpinner.cancelAnim();
5426 busyspinner_.setVisibility(View.INVISIBLE);
5427 busyspinnertext_.setText("");
5428 busyspinnertext_.setVisibility(View.INVISIBLE);
5429 Navit.set_debug_messages1("Route found");
5430 }
5431 }
5432 else if (id == 2)
5433 {
5434 if (i == 1)
5435 {
5436 // id=2,1 -> map draw finished
5437 if (DEBUG_TOUCH) System.out.println("wait_for_redraw_map=false xx1");
5438 NavitGraphics.wait_for_redraw_map = false;
5439 try
5440 {
5441 //NavitAndroidOverlay.overlay_draw_thread1.stop_redraw();
5442 //NavitAndroidOverlay.overlay_draw_thread1.stop_me();
5443 //NavitAndroidOverlay.overlay_draw_thread1 = null;
5444 }
5445 catch (Exception e)
5446 {
5447 // e.printStackTrace();
5448 }
5449 try
5450 {
5451 //System.out.println("DO__DRAW:Java:remove wait text");
5452 //System.out.println("invalidate 020");
5453 NavitAOverlay_s.postInvalidate();
5454 }
5455 catch (Exception e)
5456 {
5457 e.printStackTrace();
5458 }
5459 }
5460 else if (i == 3)
5461 {
5462 // id=2,3 -> mapdraw cancel signal
5463 //System.out.println("DO__DRAW:Java:cancel map");
5464 // draw_map_one_shot = true;
5465 //copy_backwards_map_buffer();
5466 //draw_reset_factors = true;
5467 //view_s.postInvalidate();
5468
5469 }
5470 else if (i == 2)
5471 {
5472 // id=2,2 -> mapdraw ready signal
5473 //System.out.println("DO__DRAW:Java:refresh map");
5474 // draw_map_one_shot = true;
5475
5476 if ((Navit.PREF_use_smooth_drawing) && (Navit.NG__vehicle.vehicle_speed > 12))
5477 {
5478 // delay vehicle and map update just a tiny little bit here!! -- very experimental, also delays gps position !!!
5479 final Thread t2 = new Thread(new Runnable()
5480 {
5481 public void run()
5482 {
5483 try
5484 {
5485 Thread.sleep(450);
5486 }
5487 catch (InterruptedException e)
5488 {
5489 // e.printStackTrace();
5490 }
5491
5492 if (!Global_onTouch_fingerdown)
5493 {
5494 copy_map_buffer();
5495 draw_reset_factors = true;
5496 view_s.postInvalidate();
5497 }
5498 }
5499 });
5500 t2.start();
5501 }
5502 else
5503 {
5504 copy_map_buffer();
5505 draw_reset_factors = true;
5506 view_s.postInvalidate();
5507 }
5508 }
5509 }
5510 else if (id == 3)
5511 {
5512 // id=3 -> new scale (zoom) number
5513 // 1 (=2^0) order: ~16 -> fully zoomed in
5514 // 1048576 (=2^20) order: -1 -> zoomed out to world
5515 if (DEBUG_TOUCH) System.out.println("scale=" + i);
5516 Navit.GlobalScaleLevel = i;
5517 }
5518 else if (id == 4)
5519 {
5520 Navit.set_debug_messages1("Destination reached");
5521 NavitGraphics.navit_route_status = 0;
5522 }
5523 else if (id == 5)
5524 {
5525 Navit.set_debug_messages1("Waypoint reached");
5526 }
5527 else if (id == 6)
5528 {
5529 // id=6 -> mean time for drawing map to screen (in 1/1000 of a second)
5530 Navit.set_debug_messages4("draw:" + (float) ((float) i / 1000f) + "s");
5531 }
5532 }
5533
5534 public static Bitmap rotate_and_scale_bitmap(Bitmap in, int w, int h, int angle)
5535 {
5536 int width = in.getWidth();
5537 int height = in.getHeight();
5538
5539 if ((width == w) && (height == h) && (angle == 0))
5540 {
5541 return in;
5542 }
5543
5544 // System.out.println(" @@@@@@ w="+w+" h="+h);
5545
5546 // calculate the scale
5547 float scaleWidth = ((float) w) / width;
5548 float scaleHeight = ((float) h) / height;
5549
5550 // createa matrix for the manipulation
5551 Matrix matrix = new Matrix();
5552 // resize the bit map
5553 matrix.postScale(scaleWidth, scaleHeight);
5554 // rotate the Bitmap
5555 matrix.postRotate(angle);
5556
5557 // recreate the new Bitmap
5558 return (Bitmap.createBitmap(in, 0, 0, width, height, matrix, true));
5559 }
5560
5561 public static class route_rect
5562 {
5563 int x1;
5564 int y1;
5565 int x2;
5566 int y2;
5567 int order;
5568 };
5569
5570 public static ArrayList<route_rect> route_rects = new ArrayList<route_rect>();
5571
5572 // value are NOT in pixels!! they need to be converted to pixels before drawing
5573 public static void send_route_rect_to_java(int x1, int y1, int x2, int y2, int order)
5574 {
5575 //System.out.println("send_route_rect_to_java: " + x1 + "," + y1 + " " + x2 + "," + y2 + " o=" + order);
5576
5577 //String left_top_on_screen_string = CallbackGeoCalc(11, x1, y1);
5578 //String tmp[] = left_top_on_screen_string.split(":", 2);
5579 //int pixel_top_left_x = Integer.parseInt(tmp[0]);
5580 //int pixel_top_left_y = Integer.parseInt(tmp[1]);
5581 //System.out.println(" " + pixel_top_left_x + "," + pixel_top_left_y);
5582
5583 //left_top_on_screen_string = CallbackGeoCalc(11, x2, y2);
5584 //tmp = left_top_on_screen_string.split(":", 2);
5585 //pixel_top_left_x = Integer.parseInt(tmp[0]);
5586 //pixel_top_left_y = Integer.parseInt(tmp[1]);
5587 //System.out.println(" " + pixel_top_left_x + "," + pixel_top_left_y);
5588
5589 if (route_rects == null)
5590 {
5591 route_rects = new ArrayList<route_rect>();
5592 }
5593
5594 route_rect rr = new route_rect();
5595 rr.x1 = x1;
5596 rr.y1 = y1;
5597 rr.x2 = x2;
5598 rr.y2 = y2;
5599 rr.order = order;
5600 route_rects.add(rr);
5601 }
5602
5603 }

   
Visit the ZANavi Wiki