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