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.Paint.Align;
|
27 |
import android.util.AttributeSet;
|
28 |
import android.view.View;
|
29 |
|
30 |
public class ZANaviOSDDistToNextturn extends View
|
31 |
{
|
32 |
|
33 |
private Paint paint = new Paint();
|
34 |
private Paint paint_p3 = new Paint();
|
35 |
private int OSD_element_text_shadow_001;
|
36 |
private int OSD_element_text_001;
|
37 |
|
38 |
private String my_text = "";
|
39 |
|
40 |
int nextt_str_start_x = 5;
|
41 |
int nextt_str_start_y = 5;
|
42 |
int nextt_str_font_size = 0;
|
43 |
int nextt_str_w = 0;
|
44 |
int nextt_str_h = 0;
|
45 |
int nextt_str_wB = 0;
|
46 |
int OSD_element_text_shadow_width;
|
47 |
|
48 |
float textHeight_p2;
|
49 |
float textOffset_p2;
|
50 |
float textHeight_p3;
|
51 |
float textOffset_p3;
|
52 |
|
53 |
public ZANaviOSDDistToNextturn(Context context)
|
54 |
{
|
55 |
super(context);
|
56 |
paint.setTextAlign(Paint.Align.CENTER);
|
57 |
paint_p3.setTextAlign(Paint.Align.CENTER);
|
58 |
}
|
59 |
|
60 |
public ZANaviOSDDistToNextturn(Context context, AttributeSet attrs)
|
61 |
{
|
62 |
super(context, attrs);
|
63 |
paint.setTextAlign(Paint.Align.CENTER);
|
64 |
paint_p3.setTextAlign(Paint.Align.CENTER);
|
65 |
}
|
66 |
|
67 |
@Override
|
68 |
public void onSizeChanged(int w, int h, int oldw, int oldh)
|
69 |
{
|
70 |
super.onSizeChanged(w, h, oldw, oldh);
|
71 |
|
72 |
OSD_element_text_shadow_001 = Color.rgb(0, 0, 0); // text shadow
|
73 |
OSD_element_text_001 = Color.argb(255, 255, 255, 255); // text color
|
74 |
|
75 |
paint.setTextAlign(Align.CENTER);
|
76 |
paint_p3.setTextAlign(Paint.Align.CENTER);
|
77 |
|
78 |
nextt_str_start_x = w / 2;
|
79 |
nextt_str_start_y = h / 2;
|
80 |
|
81 |
nextt_str_w = w;
|
82 |
nextt_str_h = h;
|
83 |
|
84 |
OSD_element_text_shadow_width = NavitGraphics.dp_to_px(2);
|
85 |
|
86 |
int nextt_str_font_size_hh = Navit.find_max_font_size_for_height("3.000m", h, 190, 8);
|
87 |
int nextt_str_font_size_ww = Navit.find_max_font_size_for_width("3.000m", w, 190, 6);
|
88 |
if (nextt_str_font_size_hh < nextt_str_font_size_ww)
|
89 |
{
|
90 |
nextt_str_font_size = nextt_str_font_size_hh;
|
91 |
}
|
92 |
else
|
93 |
{
|
94 |
nextt_str_font_size = nextt_str_font_size_ww;
|
95 |
}
|
96 |
|
97 |
// System.out.println("xsds:" + nextt_str_font_size_ww + " " + nextt_str_font_size_hh + " w=" + w + " h=" + h);
|
98 |
|
99 |
paint.setTextSize(nextt_str_font_size);
|
100 |
paint_p3.setTextSize(nextt_str_font_size);
|
101 |
|
102 |
// nextt_str_wB = w;
|
103 |
//
|
104 |
// float draw_factor = 1.0f;
|
105 |
// if (Navit.my_display_density.compareTo("mdpi") == 0)
|
106 |
// {
|
107 |
// draw_factor = 1.0f;
|
108 |
// }
|
109 |
// else if (Navit.my_display_density.compareTo("ldpi") == 0)
|
110 |
// {
|
111 |
// draw_factor = 0.7f;
|
112 |
// }
|
113 |
// else if (Navit.my_display_density.compareTo("hdpi") == 0)
|
114 |
// {
|
115 |
// draw_factor = 1.5f;
|
116 |
// }
|
117 |
// float draw_factor2 = draw_factor;
|
118 |
// // correct for ultra high DPI
|
119 |
// if (Navit.metrics.densityDpi >= 320) //&& (Navit.PREF_shrink_on_high_dpi))
|
120 |
// {
|
121 |
// draw_factor2 = 1.8f * Navit.metrics.densityDpi / NavitGraphics.Global_want_dpi_other;
|
122 |
// NavitStreetFontLetterWidth = (int) ((float) NavitStreetFontLetterWidth_base * Navit.metrics.densityDpi / NavitGraphics.Global_want_dpi_other);
|
123 |
// }
|
124 |
|
125 |
paint.setColor(OSD_element_text_shadow_001);
|
126 |
paint.setStrokeWidth(OSD_element_text_shadow_width);
|
127 |
paint.setStyle(Paint.Style.STROKE);
|
128 |
paint.setAntiAlias(true);
|
129 |
|
130 |
paint_p3.setColor(OSD_element_text_001);
|
131 |
paint_p3.setStrokeWidth(3);
|
132 |
paint_p3.setStyle(Paint.Style.FILL);
|
133 |
paint_p3.setAntiAlias(true);
|
134 |
|
135 |
textHeight_p2 = paint.descent() - paint.ascent();
|
136 |
textOffset_p2 = (textHeight_p2 / 2) - paint.descent();
|
137 |
textHeight_p3 = paint_p3.descent() - paint_p3.ascent();
|
138 |
textOffset_p3 = (textHeight_p3 / 2) - paint_p3.descent();
|
139 |
}
|
140 |
|
141 |
public void onDraw(Canvas c)
|
142 |
{
|
143 |
super.onDraw(c);
|
144 |
int dest_valid = NavitGraphics.CallbackDestinationValid2();
|
145 |
|
146 |
try
|
147 |
{
|
148 |
if ((Navit.OSD_nextturn.nextturn_distance_valid) && (dest_valid > 0))
|
149 |
{
|
150 |
my_text = Navit.OSD_nextturn.nextturn_distance;
|
151 |
c.drawText(my_text, nextt_str_start_x, nextt_str_start_y + textOffset_p2, paint);
|
152 |
c.drawText(my_text, nextt_str_start_x, nextt_str_start_y + textOffset_p3, paint_p3);
|
153 |
}
|
154 |
else
|
155 |
{
|
156 |
c.drawColor(Color.TRANSPARENT);
|
157 |
}
|
158 |
}
|
159 |
catch (Exception e)
|
160 |
{
|
161 |
}
|
162 |
|
163 |
// System.out.println("onDraw:OSDDist2nextturn");
|
164 |
|
165 |
}
|
166 |
}
|