1 |
/**
|
2 |
* ZANavi, Zoff Android Navigation system.
|
3 |
* Copyright (C) 2013 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.Canvas;
|
24 |
import android.graphics.Color;
|
25 |
import android.graphics.Paint;
|
26 |
import android.graphics.Rect;
|
27 |
import android.util.AttributeSet;
|
28 |
import android.view.View;
|
29 |
import android.widget.LinearLayout;
|
30 |
|
31 |
public class ZANaviLinearLayout extends LinearLayout
|
32 |
{
|
33 |
private boolean need_size_change = false;
|
34 |
private Paint paint_crosshair = new Paint();
|
35 |
private Paint paint_sat_status = new Paint();
|
36 |
int delta_1 = 8;
|
37 |
int delta_2 = 35;
|
38 |
int wm;
|
39 |
int hm;
|
40 |
int sat_status_max_sats = 13;
|
41 |
int sat_status_lt_x = 0;
|
42 |
int sat_status_lt_y = 0;
|
43 |
int sat_status_lt_w = 1;
|
44 |
int sat_status_lt_h = 1;
|
45 |
Rect r1 = new Rect(0, 0, 1, 1);
|
46 |
Rect r2 = new Rect(0, 0, 1, 1);
|
47 |
Rect r3 = new Rect(0, 0, 1, 1);
|
48 |
Rect r4 = new Rect(0, 0, 1, 1);
|
49 |
View child1;
|
50 |
View child2;
|
51 |
View child3;
|
52 |
View child4;
|
53 |
View child5;
|
54 |
View child6;
|
55 |
View child7;
|
56 |
View child8;
|
57 |
View child9;
|
58 |
|
59 |
public ZANaviLinearLayout(Context context)
|
60 |
{
|
61 |
super(context);
|
62 |
paint_crosshair.setColor(Color.DKGRAY);
|
63 |
paint_crosshair.setStyle(Paint.Style.STROKE);
|
64 |
}
|
65 |
|
66 |
public ZANaviLinearLayout(Context context, AttributeSet attrs)
|
67 |
{
|
68 |
super(context, attrs);
|
69 |
paint_crosshair.setColor(Color.DKGRAY);
|
70 |
paint_crosshair.setStyle(Paint.Style.STROKE);
|
71 |
}
|
72 |
|
73 |
@Override
|
74 |
public void onDraw(Canvas c)
|
75 |
{
|
76 |
|
77 |
// System.out.println("XYZ:ZANaviLinearLayout -> onDraw");
|
78 |
|
79 |
// if (2 == 1 + 1)
|
80 |
// {
|
81 |
// return;
|
82 |
// }
|
83 |
|
84 |
if (this.need_size_change)
|
85 |
{
|
86 |
// System.out.println("XYZ:ZANaviLinearLayout -> onDraw [need_size_change]");
|
87 |
|
88 |
int w = this.getWidth();
|
89 |
int h = this.getHeight();
|
90 |
|
91 |
float draw_factor = 1.0f;
|
92 |
if (Navit.my_display_density.compareTo("mdpi") == 0)
|
93 |
{
|
94 |
draw_factor = 1.0f;
|
95 |
}
|
96 |
else if (Navit.my_display_density.compareTo("ldpi") == 0)
|
97 |
{
|
98 |
draw_factor = 0.7f;
|
99 |
}
|
100 |
else if (Navit.my_display_density.compareTo("hdpi") == 0)
|
101 |
{
|
102 |
draw_factor = 1.5f;
|
103 |
}
|
104 |
|
105 |
float draw_factor2 = draw_factor;
|
106 |
// correct for ultra high DPI
|
107 |
if (Navit.metrics.densityDpi >= 320) //&& (Navit.PREF_shrink_on_high_dpi))
|
108 |
{
|
109 |
draw_factor2 = 1.8f * Navit.metrics.densityDpi / NavitGraphics.Global_want_dpi_other;
|
110 |
NavitOSDJava.NavitStreetFontLetterWidth = (int) ((float) NavitOSDJava.NavitStreetFontLetterWidth_base * Navit.metrics.densityDpi / NavitGraphics.Global_want_dpi_other);
|
111 |
}
|
112 |
|
113 |
float real_factor = draw_factor2 / 1.5f;
|
114 |
//
|
115 |
//
|
116 |
//
|
117 |
|
118 |
sat_status_lt_w = (int) (8f * draw_factor);
|
119 |
sat_status_lt_h = (int) (h * 0.35);
|
120 |
sat_status_lt_x = (int) (2f * draw_factor);
|
121 |
sat_status_lt_y = (int) ((h / 2) - (sat_status_lt_h / 2));
|
122 |
|
123 |
r1.set(sat_status_lt_x, sat_status_lt_y, sat_status_lt_x + sat_status_lt_w, sat_status_lt_y + sat_status_lt_h);
|
124 |
|
125 |
int mCanvasWidth = w;
|
126 |
int mCanvasHeight = h;
|
127 |
|
128 |
LayoutParams params = null;
|
129 |
|
130 |
//
|
131 |
child1 = Navit.Global_Navit_Object.findViewById(R.id.top_bar);
|
132 |
child2 = Navit.Global_Navit_Object.findViewById(R.id.osd_compass_new);
|
133 |
child3 = Navit.Global_Navit_Object.findViewById(R.id.osd_nextturn_new);
|
134 |
child4 = Navit.Global_Navit_Object.findViewById(R.id.osd_timetoturn_new);
|
135 |
child5 = Navit.Global_Navit_Object.findViewById(R.id.osd_timetodest_new);
|
136 |
child6 = Navit.Global_Navit_Object.findViewById(R.id.osd_roaddistance_new);
|
137 |
child7 = Navit.Global_Navit_Object.findViewById(R.id.osd_eta_new);
|
138 |
child8 = Navit.Global_Navit_Object.findViewById(R.id.view_speeding);
|
139 |
child9 = Navit.Global_Navit_Object.findViewById(R.id.view_laneassist);
|
140 |
//
|
141 |
|
142 |
this.need_size_change = false;
|
143 |
}
|
144 |
|
145 |
super.onDraw(c);
|
146 |
|
147 |
// System.out.println("onDraw:ZANaviLinearLayout");
|
148 |
|
149 |
try
|
150 |
{
|
151 |
if (!Navit.PAINT_OLD_API)
|
152 |
{
|
153 |
child1.postInvalidate();
|
154 |
child2.postInvalidate();
|
155 |
child3.postInvalidate();
|
156 |
child4.postInvalidate();
|
157 |
child5.postInvalidate();
|
158 |
child6.postInvalidate();
|
159 |
child7.postInvalidate();
|
160 |
child8.postInvalidate();
|
161 |
child9.postInvalidate();
|
162 |
}
|
163 |
else
|
164 |
{
|
165 |
// child1.postInvalidate();
|
166 |
// child2.postInvalidate();
|
167 |
// child3.postInvalidate();
|
168 |
// child4.postInvalidate();
|
169 |
// child5.postInvalidate();
|
170 |
// child6.postInvalidate();
|
171 |
// child7.postInvalidate();
|
172 |
// child8.postInvalidate();
|
173 |
// child9.postInvalidate();
|
174 |
}
|
175 |
}
|
176 |
catch (Exception e)
|
177 |
{
|
178 |
}
|
179 |
|
180 |
try
|
181 |
{
|
182 |
if (Navit.p.PREF_show_sat_status)
|
183 |
{
|
184 |
if (Navit.sats > sat_status_max_sats)
|
185 |
{
|
186 |
sat_status_max_sats = Navit.sats;
|
187 |
}
|
188 |
|
189 |
// old status
|
190 |
NavitVehicle.sat_status_icon_last = NavitVehicle.sat_status_icon_now;
|
191 |
|
192 |
// get new status
|
193 |
//if (Navit.satsInFix > 3)
|
194 |
if (Navit.isGPSFix)
|
195 |
{
|
196 |
// GPS found position
|
197 |
NavitVehicle.sat_status_icon_now = 1;
|
198 |
}
|
199 |
else
|
200 |
{
|
201 |
// GPS lost position
|
202 |
NavitVehicle.sat_status_icon_now = 0;
|
203 |
}
|
204 |
|
205 |
if (NavitVehicle.sat_status_icon_now != NavitVehicle.sat_status_icon_last)
|
206 |
{
|
207 |
try
|
208 |
{
|
209 |
//if (NavitVehicle.sat_status_icon_now == 1)
|
210 |
if (Navit.isGPSFix)
|
211 |
{
|
212 |
Navit.Global_Navit_Object.getSupportActionBar().setIcon(R.drawable.ic_action_location_found);
|
213 |
}
|
214 |
else
|
215 |
{
|
216 |
Navit.Global_Navit_Object.getSupportActionBar().setIcon(R.drawable.ic_action_location_searching);
|
217 |
}
|
218 |
}
|
219 |
catch (Exception e)
|
220 |
{
|
221 |
e.printStackTrace();
|
222 |
}
|
223 |
}
|
224 |
|
225 |
r2.set(sat_status_lt_x, sat_status_lt_y + sat_status_lt_h - (sat_status_lt_h / sat_status_max_sats * Navit.sats), sat_status_lt_x + sat_status_lt_w, sat_status_lt_y + sat_status_lt_h);
|
226 |
r3.set(sat_status_lt_x, sat_status_lt_y + sat_status_lt_h - (sat_status_lt_h / sat_status_max_sats * Navit.satsInFix), sat_status_lt_x + sat_status_lt_w, sat_status_lt_y + sat_status_lt_h);
|
227 |
r4.set(sat_status_lt_x, sat_status_lt_y, sat_status_lt_x + sat_status_lt_w, sat_status_lt_y + sat_status_lt_h);
|
228 |
|
229 |
// fill rect
|
230 |
paint_sat_status.setColor(Color.GRAY);
|
231 |
paint_sat_status.setStyle(Paint.Style.FILL);
|
232 |
paint_sat_status.setStrokeWidth(0);
|
233 |
paint_sat_status.setAntiAlias(true);
|
234 |
c.drawRect(r1, paint_sat_status);
|
235 |
|
236 |
// fill inactive sats
|
237 |
paint_sat_status.setColor(Color.YELLOW);
|
238 |
paint_sat_status.setStyle(Paint.Style.FILL);
|
239 |
paint_sat_status.setStrokeWidth(0);
|
240 |
paint_sat_status.setAntiAlias(true);
|
241 |
c.drawRect(r2, paint_sat_status);
|
242 |
|
243 |
// fill active sats
|
244 |
paint_sat_status.setColor(Color.GREEN);
|
245 |
paint_sat_status.setStyle(Paint.Style.FILL);
|
246 |
paint_sat_status.setStrokeWidth(0);
|
247 |
paint_sat_status.setAntiAlias(true);
|
248 |
c.drawRect(r3, paint_sat_status);
|
249 |
|
250 |
// black rect around it all
|
251 |
paint_sat_status.setColor(Color.BLACK);
|
252 |
paint_sat_status.setStyle(Paint.Style.STROKE);
|
253 |
paint_sat_status.setStrokeWidth(1);
|
254 |
paint_sat_status.setAntiAlias(true);
|
255 |
c.drawRect(r4, paint_sat_status);
|
256 |
}
|
257 |
else
|
258 |
// sat status is turned off!
|
259 |
{
|
260 |
// old status
|
261 |
NavitVehicle.sat_status_icon_last = NavitVehicle.sat_status_icon_now;
|
262 |
|
263 |
// get new status
|
264 |
NavitVehicle.sat_status_icon_now = -1;
|
265 |
|
266 |
if (NavitVehicle.sat_status_icon_now != NavitVehicle.sat_status_icon_last)
|
267 |
{
|
268 |
try
|
269 |
{
|
270 |
Navit.Global_Navit_Object.getSupportActionBar().setIcon(R.drawable.icon);
|
271 |
}
|
272 |
catch (Exception e)
|
273 |
{
|
274 |
}
|
275 |
}
|
276 |
|
277 |
}
|
278 |
}
|
279 |
catch (Exception e)
|
280 |
{
|
281 |
//e.printStackTrace();
|
282 |
}
|
283 |
|
284 |
if (!Navit.p.PREF_follow_gps)
|
285 |
{
|
286 |
if (!NavitGraphics.MAP_DISPLAY_OFF)
|
287 |
{
|
288 |
// show cross hair
|
289 |
delta_1 = 8;
|
290 |
delta_2 = 35;
|
291 |
if (Navit.metrics.densityDpi >= 320) //&& (Navit.PREF_shrink_on_high_dpi))
|
292 |
{
|
293 |
paint_crosshair.setStrokeWidth(2);
|
294 |
delta_1 = 8 * 2;
|
295 |
delta_2 = 35 * 2;
|
296 |
}
|
297 |
else
|
298 |
{
|
299 |
paint_crosshair.setStrokeWidth(1);
|
300 |
}
|
301 |
paint_crosshair.setAntiAlias(true);
|
302 |
c.drawLine(wm - delta_1, hm, wm - delta_2, hm, paint_crosshair);
|
303 |
c.drawLine(wm + delta_1, hm, wm + delta_2, hm, paint_crosshair);
|
304 |
c.drawLine(wm, hm - delta_1, wm, hm - delta_2, paint_crosshair);
|
305 |
c.drawLine(wm, hm + delta_1, wm, hm + delta_2, paint_crosshair);
|
306 |
}
|
307 |
}
|
308 |
|
309 |
}
|
310 |
|
311 |
static void redraw_OSD(final int i)
|
312 |
{
|
313 |
Navit.runOnUI(new Runnable()
|
314 |
{
|
315 |
@Override
|
316 |
public void run()
|
317 |
{
|
318 |
// System.out.println("onDraw:redraw_OSD");
|
319 |
NavitGraphics.OSD_new.redraw_OSD_view(i);
|
320 |
}
|
321 |
});
|
322 |
}
|
323 |
|
324 |
public void redraw_OSD_view(int i)
|
325 |
{
|
326 |
try
|
327 |
{
|
328 |
// child1 = Navit.Global_Navit_Object.findViewById(R.id.top_bar); // streetname
|
329 |
// child2 = Navit.Global_Navit_Object.findViewById(R.id.osd_compass_new);
|
330 |
// child3 = Navit.Global_Navit_Object.findViewById(R.id.osd_nextturn_new);
|
331 |
// child4 = Navit.Global_Navit_Object.findViewById(R.id.osd_timetoturn_new);
|
332 |
// child5 = Navit.Global_Navit_Object.findViewById(R.id.osd_timetodest_new);
|
333 |
// child6 = Navit.Global_Navit_Object.findViewById(R.id.osd_roaddistance_new);
|
334 |
// child7 = Navit.Global_Navit_Object.findViewById(R.id.osd_eta_new);
|
335 |
// child8 = Navit.Global_Navit_Object.findViewById(R.id.view_speeding);
|
336 |
// child9 = Navit.Global_Navit_Object.findViewById(R.id.view_laneassist);
|
337 |
|
338 |
switch (i)
|
339 |
{
|
340 |
case 1:
|
341 |
child1.postInvalidate();
|
342 |
break;
|
343 |
case 2:
|
344 |
child2.postInvalidate();
|
345 |
break;
|
346 |
case 3:
|
347 |
child3.postInvalidate();
|
348 |
break;
|
349 |
case 4:
|
350 |
child4.postInvalidate();
|
351 |
break;
|
352 |
case 5:
|
353 |
child5.postInvalidate();
|
354 |
break;
|
355 |
case 6:
|
356 |
child6.postInvalidate();
|
357 |
break;
|
358 |
case 7:
|
359 |
child7.postInvalidate();
|
360 |
break;
|
361 |
case 8:
|
362 |
child8.postInvalidate();
|
363 |
break;
|
364 |
case 9:
|
365 |
child9.postInvalidate();
|
366 |
break;
|
367 |
}
|
368 |
|
369 |
}
|
370 |
catch (Exception e)
|
371 |
{
|
372 |
}
|
373 |
}
|
374 |
|
375 |
@Override
|
376 |
public void onSizeChanged(int w, int h, int oldw, int oldh)
|
377 |
{
|
378 |
super.onSizeChanged(w, h, oldw, oldh);
|
379 |
this.wm = w / 2;
|
380 |
this.hm = h / 2;
|
381 |
|
382 |
System.out.println("XYZ:ZANaviLinearLayout -> onSizeChanged w=" + w + " oldw=" + oldw + " h=" + h + " oldh=" + oldh);
|
383 |
if ((w == oldw) & (h == oldh))
|
384 |
{
|
385 |
}
|
386 |
else
|
387 |
{
|
388 |
this.need_size_change = true;
|
389 |
}
|
390 |
|
391 |
}
|
392 |
}
|