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

Contents of /navit/navit/android/src/com/zoffcc/applications/zanavi/ZANaviOSDSpeeding.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (show annotations) (download)
Tue Aug 11 18:50:37 2015 UTC (8 years, 8 months ago) by zoff99
File size: 3553 byte(s)
many fixes, and new features
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2015 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.graphics.Paint.Style;
28 import android.graphics.RectF;
29 import android.util.AttributeSet;
30 import android.view.View;
31
32 public class ZANaviOSDSpeeding extends View
33 {
34 int w = 10;
35 int h = 10;
36 RectF bounds_speedwarning = new RectF(120, 800, 120 + 200, 800 + 200);
37 Paint paint_speedwarning = new Paint(0);
38 float textHeight = 10;
39 float textOffset = 10;
40
41 public ZANaviOSDSpeeding(Context context)
42 {
43 super(context);
44 }
45
46 public ZANaviOSDSpeeding(Context context, AttributeSet attrs)
47 {
48 super(context, attrs);
49 }
50
51 @Override
52 public void onSizeChanged(int w1, int h1, int oldw, int oldh)
53 {
54 super.onSizeChanged(w1, h1, oldw, oldh);
55 this.w = w1;
56 this.h = h1;
57 bounds_speedwarning = new RectF(NavitGraphics.dp_to_px(5), NavitGraphics.dp_to_px(5), w1 - NavitGraphics.dp_to_px(5), h1 - NavitGraphics.dp_to_px(5));
58 }
59
60 public void onDraw(Canvas c)
61 {
62 super.onDraw(c);
63
64 if (Navit.p.PREF_roadspeed_warning)
65 // DEBUG // if (1 == 2 - 1)
66 {
67 // DEBUG // Navit.cur_max_speed = 50;
68 if ((Navit.cur_max_speed != -1) && (Navit.your_are_speeding))
69 {
70 paint_speedwarning.setAntiAlias(true);
71 paint_speedwarning.setColor(Color.WHITE);
72 paint_speedwarning.setStyle(Style.FILL);
73 c.drawOval(bounds_speedwarning, paint_speedwarning);
74
75 paint_speedwarning.setColor(Color.RED);
76 paint_speedwarning.setStyle(Style.STROKE);
77 paint_speedwarning.setStrokeWidth(NavitGraphics.dp_to_px(8));
78 c.drawOval(bounds_speedwarning, paint_speedwarning);
79
80 paint_speedwarning.setColor(Color.BLACK);
81 paint_speedwarning.setStyle(Style.FILL_AND_STROKE);
82 paint_speedwarning.setStrokeWidth(2);
83 if (Navit.p.PREF_use_imperial)
84 {
85 Navit.cur_max_speed_corr = (int) ((((float) Navit.cur_max_speed) / 1.6f) + 0.5f);
86 }
87 else
88 {
89 Navit.cur_max_speed_corr = Navit.cur_max_speed;
90 }
91
92 if (Navit.cur_max_speed_corr > 99)
93 {
94 paint_speedwarning.setTextSize(NavitGraphics.dp_to_px(20));
95 }
96 else
97 {
98 paint_speedwarning.setTextSize(NavitGraphics.dp_to_px(23));
99 }
100 paint_speedwarning.setTextAlign(Align.CENTER);
101 textHeight = paint_speedwarning.descent() - paint_speedwarning.ascent();
102 textOffset = (textHeight / 2) - paint_speedwarning.descent();
103 c.drawText("" + Navit.cur_max_speed_corr, bounds_speedwarning.centerX(), bounds_speedwarning.centerY() + textOffset, paint_speedwarning);
104 }
105 }
106 else
107 {
108 c.drawColor(Color.TRANSPARENT);
109 }
110
111 // System.out.println("onDraw:OSDSpeeding");
112 }
113 }

   
Visit the ZANavi Wiki