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