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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 51 - (show annotations) (download)
Mon Jul 25 19:29:08 2016 UTC (7 years, 8 months ago) by zoff99
File size: 28998 byte(s)
v2.0.52
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 android.annotation.SuppressLint;
42 import android.content.Context;
43 import android.content.DialogInterface;
44 import android.graphics.Canvas;
45 import android.graphics.Color;
46 import android.graphics.Matrix;
47 import android.graphics.Paint;
48 import android.graphics.Path;
49 import android.graphics.Rect;
50 import android.graphics.RectF;
51 import android.os.Bundle;
52 import android.os.Message;
53 import android.util.AttributeSet;
54 import android.view.MotionEvent;
55 import android.view.View;
56
57 import com.zoffcc.applications.zanavi.Navit.geo_coord;
58
59 public class NavitAndroidOverlay extends View
60 {
61 public Boolean draw_bubble = false;
62 public Boolean draw_bubble_first = false;
63 public static Boolean confirmed_bubble = false;
64 public static int confirmed_bubble_part = 0; // 0 -> left side, 1 -> right side
65 public long bubble_showing_since = 0L;
66 public static long bubble_max_showing_timespan = 5000L; // 5 secs.
67 // public RectF follow_button_rect = new RectF(-100, 1, 1, 1);
68 //public RectF voice_recog_rect = new RectF(-100, 1, 1, 1);
69 //public RectF zoomin_button_rect = new RectF(-100, 1, 1, 1);
70 //public RectF zoomout_button_rect = new RectF(-100, 1, 1, 1);
71 //public RectF mapdrawing_button_rect = new RectF(-100, 1, 1, 1);
72 public static int zoomin_ltx = 0;
73 public static int zoomin_lty = 0;
74 public static int zoomout_ltx = 0;
75 public static int zoomout_lty = 0;
76 public static int mapdrawing_ltx = 0;
77 public static int mapdrawing_lty = 0;
78 public int mCanvasHeight = 1;
79 public int mCanvasWidth = 1;
80 public static float draw_factor = 1.0f;
81 public static boolean voice_rec_bar_visible = false;
82 public static boolean voice_rec_bar_visible2 = false;
83 public static int voice_rec_bar_x = -10;
84 public static int voice_rec_bar_y = -10;
85 public static int voice_rec_bar_limit = 10;
86 Matrix lanes_scaleMatrix = new Matrix();
87 Matrix lanes_transMatrix = new Matrix();
88 RectF lanes_rectF = new RectF();
89
90 public static boolean measure_mode = false;
91 public static int measure_result_meters = -1;
92 static int measure_1_x = 0;
93 static int measure_1_y = 0;
94 static int measure_2_x = 0;
95 static int measure_2_y = 0;
96 static boolean measure_first = true;
97 static boolean measure_valid = false;
98 static Paint paint_measure = new Paint();
99 static int measure_point_radius = 3;
100
101 private Paint paint_replay = new Paint();
102 private Paint paint_rewind_small = new Paint();
103 private Paint paint_bubble_hotpoint = new Paint();
104
105 Message msg_dd = null;
106 Bundle b_dd = new Bundle();
107
108 RectF bounds_speedwarning = new RectF(120, 800, 120 + 200, 800 + 200);
109 Paint paint_speedwarning = new Paint(0);
110
111 static boolean no_draw = false;
112
113 static Path pathForTurn = new Path();
114
115 public static BubbleThread bubble_thread = null;
116
117 public static NavitGraphics.OverlayDrawThread overlay_draw_thread1;
118
119 private class BubbleThread extends Thread
120 {
121 private Boolean running;
122 private long bubble_showing_since = 0L;
123 private NavitAndroidOverlay a_overlay = null;
124
125 BubbleThread(NavitAndroidOverlay a_ov)
126 {
127 this.running = true;
128 this.a_overlay = a_ov;
129 this.bubble_showing_since = 0L;
130 //Log.e("Navit", "BubbleThread created");
131 }
132
133 public void stop_me()
134 {
135 this.running = false;
136 }
137
138 public void run()
139 {
140 this.bubble_showing_since = System.currentTimeMillis();
141
142 // Log.e("Navit", "BubbleThread started");
143 while (this.running)
144 {
145 if ((System.currentTimeMillis() - this.bubble_showing_since) > bubble_max_showing_timespan)
146 {
147 //Log.e("Navit", "BubbleThread: bubble displaying too long, hide it");
148 // with invalidate we call the onDraw() function, that will take care of it
149 //System.out.println("invalidate 001");
150 this.a_overlay.postInvalidate();
151 this.running = false;
152 }
153 else
154 {
155 try
156 {
157 Thread.sleep(280);
158 }
159 catch (InterruptedException e)
160 {
161 // e.printStackTrace();
162 }
163 }
164 }
165 //Log.e("Navit", "BubbleThread ended");
166 }
167 }
168
169 public static class NavitAndroidOverlayBubble
170 {
171 int x;
172 int y;
173 String text = null;
174 }
175
176 NavitAndroidOverlayBubble bubble_001 = null;
177
178 public NavitAndroidOverlay(Context context)
179 {
180 super(context);
181
182 paint_measure.setColor(Color.RED);
183 paint_measure.setStyle(Paint.Style.STROKE);
184 paint_measure.setStrokeWidth(NavitGraphics.dp_to_px(6));
185 measure_point_radius = NavitGraphics.dp_to_px(10);
186
187 paint_replay.setColor(0xaa444444); // grey
188 paint_replay.setStyle(Paint.Style.FILL_AND_STROKE);
189
190 paint_rewind_small.setColor(0xaa440202); // red
191 paint_rewind_small.setStyle(Paint.Style.FILL_AND_STROKE);
192
193 paint_bubble_hotpoint.setColor(Color.RED); // red
194 paint_bubble_hotpoint.setStyle(Paint.Style.STROKE);
195 paint_bubble_hotpoint.setStrokeWidth(NavitGraphics.dp_to_px(6));
196 paint_bubble_hotpoint.setAntiAlias(true);
197 paint_bubble_hotpoint.setDither(true);
198 }
199
200 public NavitAndroidOverlay(Context context, AttributeSet attrs)
201 {
202 super(context, attrs);
203
204 paint_measure.setColor(Color.RED);
205 paint_measure.setStyle(Paint.Style.STROKE);
206 paint_measure.setStrokeWidth(NavitGraphics.dp_to_px(6));
207 measure_point_radius = NavitGraphics.dp_to_px(10);
208
209 paint_replay.setColor(0xaa444444);
210 paint_replay.setStyle(Paint.Style.FILL_AND_STROKE);
211
212 paint_rewind_small.setColor(0xaa440202); // red
213 paint_rewind_small.setStyle(Paint.Style.FILL_AND_STROKE);
214
215 paint_bubble_hotpoint.setColor(Color.RED); // red
216 paint_bubble_hotpoint.setStyle(Paint.Style.STROKE);
217 paint_bubble_hotpoint.setStrokeWidth(NavitGraphics.dp_to_px(6));
218 paint_bubble_hotpoint.setAntiAlias(true);
219 paint_bubble_hotpoint.setDither(true);
220 }
221
222 public void show_bubble()
223 {
224 //System.out.println("NavitAndroidOverlay -> show_bubble");
225 if (!this.draw_bubble)
226 {
227 try
228 {
229 Message msg = Navit.Navit_progress_h.obtainMessage();
230 Bundle b = new Bundle();
231 msg.what = 34;
232 msg.setData(b);
233 Navit.Navit_progress_h.sendMessage(msg);
234 }
235 catch (Exception e)
236 {
237 e.printStackTrace();
238 }
239
240 confirmed_bubble = false;
241 this.draw_bubble = true;
242 this.draw_bubble_first = true;
243 this.bubble_showing_since = System.currentTimeMillis();
244 bubble_thread = new BubbleThread(this);
245 bubble_thread.start();
246
247 // test test DEBUG
248 /*
249 * Message msg = new Message();
250 * Bundle b = new Bundle();
251 * b.putInt("Callback", 4);
252 * b.putInt("x", this.bubble_001.x);
253 * b.putInt("y", this.bubble_001.y);
254 * msg.setData(b);
255 * Navit.N_NavitGraphics.callback_handler.sendMessage(msg);
256 */
257 }
258 }
259
260 public Boolean get_show_bubble()
261 {
262 return this.draw_bubble;
263 }
264
265 public void hide_bubble()
266 {
267 // Log.e("NavitGraphics", "NavitAndroidOverlay -> hide_bubble");
268 confirmed_bubble = false;
269 this.draw_bubble = false;
270 this.draw_bubble_first = false;
271
272 try
273 {
274 Message msg = Navit.Navit_progress_h.obtainMessage();
275 Bundle b = new Bundle();
276 msg.what = 35;
277 msg.setData(b);
278 Navit.Navit_progress_h.sendMessage(msg);
279 }
280 catch (Exception e)
281 {
282 e.printStackTrace();
283 }
284
285 this.bubble_showing_since = 0L;
286 try
287 {
288 bubble_thread.stop_me();
289 // bubble_thread.stop();
290 }
291 catch (Exception e)
292 {
293
294 }
295 //this.postInvalidate();
296 }
297
298 public void set_bubble(NavitAndroidOverlayBubble b)
299 {
300 this.bubble_001 = b;
301 }
302
303 public void whats_button_clicked()
304 {
305 // bubble touched to confirm destination
306 confirmed_bubble = true;
307 confirmed_bubble_part = 1;
308 // draw confirmed bubble
309 //System.out.println("invalidate 003");
310 this.postInvalidate();
311
312 // whats here?
313 String item_dump_pretty = "";
314 if (Navit.GFX_OVERSPILL)
315 {
316 item_dump_pretty = NavitGraphics.CallbackGeoCalc(10, (this.bubble_001.x + NavitGraphics.mCanvasWidth_overspill) * NavitGraphics.Global_dpi_factor, (this.bubble_001.y + NavitGraphics.mCanvasHeight_overspill) * NavitGraphics.Global_dpi_factor);
317 }
318 else
319 {
320 item_dump_pretty = NavitGraphics.CallbackGeoCalc(10, this.bubble_001.x * NavitGraphics.Global_dpi_factor, this.bubble_001.y * NavitGraphics.Global_dpi_factor);
321 }
322
323 try
324 {
325 String item_dump_pretty_parsed = "";
326 String[] item_dump_lines = item_dump_pretty.split("\n");
327 int jk = 0;
328 String sep = "";
329 for (jk = 0; jk < item_dump_lines.length; jk++)
330 {
331 if (item_dump_lines[jk].startsWith("+*TYPE*+:"))
332 {
333 item_dump_pretty_parsed = item_dump_pretty_parsed + sep + item_dump_lines[jk].substring(9);
334 }
335 else if (item_dump_lines[jk].startsWith("flags="))
336 {
337
338 }
339 else if (item_dump_lines[jk].startsWith("maxspeed="))
340 {
341 item_dump_pretty_parsed = item_dump_pretty_parsed + sep + item_dump_lines[jk];
342 }
343 else if (item_dump_lines[jk].startsWith("label="))
344 {
345 item_dump_pretty_parsed = item_dump_pretty_parsed + sep + item_dump_lines[jk].substring(6);
346 }
347 else if (item_dump_lines[jk].startsWith("street_name="))
348 {
349 item_dump_pretty_parsed = item_dump_pretty_parsed + sep + item_dump_lines[jk].substring(12);
350 }
351 else if (item_dump_lines[jk].startsWith("street_name_systematic="))
352 {
353 item_dump_pretty_parsed = item_dump_pretty_parsed + sep + item_dump_lines[jk].substring(23);
354 }
355 else
356 {
357 item_dump_pretty_parsed = item_dump_pretty_parsed + sep + item_dump_lines[jk];
358 }
359
360 if (jk == 0)
361 {
362 sep = "\n";
363 }
364 }
365
366 Navit.generic_alert_box.setMessage(item_dump_pretty_parsed).setPositiveButton(Navit.get_text("Ok"), new DialogInterface.OnClickListener()
367 {
368 public void onClick(DialogInterface dialog, int id)
369 {
370 // Handle Ok
371 }
372 }).create();
373 Navit.generic_alert_box.setCancelable(true);
374 Navit.generic_alert_box.setTitle(Navit.get_text("What's here")); // TRANS
375 Navit.generic_alert_box.show();
376 }
377 catch (Exception e)
378 {
379 e.printStackTrace();
380 }
381
382 this.hide_bubble();
383 this.postInvalidate();
384 }
385
386 public void addto_button_clicked()
387 {
388 // bubble touched to confirm destination
389 confirmed_bubble = true;
390 confirmed_bubble_part = 0;
391 // draw confirmed bubble
392 //System.out.println("invalidate 002");
393 this.postInvalidate();
394 String dest_name = "Point on Screen";
395
396 // remeber recent dest.
397 try
398 {
399 if (Navit.GFX_OVERSPILL)
400 {
401 dest_name = NavitGraphics.CallbackGeoCalc(8, (this.bubble_001.x + NavitGraphics.mCanvasWidth_overspill) * NavitGraphics.Global_dpi_factor, (this.bubble_001.y + NavitGraphics.mCanvasHeight_overspill) * NavitGraphics.Global_dpi_factor);
402 }
403 else
404 {
405 dest_name = NavitGraphics.CallbackGeoCalc(8, this.bubble_001.x * NavitGraphics.Global_dpi_factor, this.bubble_001.y * NavitGraphics.Global_dpi_factor);
406 }
407
408 // System.out.println("x:"+dest_name+":y");
409 if ((dest_name.equals(" ")) || (dest_name == null))
410 {
411 dest_name = "Point on Screen";
412 }
413
414 // Navit.remember_destination_xy(dest_name, this.bubble_001.x, this.bubble_001.y);
415 }
416 catch (Exception e)
417 {
418 e.printStackTrace();
419 }
420
421 Navit.geo_coord gc1 = Navit.px_to_geo(this.bubble_001.x, this.bubble_001.y);
422
423 try
424 {
425 Navit.remember_destination(dest_name, "" + gc1.Latitude, "" + gc1.Longitude);
426 // save points
427 Navit.write_map_points();
428 }
429 catch (Exception e)
430 {
431 e.printStackTrace();
432 }
433
434 this.hide_bubble();
435 this.postInvalidate();
436 }
437
438 public void drive_button_clicked()
439 {
440 // bubble touched to confirm destination
441 confirmed_bubble = true;
442 confirmed_bubble_part = 0;
443 // draw confirmed bubble
444 //System.out.println("invalidate 002");
445 this.postInvalidate();
446 String dest_name = "Point on Screen";
447
448 // remeber recent dest.
449 try
450 {
451 if (Navit.GFX_OVERSPILL)
452 {
453 dest_name = NavitGraphics.CallbackGeoCalc(8, (this.bubble_001.x + NavitGraphics.mCanvasWidth_overspill) * NavitGraphics.Global_dpi_factor, (this.bubble_001.y + NavitGraphics.mCanvasHeight_overspill) * NavitGraphics.Global_dpi_factor);
454 }
455 else
456 {
457 dest_name = NavitGraphics.CallbackGeoCalc(8, this.bubble_001.x * NavitGraphics.Global_dpi_factor, this.bubble_001.y * NavitGraphics.Global_dpi_factor);
458 }
459
460 // System.out.println("x:"+dest_name+":y");
461 if ((dest_name.equals(" ")) || (dest_name == null))
462 {
463 dest_name = "Point on Screen";
464 }
465
466 // Navit.remember_destination_xy(dest_name, this.bubble_001.x, this.bubble_001.y);
467 }
468 catch (Exception e)
469 {
470 e.printStackTrace();
471 }
472
473 Navit.geo_coord gc1 = Navit.px_to_geo(this.bubble_001.x, this.bubble_001.y);
474
475 Navit.route_wrapper(dest_name, 0, 0, false, gc1.Latitude, gc1.Longitude, true);
476
477 final Thread zoom_to_route_008 = new Thread()
478 {
479 int wait = 1;
480 int count = 0;
481 int max_count = 60;
482
483 @Override
484 public void run()
485 {
486 while (wait == 1)
487 {
488 try
489 {
490 if ((NavitGraphics.navit_route_status == 17) || (NavitGraphics.navit_route_status == 33))
491 {
492 Navit.zoom_to_route();
493 wait = 0;
494 }
495 else
496 {
497 wait = 1;
498 }
499
500 count++;
501 if (count > max_count)
502 {
503 wait = 0;
504 }
505 else
506 {
507 Thread.sleep(400);
508 }
509 }
510 catch (Exception e)
511 {
512 }
513 }
514 }
515 };
516 zoom_to_route_008.start();
517
518 try
519 {
520 Navit.follow_button_on();
521 }
522 catch (Exception e2)
523 {
524 e2.printStackTrace();
525 }
526
527 this.hide_bubble();
528 this.postInvalidate();
529 }
530
531 @Override
532 public boolean onTouchEvent(MotionEvent event)
533 {
534 super.onTouchEvent(event);
535
536 int action = event.getAction();
537 int x = (int) event.getX();
538 int y = (int) event.getY();
539
540 //Log.e("NavitGraphics", "NavitAndroidOverlay -> action=" + action);
541
542 //if (action == MotionEvent.ACTION_UP)
543 //{
544 // Log.e("NavitGraphics", "NavitAndroidOverlay -> onTouchEvent ACTION_UP");
545 // if (NavitGraphics.in_map)
546 // {
547 // return false;
548 // }
549 //}
550
551 if (NavitAndroidOverlay.measure_mode)
552 {
553
554 if (action == MotionEvent.ACTION_UP)
555 {
556 if (measure_first)
557 {
558 measure_first = false;
559 measure_1_x = x;
560 measure_1_y = y;
561
562 measure_valid = false;
563 }
564 else
565 {
566 measure_first = true;
567 measure_2_x = x;
568 measure_2_y = y;
569
570 geo_coord gc1 = Navit.px_to_geo(measure_1_x, measure_1_y);
571 geo_coord gc2 = Navit.px_to_geo(measure_2_x, measure_2_y);
572
573 // System.out.println("XXXXXXXXXXXXXX:3a " + gc1.Latitude + " " + gc1.Longitude + " " + gc2.Latitude + " " + gc2.Longitude);
574
575 int m = NavitVehicle.distanceBetween(gc1.Latitude, gc1.Longitude, gc2.Latitude, gc2.Longitude);
576
577 measure_valid = true;
578
579 measure_result_meters = m;
580 ZANaviLinearLayout.redraw_OSD(1);
581 NavitGraphics.NavitAOverlay_s.postInvalidate();
582 }
583 }
584
585 return true;
586 }
587
588 if (ZANaviDebugReceiver.is_replaying)
589 {
590 if (action == MotionEvent.ACTION_DOWN)
591 {
592 Rect r = new Rect(40, mCanvasHeight / 5, 40 + NavitGraphics.dp_to_px(50), (mCanvasHeight / 5) + NavitGraphics.dp_to_px(50));
593 if (r.contains(x, y))
594 {
595 ZANaviDebugReceiver.DR_skip();
596 }
597
598 r = new Rect(40 + NavitGraphics.dp_to_px(80), mCanvasHeight / 5, 40 + NavitGraphics.dp_to_px(50) + NavitGraphics.dp_to_px(80), (mCanvasHeight / 5) + NavitGraphics.dp_to_px(50));
599 if (r.contains(x, y))
600 {
601 ZANaviDebugReceiver.DR_rewind_small();
602 }
603
604 }
605 }
606
607 if (action == MotionEvent.ACTION_DOWN)
608 {
609 if ((this.draw_bubble) && (!confirmed_bubble))
610 {
611 int dx = (int) ((20 / 1.5f) * draw_factor);
612 int dy = (int) ((-100 / 1.5f) * draw_factor);
613 int bubble_size_x = (int) ((150 / 1.5f) * draw_factor);
614 int bubble_size_y = (int) ((60 / 1.5f) * draw_factor);
615 RectF box_rect_left = new RectF(this.bubble_001.x + dx, this.bubble_001.y + dy, this.bubble_001.x + bubble_size_x / 2 + dx, this.bubble_001.y + bubble_size_y + dy);
616 RectF box_rect_right = new RectF(this.bubble_001.x + bubble_size_x / 2 + dx, this.bubble_001.y + dy, this.bubble_001.x + bubble_size_x + dx, this.bubble_001.y + bubble_size_y + dy);
617
618 if (box_rect_left.contains(x, y))
619 {
620 }
621 // else if (2 == 1)
622 // {
623 // // share the current location with your friends
624 // share_location("48.422", "16.34", "Meeting Point");
625 // }
626 else if (box_rect_right.contains(x, y))
627 {
628 }
629 }
630 }
631
632 // false -> we dont use this event, give it to other layers
633 return false;
634 }
635
636 @Override
637 public void onSizeChanged(int w, int h, int oldw, int oldh)
638 {
639 // super.onSizeChanged(w, h, oldw, oldh);
640 this.mCanvasWidth = w;
641 this.mCanvasHeight = h;
642
643 draw_factor = 1.0f;
644 if (Navit.my_display_density.compareTo("mdpi") == 0)
645 {
646 draw_factor = 1.0f;
647 }
648 else if (Navit.my_display_density.compareTo("ldpi") == 0)
649 {
650 draw_factor = 0.7f;
651 }
652 else if (Navit.my_display_density.compareTo("hdpi") == 0)
653 {
654 draw_factor = 1.5f;
655 }
656
657 // correct for ultra high DPI
658 if (Navit.metrics.densityDpi >= 320) //&& (Navit.PREF_shrink_on_high_dpi))
659 {
660 draw_factor = 1.8f * Navit.metrics.densityDpi / NavitGraphics.Global_want_dpi_other;
661 }
662
663 int w_1 = (int) ((10f / 1.5f) * draw_factor);
664 int h_1 = (int) ((200f / 1.5f) * draw_factor);
665 // this.follow_button_rect = new RectF(this.mCanvasWidth - Navit.follow_current.getWidth() - w_1, this.mCanvasHeight - Navit.follow_current.getHeight() - h_1, this.mCanvasWidth - w_1, this.mCanvasHeight - h_1);
666
667 // rect to slide open voice recognition
668 // this.voice_recog_rect = new RectF(0, (this.mCanvasHeight / 2f) - 100 * draw_factor, 16 * draw_factor, (this.mCanvasHeight / 2f) + 100 * draw_factor);
669 NavitAndroidOverlay.voice_rec_bar_limit = this.mCanvasWidth / 2;
670
671 /*
672 * int w_2 = (int) ((0 / 1.5f) * draw_factor) + 5;
673 * int h_2 = (int) ((0f / 1.5f) * draw_factor) + 5;
674 * int h_button_zoom = Navit.zoomin.getHeight();
675 * zoomin_ltx = w_2;
676 * zoomin_lty = h_2;
677 * this.zoomin_button_rect = new RectF(w_2, h_2, Navit.zoomin.getWidth() + w_2, h_button_zoom + h_2);
678 */
679
680 int w_2 = (int) ((0 / 1.5f) * draw_factor) + 5;
681 int h_2 = (int) ((70f / 1.5f) * draw_factor) + 5 + 25;
682 int h_button_zoom = Navit.zoomin.getHeight();
683 zoomin_ltx = w_2;
684 zoomin_lty = h_2;
685 // this.zoomin_button_rect = new RectF(w_2, h_2, Navit.zoomin.getWidth() + w_2, h_button_zoom + h_2);
686
687 w_2 = (int) ((0 / 1.5f) * draw_factor) + 5;
688 h_2 = (int) ((2 * 70f / 1.5f) * draw_factor) + 5 + 25 + 25;
689 zoomout_ltx = w_2;
690 zoomout_lty = h_2;
691 // this.zoomout_button_rect = new RectF(w_2, h_2, Navit.zoomout.getWidth() + w_2, h_button_zoom + h_2);
692
693 int mapdrawing_width = (int) ((75f / 1.5f) * draw_factor);
694 int mapdrawing_height = (int) ((75f / 1.5f) * draw_factor);
695 w_2 = (int) ((this.mCanvasWidth - mapdrawing_width) - 5);
696 h_2 = (int) ((70f / 1.5f) * draw_factor) + 5 + 25;
697 mapdrawing_ltx = w_2;
698 mapdrawing_lty = h_2;
699 // this.mapdrawing_button_rect = new RectF(w_2, h_2, mapdrawing_width + w_2, mapdrawing_height + h_2);
700
701 // on small screens (like the blackberry Q10) the follow button overlaps the 2d/3d button (mapdrawing button)
702 // check and then move 2d/3d button to the left
703 // boolean must_move_2d3d_button = false;
704 // if (mapdrawing_button_rect.contains(follow_button_rect.left, follow_button_rect.top))
705 // {
706 // must_move_2d3d_button = true;
707 // }
708 // else if (mapdrawing_button_rect.contains(follow_button_rect.right, follow_button_rect.top))
709 // {
710 // must_move_2d3d_button = true;
711 // }
712 // else if (mapdrawing_button_rect.contains(follow_button_rect.left, follow_button_rect.bottom))
713 // {
714 // must_move_2d3d_button = true;
715 // }
716 // else if (mapdrawing_button_rect.contains(follow_button_rect.left, follow_button_rect.bottom))
717 // {
718 // must_move_2d3d_button = true;
719 // }
720 //
721 // if (must_move_2d3d_button)
722 // {
723 // // move to left of follow button
724 // this.mapdrawing_button_rect = new RectF(w_2 - (this.mCanvasWidth - follow_button_rect.left), h_2, mapdrawing_width + w_2 - (this.mCanvasWidth - follow_button_rect.left), mapdrawing_height + h_2);
725 // }
726
727 // put menu button below "2D/3D" button
728 if (Navit.metrics.densityDpi >= 320) // && (Navit.PREF_shrink_on_high_dpi))
729 {
730 Navit.menu_button_rect = new RectF(this.mCanvasWidth - 10 - Navit.menu_button.getWidth(), 10 + mapdrawing_height + h_2 + 5, this.mCanvasWidth - 10, Navit.menu_button.getHeight() + 10 + mapdrawing_height + h_2 + 5);
731 Navit.menu_button_rect_touch = new RectF(this.mCanvasWidth - 10 - Navit.menu_button.getWidth(), 10 + mapdrawing_height + h_2 + 5, this.mCanvasWidth - 10, Navit.menu_button.getHeight() + 10 + mapdrawing_height + h_2 + 5);
732 }
733 else
734 {
735 final int addon_left = 0; //50;
736 final int addon_down = 0; //40;
737 Navit.menu_button_rect = new RectF(this.mCanvasWidth - 10 - Navit.menu_button.getWidth(), 10 + mapdrawing_height + h_2 + 5, this.mCanvasWidth - 10, Navit.menu_button.getHeight() + 10 + mapdrawing_height + h_2 + 5);
738 Navit.menu_button_rect_touch = new RectF(this.mCanvasWidth - 10 - Navit.menu_button.getWidth() - addon_left, 10 + mapdrawing_height + h_2 + 5, this.mCanvasWidth - 10, Navit.menu_button.getHeight() + 10 + mapdrawing_height + h_2 + 5 + addon_down);
739 }
740 }
741
742 int get_lanes_kind_count(int parsed_num_lanes, String[] lanes_split)
743 {
744 final int num_of_kinds = 6;
745 int[] lanes_kind = new int[num_of_kinds];
746 int lanes_kind_count = 0;
747
748 int k = 0;
749 for (k = 0; k < num_of_kinds; k++)
750 {
751 lanes_kind[k] = 0; // reset all
752 }
753
754 int j = 0;
755 for (j = 0; j < parsed_num_lanes; j++)
756 {
757 String lanes_split_sub[] = lanes_split[j].split(";");
758 int parsed_num_lanes_sub = lanes_split_sub.length;
759
760 k = 0;
761 String single_arrow = "";
762 for (k = 0; k < parsed_num_lanes_sub; k++)
763 {
764 single_arrow = lanes_split_sub[k].replaceAll("\\s", "");
765
766 // none 3
767 // through 3
768 // left 1
769 // right 5
770 // slight_left 2
771 // slight_right 4
772 // sharp_left 1
773 // sharp_right 5
774 // mergeto_left -
775 // mergeto_right -
776 // merge_to_left -
777 // merge_to_right -
778
779 if (single_arrow.equalsIgnoreCase("sharp_left"))
780 {
781 lanes_kind[1] = 1;
782 }
783 else if (single_arrow.equalsIgnoreCase("sharp_right"))
784 {
785 lanes_kind[5] = 1;
786 }
787 else if (single_arrow.equalsIgnoreCase("none"))
788 {
789 lanes_kind[3] = 1;
790 }
791 else if (single_arrow.equalsIgnoreCase("through"))
792 {
793 lanes_kind[3] = 1;
794 }
795 else if (single_arrow.equalsIgnoreCase("left"))
796 {
797 lanes_kind[1] = 1;
798 }
799 else if (single_arrow.equalsIgnoreCase("right"))
800 {
801 lanes_kind[5] = 1;
802 }
803 else if (single_arrow.equalsIgnoreCase("slight_left"))
804 {
805 lanes_kind[2] = 1;
806 }
807 else if (single_arrow.equalsIgnoreCase("slight_right"))
808 {
809 lanes_kind[4] = 1;
810 }
811
812 }
813 }
814
815 lanes_kind_count = 0;
816 for (k = 0; k < num_of_kinds; k++)
817 {
818 if (lanes_kind[k] == 1)
819 {
820 lanes_kind_count++;
821 }
822 }
823
824 return lanes_kind_count;
825 }
826
827 @SuppressLint("NewApi")
828 public void onDraw(Canvas c)
829 {
830
831 if (measure_mode)
832 {
833 if (measure_valid)
834 {
835 // draw the line
836 c.drawLine(measure_1_x, measure_1_y, measure_2_x, measure_2_y, paint_measure);
837 c.drawCircle(measure_1_x, measure_1_y, measure_point_radius, paint_measure);
838 c.drawCircle(measure_2_x, measure_2_y, measure_point_radius, paint_measure);
839 }
840
841 return;
842 }
843
844 if (ZANaviDebugReceiver.is_replaying)
845 {
846 c.drawRect(40, mCanvasHeight / 5, 40 + NavitGraphics.dp_to_px(50), (mCanvasHeight / 5) + NavitGraphics.dp_to_px(50), paint_replay);
847 c.drawRect(40 + NavitGraphics.dp_to_px(80), mCanvasHeight / 5, 40 + NavitGraphics.dp_to_px(50) + NavitGraphics.dp_to_px(80), (mCanvasHeight / 5) + NavitGraphics.dp_to_px(50), paint_rewind_small);
848 }
849
850 if (this.draw_bubble)
851 {
852 if ((System.currentTimeMillis() - this.bubble_showing_since) > bubble_max_showing_timespan)
853 {
854 // bubble has been showing too log, hide it
855 this.hide_bubble();
856 }
857 }
858
859 if (this.draw_bubble)
860 {
861 if (Navit.PAINT_OLD_API)
862 {
863 c.drawCircle(this.bubble_001.x, this.bubble_001.y, NavitGraphics.dp_to_px(10), paint_bubble_hotpoint);
864 }
865
866 if (draw_bubble_first)
867 {
868 try
869 {
870 System.out.println("BB:09");
871 msg_dd = Navit.Navit_progress_h.obtainMessage();
872 msg_dd.what = 36;
873 msg_dd.setData(b_dd);
874 Navit.Navit_progress_h.sendMessage(msg_dd);
875 }
876 catch (Exception e)
877 {
878 e.printStackTrace();
879 }
880
881 try
882 {
883 System.out.println("BB:10");
884 msg_dd = Navit.Navit_progress_h.obtainMessage();
885 msg_dd.what = 37;
886 msg_dd.setData(b_dd);
887 Navit.Navit_progress_h.sendMessage(msg_dd);
888 }
889 catch (Exception e)
890 {
891 e.printStackTrace();
892 }
893
894 draw_bubble_first = false;
895 }
896 }
897
898 if (Navit.DEBUG_LUX_VALUE)
899 {
900 // ------- DEBUG --------------
901 // ------- DEBUG --------------
902 // ------- DEBUG --------------
903 Paint paint_lux = new Paint(0);
904 paint_lux.setAntiAlias(true);
905 paint_lux.setColor(Color.BLUE);
906 paint_lux.setAlpha(240);
907 paint_lux.setStrokeWidth(6);
908 paint_lux.setTextSize(NavitGraphics.dp_to_px(60));
909 c.drawText(" " + Navit.debug_cur_lux_value, (int)((float)NavitGraphics.mCanvasWidth / 2.5f), (int) ((float) NavitGraphics.mCanvasHeight / 2.0f), paint_lux);
910 // ------- DEBUG --------------
911 // ------- DEBUG --------------
912 // ------- DEBUG --------------
913 }
914
915 if (Navit.p.PREF_item_dump)
916 {
917 if (!Navit.debug_item_dump.equals(""))
918 {
919 Paint paint = new Paint(0);
920 paint.setAntiAlias(true);
921 paint.setColor(Color.BLUE);
922 // paint.setAlpha(240);
923 // paint.setColor(Color.parseColor("#888888"));
924 paint.setStrokeWidth(2);
925 paint.setTextSize(52);
926
927 // System.out.println("XX11 " + Navit.debug_item_dump);
928 String[] s = Navit.debug_item_dump.split("\n");
929 // System.out.println("XX11 " + s.length);
930
931 int i3;
932 int i4 = 0;
933 int max_char = 37;
934
935 int start_x = 110;
936 int start_y = 300;
937 int line_size_y = 54;
938 int one_indent = 24;
939
940 for (i3 = 0; i3 < s.length; i3++)
941 {
942 if (s[i3].length() > max_char)
943 {
944 int j3;
945 int indent = 0;
946 for (j3 = 0; j3 < (int) (s[i3].length() / max_char); j3++)
947 {
948 if (j3 > 0)
949 {
950 indent = one_indent;
951 }
952 c.drawText(s[i3].substring(j3 * max_char, ((j3 + 1) * max_char) - 0), start_x + indent, start_y + (i4 * line_size_y), paint);
953 i4++;
954 }
955 if ((((int) (s[i3].length() / max_char)) * max_char) < s[i3].length())
956 {
957 indent = one_indent;
958 c.drawText(s[i3].substring(j3 * max_char), start_x + indent, start_y + (i4 * line_size_y), paint);
959 i4++;
960 }
961 }
962 else
963 {
964 c.drawText(s[i3], start_x, start_y + (i4 * line_size_y), paint);
965 i4++;
966 }
967 }
968 }
969 }
970
971 }
972
973 public static void cleanup_measure_mode()
974 {
975 measure_valid = false;
976 measure_result_meters = -1;
977 NavitGraphics.NavitAOverlay_s.postInvalidate();
978 }
979 }

   
Visit the ZANavi Wiki