/[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 28 - (show annotations) (download)
Sun Jun 17 08:12:47 2012 UTC (11 years, 10 months ago) by zoff99
File size: 111892 byte(s)
lots of new stuff and fixes
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.lang.reflect.Method;
42 import java.util.ArrayList;
43
44 import android.app.Activity;
45 import android.graphics.Bitmap;
46 import android.graphics.BitmapFactory;
47 import android.graphics.Canvas;
48 import android.graphics.Color;
49 import android.graphics.DashPathEffect;
50 import android.graphics.Matrix;
51 import android.graphics.Paint;
52 import android.graphics.Path;
53 import android.graphics.PointF;
54 import android.graphics.Rect;
55 import android.os.Bundle;
56 import android.os.Debug;
57 import android.os.Handler;
58 import android.os.Message;
59 import android.util.FloatMath;
60 import android.util.Log;
61 import android.view.Gravity;
62 import android.view.KeyEvent;
63 import android.view.MotionEvent;
64 import android.view.View;
65 import android.widget.RelativeLayout;
66 import android.widget.ScrollView;
67 import android.widget.TextView;
68
69 import com.zoffcc.applications.zanavi.Navit.Navit_Address_Result_Struct;
70 import com.zoffcc.applications.zanavi.NavitAndroidOverlay.NavitAndroidOverlayBubble;
71
72 public class NavitGraphics
73 {
74 private NavitGraphics parent_graphics;
75 private ArrayList overlays = new ArrayList();
76
77 public final static DashPathEffect dashed_map_lines__high = new DashPathEffect(new float[] { 4, 2 }, 1);
78 public final static DashPathEffect dashed_map_lines__low = new DashPathEffect(new float[] { 15, 11 }, 1);
79 public final static DashPathEffect dashed_map_lines__no_dash = null;
80
81 public final static DashPathEffect h001 = new DashPathEffect(new float[] { 6, 3 }, 1);
82 public final static DashPathEffect l001 = new DashPathEffect(new float[] { 6, 3 }, 1);
83 public final static DashPathEffect h002 = new DashPathEffect(new float[] { 6, 3 }, 1);
84 public final static DashPathEffect l002 = new DashPathEffect(new float[] { 6, 3 }, 1);
85 public final static DashPathEffect h003 = new DashPathEffect(new float[] { 6, 3 }, 1);
86 public final static DashPathEffect l003 = new DashPathEffect(new float[] { 6, 3 }, 1);
87 public final static DashPathEffect h004 = new DashPathEffect(new float[] { 6, 3 }, 1);
88 public final static DashPathEffect l004 = new DashPathEffect(new float[] { 6, 3 }, 1);
89 public final static DashPathEffect h005 = new DashPathEffect(new float[] { 6, 3 }, 1);
90 public final static DashPathEffect l005 = new DashPathEffect(new float[] { 6, 3 }, 1);
91 public final static DashPathEffect h006 = new DashPathEffect(new float[] { 6, 3 }, 1);
92 public final static DashPathEffect l006 = new DashPathEffect(new float[] { 6, 3 }, 1);
93
94 public final static DashPathEffect[] dashes__low = { null, l001, l002, l003, l004, l005, l006 };
95 public final static DashPathEffect[] dashes__high = { null, h001, h002, h003, h004, h005, h006 };
96
97 public static int navit_route_status = 0;
98
99 public final float BIGMAP_FACTOR = (10465f / 2f) * 0.8f;
100
101 public static long last_paint_OSD = 0;
102
103 public static Boolean wait_for_redraw_map = false;
104
105 public static Boolean MAP_DISPLAY_OFF = false;
106
107 public static int mCanvasWidth = 1;
108 public static int mCanvasHeight = 1;
109
110 public static final Boolean DEBUG_TOUCH = false;
111 public static Boolean ZOOM_MODE_ACTIVE = false;
112 public static float ZOOM_MODE_SCALE = 0;
113
114 public static float draw_factor = 1.0f;
115
116 public static String debug_line_1 = "";
117 public static String debug_line_2 = "";
118 public static String debug_line_3 = "";
119 public static String debug_line_4 = "";
120
121 public static final int DRAW_ONEWAY_ARROWS_AT_ORDER = 13;
122 public static final int DRAW_DETAIL_DASHES_AT_ORDER = 13;
123 public static final int DRAW_MORE_DETAILS_AT_ORDER = 9;
124 public static final int DRAW_MORE_DETAILS_TUNNEL_BRIDGES_AT_ORDER = 8;
125
126 public static long[] OverlayDrawThread_cancel_drawing_timeout__options = { 300L, 900L, 2100L, 20000L }; // 900L normal, 300L short, 2100L long
127 public static int[] OverlayDrawThread_cancel_thread_sleep_time__options = { 100, 200, 400, 400 };
128 public static long[] OverlayDrawThread_cancel_thread_timeout__options = { 3000L, 3000L, 3000L, 22000L };
129
130 public static long OverlayDrawThread_cancel_drawing_timeout = OverlayDrawThread_cancel_drawing_timeout__options[1];
131 public static int OverlayDrawThread_cancel_thread_sleep_time = OverlayDrawThread_cancel_thread_sleep_time__options[1];
132 public static long OverlayDrawThread_cancel_thread_timeout = OverlayDrawThread_cancel_thread_timeout__options[1];
133
134 int loc_dot_x = 0;
135 int loc_dot_y = 0;
136 int loc_dot_x2 = 0;
137 int loc_dot_y2 = 0;
138 int loc_1_x = 0;
139 int loc_1_y = 0;
140 int loc_2_x = 0;
141 int loc_2_y = 0;
142 Boolean loc_12_valid = false;
143 Boolean loc_dot_valid = false;
144
145 int bitmap_w;
146 int bitmap_h;
147 int pos_x;
148 int pos_y;
149 // drag pos
150 public static int d_pos_x_old = -1;
151 public static int d_pos_y_old = -1;
152 // drag post
153 int pos_wraparound;
154 int overlay_disabled;
155 float trackball_x, trackball_y;
156 View view;
157 RelativeLayout relativelayout;
158 // --obsolote --- // NavitCamera camera;
159 Activity activity;
160
161 private Bitmap bigmap_bitmap_temp = null;
162 private Matrix matrix_oneway_arrows = null;
163 private float wsave_003 = 0f;
164 private float wsave_004 = 0f;
165 private Boolean b_paint_antialias = true;
166 private Path b_paint_path = new Path();
167
168 public static Boolean in_map = true; // always in map mode, now
169
170 // for menu key
171 private static long time_for_long_press = 300L;
172 private static long interval_for_long_press = 200L;
173
174 // for touch screen
175 private long last_touch_on_screen = 0L;
176 private static long long_press_on_screen_interval = 1000L;
177 private static float long_press_on_screen_max_distance = 8f;
178
179 // Overlay View for Android
180 //
181 // here you can draw all the nice things you want
182 // and get touch events for it (without touching C-code)
183 public NavitAndroidOverlay NavitAOverlay = null;
184 public static NavitAndroidOverlay NavitAOverlay_s = null;
185 private NavitOSDJava NavitAOSDJava = null;
186 public static NavitOSDJava NavitAOSDJava_ = null;
187 private TextView NavitMsgTv = null;
188 public static TextView NavitMsgTv_ = null;
189 public ZANaviBusySpinner busyspinner = null;
190 public static ZANaviBusySpinner busyspinner_ = null;
191 public ZANaviBusyText busyspinnertext = null;
192 public static ZANaviBusyText busyspinnertext_ = null;
193
194 private TextView NavitMsgTv2 = null;
195 public static TextView NavitMsgTv2_ = null;
196
197 public static NavitGlobalMap NavitGlobalMap_ = null;
198
199 public void SetCamera(int use_camera)
200 {
201 // ------ obsolete
202
203 /*
204 * if (use_camera != 0 && camera == null)
205 * {
206 * // activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
207 * camera = new NavitCamera(activity);
208 * relativelayout.addView(camera);
209 * relativelayout.bringChildToFront(view);
210 * }
211 */
212 }
213
214 public static SensorThread touch_sensor_thread = null;
215
216 private class SensorThread extends Thread
217 {
218 private Boolean running;
219 private long last_down_action = 0L;
220 private Boolean is_still_pressing;
221 private View v = null;
222 private NavitAndroidOverlay n_overlay = null;
223 private float prev_x;
224 private float prev_y;
225 private float x;
226 private float y;
227
228 SensorThread(long last_touch, View v, NavitAndroidOverlay n_ov, float x, float y)
229 {
230 this.prev_x = x;
231 this.prev_y = y;
232 this.x = x;
233 this.y = y;
234 this.running = true;
235 this.n_overlay = n_ov;
236 this.v = v;
237 this.is_still_pressing = true;
238 last_down_action = System.currentTimeMillis();
239 if (DEBUG_TOUCH) Log.e("NavitGraphics", "SensorThread created");
240 }
241
242 public void down()
243 {
244 this.is_still_pressing = true;
245 }
246
247 // public void up()
248 // {
249 // this.is_still_pressing=false;
250 // }
251
252 public void stop_me()
253 {
254 this.running = false;
255 }
256
257 public void run()
258 {
259 if (DEBUG_TOUCH) Log.e("NavitGraphics", "SensorThread started");
260 while (this.running)
261 {
262 if ((System.currentTimeMillis() - this.last_down_action) > long_press_on_screen_interval)
263 {
264 // ok, we have counted a long press on screen
265 // do stuff and then stop this thread
266 if (DEBUG_TOUCH) Log.e("NavitGraphics", "SensorThread: LONG PRESS");
267 try
268 {
269 // find the class, to get the method "do_longpress_action"
270 // and then call the method
271 Class cls = this.v.getClass();
272 //Log.e("NavitGraphics", "c=" + String.valueOf(cls));
273 Class partypes[] = new Class[2];
274 partypes[0] = Float.TYPE;
275 partypes[1] = Float.TYPE;
276 Method meth = cls.getMethod("do_longpress_action", partypes);
277 View methobj = this.v;
278 Object arglist[] = new Object[2];
279 arglist[0] = new Float(this.x);
280 arglist[1] = new Float(this.y);
281 if (running)
282 {
283 Object retobj = meth.invoke(methobj, arglist);
284 }
285 }
286 catch (Throwable e)
287 {
288 System.err.println(e);
289 }
290 this.running = false;
291 }
292 else if (!this.is_still_pressing)
293 {
294 if (DEBUG_TOUCH) Log.e("NavitGraphics", "SensorThread: stopped pressing");
295 this.running = false;
296 }
297 else
298 {
299 // Log.e("NavitGraphics", "SensorThread running");
300 try
301 {
302 Thread.sleep(50);
303 }
304 catch (InterruptedException e)
305 {
306 // e.printStackTrace();
307 }
308 }
309 }
310 if (DEBUG_TOUCH) Log.e("NavitGraphics", "SensorThread ended");
311 }
312 }
313
314 public static OverlayDrawThread overlay_draw_thread = null;
315
316 public static class OverlayDrawThread extends Thread
317 {
318 private Boolean running = true;
319 private Boolean redraw = false;
320 private long start_timestamp = 0L;
321
322 OverlayDrawThread()
323 {
324 // Log.e("NavitGraphics", "OverlayDrawThread created");
325 start_timestamp = System.currentTimeMillis();
326 }
327
328 public void run()
329 {
330 this.running = true;
331 this.redraw = true;
332
333 // start_timestamp = System.currentTimeMillis();
334 // Log.e("NavitGraphics", "OverlayDrawThread starting"+start_timestamp);
335
336 while (this.running)
337 {
338
339 if (System.currentTimeMillis() > (start_timestamp + OverlayDrawThread_cancel_drawing_timeout))
340 {
341 // after xxx milliseconds of delay, stop drawing the map!
342 // most likely the device is too slow, or there are too much items to draw
343 try
344 {
345 //Log.e("NavitGraphics", "## stop map drawing x1: NOW ##" + System.currentTimeMillis());
346 NavitGraphics.CallbackMessageChannel(50, "");
347 //Message msg = new Message();
348 //Bundle b = new Bundle();
349 //b.putInt("Callback", 50);
350 //msg.setData(b);
351 //callback_handler.sendMessage(msg);
352 //Log.e("NavitGraphics", "## stop map drawing x2: NOW ##" + System.currentTimeMillis());
353 this.running = false;
354 break;
355 }
356 catch (Exception e)
357 {
358 e.printStackTrace();
359 }
360 }
361
362 if (System.currentTimeMillis() > (start_timestamp + OverlayDrawThread_cancel_thread_timeout))
363 {
364 // just to be safe, stop after 5 seconds
365 this.running = false;
366 }
367
368 //Log.e("NavitGraphics", "OverlayDrawThread running");
369 if (this.redraw)
370 {
371 //Log.e("NavitGraphics", "OverlayDrawThread -> redraw");
372 try
373 {
374 //NavitAOverlay_s.invalidate();
375 Message msg = Navit.Navit_progress_h.obtainMessage();
376 Bundle b = new Bundle();
377 msg.what = 16;
378 msg.setData(b);
379 Navit.Navit_progress_h.sendMessage(msg);
380 }
381 catch (Exception e)
382 {
383 e.printStackTrace();
384 }
385
386 //this.redraw = false;
387 }
388
389 try
390 {
391 Thread.sleep(OverlayDrawThread_cancel_thread_sleep_time);
392 }
393 catch (InterruptedException e)
394 {
395 e.printStackTrace();
396 }
397 }
398
399 //Log.e("NavitGraphics", "OverlayDrawThread finished");
400 }
401
402 public void redraw_overlay()
403 {
404 //Log.e("NavitGraphics", "OverlayDrawThread set redraw");
405 this.redraw = true;
406 }
407
408 public void stop_me()
409 {
410 this.running = false;
411 }
412
413 public void stop_redraw()
414 {
415 this.redraw = false;
416 }
417 }
418
419 public NavitGraphics(Activity activity, NavitGraphics parent, int x, int y, int w, int h, int alpha, int wraparound, int use_camera)
420 {
421
422 System.out.println("GC001--");
423
424 if (parent == null)
425 {
426 System.out.println("GC002--");
427
428 this.activity = activity;
429 view = new View(activity)
430 {
431 int touch_mode = NONE;
432 float oldDist = 0;
433 PointF touch_now = new PointF(0, 0);
434 PointF touch_now_center = new PointF(0, 0);
435 PointF touch_start = new PointF(0, 0);
436 PointF touch_prev = new PointF(0, 0);
437 static final int NONE = 0;
438 static final int DRAG = 1;
439 static final int ZOOM = 2;
440 static final int PRESS = 3;
441
442 @Override
443 protected void onDraw(Canvas canvas)
444 {
445 super.onDraw(canvas);
446
447 if (!MAP_DISPLAY_OFF)
448 {
449 if (ZOOM_MODE_ACTIVE)
450 {
451 canvas.save();
452 canvas.scale(ZOOM_MODE_SCALE, ZOOM_MODE_SCALE, this.touch_now_center.x, this.touch_now_center.y);
453 }
454 canvas.drawBitmap(draw_bitmap, pos_x, pos_y, null);
455 if (ZOOM_MODE_ACTIVE)
456 {
457 canvas.restore();
458 }
459 }
460 if (overlay_disabled == 0)
461 {
462 //Log.e("NavitGraphics", "view -> onDraw 1");
463 // assume we ARE in map view mode!
464 in_map = true;
465
466 if (!MAP_DISPLAY_OFF)
467 {
468 Object overlays_array[];
469 overlays_array = overlays.toArray();
470 //int ov_count = 0;
471 for (Object overlay : overlays_array)
472 {
473 //ov_count++;
474 //Log.e("NavitGraphics", "view -> onDraw 2:" + ov_count);
475
476 NavitGraphics overlay_graphics = (NavitGraphics) overlay;
477 if (overlay_graphics.overlay_disabled == 0)
478 {
479 //Log.e("NavitGraphics", "view -> onDraw 3:" + ov_count);
480
481 int x = overlay_graphics.pos_x;
482 int y = overlay_graphics.pos_y;
483 if (overlay_graphics.pos_wraparound != 0 && x < 0) x += bitmap_w;
484 if (overlay_graphics.pos_wraparound != 0 && y < 0) y += bitmap_h;
485 canvas.drawBitmap(overlay_graphics.draw_bitmap, x, y, null);
486 }
487 }
488 }
489 }
490 }
491
492 @Override
493 protected void onSizeChanged(int w, int h, int oldw, int oldh)
494 {
495 mCanvasWidth = w;
496 mCanvasHeight = h;
497
498 Log.e("Navit", "NavitGraphics -> onSizeChanged pixels x=" + w + " pixels y=" + h);
499 Log.e("Navit", "NavitGraphics -> onSizeChanged dpi=" + Navit.metrics.densityDpi);
500 Log.e("Navit", "NavitGraphics -> onSizeChanged density=" + Navit.metrics.density);
501 Log.e("Navit", "NavitGraphics -> onSizeChanged scaledDensity=" + Navit.metrics.scaledDensity);
502 super.onSizeChanged(w, h, oldw, oldh);
503 if (draw_bitmap != null)
504 {
505 // try to avoid out of memory errors
506 draw_bitmap.recycle();
507 }
508
509 try
510 {
511 draw_bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
512 }
513 catch (OutOfMemoryError e)
514 {
515 int usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
516 String usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
517 System.out.println("" + usedMegsString);
518 System.out.println("@@@@@@@@ out of VM Memory @@@@@@@@");
519 System.gc();
520 usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
521 usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
522 System.out.println("" + usedMegsString);
523 // try again
524 draw_bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
525 }
526
527 draw_canvas = new Canvas(draw_bitmap);
528 bitmap_w = w;
529 bitmap_h = h;
530 SizeChangedCallback(w, h);
531
532 draw_factor = 1.0f;
533 if (Navit.my_display_density.compareTo("mdpi") == 0)
534 {
535 draw_factor = 1.0f;
536 }
537 else if (Navit.my_display_density.compareTo("ldpi") == 0)
538 {
539 draw_factor = 0.7f;
540 }
541 else if (Navit.my_display_density.compareTo("hdpi") == 0)
542 {
543 draw_factor = 1.5f;
544 }
545
546 if (Navit.first_ever_startup)
547 {
548 Navit.first_ever_startup = false;
549 System.out.println("");
550 System.out.println("*** Zoom out FULL (#startup#) ***");
551 System.out.println("");
552 Message msg = new Message();
553 Bundle b = new Bundle();
554 b.putInt("Callback", 8);
555 msg.setData(b);
556 callback_handler.sendMessage(msg);
557 }
558 }
559
560 public void do_longpress_action(float x, float y)
561 {
562 // this is called!!! yes really!! via REFLECT (make it better later)
563 if (!NavitAndroidOverlay.confirmed_bubble)
564 {
565 Log.e("NavitGraphics", "do_longpress_action enter");
566 NavitAndroidOverlayBubble b = new NavitAndroidOverlayBubble();
567 b.x = (int) x;
568 b.y = (int) y;
569 NavitAOverlay.set_bubble(b);
570 NavitAOverlay.show_bubble();
571 this.postInvalidate();
572 NavitAOverlay.invalidate();
573 }
574 }
575
576 @Override
577 public boolean onTouchEvent(MotionEvent event)
578 {
579 PointF touch_now2 = null;
580 PointF touch_start2 = null;
581 PointF touch_prev2 = null;
582 PointF touch_last_load_tiles2 = null;
583
584 if (DEBUG_TOUCH) Log.e("NavitGraphics", "onTouchEvent");
585 if (DEBUG_TOUCH) Log.e("NavitGraphics", "systime1:" + System.currentTimeMillis());
586 if (DEBUG_TOUCH) Log.e("NavitGraphics", "eventtime1:" + event.getEventTime());
587
588 super.onTouchEvent(event);
589 int action = event.getAction();
590 int x = (int) event.getX();
591 int y = (int) event.getY();
592
593 int _ACTION_POINTER_UP_ = MotionEvent.ACTION_POINTER_UP;
594 int _ACTION_POINTER_DOWN_ = MotionEvent.ACTION_POINTER_DOWN;
595 int _ACTION_MASK_ = MotionEvent.ACTION_MASK;
596
597 // calculate value
598 int switch_value = (event.getAction() & _ACTION_MASK_);
599 if (DEBUG_TOUCH) Log.e("NavitGraphics", "switch_value=" + switch_value);
600 if (DEBUG_TOUCH) Log.e("NavitGraphics", "_ACTION_MASK_=" + _ACTION_MASK_);
601 // calculate value
602
603 if (DEBUG_TOUCH) Log.e("NavitGraphics", "event x=" + event.getX() + " y=" + event.getY());
604
605 if (switch_value == MotionEvent.ACTION_DOWN)
606 {
607 this.touch_now.set(event.getX(), event.getY());
608 this.touch_start.set(event.getX(), event.getY());
609 this.touch_prev.set(event.getX(), event.getY());
610 if (DEBUG_TOUCH) Log.e("NavitGraphics", "ACTION_DOWN start");
611
612 d_pos_x_old = pos_x;
613 d_pos_y_old = pos_y;
614 //Log.e("NavitGraphics", "pos_x=" + pos_x);
615 //Log.e("NavitGraphics", "pos_y=" + pos_y);
616
617 if (in_map)
618 {
619 if (!NavitAOverlay.get_show_bubble())
620 {
621 if (DEBUG_TOUCH) Log.e("NavitGraphics", "hide bubble X1");
622 NavitAOverlay.hide_bubble();
623 // remember last press on screen time
624 last_touch_on_screen = event.getEventTime(); // System.currentTimeMillis();
625 touch_sensor_thread = new SensorThread(last_touch_on_screen, this, NavitAOverlay, this.touch_now.x, this.touch_now.y);
626 touch_sensor_thread.start();
627 }
628 }
629
630 wait_for_redraw_map = true;
631 if (DEBUG_TOUCH) System.out.println("wait_for_redraw_map=true");
632
633 // down
634 // Message msg = new Message();
635 // Bundle b = new Bundle();
636 // b.putInt("Callback", 21);
637 // b.putInt("x", x);
638 // b.putInt("y", y);
639 // msg.setData(b);
640 // callback_handler.sendMessage(msg);
641 // ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
642
643 // wait_for_redraw_map = false;
644
645 touch_mode = DRAG;
646
647 if (DEBUG_TOUCH) Log.e("NavitGraphics", "ACTION_DOWN end");
648
649 // hold all map drawing -----------
650 Message msg = new Message();
651 Bundle b = new Bundle();
652 b.putInt("Callback", 69);
653 msg.setData(b);
654 try
655 {
656 callback_handler.sendMessage(msg);
657 }
658 catch (Exception e)
659 {
660 }
661 // hold all map drawing -----------
662 }
663 else if ((switch_value == MotionEvent.ACTION_UP) || (switch_value == _ACTION_POINTER_UP_))
664 {
665 this.touch_now.set(event.getX(), event.getY());
666 touch_now2 = touch_now;
667 touch_start2 = touch_start;
668 if (DEBUG_TOUCH) Log.e("NavitGraphics", "ACTION_UP start");
669 if (DEBUG_TOUCH) Log.e("NavitGraphics", "xxxxxxxxxx");
670 try
671 {
672 if (DEBUG_TOUCH) Log.e("NavitGraphics", "sensor thread stop X1");
673 //touch_sensor_thread.down();
674 touch_sensor_thread.stop_me();
675 // touch_sensor_thread.stop();
676 }
677 catch (Exception e)
678 {
679
680 }
681 // if it was a real longpress, dont hide the bubble
682 long real_event_time = event.getEventTime();
683 // long real_event_time = System.currentTimeMillis();
684 if ((in_map) && ((real_event_time - last_touch_on_screen) > long_press_on_screen_interval))
685 {
686 // real long press
687 }
688 else
689 {
690 if (DEBUG_TOUCH) Log.e("NavitGraphics", "hide bubble 1");
691 NavitAOverlay.hide_bubble();
692 }
693
694 if ((touch_mode == DRAG) && (spacing(touch_start2, touch_now2) < long_press_on_screen_max_distance))
695 {
696 // just a single press down
697 touch_mode = PRESS;
698
699 try
700 {
701 if (DEBUG_TOUCH) Log.e("NavitGraphics", "touch_sensor_thread.stop 1");
702 //touch_sensor_thread.down();
703 touch_sensor_thread.stop_me();
704 // touch_sensor_thread.stop();
705 }
706 catch (Exception e)
707 {
708
709 }
710
711 // was it a long press? or normal quick touch?
712 //if ((in_map) && ((System.currentTimeMillis() - last_touch_on_screen) > long_press_on_screen_interval))
713 //{
714 // Log.e("NavitGraphics", "onTouch up (LONG PRESS 1)");
715 // do_longpress_action(touch_now.x, touch_now.y);
716 //}
717 //else
718 //{
719 //Log.e("NavitGraphics", "onTouch up (quick touch)");
720 //wait_for_redraw_map = true;
721 //System.out.println("wait_for_redraw_map=true 2");
722
723 //*ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
724
725 // quick touch --> here we could repeat the last spoken direction ...
726 // quick touch --> here we could repeat the last spoken direction ...
727 // quick touch --> here we could repeat the last spoken direction ...
728 // quick touch --> here we could repeat the last spoken direction ...
729 // quick touch --> here we could repeat the last spoken direction ...
730 // quick touch --> here we could repeat the last spoken direction ...
731 // quick touch --> here we could repeat the last spoken direction ...
732 // quick touch --> here we could repeat the last spoken direction ...
733
734 if (DEBUG_TOUCH) System.out.println("wait_for_redraw_map=false 9");
735 NavitGraphics.wait_for_redraw_map = false;
736 try
737 {
738 if (DEBUG_TOUCH) Log.e("NavitGraphics", "overlay thread stop X1");
739 NavitAndroidOverlay.overlay_draw_thread1.stop_redraw();
740 NavitAndroidOverlay.overlay_draw_thread1.stop_me();
741 NavitAndroidOverlay.overlay_draw_thread1 = null;
742 }
743 catch (Exception e)
744 {
745 //e.printStackTrace();
746 }
747 try
748 {
749 NavitAOverlay_s.postInvalidate();
750 }
751 catch (Exception e)
752 {
753 e.printStackTrace();
754 }
755 //}
756 touch_mode = NONE;
757 }
758 else
759 {
760 if (touch_mode == DRAG)
761 {
762 touch_now2 = touch_now;
763 touch_start2 = touch_start;
764
765 if (DEBUG_TOUCH) Log.e("NavitGraphics", "onTouch move");
766
767 try
768 {
769 if (DEBUG_TOUCH) Log.e("NavitGraphics", "sensor thread stop X2");
770 //touch_sensor_thread.down();
771 touch_sensor_thread.stop_me();
772 // touch_sensor_thread.stop();
773 }
774 catch (Exception e)
775 {
776
777 }
778
779 // if we drag, hide the bubble --> NO !!
780 // NavitAOverlay.hide_bubble();
781
782 // wait_for_redraw_map = true;
783 //System.out.println("wait_for_redraw_map=true 3");
784
785 // DRAG ----------- new END --------------
786 // DRAG ----------- new END --------------
787 // DRAG ----------- new END --------------
788 // this.touch_start
789 // this.touch_now
790 //pos_x = (int) (this.touch_now.x - this.touch_start.x);
791 //pos_y = (int) (this.touch_now.y - this.touch_start.y);
792 pos_x = d_pos_x_old;
793 pos_y = d_pos_y_old;
794 // ??? // ButtonCallback(1, 1, (int) this.touch_start.x, (int) this.touch_start.y); // down
795 //this.invalidate();
796 //this.postInvalidate();
797 // DRAG ----------- new END --------------
798 // DRAG ----------- new END --------------
799 // DRAG ----------- new END --------------
800
801 // allow all map drawing -----------
802 Message msg2 = new Message();
803 Bundle b2 = new Bundle();
804 b2.putInt("Callback", 70);
805 msg2.setData(b2);
806 try
807 {
808 callback_handler.sendMessage(msg2);
809 }
810 catch (Exception e)
811 {
812 }
813
814 // MotionCallback(x, y);
815 MotionCallback((int) this.touch_start.x, (int) this.touch_start.y, (int) this.touch_now.x, (int) this.touch_now.y);
816 // ??? // ButtonCallback(0, 1, x, y); // up
817
818 try
819 {
820 // try to show current location/streetname
821 Message msg1 = new Message();
822 Bundle b1 = new Bundle();
823 b1.putInt("Callback", 9901);
824 msg1.setData(b1);
825 NavitGraphics.callback_handler_s.sendMessage(msg1);
826 }
827 catch (Exception e)
828 {
829
830 }
831
832 touch_mode = NONE;
833 }
834 else
835 {
836 if (touch_mode == ZOOM)
837 {
838 // end of "pinch zoom" move
839 ZOOM_MODE_ACTIVE = false;
840 ZOOM_MODE_SCALE = 0;
841
842 if (DEBUG_TOUCH) Log.e("NavitGraphics", "onTouch zoom");
843
844 float newDist = spacing(event);
845 float scale = 0;
846 if (newDist > 10f)
847 {
848 scale = newDist / oldDist;
849 }
850
851 if (scale > 1.05)
852 {
853 wait_for_redraw_map = true;
854 if (DEBUG_TOUCH) System.out.println("wait_for_redraw_map=true 4");
855
856 try
857 {
858 if (DEBUG_TOUCH) Log.e("NavitGraphics", "sensor thread stop X3");
859 //touch_sensor_thread.down();
860 touch_sensor_thread.stop_me();
861 // touch_sensor_thread.stop();
862 }
863 catch (Exception e)
864 {
865
866 }
867 if (DEBUG_TOUCH) Log.e("NavitGraphics", "hide bubble 2");
868 // if we drag, hide the bubble
869 NavitAOverlay.hide_bubble();
870
871 // zoom in
872 if (scale < 0.2f)
873 {
874 scale = 0.2f;
875 }
876 else if (scale > 5)
877 {
878 scale = 5;
879 }
880
881 pos_x = d_pos_x_old;
882 pos_y = d_pos_y_old;
883
884 Message msg = new Message();
885 Bundle b = new Bundle();
886 b.putInt("Callback", 61);
887 //System.out.println("sc1:" + Navit.GlobalScaleLevel);
888 Navit.GlobalScaleLevel = (int) (Navit.GlobalScaleLevel / scale);
889 //System.out.println("sc1.1:" + Navit.GlobalScaleLevel);
890
891 this.touch_now_center = calc_center(event);
892 b.putString("s", (int) this.touch_now_center.x + "#" + (int) this.touch_now_center.y + "#" + Integer.toString(Navit.GlobalScaleLevel));
893 msg.setData(b);
894 try
895 {
896 callback_handler.sendMessage(msg);
897 //System.out.println("touch: set zoom(in) level: " + Navit.GlobalScaleLevel);
898 }
899 catch (Exception e)
900 {
901 }
902
903 // next lines are a hack, without it screen will not get updated anymore!
904 //*ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
905 //*MotionCallback(MotionCallbackID, x + 15, y);
906 //*MotionCallback(MotionCallbackID, x - 15, y);
907 //*ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
908 //*this.postInvalidate();
909
910 try
911 {
912 if (DEBUG_TOUCH) Log.e("NavitGraphics", "sensor thread stop X4");
913 //touch_sensor_thread.down();
914 touch_sensor_thread.stop_me();
915 // touch_sensor_thread.stop();
916 }
917 catch (Exception e)
918 {
919
920 }
921 // if we drag, hide the bubble
922 if (DEBUG_TOUCH) Log.e("NavitGraphics", "hide bubble X3");
923 NavitAOverlay.hide_bubble();
924
925 if (DEBUG_TOUCH) Log.e("NavitGraphics", "onTouch zoom in");
926 }
927 else if (scale < 0.95)
928 {
929 wait_for_redraw_map = true;
930 if (DEBUG_TOUCH) System.out.println("wait_for_redraw_map=true 5");
931
932 try
933 {
934 if (DEBUG_TOUCH) Log.e("NavitGraphics", "sensor thread stop X5");
935 //touch_sensor_thread.down();
936 touch_sensor_thread.stop_me();
937 // touch_sensor_thread.stop();
938 }
939 catch (Exception e)
940 {
941
942 }
943 if (DEBUG_TOUCH) Log.e("NavitGraphics", "hide bubble 3");
944 // if we drag, hide the bubble
945 NavitAOverlay.hide_bubble();
946
947 // zoom out
948
949 if (scale < 0.2f)
950 {
951 scale = 0.2f;
952 }
953 else if (scale > 6)
954 {
955 scale = 6;
956 }
957
958 pos_x = d_pos_x_old;
959 pos_y = d_pos_y_old;
960
961 Message msg = new Message();
962 Bundle b = new Bundle();
963 b.putInt("Callback", 61);
964 //System.out.println("sc2:" + Navit.GlobalScaleLevel);
965 Navit.GlobalScaleLevel = (int) (Navit.GlobalScaleLevel / scale);
966 if (Navit.GlobalScaleLevel < 2)
967 {
968 Navit.GlobalScaleLevel = 2;
969 }
970 //System.out.println("sc2.1:" + Navit.GlobalScaleLevel);
971 this.touch_now_center = calc_center(event);
972 b.putString("s", (int) this.touch_now_center.x + "#" + (int) this.touch_now_center.y + "#" + Integer.toString(Navit.GlobalScaleLevel));
973 msg.setData(b);
974 try
975 {
976 callback_handler.sendMessage(msg);
977 //System.out.println("touch: set zoom(out) level: " + Navit.GlobalScaleLevel);
978 }
979 catch (Exception e)
980 {
981 }
982
983 // next lines are a hack, without it screen will not get updated anymore!
984 //*ButtonCallback(ButtonCallbackID, 1, 1, x, y); // down
985 //*MotionCallback(MotionCallbackID, x + 15, y);
986 //*MotionCallback(MotionCallbackID, x - 15, y);
987 //*ButtonCallback(ButtonCallbackID, 0, 1, x, y); // up
988 //*this.postInvalidate();
989
990 try
991 {
992 if (DEBUG_TOUCH) Log.e("NavitGraphics", "sensor thread stop X6");
993 //touch_sensor_thread.down();
994 touch_sensor_thread.stop_me();
995 // touch_sensor_thread.stop();
996 }
997 catch (Exception e)
998 {
999
1000 }
1001 if (DEBUG_TOUCH) Log.e("NavitGraphics", "hide bubble 4");
1002 // if we drag, hide the bubble
1003 NavitAOverlay.hide_bubble();
1004
1005 if (DEBUG_TOUCH) Log.e("NavitGraphics", "onTouch zoom out");
1006 }
1007 else
1008 {
1009 pos_x = d_pos_x_old;
1010 pos_y = d_pos_y_old;
1011
1012 // move was not zoom-out OR zoom-in
1013 // so just ignore and remove any pending stuff
1014 if (DEBUG_TOUCH) System.out.println("wait_for_redraw_map=false 10");
1015 NavitGraphics.wait_for_redraw_map = false;
1016 try
1017 {
1018 if (DEBUG_TOUCH) Log.e("NavitGraphics", "overlay thread stop X10");
1019 NavitAndroidOverlay.overlay_draw_thread1.stop_redraw();
1020 NavitAndroidOverlay.overlay_draw_thread1.stop_me();
1021 NavitAndroidOverlay.overlay_draw_thread1 = null;
1022 }
1023 catch (Exception e)
1024 {
1025 //e.printStackTrace();
1026 }
1027 try
1028 {
1029 NavitAOverlay_s.postInvalidate();
1030 }
1031 catch (Exception e)
1032 {
1033 e.printStackTrace();
1034 }
1035 }
1036 touch_mode = NONE;
1037 }
1038 else
1039 {
1040 if (DEBUG_TOUCH) Log.d("NavitGraphics", "touch_mode=NONE (END of ZOOM part 2)");
1041 touch_mode = NONE;
1042 }
1043 }
1044 }
1045
1046 //Log.e("NavitGraphics", "pos_x=" + pos_x);
1047 //Log.e("NavitGraphics", "pos_y=" + pos_y);
1048 //Log.e("NavitGraphics", "d_pos_x_old=" + d_pos_x_old);
1049 //Log.e("NavitGraphics", "d_pos_y_old=" + d_pos_y_old);
1050
1051 // on final "UP" action, always reset the display center
1052 if (switch_value == MotionEvent.ACTION_UP)
1053 {
1054 pos_x = d_pos_x_old;
1055 pos_y = d_pos_y_old;
1056
1057 try
1058 {
1059 if (DEBUG_TOUCH) Log.e("NavitGraphics", "sensor thread stop final88");
1060 touch_sensor_thread.stop_me();
1061 }
1062 catch (Exception e)
1063 {
1064
1065 }
1066
1067 // allow all map drawing -----------
1068 Message msg2 = new Message();
1069 Bundle b2 = new Bundle();
1070 b2.putInt("Callback", 70);
1071 msg2.setData(b2);
1072 try
1073 {
1074 callback_handler.sendMessage(msg2);
1075 }
1076 catch (Exception e)
1077 {
1078 }
1079 // allow all map drawing -----------
1080 }
1081 }
1082 else if (switch_value == MotionEvent.ACTION_MOVE)
1083 {
1084 if (DEBUG_TOUCH) Log.e("NavitGraphics", "ACTION_MOVE");
1085
1086 if (touch_mode == DRAG)
1087 {
1088 if (DEBUG_TOUCH) Log.e("NavitGraphics", "mode = DRAG");
1089
1090 this.touch_now.set(event.getX(), event.getY());
1091 touch_now2 = touch_now;
1092 touch_start2 = touch_start;
1093 touch_prev2 = touch_prev;
1094 this.touch_prev.set(event.getX(), event.getY());
1095
1096 // try
1097 // {
1098 // //touch_sensor_thread.down();
1099 // touch_sensor_thread.stop_me();
1100 // // touch_sensor_thread.stop();
1101 // }
1102 // catch (Exception e)
1103 // {
1104 //
1105 // }
1106
1107 if (DEBUG_TOUCH) Log.e("NavitGraphics", "systime2:" + System.currentTimeMillis());
1108 if (DEBUG_TOUCH) Log.e("NavitGraphics", "eventtime2:" + event.getEventTime());
1109 if (DEBUG_TOUCH) Log.e("NavitGraphics", "last touch screen:" + last_touch_on_screen);
1110 // if ((System.currentTimeMillis() - last_touch_on_screen) > long_press_on_screen_interval)
1111 // {
1112 // Log.e("NavitGraphics", "onTouch up (LONG PRESS 2) ***** 11 *****");
1113 // // do_longpress_action(touch_now.x, touch_now.y);
1114 // }
1115
1116 if ((in_map) && (spacing(touch_start2, touch_now2) < long_press_on_screen_max_distance))
1117 {
1118 // now its still a PRESS, because we have not moved around too much!
1119
1120 if (DEBUG_TOUCH) Log.e("NavitGraphics", "in move: still a PRESS action");
1121
1122 // is it a still ongoing long press?
1123 if ((System.currentTimeMillis() - last_touch_on_screen) > long_press_on_screen_interval)
1124 {
1125 if (DEBUG_TOUCH) Log.e("NavitGraphics", "onTouch up (LONG PRESS 2) ***** 22 *****");
1126 // do_longpress_action(touch_now.x, touch_now.y);
1127 }
1128 }
1129 else
1130 {
1131 if (DEBUG_TOUCH) Log.e("NavitGraphics", "onTouch move2");
1132 // MotionCallback(MotionCallbackID, x, y);
1133 // DRAG ----------- new --------------
1134 // DRAG ----------- new --------------
1135 // DRAG ----------- new --------------
1136
1137 try
1138 {
1139 if (DEBUG_TOUCH) Log.e("NavitGraphics", "sensor thread stop X6");
1140 //touch_sensor_thread.down();
1141 touch_sensor_thread.stop_me();
1142 // touch_sensor_thread.stop();
1143 }
1144 catch (Exception e)
1145 {
1146
1147 }
1148
1149 pos_x = (int) (this.touch_now.x - this.touch_start.x);
1150 pos_y = (int) (this.touch_now.y - this.touch_start.y);
1151 this.invalidate();
1152 // this.postInvalidate();
1153 // DRAG ----------- new --------------
1154 // DRAG ----------- new --------------
1155 // DRAG ----------- new --------------
1156
1157 }
1158 }
1159 else if (touch_mode == ZOOM)
1160 {
1161 this.touch_now.set(event.getX(), event.getY());
1162 this.touch_prev.set(event.getX(), event.getY());
1163
1164 if (DEBUG_TOUCH) Log.e("NavitGraphics", "zoom 2");
1165
1166 if (DEBUG_TOUCH) Log.e("NavitGraphics", "hide bubble 73");
1167 NavitAOverlay.hide_bubble();
1168 try
1169 {
1170 if (DEBUG_TOUCH) Log.e("NavitGraphics", "touch_sensor_thread.stop 73");
1171 touch_sensor_thread.stop_me();
1172 }
1173 catch (Exception e)
1174 {
1175 }
1176 if (DEBUG_TOUCH) Log.e("NavitGraphics", "hide bubble 74");
1177 NavitAOverlay.hide_bubble();
1178
1179 // were are in the middle of a zooming action here ----------
1180 // were are in the middle of a zooming action here ----------
1181
1182 this.touch_now_center = calc_center(event);
1183 float newDist = spacing(event);
1184 float scale = 0;
1185 try
1186 {
1187 scale = newDist / oldDist;
1188 }
1189 catch (Exception ee)
1190 {
1191
1192 }
1193 ZOOM_MODE_SCALE = scale;
1194 ZOOM_MODE_ACTIVE = true;
1195 this.invalidate();
1196 // Log.e("NavitGraphics", "x:" + this.touch_now.x + " y:" + this.touch_now.y);
1197 // were are in the middle of a zooming action here ----------
1198 // were are in the middle of a zooming action here ----------
1199 }
1200 }
1201 else if (switch_value == _ACTION_POINTER_DOWN_)
1202 {
1203 if (DEBUG_TOUCH) Log.e("NavitGraphics", "ACTION_POINTER_DOWN");
1204
1205 oldDist = spacing(event);
1206 if (oldDist > 10f)
1207 {
1208 touch_mode = ZOOM;
1209 if (DEBUG_TOUCH) Log.e("NavitGraphics", "--> zoom");
1210 // zoom action starts here --------
1211 // zoom action starts here --------
1212 // zoom action starts here --------
1213 // zoom action starts here --------
1214 }
1215 }
1216 return true;
1217 }
1218
1219 private float spacing(PointF a, PointF b)
1220 {
1221 float x = a.x - b.x;
1222 float y = a.y - b.y;
1223 return FloatMath.sqrt(x * x + y * y);
1224 }
1225
1226 public PointF calc_center(MotionEvent event)
1227 {
1228 //float x;
1229 //float y;
1230 PointF ret = new PointF(0, 0);
1231 try
1232 {
1233 float y0 = 0;
1234 float y1 = 0;
1235 float x0 = 0;
1236 float x1 = 0;
1237
1238 x0 = event.getX(0);
1239 y0 = event.getY(0);
1240 try
1241 {
1242 x1 = event.getX(1);
1243 y1 = event.getY(1);
1244 }
1245 catch (Exception ex)
1246 {
1247 ex.printStackTrace();
1248 }
1249 ret.x = x0 - ((x0 - x1) / 2);
1250 ret.y = y0 - ((y0 - y1) / 2);
1251 }
1252 catch (Exception ex)
1253 {
1254 ex.printStackTrace();
1255 ret.x = event.getX(0);
1256 ret.y = event.getY(0);
1257 }
1258 return ret;
1259 }
1260
1261 public float spacing(MotionEvent event)
1262 {
1263 float x;
1264 float y;
1265 try
1266 {
1267 float y0 = 0;
1268 float y1 = 0;
1269 float x0 = 0;
1270 float x1 = 0;
1271
1272 x0 = event.getX(0);
1273 y0 = event.getY(0);
1274 try
1275 {
1276 x1 = event.getX(1);
1277 y1 = event.getY(1);
1278 }
1279 catch (Exception ex)
1280 {
1281 ex.printStackTrace();
1282 }
1283 x = x0 - x1;
1284 y = y0 - y1;
1285 }
1286 catch (Exception ex)
1287 {
1288 ex.printStackTrace();
1289 x = 0;
1290 y = 0;
1291 }
1292 return FloatMath.sqrt(x * x + y * y);
1293 }
1294
1295 @Override
1296 public boolean onKeyDown(int keyCode, KeyEvent event)
1297 {
1298 if (keyCode == KeyEvent.KEYCODE_BACK)
1299 {
1300 // override back button, so it does NOT quit the application
1301 return true;
1302 }
1303 return super.onKeyDown(keyCode, event);
1304 }
1305
1306 @Override
1307 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect)
1308 {
1309 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
1310 Log.e("NavitGraphics", "FocusChange " + gainFocus);
1311 }
1312 };
1313
1314 view.setFocusable(true);
1315 view.setFocusableInTouchMode(true);
1316 view.setKeepScreenOn(true);
1317 relativelayout = new RelativeLayout(activity);
1318 //if (use_camera != 0)
1319 //{
1320 // SetCamera(use_camera);
1321 //}
1322 relativelayout.addView(view);
1323
1324 // android overlay
1325 Log.e("Navit", "create android overlay");
1326 NavitAOverlay = new NavitAndroidOverlay(relativelayout.getContext());
1327 NavitAOverlay_s = NavitAOverlay;
1328 RelativeLayout.LayoutParams NavitAOverlay_lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
1329 relativelayout.addView(NavitAOverlay, NavitAOverlay_lp);
1330 NavitAOverlay.bringToFront();
1331 NavitAOverlay.invalidate();
1332 // android overlay
1333
1334 // android OSDJava
1335 Log.e("Navit", "create android OSDJava");
1336 NavitAOSDJava = new NavitOSDJava(relativelayout.getContext());
1337 NavitAOSDJava_ = NavitAOSDJava;
1338 RelativeLayout.LayoutParams NavitAOSDJava_lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
1339 relativelayout.addView(NavitAOSDJava, NavitAOSDJava_lp);
1340 NavitAOSDJava.bringToFront();
1341 NavitAOSDJava.invalidate();
1342 // android OSDJava
1343
1344 // android Messages TextView
1345 Log.e("Navit", "create android Messages TextView");
1346 NavitMsgTv = new TextView(relativelayout.getContext());
1347 NavitMsgTv_ = NavitMsgTv;
1348 RelativeLayout.LayoutParams NavitMsgTv_lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
1349 // NavitMsgTv_lp.height = 50;
1350 NavitMsgTv_lp.leftMargin = 120;
1351 // NavitMsgTv.setHeight(10);
1352 int tc = Color.argb(125, 0, 0, 0); // half transparent black
1353 NavitMsgTv.setBackgroundColor(tc);
1354 NavitMsgTv.setLines(4);
1355 NavitMsgTv.setTextSize(12);
1356 NavitMsgTv.setTextColor(Color.argb(255, 200, 200, 200)); // almost white
1357 relativelayout.addView(NavitMsgTv, NavitMsgTv_lp);
1358 NavitMsgTv.bringToFront();
1359 NavitMsgTv.invalidate();
1360 // android Messages TextView
1361
1362 // android Speech Messages TextView
1363 Log.e("Navit", "create android Speech Messages TextView");
1364 NavitMsgTv2 = new TextView(relativelayout.getContext());
1365 NavitMsgTv2_ = NavitMsgTv2;
1366 RelativeLayout.LayoutParams NavitMsgTv_lp2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
1367 NavitMsgTv_lp2.leftMargin = 10;
1368 NavitMsgTv_lp2.rightMargin = 10;
1369 int tc2 = Color.argb(125, 0, 0, 0); // half transparent black
1370 NavitMsgTv2.setBackgroundColor(tc2);
1371 NavitMsgTv2.setTextSize(15);
1372 NavitMsgTv2.setTextColor(Color.argb(255, 200, 200, 200)); // almost white
1373
1374 ScrollView sc = new ScrollView(relativelayout.getContext());
1375 RelativeLayout.LayoutParams NavitMsgTv_lp3 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
1376 sc.addView(NavitMsgTv2, NavitMsgTv_lp2);
1377 sc.setFadingEdgeLength(20);
1378 sc.setScrollbarFadingEnabled(true);
1379 sc.setHorizontalScrollBarEnabled(true);
1380 sc.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
1381 NavitMsgTv2.setGravity(Gravity.BOTTOM);
1382 relativelayout.addView(sc, NavitMsgTv_lp3);
1383
1384 NavitMsgTv2.bringToFront();
1385 NavitMsgTv2.invalidate();
1386 NavitMsgTv2.setEnabled(false);
1387 NavitMsgTv2.setVisibility(View.GONE);
1388 // android Speech Messages TextView
1389
1390 // busy spinner view on top of everything
1391 ZANaviBusySpinner busyspinner = new ZANaviBusySpinner(relativelayout.getContext());
1392 busyspinner_ = busyspinner;
1393 RelativeLayout.LayoutParams ZANaviBusySpinner_lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
1394 relativelayout.addView(busyspinner, ZANaviBusySpinner_lp);
1395 busyspinner.bringToFront();
1396 busyspinner.invalidate();
1397 busyspinner.setVisibility(View.INVISIBLE);
1398
1399 ZANaviBusyText busyspinnertext = new ZANaviBusyText(relativelayout.getContext());
1400 busyspinnertext_ = busyspinnertext;
1401 RelativeLayout.LayoutParams ZANaviBusyText_lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
1402 relativelayout.addView(busyspinnertext, ZANaviBusyText_lp);
1403 busyspinnertext.bringToFront();
1404 busyspinnertext.invalidate();
1405 busyspinnertext.setVisibility(View.INVISIBLE);
1406 // busy spinner view on top of everything
1407
1408 // big map overlay
1409 // NavitGlobalMap_ = new NavitGlobalMap(relativelayout.getContext());
1410 // RelativeLayout.LayoutParams NavitGlobalMap_lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
1411 // relativelayout.addView(NavitGlobalMap_, NavitGlobalMap_lp);
1412 // NavitGlobalMap_.bringToFront();
1413 // NavitGlobalMap_.invalidate();
1414 // big map overlay
1415
1416 activity.setContentView(relativelayout);
1417 view.requestFocus();
1418 }
1419 else
1420 {
1421 if (draw_bitmap != null)
1422 {
1423 // try to avoid out of memory errors
1424 draw_bitmap.recycle();
1425 }
1426
1427 try
1428 {
1429 draw_bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
1430 }
1431 catch (OutOfMemoryError e)
1432 {
1433 int usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
1434 String usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
1435 System.out.println("" + usedMegsString);
1436 System.out.println("@@@@@@@@ out of VM Memory @@@@@@@@");
1437 System.gc();
1438 usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
1439 usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
1440 System.out.println("" + usedMegsString);
1441 // try again
1442 draw_bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
1443 }
1444
1445 bitmap_w = w;
1446 bitmap_h = h;
1447 pos_x = x;
1448 pos_y = y;
1449 pos_wraparound = wraparound;
1450 draw_canvas = new Canvas(draw_bitmap);
1451 parent.overlays.add(this);
1452 }
1453 parent_graphics = parent;
1454 }
1455
1456 public Handler callback_handler = new Handler()
1457 {
1458 public void handleMessage(Message msg)
1459 {
1460 if (msg.getData().getInt("Callback") == 1)
1461 {
1462 // zoom in
1463 CallbackMessageChannel(1, "");
1464 }
1465 else if (msg.getData().getInt("Callback") == 2)
1466 {
1467 // zoom out
1468 CallbackMessageChannel(2, "");
1469 }
1470 else if (msg.getData().getInt("Callback") == 3)
1471 {
1472 // get values
1473 String lat = msg.getData().getString("lat");
1474 String lon = msg.getData().getString("lon");
1475 String q = msg.getData().getString("q");
1476 // set routing target to lat,lon
1477 CallbackMessageChannel(3, lat + "#" + lon + "#" + q);
1478 }
1479 else if (msg.getData().getInt("Callback") == 48)
1480 {
1481 // get values
1482 String lat = msg.getData().getString("lat");
1483 String lon = msg.getData().getString("lon");
1484 String q = msg.getData().getString("q");
1485 // append to routing, add waypoint at lat,lon
1486 CallbackMessageChannel(48, lat + "#" + lon + "#" + q);
1487 }
1488 else if (msg.getData().getInt("Callback") == 4)
1489 {
1490 // set routing target to pixel x,y
1491 int x = msg.getData().getInt("x");
1492 int y = msg.getData().getInt("y");
1493
1494 CallbackMessageChannel(4, "" + x + "#" + y);
1495 try
1496 {
1497 Navit.follow_button_on();
1498 }
1499 catch (Exception e2)
1500 {
1501 e2.printStackTrace();
1502 }
1503 }
1504 else if (msg.getData().getInt("Callback") == 49)
1505 {
1506 // set routing target to pixel x,y
1507 int x = msg.getData().getInt("x");
1508 int y = msg.getData().getInt("y");
1509
1510 CallbackMessageChannel(49, "" + x + "#" + y);
1511 try
1512 {
1513 Navit.follow_button_on();
1514 }
1515 catch (Exception e2)
1516 {
1517 e2.printStackTrace();
1518 }
1519 }
1520 else if (msg.getData().getInt("Callback") == 5)
1521 {
1522 String cmd = msg.getData().getString("cmd");
1523 CallbackMessageChannel(5, cmd);
1524 }
1525 else if (msg.getData().getInt("Callback") == 7)
1526 {
1527 CallbackMessageChannel(7, "");
1528 }
1529 else if ((msg.getData().getInt("Callback") > 7) && (msg.getData().getInt("Callback") < 21))
1530 {
1531 CallbackMessageChannel(msg.getData().getInt("Callback"), "");
1532 }
1533 else if (msg.getData().getInt("Callback") == 21)
1534 {
1535 int x = msg.getData().getInt("x");
1536 int y = msg.getData().getInt("y");
1537 // ??? // ButtonCallback(1, 1, x, y); // down
1538 }
1539 else if (msg.getData().getInt("Callback") == 22)
1540 {
1541 int x = msg.getData().getInt("x");
1542 int y = msg.getData().getInt("y");
1543 // ??? // ButtonCallback(0, 1, x, y); // up
1544 }
1545 else if (msg.getData().getInt("Callback") == 23)
1546 {
1547 int x = msg.getData().getInt("x");
1548 int y = msg.getData().getInt("y");
1549 MotionCallback(x, y, 0, 0);
1550 }
1551 else if (msg.getData().getInt("Callback") == 24)
1552 {
1553 try
1554 {
1555 NavitGraphics.NavitMsgTv_.setVisibility(View.VISIBLE);
1556 }
1557 catch (Exception e)
1558 {
1559
1560 }
1561 }
1562 else if (msg.getData().getInt("Callback") == 25)
1563 {
1564 try
1565 {
1566 NavitGraphics.NavitMsgTv_.setVisibility(View.INVISIBLE);
1567 }
1568 catch (Exception e)
1569 {
1570
1571 }
1572 }
1573 else if (msg.getData().getInt("Callback") == 30)
1574 {
1575 // 2D
1576 // String s = msg.getData().getString("s");
1577 CallbackMessageChannel(30, "");
1578 }
1579 else if (msg.getData().getInt("Callback") == 31)
1580 {
1581 // 3D
1582 // String s = msg.getData().getString("s");
1583 CallbackMessageChannel(31, "");
1584 }
1585 else if (msg.getData().getInt("Callback") == 32)
1586 {
1587 // switch to specific 3D pitch
1588 String s = msg.getData().getString("s");
1589 CallbackMessageChannel(32, s);
1590 }
1591 else if (msg.getData().getInt("Callback") == 33)
1592 {
1593 // zoom to specific zoomlevel
1594 String s = msg.getData().getString("s");
1595 CallbackMessageChannel(33, s);
1596 }
1597 else if (msg.getData().getInt("Callback") == 34)
1598 {
1599 // announcer voice OFF
1600 CallbackMessageChannel(34, "");
1601 }
1602 else if (msg.getData().getInt("Callback") == 35)
1603 {
1604 // announcer voice ON
1605 CallbackMessageChannel(35, "");
1606 }
1607 else if (msg.getData().getInt("Callback") == 36)
1608 {
1609 // switch "Lock on road" ON
1610 CallbackMessageChannel(36, "");
1611 }
1612 else if (msg.getData().getInt("Callback") == 37)
1613 {
1614 // switch "Lock on road" OFF
1615 CallbackMessageChannel(37, "");
1616 }
1617 else if (msg.getData().getInt("Callback") == 38)
1618 {
1619 // switch "Northing" ON
1620 CallbackMessageChannel(38, "");
1621 }
1622 else if (msg.getData().getInt("Callback") == 39)
1623 {
1624 // switch "Northing" OFF
1625 CallbackMessageChannel(39, "");
1626 }
1627 else if (msg.getData().getInt("Callback") == 40)
1628 {
1629 // switch "Map follows Vehicle" ON
1630 CallbackMessageChannel(40, "");
1631 }
1632 else if (msg.getData().getInt("Callback") == 41)
1633 {
1634 // switch "Map follows Vehicle" OFF
1635 CallbackMessageChannel(41, "");
1636 }
1637 else if (msg.getData().getInt("Callback") == 42)
1638 {
1639 // routing mode "highways"
1640 CallbackMessageChannel(42, "");
1641 }
1642 else if (msg.getData().getInt("Callback") == 43)
1643 {
1644 // routing mode "normal roads"
1645 CallbackMessageChannel(43, "");
1646 }
1647 else if (msg.getData().getInt("Callback") == 44)
1648 {
1649 // show duplicates in search results
1650 CallbackMessageChannel(44, "");
1651 }
1652 else if (msg.getData().getInt("Callback") == 45)
1653 {
1654 // filter duplicates in search results
1655 CallbackMessageChannel(45, "");
1656 }
1657 else if (msg.getData().getInt("Callback") == 46)
1658 {
1659 // stop searching and show results found until now
1660 CallbackMessageChannel(46, "");
1661 }
1662 else if (msg.getData().getInt("Callback") == 47)
1663 {
1664 // change maps data dir
1665 String s = msg.getData().getString("s");
1666 CallbackMessageChannel(47, s);
1667 }
1668 else if (msg.getData().getInt("Callback") == 50)
1669 {
1670 // we request to stop drawing the map
1671 CallbackMessageChannel(50, "");
1672 }
1673 else if (msg.getData().getInt("Callback") == 51)
1674 {
1675 // set position to pixel x,y
1676 int x = msg.getData().getInt("x");
1677 int y = msg.getData().getInt("y");
1678 CallbackMessageChannel(51, "" + x + "#" + y);
1679 }
1680 else if (msg.getData().getInt("Callback") == 52)
1681 {
1682 // switch to demo vehicle
1683 String s = msg.getData().getString("s");
1684 CallbackMessageChannel(52, s);
1685 }
1686 else if (msg.getData().getInt("Callback") == 53)
1687 {
1688 // dont speak streetnames
1689 CallbackMessageChannel(53, "");
1690 }
1691 else if (msg.getData().getInt("Callback") == 54)
1692 {
1693 // speak streetnames
1694 CallbackMessageChannel(54, "");
1695 }
1696 else if (msg.getData().getInt("Callback") == 55)
1697 {
1698 // set cache size for (map-)files
1699 String s = msg.getData().getString("s");
1700 CallbackMessageChannel(55, s);
1701 }
1702 // else if (msg.getData().getInt("Callback") == 56)
1703 // {
1704 // // draw polylines with/without circles at the end
1705 // String s = msg.getData().getString("s");
1706 // CallbackMessageChannel(56, s); // 0 -> draw circles, 1 -> DO NOT draw circles
1707 // }
1708 else if (msg.getData().getInt("Callback") == 57)
1709 {
1710 // keep drawing streets as if at "order" level xxx
1711 String s = msg.getData().getString("s");
1712 CallbackMessageChannel(57, s);
1713 }
1714 else if (msg.getData().getInt("Callback") == 58)
1715 {
1716 // street search radius factor (multiplier)
1717 String s = msg.getData().getString("s");
1718 CallbackMessageChannel(58, s);
1719 }
1720 else if (msg.getData().getInt("Callback") == 59)
1721 {
1722 // enable layer "name"
1723 String s = msg.getData().getString("s");
1724 CallbackMessageChannel(59, s);
1725 }
1726 else if (msg.getData().getInt("Callback") == 60)
1727 {
1728 // disable layer "name"
1729 String s = msg.getData().getString("s");
1730 CallbackMessageChannel(60, s);
1731 }
1732 else if (msg.getData().getInt("Callback") == 61)
1733 {
1734 // zoom to specific zoomlevel at given point as center
1735 // pixel-x#pixel-y#zoom-level
1736 String s = msg.getData().getString("s");
1737 CallbackMessageChannel(61, s);
1738 }
1739 else if (msg.getData().getInt("Callback") == 62)
1740 {
1741 // disable map drawing
1742 CallbackMessageChannel(62, "");
1743 }
1744 else if (msg.getData().getInt("Callback") == 63)
1745 {
1746 // enable map drawing
1747 CallbackMessageChannel(63, "");
1748 }
1749 else if (msg.getData().getInt("Callback") == 64)
1750 {
1751 // draw map
1752 CallbackMessageChannel(64, "");
1753 }
1754 else if (msg.getData().getInt("Callback") == 65)
1755 {
1756 // draw map async
1757 CallbackMessageChannel(65, "");
1758 }
1759 else if (msg.getData().getInt("Callback") == 66)
1760 {
1761 // enable "water from relations"
1762 CallbackMessageChannel(66, "");
1763 }
1764 else if (msg.getData().getInt("Callback") == 67)
1765 {
1766 // disable "water from relations"
1767 CallbackMessageChannel(67, "");
1768 }
1769 else if (msg.getData().getInt("Callback") == 68)
1770 {
1771 // shift "order" by this value (only for drawing objects)
1772 String s = msg.getData().getString("s");
1773 CallbackMessageChannel(68, s);
1774 }
1775 else if (msg.getData().getInt("Callback") == 69)
1776 {
1777 // stop drawing map
1778 CallbackMessageChannel(69, "");
1779 }
1780 else if (msg.getData().getInt("Callback") == 70)
1781 {
1782 // allow drawing map
1783 CallbackMessageChannel(70, "");
1784 }
1785 else if (msg.getData().getInt("Callback") == 71)
1786 {
1787 // activate/deactivate "route graph" display
1788 // 0 -> deactivate
1789 // 1 -> activate
1790 String s = msg.getData().getString("s");
1791 CallbackMessageChannel(71, s);
1792 }
1793 else if (msg.getData().getInt("Callback") == 72)
1794 {
1795 // update the route path and route graph (e.g. after setting new roadblocks)
1796 // does not update destinations!!!
1797 CallbackMessageChannel(72, "");
1798 }
1799 else if (msg.getData().getInt("Callback") == 73)
1800 {
1801 // update the route path and route graph (e.g. after setting new roadblocks)
1802 // this destroys the route graph and calcs everything totally new!
1803 CallbackMessageChannel(73, "");
1804 }
1805 }
1806 };
1807
1808 public native void SizeChangedCallback(int w, int h);
1809
1810 // public native void ButtonCallback(int pressed, int button, int x, int y);
1811
1812 public native void MotionCallback(int x1, int y1, int x2, int y2);
1813
1814 // public native void KeypressCallback(String s);
1815
1816 private Canvas draw_canvas;
1817 private Bitmap draw_bitmap;
1818
1819 // private int SizeChangedCallbackID, ButtonCallbackID, MotionCallbackID, KeypressCallbackID;
1820
1821 // private int count;
1822 /*
1823 * public void setSizeChangedCallback(int id)
1824 * {
1825 * SizeChangedCallbackID = id;
1826 * }
1827 */
1828
1829 /*
1830 * public void setButtonCallback(int id)
1831 * {
1832 * ButtonCallbackID = id;
1833 * }
1834 */
1835
1836 /*
1837 * public void setMotionCallback(int id)
1838 * {
1839 * MotionCallbackID = id;
1840 * Navit.setMotionCallback(id, this);
1841 * }
1842 */
1843
1844 /*
1845 * public void setKeypressCallback(int id)
1846 * {
1847 * KeypressCallbackID = id;
1848 * // set callback id also in main intent (for menus)
1849 * Navit.setKeypressCallback(id, this);
1850 * }
1851 */
1852
1853 public void NavitSetGrObj()
1854 {
1855 // set the (static) graphics object (this is bad, please fix me!!)
1856 Navit.N_NavitGraphics = this;
1857 }
1858
1859 protected void draw_polyline(Paint paint, int c[])
1860 {
1861 // Log.e("NavitGraphics","draw_polyline");
1862 paint.setStyle(Paint.Style.STROKE);
1863 b_paint_antialias = paint.isAntiAlias();
1864 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
1865 //paint.setStrokeWidth(0);
1866 b_paint_path.reset();
1867 b_paint_path.moveTo(c[0], c[1]);
1868 for (int i = 2; i < c.length; i += 2)
1869 {
1870 b_paint_path.lineTo(c[i], c[i + 1]);
1871 }
1872 //global_path.close();
1873 draw_canvas.drawPath(b_paint_path, paint);
1874 paint.setAntiAlias(b_paint_antialias);
1875 //paint.setPathEffect(dashed_map_lines__no_dash);
1876 }
1877
1878 protected void draw_polyline2(Paint paint, int c[], int order, int oneway)
1879 {
1880 // Log.e("NavitGraphics", "draw_polyline2 count=" + c.length);
1881 if (!Navit.PREF_gui_oneway_arrows)
1882 {
1883 return;
1884 }
1885
1886 // Boolean normal = false;
1887 // Matrix matrix = null;
1888
1889 // this gets already checked in c-source!!
1890 //if (order > DRAW_ONEWAY_ARROWS_AT_ORDER)
1891 //{
1892
1893 // line less than 44px -> dont draw arrow!
1894 int len = (c[0] - c[2]) * (c[1] - c[3]);
1895 if (len < 0)
1896 {
1897 len = -len;
1898 }
1899 if (len > (2000))
1900 {
1901 paint.setStyle(Paint.Style.STROKE);
1902 b_paint_antialias = paint.isAntiAlias();
1903 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
1904
1905 // create matrix for the manipulation
1906 matrix_oneway_arrows = new Matrix();
1907
1908 int middle_x = c[0] + (int) ((c[2] - c[0]) / 2);
1909 int middle_y = c[1] + (int) ((c[3] - c[1]) / 2);
1910 double d_x = ((c[2] - c[0]) / 6);
1911 double d_y = ((c[3] - c[1]) / 6);
1912 int angle = (int) (Math.toDegrees(Math.atan2(d_y, d_x)));
1913 // System.out.println("arrow angle=" + angle);
1914 matrix_oneway_arrows.postTranslate(-Navit.oneway_arrow.getWidth() / 2, -Navit.oneway_arrow.getHeight() / 2);
1915
1916 if (oneway == 1)
1917 {
1918 // rotate the Bitmap
1919 matrix_oneway_arrows.postRotate(angle);
1920 }
1921 else if (oneway == 2)
1922 {
1923 // rotate the Bitmap
1924 matrix_oneway_arrows.postRotate(angle + 180);
1925 }
1926
1927 if (oneway > 0)
1928 {
1929 if (c.length == 4)
1930 {
1931 matrix_oneway_arrows.postTranslate(middle_x, middle_y);
1932 draw_canvas.drawBitmap(Navit.oneway_arrow, matrix_oneway_arrows, paint);
1933 }
1934
1935 paint.setAntiAlias(b_paint_antialias);
1936
1937 }
1938 else
1939 {
1940 // normal = true;
1941 return;
1942 }
1943 }
1944 //}
1945 //else
1946 //{
1947 // // normal = true;
1948 // // draw nothing, just return!
1949 // return;
1950 //}
1951
1952 //paint.setPathEffect(dashed_map_lines__no_dash);
1953 }
1954
1955 // draw normal polylines -> this function gets called the most!! XX-thousand times
1956 // draw normal polylines -> this function gets called the most!! XX-thousand times
1957 // draw normal polylines -> this function gets called the most!! XX-thousand times
1958 protected void draw_polyline3(Paint paint, int c[], int order, int width)
1959 {
1960 // Log.e("NavitGraphics","draw_polyline3");
1961 paint.setStyle(Paint.Style.STROKE);
1962 b_paint_antialias = paint.isAntiAlias();
1963 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
1964 wsave_003 = paint.getStrokeWidth();
1965 paint.setStrokeWidth(width);
1966
1967 if (order > DRAW_MORE_DETAILS_AT_ORDER)
1968 {
1969 paint.setStyle(Paint.Style.FILL);
1970 paint.setStrokeWidth(0);
1971 draw_canvas.drawCircle(c[0], c[1], (width / 2), paint);
1972 }
1973 for (int i = 2; i < c.length; i += 2)
1974 {
1975 if (order > DRAW_MORE_DETAILS_AT_ORDER)
1976 {
1977 //if (i < (c.length - 2))
1978 //{
1979 paint.setStyle(Paint.Style.FILL);
1980 paint.setStrokeWidth(0);
1981 draw_canvas.drawCircle(c[i], c[i + 1], (width / 2), paint);
1982 //}
1983 paint.setStyle(Paint.Style.STROKE);
1984 paint.setStrokeWidth(width);
1985 }
1986 draw_canvas.drawLine(c[i - 2], c[i - 1], c[i], c[i + 1], paint);
1987 }
1988 paint.setAntiAlias(b_paint_antialias);
1989 paint.setStrokeWidth(wsave_003);
1990 //paint.setPathEffect(dashed_map_lines__no_dash);
1991 }
1992
1993 // draw normal polylines -> this function gets called the most!! XX-thousand times
1994 // draw normal polylines -> this function gets called the most!! XX-thousand times
1995 // draw normal polylines -> this function gets called the most!! XX-thousand times
1996
1997 // for bridge or tunnel this function is used
1998 protected void draw_polyline4(Paint paint, int c[], int order, int width, int type)
1999 {
2000 // type:0 -> normal line
2001 // type:1 -> underground (tunnel)
2002 // type:2 -> bridge
2003
2004 b_paint_antialias = paint.isAntiAlias();
2005 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
2006 wsave_004 = paint.getStrokeWidth();
2007
2008 if (order <= DRAW_MORE_DETAILS_TUNNEL_BRIDGES_AT_ORDER)
2009 {
2010 type = 0;
2011 }
2012
2013 if (type == 2)
2014 {
2015 // bridge
2016 //
2017 //int csave = paint.getColor();
2018 paint.setAlpha(120); // 0 .. 255 // 255 -> no seethru
2019 paint.setStyle(Paint.Style.STROKE);
2020 paint.setStrokeWidth(width + 2);
2021 // paint.setColor(Color.BLACK);
2022 if (order > DRAW_DETAIL_DASHES_AT_ORDER)
2023 {
2024 paint.setStrokeWidth(width + 4);
2025 }
2026 for (int i = 2; i < c.length; i += 2)
2027 {
2028 draw_canvas.drawLine(c[i - 2], c[i - 1], c[i], c[i + 1], paint);
2029 }
2030 //paint.setColor(csave);
2031
2032 // -- circles --
2033 /*
2034 * paint.setAlpha(120);
2035 * paint.setStyle(Paint.Style.FILL);
2036 * paint.setStrokeWidth(0);
2037 * draw_canvas.drawCircle(c[0], c[1], (width / 2), paint);
2038 * for (int i = 2; i < c.length; i += 2)
2039 * {
2040 * paint.setStyle(Paint.Style.FILL);
2041 * paint.setStrokeWidth(0);
2042 * draw_canvas.drawCircle(c[i], c[i + 1], (width / 2), paint);
2043 * }
2044 */
2045 // -- circles --
2046 }
2047
2048 // ---------------------------------------
2049 paint.setStyle(Paint.Style.STROKE);
2050 paint.setStrokeWidth(width);
2051
2052 if (type == 1)
2053 {
2054 // tunnel
2055 paint.setAlpha(70); // 0 .. 255 // 255 -> no seethru
2056 if (order > DRAW_DETAIL_DASHES_AT_ORDER)
2057 {
2058 paint.setPathEffect(dashed_map_lines__low);
2059 }
2060 else
2061 {
2062 paint.setPathEffect(dashed_map_lines__high);
2063 }
2064 }
2065 else if (type == 2)
2066 {
2067 // bridge
2068 paint.setAlpha(70); // 0 .. 255 // 255 -> no seethru
2069 }
2070
2071 paint.setStyle(Paint.Style.STROKE);
2072 paint.setStrokeWidth(width);
2073 for (int i = 2; i < c.length; i += 2)
2074 {
2075 draw_canvas.drawLine(c[i - 2], c[i - 1], c[i], c[i + 1], paint);
2076 }
2077
2078 paint.setPathEffect(dashed_map_lines__no_dash);
2079 paint.setAntiAlias(b_paint_antialias);
2080 paint.setStrokeWidth(wsave_004);
2081 }
2082
2083 protected void set_dashes(Paint paint, int variant, int order)
2084 {
2085 if (variant == 0)
2086 {
2087 paint.setPathEffect(dashed_map_lines__no_dash);
2088 return;
2089 }
2090
2091 if (order > DRAW_DETAIL_DASHES_AT_ORDER)
2092 {
2093 paint.setPathEffect(dashes__low[variant]);
2094 }
2095 else
2096 {
2097 paint.setPathEffect(dashes__high[variant]);
2098 }
2099 }
2100
2101 protected void draw_polyline_dashed(Paint paint, int c[], int order, int oneway)
2102 {
2103 //
2104 //
2105 // !! this function is unsed now !!
2106 //
2107 //
2108
2109 paint.setStyle(Paint.Style.STROKE);
2110 b_paint_antialias = paint.isAntiAlias();
2111 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
2112
2113 Boolean normal = false;
2114
2115 // create matrix for the manipulation
2116 Matrix matrix = new Matrix();
2117
2118 int middle_x = c[0] + (int) ((c[2] - c[0]) / 2);
2119 int middle_y = c[1] + (int) ((c[3] - c[1]) / 2);
2120 double d_x = ((c[2] - c[0]) / 6);
2121 double d_y = ((c[3] - c[1]) / 6);
2122 int angle = (int) (Math.toDegrees(Math.atan2(d_y, d_x)));
2123 matrix.postTranslate(-Navit.oneway_arrow.getWidth() / 2, -Navit.oneway_arrow.getHeight() / 2);
2124
2125 if (order > DRAW_ONEWAY_ARROWS_AT_ORDER)
2126 {
2127 if (oneway == 1)
2128 {
2129 if (!Navit.PREF_gui_oneway_arrows)
2130 {
2131 return;
2132 }
2133 // rotate the Bitmap
2134 matrix.postRotate(angle);
2135 }
2136 else if (oneway == 2)
2137 {
2138 if (!Navit.PREF_gui_oneway_arrows)
2139 {
2140 return;
2141 }
2142 // rotate the Bitmap
2143 matrix.postRotate(angle + 180);
2144 }
2145
2146 if (oneway > 0)
2147 {
2148 if (c.length == 4)
2149 {
2150 matrix.postTranslate(middle_x, middle_y);
2151 draw_canvas.drawBitmap(Navit.oneway_arrow, matrix, paint);
2152 }
2153 }
2154 else
2155 {
2156 normal = true;
2157 }
2158 }
2159 else
2160 {
2161 normal = true;
2162 }
2163
2164 if (normal)
2165 {
2166 // normal line
2167 if (order > DRAW_DETAIL_DASHES_AT_ORDER)
2168 {
2169 paint.setPathEffect(dashed_map_lines__low);
2170 }
2171 else
2172 {
2173 paint.setPathEffect(dashed_map_lines__high);
2174 }
2175 b_paint_path.reset();
2176 b_paint_path.moveTo(c[0], c[1]);
2177 for (int i = 2; i < c.length; i += 2)
2178 {
2179 b_paint_path.lineTo(c[i], c[i + 1]);
2180 }
2181
2182 draw_canvas.drawPath(b_paint_path, paint);
2183 paint.setPathEffect(dashed_map_lines__no_dash);
2184 }
2185 paint.setAntiAlias(b_paint_antialias);
2186 }
2187
2188 protected void draw_polygon(Paint paint, int c[])
2189 {
2190 paint.setStyle(Paint.Style.FILL);
2191 b_paint_antialias = paint.isAntiAlias();
2192 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
2193 b_paint_path.reset();
2194 b_paint_path.moveTo(c[0], c[1]);
2195 for (int i = 2; i < c.length; i += 2)
2196 {
2197 b_paint_path.lineTo(c[i], c[i + 1]);
2198 }
2199 draw_canvas.drawPath(b_paint_path, paint);
2200 paint.setAntiAlias(b_paint_antialias);
2201 }
2202
2203 protected void draw_polygon2(Paint paint, int c[], int order, int oneway)
2204 {
2205 paint.setStyle(Paint.Style.FILL);
2206 b_paint_antialias = paint.isAntiAlias();
2207 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
2208 b_paint_path.reset();
2209 b_paint_path.moveTo(c[0], c[1]);
2210 for (int i = 2; i < c.length; i += 2)
2211 {
2212 b_paint_path.lineTo(c[i], c[i + 1]);
2213 }
2214
2215 if (order > DRAW_ONEWAY_ARROWS_AT_ORDER)
2216 {
2217 if (oneway == 1)
2218 {
2219 paint.setColor(Color.RED);
2220 if (!Navit.PREF_gui_oneway_arrows)
2221 {
2222 return;
2223 }
2224 }
2225 else if (oneway == 2)
2226 {
2227 paint.setColor(Color.BLUE);
2228 if (!Navit.PREF_gui_oneway_arrows)
2229 {
2230 return;
2231 }
2232 }
2233 }
2234
2235 draw_canvas.drawPath(b_paint_path, paint);
2236 paint.setAntiAlias(b_paint_antialias);
2237 }
2238
2239 protected void draw_rectangle(Paint paint, int x, int y, int w, int h)
2240 {
2241 //Log.e("NavitGraphics","draw_rectangle");
2242 Rect r = new Rect(x, y, x + w, y + h);
2243 paint.setStyle(Paint.Style.FILL);
2244 b_paint_antialias = paint.isAntiAlias();
2245 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
2246 //paint.setStrokeWidth(0);
2247 draw_canvas.drawRect(r, paint);
2248 paint.setAntiAlias(b_paint_antialias);
2249 }
2250
2251 protected void draw_circle(Paint paint, int x, int y, int r)
2252 {
2253 //Log.e("NavitGraphics","draw_circle");
2254 // float fx = x;
2255 // float fy = y;
2256 // float fr = r / 2;
2257 paint.setStyle(Paint.Style.STROKE);
2258 b_paint_antialias = paint.isAntiAlias();
2259 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
2260 draw_canvas.drawCircle(x, y, r / 2, paint);
2261 paint.setAntiAlias(b_paint_antialias);
2262 }
2263
2264 protected void draw_text(Paint paint, int x, int y, String text, int size, int dx, int dy)
2265 {
2266 // float fx = x;
2267 // float fy = y;
2268 //Log.e("NavitGraphics","Text size "+size + " vs " + paint.getTextSize());
2269 if (Navit.PREF_map_font_size != 2)
2270 {
2271 if (Navit.PREF_map_font_size == 3)
2272 {
2273 // large
2274 paint.setTextSize((int) ((size / 15) * 1.4));
2275 }
2276 else if (Navit.PREF_map_font_size == 4)
2277 {
2278 // extra large
2279 paint.setTextSize((int) ((size / 15) * 1.7));
2280 }
2281 else if (Navit.PREF_map_font_size == 5)
2282 {
2283 // extra large
2284 paint.setTextSize((int) ((size / 15) * 2.2));
2285 }
2286 else if (Navit.PREF_map_font_size == 1)
2287 {
2288 // small
2289 paint.setTextSize((int) ((size / 15) * 0.72));
2290 }
2291 else
2292 {
2293 // other? use normal size
2294 paint.setTextSize(size / 15);
2295 }
2296 }
2297 else
2298 {
2299 // normal size
2300 paint.setTextSize(size / 15);
2301 }
2302 paint.setStyle(Paint.Style.FILL);
2303 // FONT ------------------
2304 // FONT ------------------
2305 if (Navit.PREF_use_custom_font == true)
2306 {
2307 if (paint.getTypeface() == null)
2308 {
2309 try
2310 {
2311 paint.setTypeface(Navit.NavitStreetnameFont);
2312 // System.out.println("Calling setTypeface");
2313 }
2314 catch (Exception e)
2315 {
2316 }
2317 }
2318 }
2319 else
2320 {
2321 if (paint.getTypeface() != null)
2322 {
2323 paint.setTypeface(null);
2324 }
2325 }
2326 // FONT ------------------
2327 // FONT ------------------
2328 b_paint_antialias = paint.isAntiAlias();
2329 paint.setAntiAlias(Navit.PREF_use_anti_aliasing);
2330 if (dx == 0x10000 && dy == 0)
2331 {
2332 draw_canvas.drawText(text, x, y, paint);
2333 }
2334 else
2335 {
2336 b_paint_path.reset();
2337 b_paint_path.moveTo(x, y);
2338 b_paint_path.rLineTo(dx, dy);
2339 paint.setTextAlign(android.graphics.Paint.Align.LEFT);
2340 draw_canvas.drawTextOnPath(text, b_paint_path, 0, 0, paint);
2341 }
2342 paint.setAntiAlias(b_paint_antialias);
2343 }
2344
2345 protected void draw_image(Paint paint, int x, int y, Bitmap bitmap)
2346 {
2347 //Log.e("NavitGraphics","draw_image");
2348 // float fx = x;
2349 // float fy = y;
2350 draw_canvas.drawBitmap(bitmap, x, y, paint);
2351 }
2352
2353 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)
2354 {
2355 if (Navit.bigmap_bitmap != null)
2356 {
2357 // input: x,y --> screen coords of lat=0,lng=0 point!!
2358 /*
2359 * int scx = (int) (draw_canvas.getWidth() / 2);
2360 * int scy = (int) (draw_canvas.getHeight() / 2);
2361 * int px = px_;
2362 * int py = py_;
2363 */
2364
2365 // calculate the scale
2366 float scaleWidth = 1;
2367 float scaleHeight = 1;
2368
2369 /*
2370 * if (order == -1)
2371 * {
2372 * scaleWidth = scaleHeight = 0.8f * (1.5f / draw_factor);
2373 * }
2374 * else if (order == -2)
2375 * {
2376 * scaleWidth = scaleHeight = (float) ((1 / 2f) * 0.8f) * (1.5f / draw_factor);
2377 * }
2378 */
2379
2380 //System.out.println("bigmap order:" + (long) (order * 100));
2381 scaleWidth = scaleHeight = BIGMAP_FACTOR / (float) order * (1.5f / draw_factor);
2382 //System.out.println("draw_factor:" + draw_factor);
2383
2384 if ((scaleWidth == 0) || (scaleHeight == 0))
2385 {
2386 //System.out.println(" " + scaleWidth + " " + scaleHeight + " " + order);
2387 return;
2388 }
2389
2390 if (valid == 1)
2391 {
2392 //System.out.println(" px " + px + " py " + py);
2393 }
2394
2395 // create a matrix for the manipulation
2396 Matrix matrix = new Matrix();
2397 int half_x = (int) (Navit.bigmap_bitmap.getWidth() / 2);
2398 int half_y = (int) (Navit.bigmap_bitmap.getHeight() / 2);
2399 matrix.setScale(scaleWidth, scaleHeight, half_x, half_y);
2400
2401 int usedMegs;
2402 String usedMegsString;
2403 // int usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
2404 // String usedMegsString = String.format("00 - Memory Used: %d MB", usedMegs);
2405 // System.out.println("" + usedMegsString);
2406
2407 // recreate the new Bitmap
2408 try
2409 {
2410 bigmap_bitmap_temp = Bitmap.createBitmap(Navit.bigmap_bitmap, 0, 0, Navit.bigmap_bitmap.getWidth(), Navit.bigmap_bitmap.getHeight(), matrix, true);
2411 }
2412 catch (OutOfMemoryError e)
2413 {
2414 usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
2415 usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
2416 System.out.println("" + usedMegsString);
2417 System.out.println("@@@@@@@@ out of VM Memory @@@@@@@@");
2418 System.gc();
2419 usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
2420 usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
2421 System.out.println("" + usedMegsString);
2422
2423 try
2424 {
2425 bigmap_bitmap_temp = Bitmap.createBitmap(Navit.bigmap_bitmap, 0, 0, Navit.bigmap_bitmap.getWidth(), Navit.bigmap_bitmap.getHeight(), matrix, true);
2426 }
2427 catch (OutOfMemoryError e2)
2428 {
2429 e2.printStackTrace();
2430 return;
2431 }
2432 }
2433
2434 if (bigmap_bitmap_temp == null)
2435 {
2436 return;
2437 }
2438 else
2439 {
2440 try
2441 {
2442 if (bigmap_bitmap_temp.getWidth() <= 0)
2443 {
2444 return;
2445 }
2446 else if (bigmap_bitmap_temp.getHeight() <= 0)
2447 {
2448 return;
2449 }
2450 }
2451 catch (Exception e)
2452 {
2453 e.printStackTrace();
2454 return;
2455 }
2456 }
2457 // usedMegs = (int) (Debug.getNativeHeapAllocatedSize() / 1048576L);
2458 // usedMegsString = String.format(" - Memory Used: %d MB", usedMegs);
2459 // System.out.println("" + usedMegsString);
2460
2461 float top = 85.2f;
2462 //float bottom = -85.2f;
2463 float left = -180f;
2464 //float right = 180f;
2465
2466 String left_top_on_screen_string = CallbackGeoCalc(2, top, left);
2467 String tmp[] = left_top_on_screen_string.split(":", 2);
2468 int pixel_top_left_x = Integer.parseInt(tmp[0]);
2469 int pixel_top_left_y = Integer.parseInt(tmp[1]);
2470
2471 //float p_karte_pixel_x;
2472 //float p_karte_pixel_y;
2473
2474 // pixel point of 0/0 geo coord
2475 /*
2476 * p_karte_pixel_x = bigmap_bitmap_temp.getWidth() / 2;
2477 * p_karte_pixel_y = bigmap_bitmap_temp.getHeight() / 2;
2478 */
2479
2480 /*
2481 * if (!loc_12_valid)
2482 * {
2483 * // initialize them the first time
2484 * loc_1_x = x_;
2485 * loc_1_y = y_;
2486 * loc_2_x = mcx;
2487 * loc_2_y = mcy;
2488 * loc_12_valid = true;
2489 * }
2490 *
2491 * if ((loc_1_x == x_) && (loc_1_y == y_))
2492 * {
2493 * p_karte_pixel_x = p_karte_pixel_x - (loc_2_x - mcx);
2494 * p_karte_pixel_y = p_karte_pixel_y - (loc_2_y - mcy);
2495 * // System.out.println("SSSSSSSS SSSSSSSS");
2496 * }
2497 * else
2498 * {
2499 * loc_2_x = mcx;
2500 * loc_2_y = mcy;
2501 * }
2502 *
2503 * loc_1_x = x_;
2504 * loc_1_y = y_;
2505 */
2506
2507 //int ssschx = (int) (x_ - p_karte_pixel_x);
2508 //int ssschy = (int) (y_ - p_karte_pixel_y);
2509
2510 // fill canvas with ocean color
2511 draw_canvas.drawColor(Color.parseColor("#82C8EA"));
2512
2513 //int green_dot_x = scx;
2514 //int green_dot_y = scy;
2515 loc_dot_valid = true;
2516
2517 //int rotation_point_x = scx;
2518 //int rotation_point_y = scy;
2519
2520 /*
2521 * if (valid == 1)
2522 * {
2523 * green_dot_x = px;
2524 * green_dot_y = py;
2525 *
2526 * rotation_point_x = px;
2527 * rotation_point_y = py;
2528 * }
2529 */
2530 //
2531 draw_canvas.save(); // SAVE
2532 //
2533 // *********** draw_canvas.translate(green_dot_x, green_dot_y);
2534 draw_canvas.translate(pixel_top_left_x, pixel_top_left_y);
2535 draw_canvas.rotate(yaw, 0, 0);
2536
2537 draw_canvas.drawBitmap(bigmap_bitmap_temp, 0, 0, null);
2538
2539 //
2540 draw_canvas.restore(); // RESTORE
2541 //
2542 bigmap_bitmap_temp.recycle();
2543 bigmap_bitmap_temp = null;
2544 }
2545 }
2546
2547 protected 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)
2548 {
2549 //System.out.println("NavitOSDJava:" + id + " " + text1 + " " + text2 + " " + text3 + " " + i1 + " " + i2 + " " + i3 + " " + i4 + " " + f1 + " " + f2 + " " + f3);
2550 //System.out.println("NavitOSDJava:" + last_paint_OSD);
2551 Boolean needed_value = false;
2552 try
2553 {
2554 if (id.equals("scale"))
2555 {
2556 if (text1 != null)
2557 {
2558 if (text1.equals("draw_rectangle1"))
2559 {
2560 Navit.OSD_scale.base = i1;
2561 }
2562 else if (text1.equals("draw_rectangle2"))
2563 {
2564 Navit.OSD_scale.scale_valid = true;
2565 Navit.OSD_scale.var = i1;
2566 }
2567 else if (text1.equals("draw_text"))
2568 {
2569 Navit.OSD_scale.scale_valid = true;
2570 Navit.OSD_scale.scale_text = text2;
2571 }
2572 }
2573 needed_value = true;
2574 }
2575 else if (id.equals("osd_text_draw"))
2576 {
2577 if ((text1 != null) && (text1.equals("draw_text")))
2578 {
2579 if ((text2 != null) && (text2.equals("navigation:nav_position:destination_time")))
2580 {
2581 // text3 = 20:38 --> ETA time (+1 means next day!)
2582 // System.out.println("destination_time:" + text3);
2583 Navit.OSD_route_001.arriving_time = text3;
2584 Navit.OSD_route_001.arriving_time_valid = true;
2585 needed_value = true;
2586 }
2587 else if ((text2 != null) && (text2.equals("navigation:nav_position:destination_length")))
2588 {
2589 // text3 = 575m -> driving distance to target
2590 // System.out.println("destination_length:" + text3);
2591 Navit.OSD_route_001.driving_distance_to_target = text3;
2592 Navit.OSD_route_001.driving_distance_to_target_valid = true;
2593 needed_value = true;
2594 }
2595 else if ((text2 != null) && (text2.length() > 10) && (text2.substring(0, 11).equals("navigation:")))
2596 {
2597 String[] tmp_string = text2.split(":", 3);
2598 if (tmp_string.length == 3)
2599 {
2600 if (tmp_string[2].equals("length"))
2601 {
2602 // "navigation:******:length"
2603 // text3 = 250m --> when to do the next turn
2604 //System.out.println("nextturn_distance:" + text3);
2605 Navit.OSD_nextturn.nextturn_distance = text3;
2606 Navit.OSD_nextturn.nextturn_distance_valid = true;
2607 // we need to paint the OSD in any case
2608 last_paint_OSD = -1;
2609 needed_value = true;
2610 }
2611 else if (tmp_string[2].equals("street_name_systematic"))
2612 {
2613 // "navigation:******:street_name_systematic"
2614 //System.out.println("nextturn_streetname_systematic:" + text3);
2615 Navit.OSD_nextturn.nextturn_streetname_systematic = text3;
2616 needed_value = true;
2617 }
2618 else if (tmp_string[2].equals("street_name"))
2619 {
2620 // "navigation:******:street_name"
2621 //System.out.println("nextturn_streetname:" + text3);
2622 Navit.OSD_nextturn.nextturn_streetname = text3;
2623 needed_value = true;
2624 }
2625 }
2626 }
2627 else if ((text2 != null) && (text2.length() > 8) && (text2.substring(0, 9).equals("tracking:")))
2628 {
2629 if (NavitGraphics.navit_route_status == 0)
2630 {
2631 if (text2.equals("tracking:street_name:"))
2632 {
2633 //System.out.println("t2" + text2 + text3);
2634 Navit.OSD_nextturn.nextturn_streetname = text3;
2635 last_paint_OSD = -1;
2636 needed_value = true;
2637 }
2638 else if (text2.equals("tracking:street_name_systematic:"))
2639 {
2640 //System.out.println("t1" + text2 + text3);
2641 Navit.OSD_nextturn.nextturn_streetname_systematic = text3;
2642 needed_value = true;
2643 }
2644 }
2645 }
2646 else
2647 {
2648 // Log.e("NavitOSDJava", "" + id + " " + text1 + " " + text2 + " " + text3 + " " + i1 + " " + i2 + " " + i3 + " " + i4 + " " + f1 + " " + f2 + " " + f3);
2649 }
2650 }
2651 }
2652 else if (id.equals("nav_next_turn"))
2653 {
2654 if ((text1 != null) && (text1.equals("draw_image1")))
2655 {
2656 //System.out.println("tttt222:" + text2);
2657 // text2 = res/drawable/xx.png
2658 if ((text2 == null) || (text2.equals("")))
2659 {
2660 Navit.OSD_nextturn.nextturn_image_valid = false;
2661 Navit.OSD_nextturn.nextturn_image.recycle();
2662 }
2663 if (!Navit.OSD_nextturn.nextturn_image_filename.equals(text2))
2664 {
2665 // only if image is different from current image
2666 Navit.OSD_nextturn.nextturn_image_filename = text2;
2667 Navit.OSD_nextturn.nextturn_image_filename_valid = true;
2668 if (Navit.OSD_nextturn.nextturn_image != null)
2669 {
2670 try
2671 {
2672 Navit.OSD_nextturn.nextturn_image.recycle();
2673 }
2674 catch (Exception e)
2675 {
2676 }
2677 }
2678 // System.out.println("load image: " + Navit.OSD_nextturn.nextturn_image_filename);
2679 String x = Navit.OSD_nextturn.nextturn_image_filename.substring(13).replace(".png", "");
2680 // System.out.println("load image: " + x);
2681 int ResId = Navit.res_.getIdentifier("com.zoffcc.applications.zanavi:drawable/" + x, null, null);
2682 // System.out.println("ResId: " + ResId);
2683 Navit.OSD_nextturn.nextturn_image = BitmapFactory.decodeResource(Navit.res_, ResId);
2684 Navit.OSD_nextturn.nextturn_image_valid = true;
2685 }
2686 }
2687 needed_value = true;
2688 }
2689 else if (id.equals("compass"))
2690 {
2691 if ((text1 != null) && (text1.equals("text_and_dst_angle")))
2692 {
2693 if ((text2 == null) || (text2.equals("")))
2694 {
2695 Navit.OSD_compass.direct_distance_to_target = "";
2696 Navit.OSD_compass.direct_distance_to_target_valid = false;
2697 }
2698 else
2699 {
2700 Navit.OSD_compass.direct_distance_to_target = text2;
2701 Navit.OSD_compass.direct_distance_to_target_valid = true;
2702 }
2703 try
2704 {
2705 // Navit.OSD_compass.angle_target = Float.parseFloat(text3);
2706 Navit.OSD_compass.angle_target = i1;
2707 Navit.OSD_compass.angle_target_valid = true;
2708 }
2709 catch (Exception e)
2710 {
2711 //e.printStackTrace();
2712 }
2713 needed_value = true;
2714 }
2715 else if ((text1 != null) && (text1.equals("direction")))
2716 {
2717 try
2718 {
2719 // Navit.OSD_compass.angle_north = Float.parseFloat(text2);
2720 Navit.OSD_compass.angle_north = i1;
2721 Navit.OSD_compass.angle_north_valid = true;
2722 needed_value = true;
2723 }
2724 catch (Exception e)
2725 {
2726 //e.printStackTrace();
2727
2728 }
2729 }
2730 }
2731 }
2732 catch (Exception x)
2733 {
2734 x.printStackTrace();
2735 }
2736
2737 if (!needed_value)
2738 {
2739 // we got values that we dont use
2740 //System.out.println("xx paint 0 xx");
2741 return;
2742 }
2743
2744 if (NavitGraphics.MAP_DISPLAY_OFF)
2745 {
2746 // paint only every 800ms
2747 if ((last_paint_OSD + 800) < System.currentTimeMillis())
2748 {
2749 try
2750 {
2751 last_paint_OSD = System.currentTimeMillis();
2752 //System.out.println("xx paint 1 xx");
2753 NavitOSDJava.draw_real();
2754 //NavitAOSDJava.postInvalidate();
2755 }
2756 catch (Exception r)
2757 {
2758 //r.printStackTrace();
2759 }
2760 }
2761 }
2762 else
2763 {
2764 // paint only every 600ms
2765 if ((last_paint_OSD + 1200) < System.currentTimeMillis())
2766 {
2767 try
2768 {
2769 last_paint_OSD = System.currentTimeMillis();
2770 //System.out.println("xx paint 2 xx");
2771 NavitOSDJava.draw_real();
2772 //NavitAOSDJava.postInvalidate();
2773 }
2774 catch (Exception r)
2775 {
2776 //r.printStackTrace();
2777 }
2778 }
2779 }
2780 }
2781
2782 protected void draw_mode(int mode)
2783 {
2784 //Log.e("NavitGraphics", "draw_mode mode=" + mode + " parent_graphics="
2785 // + String.valueOf(parent_graphics));
2786
2787 if (mode == 2 && parent_graphics == null) view.invalidate();
2788 if (mode == 1 || (mode == 0 && parent_graphics != null)) draw_bitmap.eraseColor(0);
2789
2790 }
2791
2792 protected void draw_drag(int x, int y)
2793 {
2794 //Log.e("NavitGraphics","draw_drag");
2795 pos_x = x;
2796 pos_y = y;
2797 }
2798
2799 protected void overlay_disable(int disable)
2800 {
2801 //Log.e("NavitGraphics","overlay_disable");
2802 // assume we are NOT in map view mode!
2803 // -> always in map mode now !!!! # in_map = false;
2804
2805 // check if overlay has been initialized yet
2806 //if (NavitAOverlay != null)
2807 //{
2808 // NavitAOverlay.hide_bubble();
2809 //}
2810
2811 overlay_disabled = disable;
2812 }
2813
2814 protected void overlay_resize(int x, int y, int w, int h, int alpha, int wraparond)
2815 {
2816 //Log.e("NavitGraphics","overlay_resize");
2817 pos_x = x;
2818 pos_y = y;
2819 }
2820
2821 public static String getLocalizedString(String text)
2822 {
2823 String ret = CallbackLocalizedString(text);
2824 //Log.e("NavitGraphics", "callback_handler -> lozalized string=" + ret);
2825 return ret;
2826 }
2827
2828 static String __n_distance(int i)
2829 {
2830 String ret = "";
2831 if ((i > 0) && (i < 10))
2832 {
2833 ret = __get_distance(i, 0);
2834 }
2835 else
2836 {
2837 switch (i)
2838 {
2839 case 10:
2840 ret = "";
2841 break;
2842 case 11:
2843 ret = "soon";
2844 break;
2845 case 12:
2846 ret = "after %i roads";
2847 break;
2848 case 13:
2849 ret = "now";
2850 break;
2851 default:
2852 ret = "";
2853 }
2854 }
2855 return ret;
2856 }
2857
2858 static String __get_distance(int i, int is_length)
2859 {
2860 String ret = "";
2861
2862 if (is_length == 0)
2863 {
2864 switch (i)
2865 {
2866 case 1:
2867 ret = "in %d m";
2868 break;
2869 case 2:
2870 ret = "in %d feet";
2871 break;
2872 case 3:
2873 ret = "in %d meters";
2874 break;
2875 case 4:
2876 ret = "in %d.%d miles";
2877 break;
2878 case 5:
2879 ret = "in %d.%d kilometers";
2880 break;
2881 case 6:
2882 ret = "in one mile";
2883 break;
2884 case 7:
2885 ret = "in %d miles";
2886 break;
2887 case 8:
2888 ret = "in one kilometer";
2889 break;
2890 case 9:
2891 ret = "in %d kilometer";
2892 break;
2893 default:
2894 ret = "";
2895 }
2896 }
2897 else
2898 {
2899 switch (i)
2900 {
2901 case 1:
2902 ret = "%d m";
2903 break;
2904 case 2:
2905 ret = "%d feet";
2906 break;
2907 case 3:
2908 ret = "%d meters";
2909 break;
2910 case 4:
2911 ret = "%d.%d miles";
2912 break;
2913 case 5:
2914 ret = "%d.%d kilometers";
2915 break;
2916 case 6:
2917 ret = "one mile";
2918 break;
2919 case 7:
2920 ret = "%d miles";
2921 break;
2922 case 8:
2923 ret = "one kilometer";
2924 break;
2925 case 9:
2926 ret = "%d kilometer";
2927 break;
2928 default:
2929 ret = "";
2930 }
2931 }
2932
2933 return ret;
2934 }
2935
2936 static String __direction(int i)
2937 {
2938 String ret = "";
2939
2940 switch (i)
2941 {
2942 case 1:
2943 ret = "left";
2944 break;
2945 case 2:
2946 ret = "right";
2947 break;
2948 default:
2949 ret = "";
2950 }
2951
2952 return ret;
2953 }
2954
2955 static String __strength(int i)
2956 {
2957 String ret = "";
2958
2959 switch (i)
2960 {
2961 case 1:
2962 ret = "";
2963 break;
2964 case 2:
2965 ret = "slight ";
2966 break;
2967 case 3:
2968 ret = "hard ";
2969 break;
2970 case 4:
2971 ret = "really hard ";
2972 break;
2973 default:
2974 ret = "";
2975 }
2976
2977 return ret;
2978 }
2979
2980 static String __navigation_item_destination(int i)
2981 {
2982 String ret = "";
2983
2984 switch (i)
2985 {
2986 case 1:
2987 ret = "";
2988 break;
2989 case 2:
2990 ret = "exit";
2991 break;
2992 case 3:
2993 ret = "into the ramp";
2994 break;
2995 case 4:
2996 ret = "%sinto the street %s%s%s";
2997 break;
2998 case 5:
2999 ret = "%sinto the %s%s%s|male form";
3000 break;
3001 case 6:
3002 ret = "%sinto the %s%s%s|female form";
3003 break;
3004 case 7:
3005 ret = "%sinto the %s%s%s|neutral form";
3006 break;
3007 case 8:
3008 ret = "%sinto the %s";
3009 break;
3010 default:
3011 ret = "";
3012 }
3013
3014 return ret;
3015 }
3016
3017 public static void generate_all_speech_commands()
3018 {
3019
3020 try
3021 {
3022 NavitGraphics.NavitMsgTv2_.setVisibility(View.VISIBLE);
3023 NavitGraphics.NavitMsgTv2_.setEnabled(true);
3024 }
3025 catch (Exception e)
3026 {
3027 e.printStackTrace();
3028 }
3029
3030 String a = null;
3031 String b = null;
3032 String a1 = null;
3033 String b1 = null;
3034 String c = null;
3035 String c1 = null;
3036 String d = null;
3037 String d1 = null;
3038 int j;
3039 //
3040 //
3041 //
3042 a = "When possible, please turn around";
3043 a1 = CallbackLocalizedString(a);
3044 NavitGraphics.NavitMsgTv2_.append(a + "\n");
3045 NavitGraphics.NavitMsgTv2_.append(a1 + "\n");
3046 System.out.println(a);
3047 System.out.println(a1);
3048 //
3049 a = "Enter the roundabout soon";
3050 a1 = CallbackLocalizedString(a);
3051 NavitGraphics.NavitMsgTv2_.append(a + "\n");
3052 NavitGraphics.NavitMsgTv2_.append(a1 + "\n");
3053 System.out.println(a);
3054 System.out.println(a1);
3055 //
3056 a = "then you have reached your destination.";
3057 a1 = CallbackLocalizedString(a);
3058 NavitGraphics.NavitMsgTv2_.append(a + "\n");
3059 NavitGraphics.NavitMsgTv2_.append(a1 + "\n");
3060 System.out.println(a);
3061 System.out.println(a1);
3062 //
3063 a = "In %s, enter the roundabout";
3064 a1 = CallbackLocalizedString(a);
3065 for (j = 1; j < 10; j++)
3066 {
3067 if ((j == 4) || (j == 5))
3068 {
3069 b = __get_distance(j, 1);
3070 b1 = CallbackLocalizedString(b);
3071 c = String.format(b, 1, 4);
3072 c1 = String.format(b1, 1, 4);
3073 d = String.format(a, c);
3074 d1 = String.format(a1, c1);
3075 try
3076 {
3077 d = String.format(d, 3, 4, 5);
3078 }
3079 catch (Exception e)
3080 {
3081
3082 }
3083 try
3084 {
3085 d1 = String.format(d1, 3, 4, 5);
3086 }
3087 catch (Exception e)
3088 {
3089
3090 }
3091 NavitGraphics.NavitMsgTv2_.append(d + "\n");
3092 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
3093 System.out.println(d);
3094 System.out.println(d1);
3095 }
3096 else
3097 {
3098 b = __get_distance(j, 1);
3099 b1 = CallbackLocalizedString(b);
3100 c = String.format(b, 250);
3101 c1 = String.format(b1, 250);
3102 d = String.format(a, c);
3103 d1 = String.format(a1, c1);
3104 try
3105 {
3106 d = String.format(d, 3, 4, 5);
3107 }
3108 catch (Exception e)
3109 {
3110
3111 }
3112 try
3113 {
3114 d1 = String.format(d1, 3, 4, 5);
3115 }
3116 catch (Exception e)
3117 {
3118
3119 }
3120 NavitGraphics.NavitMsgTv2_.append(d + "\n");
3121 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
3122 System.out.println(d);
3123 System.out.println(d1);
3124 }
3125 }
3126 //
3127 a = "Follow the road for the next %s";
3128 a1 = CallbackLocalizedString(a);
3129 for (j = 1; j < 10; j++)
3130 {
3131 if ((j == 4) || (j == 5))
3132 {
3133 b = __get_distance(j, 1);
3134 b1 = CallbackLocalizedString(b);
3135 c = String.format(b, 1, 4);
3136 c1 = String.format(b1, 1, 4);
3137 d = String.format(a, c);
3138 d1 = String.format(a1, c1);
3139 try
3140 {
3141 d = String.format(d, 3, 4, 5);
3142 }
3143 catch (Exception e)
3144 {
3145
3146 }
3147 try
3148 {
3149 d1 = String.format(d1, 3, 4, 5);
3150 }
3151 catch (Exception e)
3152 {
3153
3154 }
3155 NavitGraphics.NavitMsgTv2_.append(d + "\n");
3156 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
3157 System.out.println(d);
3158 System.out.println(d1);
3159 }
3160 else
3161 {
3162 b = __get_distance(j, 1);
3163 b1 = CallbackLocalizedString(b);
3164 c = String.format(b, 250);
3165 c1 = String.format(b1, 250);
3166 d = String.format(a, c);
3167 d1 = String.format(a1, c1);
3168 try
3169 {
3170 d = String.format(d, 3, 4, 5);
3171 }
3172 catch (Exception e)
3173 {
3174
3175 }
3176 try
3177 {
3178 d1 = String.format(d1, 3, 4, 5);
3179 }
3180 catch (Exception e)
3181 {
3182
3183 }
3184 NavitGraphics.NavitMsgTv2_.append(d + "\n");
3185 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
3186 System.out.println(d);
3187 System.out.println(d1);
3188 }
3189 }
3190 //
3191 a = "Leave the roundabout at the %s";
3192 a1 = CallbackLocalizedString(a);
3193 b = String.format(a, "first exit");
3194 b1 = String.format(a1, CallbackLocalizedString("first exit"));
3195 NavitGraphics.NavitMsgTv2_.append(b + "\n");
3196 NavitGraphics.NavitMsgTv2_.append(b1 + "\n");
3197 System.out.println(b);
3198 System.out.println(b1);
3199 //
3200 a = "Leave the roundabout at the %s";
3201 a1 = CallbackLocalizedString(a);
3202 b = String.format(a, "third exit");
3203 b1 = String.format(a1, CallbackLocalizedString("third exit"));
3204 NavitGraphics.NavitMsgTv2_.append(b + "\n");
3205 NavitGraphics.NavitMsgTv2_.append(b1 + "\n");
3206 System.out.println(b);
3207 System.out.println(b1);
3208 //
3209 a = "then leave the roundabout at the %s";
3210 a1 = CallbackLocalizedString(a);
3211 b = String.format(a, "first exit");
3212 b1 = String.format(a1, CallbackLocalizedString("first exit"));
3213 NavitGraphics.NavitMsgTv2_.append(b + "\n");
3214 NavitGraphics.NavitMsgTv2_.append(b1 + "\n");
3215 System.out.println(b);
3216 System.out.println(b1);
3217 //
3218 a = "then leave the roundabout at the %s";
3219 a1 = CallbackLocalizedString(a);
3220 b = String.format(a, "third exit");
3221 b1 = String.format(a1, CallbackLocalizedString("third exit"));
3222 NavitGraphics.NavitMsgTv2_.append(b + "\n");
3223 NavitGraphics.NavitMsgTv2_.append(b1 + "\n");
3224 System.out.println(b);
3225 System.out.println(b1);
3226 //
3227 a = "Take the %1$s road to the %2$s";
3228 a1 = CallbackLocalizedString(a);
3229 b = String.format(a, "first", "left");
3230 b1 = String.format(a1, CallbackLocalizedString("first"), CallbackLocalizedString("left"));
3231 NavitGraphics.NavitMsgTv2_.append(b + "\n");
3232 NavitGraphics.NavitMsgTv2_.append(b1 + "\n");
3233 System.out.println(b);
3234 System.out.println(b1);
3235 //
3236 a = "Take the %1$s road to the %2$s";
3237 a1 = CallbackLocalizedString(a);
3238 b = String.format(a, "first", "right");
3239 b1 = String.format(a1, CallbackLocalizedString("first"), CallbackLocalizedString("right"));
3240 NavitGraphics.NavitMsgTv2_.append(b + "\n");
3241 NavitGraphics.NavitMsgTv2_.append(b1 + "\n");
3242 System.out.println(b);
3243 System.out.println(b1);
3244 //
3245 a = "Take the %1$s road to the %2$s";
3246 a1 = CallbackLocalizedString(a);
3247 b = String.format(a, "third", "left");
3248 b1 = String.format(a1, CallbackLocalizedString("third"), CallbackLocalizedString("left"));
3249 NavitGraphics.NavitMsgTv2_.append(b + "\n");
3250 NavitGraphics.NavitMsgTv2_.append(b1 + "\n");
3251 System.out.println(b);
3252 System.out.println(b1);
3253 //
3254 a = "Take the %1$s road to the %2$s";
3255 a1 = CallbackLocalizedString(a);
3256 b = String.format(a, "third", "right");
3257 b1 = String.format(a1, CallbackLocalizedString("third"), CallbackLocalizedString("right"));
3258 NavitGraphics.NavitMsgTv2_.append(b + "\n");
3259 NavitGraphics.NavitMsgTv2_.append(b1 + "\n");
3260 System.out.println(b);
3261 System.out.println(b1);
3262 //
3263 a = "You have reached your destination %s";
3264 a1 = CallbackLocalizedString(a);
3265 for (j = 1; j < 14; j++)
3266 {
3267 if (j == 10)
3268 {
3269 d = String.format(a, "");
3270 d1 = String.format(a1, "");
3271 try
3272 {
3273 d = String.format(d, 3, 4, 5);
3274 }
3275 catch (Exception e)
3276 {
3277
3278 }
3279 try
3280 {
3281 d1 = String.format(d1, 3, 4, 5);
3282 }
3283 catch (Exception e)
3284 {
3285
3286 }
3287 NavitGraphics.NavitMsgTv2_.append(d + "\n");
3288 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
3289 System.out.println(d + "\n");
3290 System.out.println(d1 + "\n");
3291 }
3292 else if (j == 12)
3293 {
3294 b = __n_distance(j);
3295 b1 = CallbackLocalizedString(b);
3296 c = b.replace("%i", "3");
3297 c1 = b1.replace("%i", "3");
3298 d = String.format(a, c);
3299 d1 = String.format(a1, c1);
3300 try
3301 {
3302 d = String.format(d, 3, 4, 5);
3303 }
3304 catch (Exception e)
3305 {
3306
3307 }
3308 try
3309 {
3310 d1 = String.format(d1, 3, 4, 5);
3311 }
3312 catch (Exception e)
3313 {
3314
3315 }
3316 NavitGraphics.NavitMsgTv2_.append(d + "\n");
3317 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
3318 System.out.println(d);
3319 System.out.println(d1);
3320 }
3321 else
3322 {
3323 b = __n_distance(j);
3324 b1 = CallbackLocalizedString(b);
3325 d = String.format(a, b);
3326 d1 = String.format(a1, b1);
3327 try
3328 {
3329 d = String.format(d, 3, 4, 5);
3330 }
3331 catch (Exception e)
3332 {
3333
3334 }
3335 try
3336 {
3337 d1 = String.format(d1, 3, 4, 5);
3338 }
3339 catch (Exception e)
3340 {
3341
3342 }
3343 NavitGraphics.NavitMsgTv2_.append(d + "\n");
3344 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
3345 System.out.println(d);
3346 System.out.println(d1);
3347 }
3348 }
3349 //
3350 a = "Turn %1$s%2$s %3$s%4$s";
3351 a1 = CallbackLocalizedString(a);
3352 String xx = null;
3353 String xx1 = null;
3354 String yy = null;
3355 String yy1 = null;
3356 for (j = 1; j < 5; j++)
3357 {
3358 if (j == 1)
3359 {
3360 b = __strength(j);
3361 b1 = "";
3362 }
3363 else
3364 {
3365 b = __strength(j);
3366 b1 = CallbackLocalizedString(b);
3367 }
3368
3369 for (int k = 1; k < 3; k++)
3370 {
3371 c = __direction(k);
3372 c1 = CallbackLocalizedString(c);
3373
3374 for (int m = 1; m < 14; m++)
3375 {
3376 if (m == 10)
3377 {
3378 xx = "";
3379 xx1 = "";
3380 }
3381 else if (m == 12)
3382 {
3383 String zz = __n_distance(m);
3384 String zz1 = CallbackLocalizedString(zz);
3385 xx = zz.replace("%i", "3");
3386 xx1 = zz1.replace("%i", "3");
3387 }
3388 else
3389 {
3390 xx = __n_distance(m);
3391 xx1 = CallbackLocalizedString(xx);
3392 }
3393
3394 for (int o = 1; o < 9; o++)
3395 {
3396 if (o == 2)
3397 {
3398 // leave out "exit"
3399 break;
3400 }
3401
3402 if (o == 1)
3403 {
3404 yy = __navigation_item_destination(o);
3405 yy1 = "";
3406 }
3407 else if (o == 4)
3408 {
3409 String zz;
3410 String zz1;
3411 zz = __navigation_item_destination(o);
3412 zz1 = CallbackLocalizedString(zz);
3413 yy = String.format(zz, " ", "somestreet", " ", "A23");
3414 yy1 = String.format(zz1, " ", "blablastrasse", " ", "A23");
3415 }
3416 else if ((o == 5) || (o == 6) || (o == 7))
3417 {
3418 String zz;
3419 String zz1;
3420 zz = __navigation_item_destination(o);
3421 zz1 = CallbackLocalizedString(zz);
3422 try
3423 {
3424 zz = zz.substring(0, zz.lastIndexOf("|"));
3425 }
3426 catch (Exception e)
3427 {
3428
3429 }
3430 try
3431 {
3432 zz1 = zz1.substring(0, zz1.lastIndexOf("|"));
3433 }
3434 catch (Exception e)
3435 {
3436
3437 }
3438 yy = String.format(zz, " ", "somestreet", " ", "A23");
3439 yy1 = String.format(zz1, " ", "blablastrasse", " ", "A23");
3440 }
3441 else if (o == 8)
3442 {
3443 String zz;
3444 String zz1;
3445 zz = __navigation_item_destination(o);
3446 zz1 = CallbackLocalizedString(zz);
3447 yy = String.format(zz, " ", "A23");
3448 yy1 = String.format(zz1, " ", "A23");
3449 }
3450 else
3451 {
3452 yy = __navigation_item_destination(o);
3453 yy1 = " " + CallbackLocalizedString(yy);
3454 yy = " " + yy;
3455 }
3456
3457 // apply parts
3458 d = String.format(a, b, c, xx, yy);
3459 d1 = String.format(a1, b1, c1, xx1, yy1);
3460 try
3461 {
3462 d = String.format(d, 3, 4, 5);
3463 }
3464 catch (Exception e)
3465 {
3466
3467 }
3468 try
3469 {
3470 d1 = String.format(d1, 3, 4, 5);
3471 }
3472 catch (Exception e)
3473 {
3474
3475 }
3476 NavitGraphics.NavitMsgTv2_.append(d + "\n");
3477 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
3478 System.out.println(d);
3479 System.out.println(d1);
3480 }
3481 }
3482 }
3483 }
3484 //
3485 a = "then turn %1$s%2$s %3$s%4$s";
3486 a1 = CallbackLocalizedString(a);
3487 xx = null;
3488 xx1 = null;
3489 yy = null;
3490 yy1 = null;
3491 for (j = 1; j < 5; j++)
3492 {
3493 if (j == 1)
3494 {
3495 b = __strength(j);
3496 b1 = "";
3497 }
3498 else
3499 {
3500 b = __strength(j);
3501 b1 = CallbackLocalizedString(b);
3502 }
3503
3504 for (int k = 1; k < 3; k++)
3505 {
3506 c = __direction(k);
3507 c1 = CallbackLocalizedString(c);
3508
3509 for (int m = 1; m < 14; m++)
3510 {
3511 if (m == 10)
3512 {
3513 xx = "";
3514 xx1 = "";
3515 }
3516 else if (m == 12)
3517 {
3518 String zz = __n_distance(m);
3519 String zz1 = CallbackLocalizedString(zz);
3520 xx = zz.replace("%i", "3");
3521 xx1 = zz1.replace("%i", "3");
3522 }
3523 else
3524 {
3525 xx = __n_distance(m);
3526 xx1 = CallbackLocalizedString(xx);
3527 }
3528
3529 for (int o = 1; o < 9; o++)
3530 {
3531 if (o == 2)
3532 {
3533 // leave out "exit"
3534 break;
3535 }
3536
3537 if (o == 1)
3538 {
3539 yy = __navigation_item_destination(o);
3540 yy1 = "";
3541 }
3542 else if (o == 4)
3543 {
3544 String zz;
3545 String zz1;
3546 zz = __navigation_item_destination(o);
3547 zz1 = CallbackLocalizedString(zz);
3548 yy = String.format(zz, " ", "somestreet", " ", "A23");
3549 yy1 = String.format(zz1, " ", "blablastrasse", " ", "A23");
3550 }
3551 else if ((o == 5) || (o == 6) || (o == 7))
3552 {
3553 String zz;
3554 String zz1;
3555 zz = __navigation_item_destination(o);
3556 zz1 = CallbackLocalizedString(zz);
3557 try
3558 {
3559 zz = zz.substring(0, zz.lastIndexOf("|"));
3560 }
3561 catch (Exception e)
3562 {
3563
3564 }
3565 try
3566 {
3567 zz1 = zz1.substring(0, zz1.lastIndexOf("|"));
3568 }
3569 catch (Exception e)
3570 {
3571
3572 }
3573 yy = String.format(zz, " ", "somestreet", " ", "A23");
3574 yy1 = String.format(zz1, " ", "blablastrasse", " ", "A23");
3575 }
3576 else if (o == 8)
3577 {
3578 String zz;
3579 String zz1;
3580 zz = __navigation_item_destination(o);
3581 zz1 = CallbackLocalizedString(zz);
3582 yy = String.format(zz, " ", "A23");
3583 yy1 = String.format(zz1, " ", "A23");
3584 }
3585 else
3586 {
3587 yy = __navigation_item_destination(o);
3588 yy1 = " " + CallbackLocalizedString(yy);
3589 yy = " " + yy;
3590 }
3591
3592 // apply parts
3593 d = String.format(a, b, c, xx, yy);
3594 d1 = String.format(a1, b1, c1, xx1, yy1);
3595 try
3596 {
3597 d = String.format(d, 3, 4, 5);
3598 }
3599 catch (Exception e)
3600 {
3601
3602 }
3603 try
3604 {
3605 d1 = String.format(d1, 3, 4, 5);
3606 }
3607 catch (Exception e)
3608 {
3609
3610 }
3611 NavitGraphics.NavitMsgTv2_.append(d + "\n");
3612 NavitGraphics.NavitMsgTv2_.append(d1 + "\n");
3613 System.out.println(d);
3614 System.out.println(d1);
3615 }
3616 }
3617 }
3618 }
3619 //
3620 //
3621 //
3622
3623 /*
3624 * speech commands:
3625 * ================
3626 *
3627 *
3628 * When possible, please turn around
3629 * Enter the roundabout soon
3630 * then you have reached your destination.
3631 *
3632 * In %s, enter the roundabout (get_distance(is_length=1))
3633 * Follow the road for the next %s (get_distance(is_length=1))
3634 *
3635 * Leave the roundabout at the %s (get_exit_count_str)
3636 * then leave the roundabout at the %s (get_exit_count_str)
3637 *
3638 * Take the %1$s road to the %2$s (get_count_str(),direction)
3639 * then take the %1$s road to the %2$s (get_count_str(),direction)
3640 *
3641 * Turn %1$s%2$s %3$s%4$s (strength,direction,distance,navigation_item_destination(" "))
3642 * then turn %1$s%2$s %3$s%4$s (strength,direction,distance,navigation_item_destination(" "))
3643 *
3644 * You have reached your destination %s (distance)
3645 *
3646 *
3647 *
3648 * distance:
3649 * ""
3650 * soon
3651 * get_distance(is_length=0)
3652 * after %i roads
3653 * now
3654 *
3655 *
3656 * direction:
3657 * left
3658 * right
3659 *
3660 * strength:
3661 * ""
3662 * slight
3663 * hard
3664 * really hard
3665 *
3666 * navigation_item_destination:
3667 * ============================
3668 * ""
3669 * (prefix)exit
3670 * (prefix)into the ramp
3671 * (prefix)into the street (streetname)(sep)(systematic streetname)
3672 * (prefix)into the (streetname)(sep)(systematic streetname) |male form %s%s%s
3673 * (prefix)into the (streetname)(sep)(systematic streetname) |female form %s%s%s
3674 * (prefix)into the (streetname)(sep)(systematic streetname) |neutral form %s%s%s
3675 * (prefix)into the (systematic streetname) %s
3676 *
3677 *
3678 *
3679 * get_count_str:
3680 * ==============
3681 * first
3682 * second
3683 * fifth
3684 *
3685 *
3686 * get_exit_count_str:
3687 * ===================
3688 * first exit
3689 * second exit
3690 * fifth exit
3691 *
3692 *
3693 *
3694 * get_distance:
3695 * =============
3696 * %d m (is_length 1)
3697 * in %d m
3698 * %d feet (is_length 1)
3699 * in %d feet
3700 * %d meters (is_length 1)
3701 * in %d meters
3702 * %d.%d miles (is_length 1)
3703 * in %d.%d miles
3704 * %d.%d kilometers (is_length 1)
3705 * in %d.%d kilometers
3706 * one mile,%d miles (is_length 1)
3707 * in one mile,in %d miles
3708 * one kilometer,%d kilometers (is_length 1)
3709 * in one kilometer,in %d kilometers
3710 */
3711
3712 }
3713
3714 /**
3715 * generic message channel to C-code
3716 */
3717 public static native int CallbackMessageChannel(int i, String s);
3718
3719 /**
3720 * return search result from C-code
3721 */
3722 public void fillStringArray(String s)
3723 {
3724 //Log.e("NavitGraphics", "**** fillStringArray s=" + s);
3725 // deactivate the spinner
3726 // --> no we want to spin ** Navit.NavitAddressSearchSpinnerActive = false;
3727
3728 if (s.equals("D:D"))
3729 {
3730 // ok its a dummy, just move the percent bar
3731 // Log.e("NavitGraphics", "**** fillStringArray s=" + s);
3732 }
3733 else
3734 {
3735 try
3736 {
3737 // we hope its a real result value
3738 Navit.Navit_Address_Result_Struct tmp_addr = new Navit_Address_Result_Struct();
3739 String[] tmp_s = s.split(":");
3740 tmp_addr.result_type = tmp_s[0];
3741 tmp_addr.item_id = tmp_s[1];
3742 tmp_addr.lat = Float.parseFloat(tmp_s[2]);
3743 tmp_addr.lon = Float.parseFloat(tmp_s[3]);
3744 // the rest ist address
3745 tmp_addr.addr = s.substring(4 + tmp_s[0].length() + tmp_s[1].length() + tmp_s[2].length() + tmp_s[3].length(), s.length());
3746
3747 // if "type" and "H id" and "text" is the same, treat it as a double entry!
3748 // this is just a crude estimate now
3749 // *OLD* String hash_id = tmp_addr.result_type + ":" + tmp_addr.item_id.split("L")[0] + ":" + tmp_addr.addr;
3750 // String hash_id = tmp_addr.result_type + ":" + tmp_addr.item_id + ":" + tmp_addr.addr;
3751 String hash_id = tmp_addr.result_type + ":" + tmp_addr.lat + ":" + tmp_addr.lon + ":" + tmp_addr.addr;
3752 //System.out.println("hash_id=" + hash_id);
3753 if (!Navit.Navit_Address_Result_double_index.contains(hash_id))
3754 {
3755 Navit.NavitAddressResultList_foundItems.add(tmp_addr);
3756 Navit.Navit_Address_Result_double_index.add(hash_id);
3757 //System.out.println("*add*=" + hash_id);
3758
3759 if (tmp_addr.result_type.equals("TWN"))
3760 {
3761 Navit.search_results_towns++;
3762 }
3763 else if (tmp_addr.result_type.equals("STR"))
3764 {
3765 Navit.search_results_streets++;
3766 }
3767 else if (tmp_addr.result_type.equals("SHN"))
3768 {
3769 Navit.search_results_streets_hn++;
3770 }
3771
3772 Navit.NavitSearchresultBar_title = Navit.get_text("loading search results");
3773 Navit.NavitSearchresultBar_text = Navit.get_text("towns") + ":" + Navit.search_results_towns + " " + Navit.get_text("Streets") + ":" + Navit.search_results_streets + "/" + Navit.search_results_streets_hn;
3774
3775 // make the dialog move its bar ...
3776 // Bundle b = new Bundle();
3777 // b.putInt("dialog_num", Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE);
3778 // b.putInt("max", Navit.ADDRESS_RESULTS_DIALOG_MAX);
3779 // b.putInt("cur", Navit.NavitAddressResultList_foundItems.size() % (Navit.ADDRESS_RESULTS_DIALOG_MAX + 1));
3780 // b.putString("title", Navit.get_text("loading search results")); //TRANS
3781 // b.putString("text", Navit.get_text("towns") + ":" + Navit.search_results_towns + " " + Navit.get_text("Streets") + ":" + Navit.search_results_streets + "/" + Navit.search_results_streets_hn);
3782 // Navit.msg_to_msg_handler(b, 10);
3783 }
3784 //else
3785 //{
3786 // //System.out.println("double " + tmp_addr.addr);
3787 //}
3788 }
3789 catch (Exception e)
3790 {
3791
3792 }
3793 }
3794
3795 // always move the bar, so that the user knows app is still doing something (and has not crashed!)
3796 // Navit.NavitSearchresultBarIndex++;
3797 // if (Navit.NavitSearchresultBarIndex > Navit.ADDRESS_RESULTS_DIALOG_MAX)
3798 // {
3799 // Navit.NavitSearchresultBarIndex = 0;
3800 // }
3801 // make the dialog move its bar ...
3802 // Bundle b = new Bundle();
3803 // b.putInt("dialog_num", Navit.SEARCHRESULTS_WAIT_DIALOG_OFFLINE);
3804 // b.putInt("max", Navit.ADDRESS_RESULTS_DIALOG_MAX);
3805 // b.putInt("cur", Navit.NavitSearchresultBarIndex);
3806 // b.putString("title", Navit.get_text("loading search results")); //TRANS
3807 // b.putString("text", Navit.get_text("towns") + ":" + Navit.search_results_towns + " " + Navit.get_text("Streets") + ":" + Navit.search_results_streets + "/" + Navit.search_results_streets_hn);
3808 // Navit.msg_to_msg_handler(b, 10);
3809 }
3810
3811 public void SearchResultList(int i, int partial_match, String text, int flags, String country_iso2, String search_latlon, int search_radius)
3812 {
3813 CallbackSearchResultList(i, partial_match, text, flags, country_iso2, search_latlon, search_radius);
3814 }
3815
3816 public native void CallbackSearchResultList(int i, int partial_match, String s, int flags, String country_iso2, String search_latlon, int search_radius);
3817
3818 /**
3819 * get localized string
3820 */
3821 public static native String CallbackLocalizedString(String s);
3822
3823 //
3824 //
3825 //
3826 // get route_status value from C-lib
3827 /*
3828 * route_status_no_destination=0, # 0 --> no dest. set
3829 * route_status_destination_set=1, # 1
3830 * route_status_not_found=1|2, # 3 --> no route to destination found / route blocked
3831 * route_status_building_path=1|4, # 5
3832 * route_status_building_graph=1|4|8, # 13
3833 * route_status_path_done_new=1|16, # 17 --> route found
3834 * route_status_path_done_incremental=1|32, # 33 --> route found
3835 */
3836 // now we get the value pushed from C automatically
3837 public static int CallbackDestinationValid2()
3838 {
3839 return NavitGraphics.navit_route_status;
3840 }
3841
3842 // call C-function to get value --> not used anymore now!!
3843 public static native int CallbackDestinationValid();
3844
3845 public static Handler callback_handler_s = new Handler()
3846 {
3847 public void handleMessage(Message msg)
3848 {
3849 if (msg.getData().getInt("Callback") == 18)
3850 {
3851 CallbackMessageChannel(18, "");
3852 }
3853 else if (msg.getData().getInt("Callback") == 47)
3854 {
3855 // get values
3856 String s = msg.getData().getString("s");
3857 // set routing target to lat,lon
3858 CallbackMessageChannel(47, s);
3859 }
3860 else if (msg.getData().getInt("Callback") == 55)
3861 {
3862 // set cache size for (map-)files
3863 String s = msg.getData().getString("s");
3864 CallbackMessageChannel(55, s);
3865 }
3866 else if (msg.getData().getInt("Callback") == 9901)
3867 {
3868 // if follow mode is on, then dont show freeview streetname
3869 if (!Navit.PREF_follow_gps)
3870 {
3871 Navit.OSD_nextturn.nextturn_streetname_systematic = "";
3872 Navit.OSD_nextturn.nextturn_streetname = NavitGraphics.CallbackGeoCalc(5, mCanvasWidth / 2, mCanvasHeight / 2);
3873 // System.out.println("location:" + Navit.OSD_nextturn.nextturn_streetname);
3874 NavitAOSDJava_.postInvalidate();
3875 }
3876 }
3877 }
3878 };
3879
3880 //
3881 //
3882 //
3883
3884 // i=1 -> pixel a,b (x,y) -> geo string "lat(float)#lng(float)"
3885 // i=2 -> geo a,b (lat,lng) -> pixel string "x(int)#y(int)"
3886 public static native String CallbackGeoCalc(int i, float a, float b);
3887
3888 public static void send_generic_text(int id, String text)
3889 {
3890 if (id == 1)
3891 {
3892 // speech textblock
3893 if (NavitGraphics.NavitMsgTv2_.getVisibility() == View.VISIBLE)
3894 {
3895 NavitMsgTv2_.append("TEXT:" + text);
3896 }
3897 }
3898 }
3899
3900 public static void return_generic_int(int id, int i)
3901 {
3902 // System.out.println("id=" + id + " i=" + i);
3903
3904 if (id == 1)
3905 {
3906 // id=1 -> route_status
3907 NavitGraphics.navit_route_status = i;
3908 if (i == 0)
3909 {
3910 ZANaviBusySpinner.active = false;
3911 ZANaviBusySpinner.cancelAnim();
3912 busyspinner_.setVisibility(View.INVISIBLE);
3913 busyspinnertext_.setText("");
3914 busyspinnertext_.setVisibility(View.INVISIBLE);
3915 Navit.set_debug_messages1("");
3916 }
3917 else if (i == 1)
3918 {
3919 ZANaviBusySpinner.active = true;
3920 busyspinner_.setVisibility(View.VISIBLE);
3921 busyspinner_.postInvalidate();
3922 busyspinnertext_.setText(Navit.get_text("Destination set")); // TRANS
3923 busyspinnertext_.setVisibility(View.VISIBLE);
3924 Navit.set_debug_messages1("Destination set");
3925 }
3926 else if (i == 3)
3927 {
3928 ZANaviBusySpinner.active = true;
3929 ZANaviBusySpinner.cancelAnim();
3930 busyspinner_.setVisibility(View.VISIBLE);
3931 busyspinnertext_.setText(Navit.get_text("No route found / Route blocked")); // TRANS
3932 busyspinnertext_.setVisibility(View.VISIBLE);
3933 Navit.set_debug_messages1("No route found / Route blocked");
3934 }
3935 else if (i == 5)
3936 {
3937 ZANaviBusySpinner.active = true;
3938 busyspinner_.setVisibility(View.VISIBLE);
3939 busyspinner_.postInvalidate();
3940 busyspinnertext_.setText(Navit.get_text("Building route path")); // TRANS
3941 busyspinnertext_.setVisibility(View.VISIBLE);
3942 Navit.set_debug_messages1("Building route path");
3943 }
3944 else if (i == 13)
3945 {
3946 ZANaviBusySpinner.active = true;
3947 busyspinner_.setVisibility(View.VISIBLE);
3948 busyspinner_.postInvalidate();
3949 busyspinnertext_.setText(Navit.get_text("Building route graph")); // TRANS
3950 busyspinnertext_.setVisibility(View.VISIBLE);
3951 Navit.set_debug_messages1("Building route graph");
3952 }
3953 else if (i == 17)
3954 {
3955 ZANaviBusySpinner.active = false;
3956 ZANaviBusySpinner.cancelAnim();
3957 busyspinner_.setVisibility(View.INVISIBLE);
3958 busyspinnertext_.setText("");
3959 busyspinnertext_.setVisibility(View.INVISIBLE);
3960 Navit.set_debug_messages1("Route found");
3961 }
3962 else if (i == 33)
3963 {
3964 ZANaviBusySpinner.active = false;
3965 ZANaviBusySpinner.cancelAnim();
3966 busyspinner_.setVisibility(View.INVISIBLE);
3967 busyspinnertext_.setText("");
3968 busyspinnertext_.setVisibility(View.INVISIBLE);
3969 Navit.set_debug_messages1("Route found");
3970 }
3971 }
3972 else if (id == 2)
3973 {
3974 // id=2 -> map draw finished
3975 if (DEBUG_TOUCH) System.out.println("wait_for_redraw_map=false xx1");
3976 NavitGraphics.wait_for_redraw_map = false;
3977 try
3978 {
3979 NavitAndroidOverlay.overlay_draw_thread1.stop_redraw();
3980 NavitAndroidOverlay.overlay_draw_thread1.stop_me();
3981 NavitAndroidOverlay.overlay_draw_thread1 = null;
3982 }
3983 catch (Exception e)
3984 {
3985 // e.printStackTrace();
3986 }
3987 try
3988 {
3989 NavitAOverlay_s.postInvalidate();
3990 }
3991 catch (Exception e)
3992 {
3993 e.printStackTrace();
3994 }
3995 }
3996 else if (id == 3)
3997 {
3998 // id=3 -> new scale (zoom) number
3999 // 1 (=2^0) order: ~16 -> fully zoomed in
4000 // 1048576 (=2^20) order: -1 -> zoomed out to world
4001 if (DEBUG_TOUCH) System.out.println("scale=" + i);
4002 Navit.GlobalScaleLevel = i;
4003 }
4004 else if (id == 4)
4005 {
4006 Navit.set_debug_messages1("Destination reached");
4007 NavitGraphics.navit_route_status = 0;
4008 }
4009 else if (id == 5)
4010 {
4011 Navit.set_debug_messages1("Waypoint reached");
4012 }
4013 else if (id == 6)
4014 {
4015 // id=6 -> mean time for drawing map to screen (in 1/1000 of a second)
4016 Navit.set_debug_messages4("draw:" + (float) ((float) i / 1000f) + "s");
4017 }
4018 }
4019
4020 public static Bitmap rotate_and_scale_bitmap(Bitmap in, int w, int h, int angle)
4021 {
4022 int width = in.getWidth();
4023 int height = in.getHeight();
4024
4025 if ((width == w) && (height == h) && (angle == 0))
4026 {
4027 return in;
4028 }
4029
4030 // System.out.println(" @@@@@@ w="+w+" h="+h);
4031
4032 // calculate the scale
4033 float scaleWidth = ((float) w) / width;
4034 float scaleHeight = ((float) h) / height;
4035
4036 // createa matrix for the manipulation
4037 Matrix matrix = new Matrix();
4038 // resize the bit map
4039 matrix.postScale(scaleWidth, scaleHeight);
4040 // rotate the Bitmap
4041 matrix.postRotate(angle);
4042
4043 // recreate the new Bitmap
4044 return (Bitmap.createBitmap(in, 0, 0, width, height, matrix, true));
4045 }
4046
4047 }

   
Visit the ZANavi Wiki