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.util.AttributeSet;
|
27 |
import android.view.View;
|
28 |
|
29 |
public class ZANaviOSDRoadDist extends View
|
30 |
{
|
31 |
|
32 |
private Paint paint = new Paint();
|
33 |
int end_x;
|
34 |
int end_y;
|
35 |
int nt_text_start_x = 0;
|
36 |
int nt_text_start_y = 0;
|
37 |
int nt_font_size = 10;
|
38 |
float draw_factor = 1;
|
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;
|
43 |
String my_text = "";
|
44 |
int w2;
|
45 |
int h2;
|
46 |
int h3;
|
47 |
int w;
|
48 |
int h;
|
49 |
int font_size = 10;
|
50 |
float textHeight = 0;
|
51 |
float textOffset = 0;
|
52 |
|
53 |
public ZANaviOSDRoadDist(Context context)
|
54 |
{
|
55 |
super(context);
|
56 |
paint.setTextAlign(Paint.Align.CENTER);
|
57 |
}
|
58 |
|
59 |
public ZANaviOSDRoadDist(Context context, AttributeSet attrs)
|
60 |
{
|
61 |
super(context, attrs);
|
62 |
paint.setTextAlign(Paint.Align.CENTER);
|
63 |
}
|
64 |
|
65 |
@Override
|
66 |
public void onSizeChanged(int w, int h, int oldw, int oldh)
|
67 |
{
|
68 |
super.onSizeChanged(w, h, oldw, oldh);
|
69 |
this.w2 = w / 2;
|
70 |
this.h2 = h / 2;
|
71 |
this.w = w;
|
72 |
this.h = h;
|
73 |
this.h3 = (int) (h + (paint.ascent() / 2));
|
74 |
|
75 |
OSD_element_text_shadow_width = NavitGraphics.dp_to_px(2);
|
76 |
|
77 |
font_size = Navit.find_max_font_size_for_height("7,544 km", h, 93, 9);
|
78 |
|
79 |
// System.out.println("aAA:1:" + font_size + " " + w + " " + h);
|
80 |
|
81 |
paint.setTextSize(font_size);
|
82 |
paint.setAntiAlias(true);
|
83 |
|
84 |
textHeight = paint.descent() - paint.ascent();
|
85 |
textOffset = (textHeight / 2) - paint.descent();
|
86 |
}
|
87 |
|
88 |
public void onDraw(Canvas c)
|
89 |
{
|
90 |
super.onDraw(c);
|
91 |
int dest_valid = NavitGraphics.CallbackDestinationValid2();
|
92 |
|
93 |
try
|
94 |
{
|
95 |
if ((Navit.OSD_route_001.driving_distance_to_target_valid) && (dest_valid > 0))
|
96 |
{
|
97 |
my_text = Navit.OSD_route_001.driving_distance_to_target;
|
98 |
|
99 |
paint.setColor(OSD_element_text_shadow_001);
|
100 |
paint.setStrokeWidth(OSD_element_text_shadow_width);
|
101 |
paint.setStyle(Paint.Style.STROKE);
|
102 |
c.drawText(my_text, w2, h2 + textOffset, paint);
|
103 |
|
104 |
paint.setColor(OSD_element_text_001);
|
105 |
paint.setStrokeWidth(3);
|
106 |
paint.setStyle(Paint.Style.FILL);
|
107 |
c.drawText(my_text, w2, h2 + textOffset, paint);
|
108 |
}
|
109 |
else
|
110 |
{
|
111 |
c.drawColor(Color.TRANSPARENT);
|
112 |
}
|
113 |
}
|
114 |
catch (Exception e)
|
115 |
{
|
116 |
//e.printStackTrace();
|
117 |
}
|
118 |
|
119 |
// System.out.println("onDraw:OSDRoadDist");
|
120 |
}
|
121 |
}
|