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

Diff of /navit/navit/android/src/com/zoffcc/applications/zanavi/ZANaviOSDRoadDist.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 40 Revision 41
21 21
22import android.content.Context; 22import android.content.Context;
23import android.graphics.Canvas; 23import android.graphics.Canvas;
24import android.graphics.Color; 24import android.graphics.Color;
25import android.graphics.Paint; 25import android.graphics.Paint;
26import android.graphics.RectF;
27import android.util.AttributeSet; 26import android.util.AttributeSet;
28import android.view.View; 27import android.view.View;
29 28
30public class ZANaviOSDRoadDist extends View 29public class ZANaviOSDRoadDist extends View
31{ 30{
32 31
33 private Paint paint = new Paint(); 32 private Paint paint = new Paint();
34 private RectF f;
35 int end_x; 33 int end_x;
36 int end_y; 34 int end_y;
37 int nt_text_start_x = 0; 35 int nt_text_start_x = 0;
38 int nt_text_start_y = 0; 36 int nt_text_start_y = 0;
39 int nt_font_size = 10; 37 int nt_font_size = 10;
40 float draw_factor = 1; 38 float draw_factor = 1;
41 int OSD_element_bg_001 = Color.argb(255, 80, 80, 150); // Color.argb(255, 190, 190, 190); // Color.argb(140, 136, 136, 136); 39 int OSD_element_bg_001 = Navit.OSD_blueish_bg_color; // Color.argb(255, 190, 190, 190); // Color.argb(140, 136, 136, 136);
40 int OSD_element_text_shadow_001 = Color.rgb(255, 255, 255); // text shadow
41 int OSD_element_text_001 = Color.rgb(117, 117, 117); // = #757575
42 int OSD_element_text_shadow_width = 1;
42 String my_text = ""; 43 String my_text = "";
43 int w2; 44 int w2;
44 int h2; 45 int h2;
46 int h3;
45 int w; 47 int w;
46 int h; 48 int h;
49 int font_size = 10;
50 float textHeight = 0;
51 float textOffset = 0;
47 52
48 public ZANaviOSDRoadDist(Context context) 53 public ZANaviOSDRoadDist(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);
53 } 57 }
54 58
55 public ZANaviOSDRoadDist(Context context, AttributeSet attrs) 59 public ZANaviOSDRoadDist(Context context, AttributeSet attrs)
56 { 60 {
57 super(context, attrs); 61 super(context, attrs);
58 f = new RectF(0, 0, 1, 1);
59 paint.setTextAlign(Paint.Align.CENTER); 62 paint.setTextAlign(Paint.Align.CENTER);
60 } 63 }
61 64
62 @Override 65 @Override
63 public void onSizeChanged(int w, int h, int oldw, int oldh) 66 public void onSizeChanged(int w, int h, int oldw, int oldh)
65 super.onSizeChanged(w, h, oldw, oldh); 68 super.onSizeChanged(w, h, oldw, oldh);
66 this.w2 = w / 2; 69 this.w2 = w / 2;
67 this.h2 = h / 2; 70 this.h2 = h / 2;
68 this.w = w; 71 this.w = w;
69 this.h = h; 72 this.h = h;
73 this.h3 = (int) (h + (paint.ascent() / 2));
70 74
71 draw_factor = 1.0f; 75 OSD_element_text_shadow_width = NavitGraphics.dp_to_px(2);
72 if (Navit.my_display_density.compareTo("mdpi") == 0)
73 {
74 draw_factor = 1.0f;
75 }
76 else if (Navit.my_display_density.compareTo("ldpi") == 0)
77 {
78 draw_factor = 0.7f;
79 }
80 else if (Navit.my_display_density.compareTo("hdpi") == 0)
81 {
82 draw_factor = 1.5f;
83 }
84 76
85 // correct for ultra high DPI 77 font_size = Navit.find_max_font_size_for_height("7,544 km", h, 93, 9);
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 78
91 float real_factor = draw_factor / 1.5f; 79 // System.out.println("aAA:1:" + font_size + " " + w + " " + h);
92 80
93 f = new RectF(0 + 6, 0 + 6, w - 6, h - 6); 81 paint.setTextSize(font_size);
82 paint.setAntiAlias(true);
94 83
95 nt_text_start_x = (int) (20 * real_factor); 84 textHeight = paint.descent() - paint.ascent();
96 nt_text_start_y = (int) (30 * real_factor); 85 textOffset = (textHeight / 2) - paint.descent();
97 nt_font_size = (int) (24 * real_factor);
98 } 86 }
99 87
100 public void onDraw(Canvas c) 88 public void onDraw(Canvas c)
101 { 89 {
102 super.onDraw(c); 90 super.onDraw(c);
106 { 94 {
107 if ((Navit.OSD_route_001.driving_distance_to_target_valid) && (dest_valid > 0)) 95 if ((Navit.OSD_route_001.driving_distance_to_target_valid) && (dest_valid > 0))
108 { 96 {
109 my_text = Navit.OSD_route_001.driving_distance_to_target; 97 my_text = Navit.OSD_route_001.driving_distance_to_target;
110 98
111 if (NavitGraphics.MAP_DISPLAY_OFF) 99 paint.setColor(OSD_element_text_shadow_001);
112 { 100 paint.setStrokeWidth(OSD_element_text_shadow_width);
113 paint.setColor(Color.argb(255, 20, 20, 230));
114 paint.setStyle(Paint.Style.FILL_AND_STROKE); 101 paint.setStyle(Paint.Style.STROKE);
115 paint.setStrokeWidth(2); 102 c.drawText(my_text, w2, h2 + textOffset, paint);
116 paint.setAntiAlias(true);
117 c.drawRoundRect(f, 10, 10, paint);
118 103
119 paint.setColor(Color.WHITE); 104 paint.setColor(OSD_element_text_001);
120 paint.setStrokeWidth(3); 105 paint.setStrokeWidth(3);
121 paint.setStyle(Paint.Style.FILL); 106 paint.setStyle(Paint.Style.FILL);
122 paint.setTextSize(nt_font_size); 107 c.drawText(my_text, w2, h2 + textOffset, paint);
123 paint.setAntiAlias(true);
124 c.drawText(my_text, nt_text_start_x, nt_text_start_y, paint);
125 } 108 }
126 else 109 else
127 { 110 {
128 paint.setColor(OSD_element_bg_001); 111 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 } 112 }
149 } 113 }
150 catch (Exception e) 114 catch (Exception e)
151 { 115 {
152 //e.printStackTrace(); 116 //e.printStackTrace();
153 } 117 }
154 118
119 // System.out.println("onDraw:OSDRoadDist");
155 } 120 }
156} 121}

Legend:
Removed from v.40  
changed lines
  Added in v.41

   
Visit the ZANavi Wiki