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 |
package com.zoffcc.applications.zanavi;
|
21 |
|
22 |
import android.content.Context;
|
23 |
import android.graphics.Bitmap;
|
24 |
import android.graphics.Canvas;
|
25 |
import android.graphics.Paint;
|
26 |
import android.graphics.RectF;
|
27 |
import android.os.Handler;
|
28 |
import android.os.Message;
|
29 |
|
30 |
public class NavitOSDJava // extends View
|
31 |
{
|
32 |
public static int mCanvasWidth = 1;
|
33 |
public static int mCanvasHeight = 1;
|
34 |
public static float draw_factor = 1.0f;
|
35 |
|
36 |
public static int OSD_element_bg_001;
|
37 |
public static int OSD_element_bg_001_compass;
|
38 |
public static int OSD_element_text_001;
|
39 |
public static int OSD_element_text_shadow_001;
|
40 |
public static int OSD_element_text_shadow_width;
|
41 |
|
42 |
int delta_1 = 8;
|
43 |
int delta_2 = 35;
|
44 |
int wm;
|
45 |
int hm;
|
46 |
static int dest_valid;
|
47 |
static RectF dst;
|
48 |
static int end_x;
|
49 |
static int end_y;
|
50 |
|
51 |
private static Object sync_dummy_001 = new Object();
|
52 |
private static Boolean allow_drawing = true;
|
53 |
public static Integer synchro_obj = 0;
|
54 |
// private static Boolean in_draw_real = false;
|
55 |
|
56 |
// public static Handler progress_handler_ = new Handler();
|
57 |
|
58 |
private static Boolean show_scale = false;
|
59 |
|
60 |
//private static Boolean one_shot = false;
|
61 |
private static long last_paint_me = 0L;
|
62 |
|
63 |
// this number is an estimate
|
64 |
static int NavitStreetFontLetterWidth = 28;
|
65 |
static final int NavitStreetFontLetterWidth_base = 28;
|
66 |
|
67 |
static Bitmap compass_b = null;
|
68 |
static Canvas compass_c = null;
|
69 |
static int compass_radius = 0;
|
70 |
static int compass_center_x = 0;
|
71 |
static int compass_center_y = 0;
|
72 |
static int compass_lt_x = 0;
|
73 |
static int compass_lt_y = 0;
|
74 |
static int compass_w = 0;
|
75 |
static int compass_h = 0;
|
76 |
static Boolean did_draw_circle = false;
|
77 |
|
78 |
static Bitmap ddtt_b = null;
|
79 |
static Canvas ddtt_c = null;
|
80 |
static int ddtt_lt_x = 0;
|
81 |
static int ddtt_lt_y = 0;
|
82 |
static int ddtt_text_start_x = 0;
|
83 |
static int ddtt_text_start_y = 0;
|
84 |
static int ddtt_w = 0;
|
85 |
static int ddtt_h = 0;
|
86 |
static int ddtt_font_size = 0;
|
87 |
|
88 |
static Bitmap eta_b = null;
|
89 |
static Canvas eta_c = null;
|
90 |
static int eta_lt_x = 0;
|
91 |
static int eta_lt_y = 0;
|
92 |
static int eta_text_start_x = 0;
|
93 |
static int eta_text_start_y = 0;
|
94 |
static int eta_w = 0;
|
95 |
static int eta_h = 0;
|
96 |
static int eta_font_size = 0;
|
97 |
|
98 |
static Bitmap nt_b = null;
|
99 |
static Canvas nt_c = null;
|
100 |
static int nt_lt_x = 0;
|
101 |
static int nt_lt_y = 0;
|
102 |
static int nt_lt_xB = 0;
|
103 |
static int nt_lt_yB = 0;
|
104 |
static int nt_text_start_x = 0;
|
105 |
static int nt_text_start_y = 0;
|
106 |
static int nt_w = 0;
|
107 |
static int nt_h = 0;
|
108 |
static int nt_font_size = 0;
|
109 |
|
110 |
static Bitmap dttarget_b = null;
|
111 |
static Canvas dttarget_c = null;
|
112 |
static int dttarget_lt_x = 0;
|
113 |
static int dttarget_lt_y = 0;
|
114 |
static int dttarget_text_start_x = 0;
|
115 |
static int dttarget_text_start_y = 0;
|
116 |
static int dttarget_w = 0;
|
117 |
static int dttarget_h = 0;
|
118 |
static int dttarget_font_size = 0;
|
119 |
|
120 |
Bitmap scale_b = null;
|
121 |
Canvas scale_c = null;
|
122 |
static int scale_lt_x = 0;
|
123 |
static int scale_lt_y = 0;
|
124 |
static int scale_text_start_x = 0;
|
125 |
static int scale_text_start_y = 0;
|
126 |
static int scale_line_start_x = 0;
|
127 |
static int scale_line_end_x = 0;
|
128 |
static int scale_line_start_y = 0;
|
129 |
static int scale_line_middle_y = 0;
|
130 |
static int scale_line_end_y = 0;
|
131 |
static int scale_w = 0;
|
132 |
static int scale_h = 0;
|
133 |
static int scale_font_size = 0;
|
134 |
|
135 |
Bitmap rest_osd_b = null;
|
136 |
Canvas rest_osd_c = null;
|
137 |
|
138 |
Bitmap buffer_osd_b = null;
|
139 |
Canvas buffer_osd_c = null;
|
140 |
|
141 |
// Bitmap buffer2_osd_b = null;
|
142 |
// Canvas buffer2_osd_c = null;
|
143 |
|
144 |
static int nextt_lt_x = 0;
|
145 |
static int nextt_lt_y = 0;
|
146 |
static int nextt_w = 0;
|
147 |
static int nextt_h = 0;
|
148 |
static int nextt_lt_xB = 0;
|
149 |
static int nextt_lt_yB = 0;
|
150 |
static int nextt_wB = 0;
|
151 |
static int nextt_hB = 0;
|
152 |
|
153 |
static int nextt_str_ltx = 0;
|
154 |
static int nextt_str_lty = 0;
|
155 |
static int nextt_str_ltxB = 0;
|
156 |
static int nextt_str_ltyB = 0;
|
157 |
//static int nextt_str_w = 0;
|
158 |
static int nextt_str_h = 0;
|
159 |
static int nextt_str_wB = 0;
|
160 |
static int nextt_str_hB = 0;
|
161 |
// static int nextt_str_font_size = 0;
|
162 |
// static int nextt_str_start_x = 0;
|
163 |
// static int nextt_str_start_y = 0;
|
164 |
|
165 |
static int sat_status_lt_x = 0;
|
166 |
static int sat_status_lt_y = 0;
|
167 |
static int sat_status_lt_w = 0;
|
168 |
static int sat_status_lt_h = 0;
|
169 |
static int sat_status_max_sats = 13;
|
170 |
|
171 |
static Paint paint = new Paint();
|
172 |
static Paint paint_crosshair = new Paint();
|
173 |
|
174 |
// private long last_timestamp = 0L;
|
175 |
// public static final int UPDATE_INTERVAL = 400; // in ms
|
176 |
|
177 |
// ------ UNUSED !!!!!!!! --------
|
178 |
// ------ UNUSED !!!!!!!! --------
|
179 |
// ------ UNUSED !!!!!!!! --------
|
180 |
// ------ UNUSED !!!!!!!! --------
|
181 |
public NavitOSDJava(Context context)
|
182 |
{
|
183 |
// // super(context);
|
184 |
//
|
185 |
// progress_handler_ = this.progress_handler;
|
186 |
//
|
187 |
// OSD_element_bg_001_compass = Color.argb(255, 236, 229, 182); // 236, 229, 182
|
188 |
// OSD_element_text_001 = Color.argb(255, 255, 255, 255); // text color
|
189 |
// OSD_element_text_shadow_001 = Color.rgb(0, 0, 0); // text shadow
|
190 |
// OSD_element_text_shadow_width = 5; // 3 + 2;
|
191 |
//
|
192 |
// // b_ = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
|
193 |
// // compass_b = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
|
194 |
// compass_b = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
|
195 |
// compass_c = new Canvas(compass_b);
|
196 |
// ddtt_b = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
|
197 |
// ddtt_c = new Canvas(ddtt_b);
|
198 |
// scale_b = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
|
199 |
// scale_c = new Canvas(ddtt_b);
|
200 |
// dttarget_b = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
|
201 |
// dttarget_c = new Canvas(dttarget_b);
|
202 |
// eta_b = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
|
203 |
// eta_c = new Canvas(eta_b);
|
204 |
// nt_b = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
|
205 |
// nt_c = new Canvas(nt_b);
|
206 |
//
|
207 |
// rest_osd_b = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
|
208 |
// rest_osd_c = new Canvas(rest_osd_b);
|
209 |
//
|
210 |
// buffer_osd_b = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
|
211 |
// buffer_osd_c = new Canvas(buffer_osd_b);
|
212 |
//
|
213 |
// // buffer2_osd_b = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
|
214 |
// // buffer2_osd_c = new Canvas(buffer2_osd_b);
|
215 |
}
|
216 |
|
217 |
// @Override
|
218 |
// public void onSizeChanged(int w, int h, int oldw, int oldh)
|
219 |
// {
|
220 |
// super.onSizeChanged(w, h, oldw, oldh);
|
221 |
// }
|
222 |
|
223 |
public static class drawOSDThread extends Thread
|
224 |
{
|
225 |
private Boolean running = true;
|
226 |
private boolean start_work = false;
|
227 |
private boolean need_redraw_osd = false;
|
228 |
private boolean need_redraw_overlay = false;
|
229 |
|
230 |
drawOSDThread()
|
231 |
{
|
232 |
this.running = true;
|
233 |
}
|
234 |
|
235 |
public void run()
|
236 |
{
|
237 |
|
238 |
while (running)
|
239 |
{
|
240 |
try
|
241 |
{
|
242 |
Thread.sleep(5000);
|
243 |
}
|
244 |
catch (InterruptedException e)
|
245 |
{
|
246 |
}
|
247 |
|
248 |
if (this.start_work)
|
249 |
{
|
250 |
work(need_redraw_osd, need_redraw_overlay);
|
251 |
this.start_work = false;
|
252 |
this.need_redraw_osd = false;
|
253 |
this.need_redraw_overlay = false;
|
254 |
}
|
255 |
}
|
256 |
}
|
257 |
|
258 |
synchronized void work(boolean redraw_osd, boolean redraw_overlay)
|
259 |
{
|
260 |
// draw_real();
|
261 |
|
262 |
if (redraw_osd)
|
263 |
{
|
264 |
//NavitGraphics.NavitAOSDJava_.postInvalidate();
|
265 |
NavitGraphics.OSD_new.postInvalidate();
|
266 |
}
|
267 |
|
268 |
if (redraw_overlay)
|
269 |
{
|
270 |
NavitGraphics.NavitAOverlay_s.postInvalidate();
|
271 |
}
|
272 |
}
|
273 |
|
274 |
public void buzz(boolean redraw_osd, boolean redraw_overlay)
|
275 |
{
|
276 |
this.start_work = true;
|
277 |
this.need_redraw_osd = redraw_osd;
|
278 |
this.need_redraw_overlay = redraw_overlay;
|
279 |
|
280 |
this.interrupt();
|
281 |
}
|
282 |
}
|
283 |
|
284 |
public static void draw_real_wrapper(boolean redraw_osd, boolean redraw_overlay)
|
285 |
{
|
286 |
// System.out.println("OSD:draw_real_wrapper:begin");
|
287 |
Navit.draw_osd_thread.buzz(redraw_osd, redraw_overlay);
|
288 |
//++ draw_real();
|
289 |
// System.out.println("OSD:draw_real_wrapper:end");
|
290 |
}
|
291 |
|
292 |
synchronized public static void draw_real()
|
293 |
{
|
294 |
|
295 |
}
|
296 |
|
297 |
public void onDraw(Canvas c)
|
298 |
{
|
299 |
// System.out.println("XYZ:NavitOSDJava -> onDraw");
|
300 |
// NOTHING HERE anymore !!!!!!
|
301 |
}
|
302 |
|
303 |
public static boolean take_synchro()
|
304 |
{
|
305 |
synchronized (synchro_obj)
|
306 |
{
|
307 |
if (synchro_obj < 1)
|
308 |
{
|
309 |
synchro_obj++;
|
310 |
return true;
|
311 |
}
|
312 |
else
|
313 |
{
|
314 |
return false;
|
315 |
}
|
316 |
}
|
317 |
}
|
318 |
|
319 |
public static boolean release_synchro()
|
320 |
{
|
321 |
synchronized (synchro_obj)
|
322 |
{
|
323 |
if (synchro_obj > 0)
|
324 |
{
|
325 |
synchro_obj = 0;
|
326 |
return true;
|
327 |
}
|
328 |
else
|
329 |
{
|
330 |
return false;
|
331 |
}
|
332 |
}
|
333 |
}
|
334 |
|
335 |
public static void onDraw_part2()
|
336 |
{
|
337 |
//if (allow_drawing == false)
|
338 |
//{
|
339 |
// return;
|
340 |
//}
|
341 |
|
342 |
//synchronized (sync_dummy_001)
|
343 |
//{
|
344 |
//System.out.println("draw real 2");
|
345 |
|
346 |
try
|
347 |
{
|
348 |
// NavitGraphics.NavitAOSDJava_.rest_osd_c.drawBitmap(NavitGraphics.NavitAOSDJava_.rest_osd_b, 0, 0, null);
|
349 |
NavitGraphics.NavitAOSDJava_.rest_osd_c.drawBitmap(compass_b, compass_lt_x, compass_lt_y, null);
|
350 |
NavitGraphics.NavitAOSDJava_.rest_osd_c.drawBitmap(ddtt_b, ddtt_lt_x, ddtt_lt_y, null);
|
351 |
NavitGraphics.NavitAOSDJava_.rest_osd_c.drawBitmap(dttarget_b, dttarget_lt_x, dttarget_lt_y, null);
|
352 |
NavitGraphics.NavitAOSDJava_.rest_osd_c.drawBitmap(eta_b, eta_lt_x, eta_lt_y, null);
|
353 |
|
354 |
if (NavitGraphics.MAP_DISPLAY_OFF)
|
355 |
{
|
356 |
NavitGraphics.NavitAOSDJava_.rest_osd_c.drawBitmap(nt_b, nt_lt_xB, nt_lt_yB, null);
|
357 |
}
|
358 |
else
|
359 |
{
|
360 |
NavitGraphics.NavitAOSDJava_.rest_osd_c.drawBitmap(nt_b, nt_lt_x, nt_lt_y, null);
|
361 |
}
|
362 |
}
|
363 |
catch (Exception e)
|
364 |
{
|
365 |
e.printStackTrace();
|
366 |
}
|
367 |
|
368 |
if (show_scale)
|
369 |
{
|
370 |
try
|
371 |
{
|
372 |
NavitGraphics.NavitAOSDJava_.rest_osd_c.drawBitmap(NavitGraphics.NavitAOSDJava_.scale_b, scale_lt_x, scale_lt_y, null);
|
373 |
}
|
374 |
catch (Exception e)
|
375 |
{
|
376 |
//e.printStackTrace();
|
377 |
}
|
378 |
}
|
379 |
|
380 |
//++try
|
381 |
//++{
|
382 |
// Thread.sleep(5);
|
383 |
//++boolean got_it = take_synchro();
|
384 |
// System.out.println("OO:001:synchro_obj=" + synchro_obj);
|
385 |
//++if (got_it)
|
386 |
//++{
|
387 |
//System.out.println("OO:001:start");
|
388 |
|
389 |
// ------------------ CLEAR ---------------
|
390 |
//NavitGraphics.NavitAOSDJava_.buffer_osd_b.eraseColor(Color.TRANSPARENT);
|
391 |
// just clear where we really need it
|
392 |
// ++NavitGraphics.NavitAOSDJava_.buffer_osd_c.clipRect(compass_lt_x, compass_lt_y, compass_lt_x + compass_w + 1, compass_lt_y + compass_h + 1, Region.Op.REPLACE);
|
393 |
// NavitGraphics.NavitAOSDJava_.buffer_osd_c.clipRect(scale_lt_x, scale_lt_y, scale_lt_x + scale_w + 1, scale_lt_y + scale_h + 1, Region.Op.UNION);
|
394 |
//
|
395 |
// ++NavitGraphics.NavitAOSDJava_.buffer_osd_c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
|
396 |
// **TEST** // NavitGraphics.NavitAOSDJava_.buffer_osd_c.drawColor(Color.BLUE, PorterDuff.Mode.XOR);
|
397 |
// ------------------ CLEAR ---------------
|
398 |
|
399 |
// ------------------ RESET ---------------
|
400 |
// ++NavitGraphics.NavitAOSDJava_.buffer_osd_c.clipRect(0, 0, NavitOSDJava.mCanvasWidth, NavitOSDJava.mCanvasHeight, Region.Op.REPLACE);
|
401 |
// ------------------ RESET ---------------
|
402 |
|
403 |
if (allow_drawing == false)
|
404 |
{
|
405 |
try
|
406 |
{
|
407 |
Thread.sleep(5);
|
408 |
}
|
409 |
catch (Exception e)
|
410 |
{
|
411 |
|
412 |
}
|
413 |
}
|
414 |
// ------------------ DRAW ---------------
|
415 |
try
|
416 |
{
|
417 |
//if (!NavitGraphics.NavitAOSDJava_.rest_osd_b.isRecycled())
|
418 |
//{
|
419 |
NavitGraphics.NavitAOSDJava_.buffer_osd_c.drawBitmap(NavitGraphics.NavitAOSDJava_.rest_osd_b, 0, 0, null);
|
420 |
//}
|
421 |
}
|
422 |
catch (Exception e)
|
423 |
{
|
424 |
e.printStackTrace();
|
425 |
}
|
426 |
// ------------------ DRAW ---------------
|
427 |
|
428 |
//System.out.println("OO:001:end");
|
429 |
//++ release_synchro();
|
430 |
//++}
|
431 |
//++}
|
432 |
//++catch (Exception e)
|
433 |
//++{
|
434 |
//++ //e.printStackTrace();
|
435 |
//++}
|
436 |
|
437 |
//if (NavitGraphics.MAP_DISPLAY_OFF)
|
438 |
//{
|
439 |
// if (one_shot)
|
440 |
// {
|
441 |
// //System.out.println("one shot");
|
442 |
// one_shot = false;
|
443 |
// //this.postInvalidate();
|
444 |
// }
|
445 |
//}
|
446 |
//}
|
447 |
}
|
448 |
|
449 |
// @Override
|
450 |
// public boolean onTouchEvent(MotionEvent event)
|
451 |
// {
|
452 |
// Boolean x = super.onTouchEvent(event);
|
453 |
// return false;
|
454 |
// }
|
455 |
|
456 |
public Handler progress_handler = new Handler()
|
457 |
{
|
458 |
public void handleMessage(Message msg)
|
459 |
{
|
460 |
switch (msg.what)
|
461 |
{
|
462 |
case 1:
|
463 |
//System.out.println("OSDJava:handleMessage:1");
|
464 |
//System.out.println("invalidate 007");
|
465 |
// ** // postInvalidate();
|
466 |
break;
|
467 |
}
|
468 |
}
|
469 |
};
|
470 |
|
471 |
// @Override
|
472 |
// protected void onLayout(boolean changed, int l, int t, int r, int b)
|
473 |
// {
|
474 |
// }
|
475 |
}
|