/[aagtl_public1]/src/com/zoffcc/applications/aagtl/CrossHair.java
aagtl

Contents of /src/com/zoffcc/applications/aagtl/CrossHair.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (show annotations) (download)
Sat Aug 1 08:47:10 2015 UTC (8 years, 7 months ago) by zoffadmin
File size: 13535 byte(s)
1.0.35
1 /**
2 * aagtl Advanced Geocaching Tool for Android
3 * loosely based on agtl by Daniel Fett <fett@danielfett.de>
4 * Copyright (C) 2010 - 2012 Zoff <aagtl@work.zoff.cc>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 package com.zoffcc.applications.aagtl;
22
23 import android.content.Context;
24 import android.graphics.Canvas;
25 import android.graphics.Color;
26 import android.graphics.Paint;
27 import android.graphics.Path;
28 import android.graphics.RectF;
29 import android.widget.ImageView;
30
31 public class CrossHair extends ImageView
32 {
33 int middle_size = 10;
34 double gps_acc = -1;
35 double gps_heading = -1;
36 int used_sats = 0;
37 Path menu_text_path = new Path();
38 Paint paint_gps = new Paint(0);
39
40 aagtl main_aagtl;
41
42 public CrossHair(Context context, aagtl main)
43 {
44 super(context);
45 this.main_aagtl = main;
46 }
47
48 public void set_used_sats(int count)
49 {
50 this.used_sats = count;
51 }
52
53 public void set_gps_heading(double degrees)
54 {
55 this.gps_heading = degrees;
56 if (this.main_aagtl.global_settings.options_turn_map_on_heading)
57 {
58 // user wants map to turn with heading
59 // so draw map
60 //this.main_aagtl.rose.invalidate();
61 //System.out.println("iigcYYYYY");
62 this.main_aagtl.rose.draw_view();
63 }
64 }
65
66 public double get_gps_heading()
67 {
68 return this.gps_heading;
69 }
70
71 public void set_gps_acc(double meters)
72 {
73 this.gps_acc = meters;
74 }
75
76 public void onDraw(Canvas c)
77 {
78 //System.out.println("CrossHair: onDraw");
79
80 Paint paint = new Paint(0);
81 paint.setAntiAlias(false);
82 paint.setColor(Color.GRAY);
83 c.drawLine(this.getWidth() / 2, 0, this.getWidth() / 2, this.getHeight() / 2 - middle_size, paint);
84 c.drawLine(this.getWidth() / 2, this.getHeight() / 2 + middle_size, this.getWidth() / 2, this.getHeight(), paint);
85
86 c.drawLine(0, this.getHeight() / 2, this.getWidth() / 2 - middle_size, this.getHeight() / 2, paint);
87 c.drawLine(this.getWidth() / 2 + middle_size, this.getHeight() / 2, this.getWidth(), this.getHeight() / 2, paint);
88
89 // -- SUN --
90 // -- SUN --
91 // -- SUN --
92 // set correct sun values
93 this.main_aagtl.arrowview.calc_sun_stats();
94
95 //c.drawText("sunrise: " + this.sunrise_cache, 10, this.getHeight() - 34 * 4, text_paint);
96 //c.drawText("sunset: " + this.sunset_cache, 10, this.getHeight() - 34 * 3, text_paint);
97
98 if (this.main_aagtl.arrowview.moon_evelation_cache < -0.83)
99 {
100 // moon not visible
101 }
102 else
103 {
104 // moon is visible!!
105 double x1 = this.getWidth() / 2 + Math.sin(Math.toRadians(this.main_aagtl.arrowview.moon_azimuth_cache)) * (this.getWidth() / 2) * 0.9;
106 double y1 = this.getHeight() / 2 - Math.cos(Math.toRadians(this.main_aagtl.arrowview.moon_azimuth_cache)) * (this.getHeight() / 2) * 0.9;
107
108 int radius_x = 6;
109 int radius_y = 6;
110 RectF sun_oval = null;
111 // day
112
113 // draw yellow sun
114 paint_gps.reset();
115 paint_gps.setColor(Color.parseColor("#EBEBEB"));
116 paint_gps.setStyle(Paint.Style.FILL);
117 paint_gps.setAntiAlias(true);
118 radius_x = 6;
119 radius_y = 6;
120 sun_oval = new RectF((int) (x1 - radius_x), (int) (y1 - radius_y), (int) (x1 + radius_x), (int) (y1 + radius_y));
121 c.drawArc(sun_oval, 0, 360, false, paint_gps);
122 //
123 // draw black circle
124 paint_gps.setColor(Color.parseColor("#000000"));
125 paint_gps.setStyle(Paint.Style.STROKE);
126 paint_gps.setAntiAlias(true);
127 paint_gps.setStrokeWidth(1);
128 radius_x = 6;
129 radius_y = 6;
130 sun_oval = new RectF((int) (x1 - radius_x), (int) (y1 - radius_y), (int) (x1 + radius_x), (int) (y1 + radius_y));
131 c.drawArc(sun_oval, 0, 360, false, paint_gps);
132
133 }
134
135 if (this.main_aagtl.arrowview.elevation < -0.83)
136 {
137 // night
138 }
139 else
140 {
141 double x1 = this.getWidth() / 2 + Math.sin(Math.toRadians(this.main_aagtl.arrowview.azmiuth_cache)) * (this.getWidth() / 2) * 0.9;
142 double y1 = this.getHeight() / 2 - Math.cos(Math.toRadians(this.main_aagtl.arrowview.azmiuth_cache)) * (this.getHeight() / 2) * 0.9;
143
144 int radius_x = 6;
145 int radius_y = 6;
146 RectF sun_oval = null;
147 // day
148
149 // draw yellow sun
150 paint_gps.reset();
151 paint_gps.setColor(Color.parseColor("#FFFF66"));
152 paint_gps.setStyle(Paint.Style.FILL);
153 paint_gps.setAntiAlias(true);
154 radius_x = 6;
155 radius_y = 6;
156 sun_oval = new RectF((int) (x1 - radius_x), (int) (y1 - radius_y), (int) (x1 + radius_x), (int) (y1 + radius_y));
157 c.drawArc(sun_oval, 0, 360, false, paint_gps);
158 //
159 // draw black circle
160 paint_gps.setColor(Color.parseColor("#000000"));
161 paint_gps.setStyle(Paint.Style.STROKE);
162 paint_gps.setAntiAlias(true);
163 paint_gps.setStrokeWidth(1);
164 radius_x = 6;
165 radius_y = 6;
166 sun_oval = new RectF((int) (x1 - radius_x), (int) (y1 - radius_y), (int) (x1 + radius_x), (int) (y1 + radius_y));
167 c.drawArc(sun_oval, 0, 360, false, paint_gps);
168 }
169
170 // -- SUN --
171 // -- SUN --
172 // -- SUN --
173
174 if (this.main_aagtl.isGPSFix)
175 {
176 if (!this.main_aagtl.global_settings.options_turn_map_on_heading)
177 {
178 // have gps fix
179 if (this.gps_acc != -1)
180 {
181 paint_gps.reset();
182 paint_gps.setColor(Color.parseColor("#0000AA"));
183 paint_gps.setStyle(Paint.Style.STROKE);
184 paint_gps.setAntiAlias(true);
185
186 // calc gps_acc (in meters) into pixels (in current zoomlevel)
187 // zoom = 19 -> tile_size = 100/2m =50*1m
188 // zoom = 18 -> tile_size = 100m =50*2m
189 // zoom = 17 -> tile_size = 100*2m =50*4m
190 int temp = 19 - this.main_aagtl.rose.zoom;
191 double n = (1 << temp);
192 int radius_x = (int) (gps_acc * (this.main_aagtl.rose.tile_size_x / (50 * n)));
193 int radius_y = (int) (gps_acc * (this.main_aagtl.rose.tile_size_y / (50 * n)));
194
195 //System.out.println("acc radius x=" + radius_x);
196 //System.out.println("acc radius y=" + radius_y);
197 //System.out.println("zoom=" + this.main_aagtl.rose.zoom);
198 //System.out.println("gps acc=" + gps_acc);
199 //System.out.println("n=" + n);
200
201 RectF gps_oval = new RectF(this.getWidth() / 2 - (int) radius_x, this.getHeight() / 2 - (int) radius_y, this.getWidth() / 2 + (int) radius_x, this.getHeight() / 2 + (int) radius_y);
202 c.drawArc(gps_oval, 0, 360, false, paint_gps);
203
204 // show the heading on map
205 //System.out.println("-> heading=" + this.gps_heading);
206 int size = 16;
207 double s1 = Math.sin(Math.toRadians(this.gps_heading));
208 double c1 = Math.cos(Math.toRadians(this.gps_heading));
209 double radius_x2 = (this.getWidth() / 2) - 34;
210 double radius_y2 = (this.getHeight() / 2) - 34;
211 double[] my_shape = { 0.7, +0, 0, -1, -0.7, 0 };
212
213 Path p = new Path();
214 for (int i = 0; i < 3; i++)
215 {
216 if (i == 0)
217 {
218 //System.out.println("" + my_shape[(i + 1) * 2 - 2]);
219 //System.out.println("" + my_shape[(i + 1) * 2 - 1]);
220 p.moveTo((float) (my_shape[(i + 1) * 2 - 2] * size * c1 + this.getWidth() / 2 - my_shape[(i + 1) * 2 - 1] * size * s1 + s1 * radius_x2), (float) (my_shape[(i + 1) * 2 - 1] * size * c1 + this.getHeight() / 2 + my_shape[(i + 1) * 2 - 2] * size * s1 - c1 * radius_y2));
221 }
222 else
223 {
224 //System.out.println(""
225 // + (my_shape[(i + 1) * 2 - 2] * size * c1 + this.getWidth() / 2
226 // - my_shape[(i + 1) * 2 - 1] * size * s1 + s1 * radius));
227 //System.out.println(""
228 // + ((my_shape[(i + 1) * 2 - 1] * size * c1 + this.getHeight() / 2
229 // + my_shape[(i + 1) * 2 - 2] * size * s1 - c1 * radius)));
230 p.lineTo((float) (my_shape[(i + 1) * 2 - 2] * size * c1 + this.getWidth() / 2 - my_shape[(i + 1) * 2 - 1] * size * s1 + s1 * radius_x2), (float) (my_shape[(i + 1) * 2 - 1] * size * c1 + this.getHeight() / 2 + my_shape[(i + 1) * 2 - 2] * size * s1 - c1 * radius_y2));
231 }
232 }
233 p.close();
234 paint_gps.setStyle(Paint.Style.STROKE);
235 paint_gps.setStrokeWidth(4);
236 paint_gps.setColor(Color.parseColor("#00EE00"));
237 c.drawPath(p, paint_gps);
238 paint_gps.setStrokeWidth(2);
239 paint_gps.setColor(Color.parseColor("#157DEC"));
240 c.drawPath(p, paint_gps);
241
242 paint_gps.setTextSize(14);
243 paint_gps.setStrokeWidth(1);
244 paint_gps.setColor(Color.parseColor("#00EE00"));
245 c.drawText("*gps fix* (" + this.used_sats + ")", this.getWidth() - 90, this.getHeight() - 17, paint_gps);
246 }
247 }
248 }
249 else
250 {
251 if (!this.main_aagtl.global_settings.options_turn_map_on_heading)
252 {
253 if (this.main_aagtl.global_settings.options_use_compass_heading)
254 {
255 // show the heading on map
256 //System.out.println("-> heading=" + this.gps_heading);
257 int size = 16;
258 double s1 = Math.sin(Math.toRadians(this.gps_heading));
259 double c1 = Math.cos(Math.toRadians(this.gps_heading));
260 double radius_x2 = (this.getWidth() / 2) - 34;
261 double radius_y2 = (this.getHeight() / 2) - 34;
262 double[] my_shape = { 0.7, +0, 0, -1, -0.7, 0 };
263
264 Path p = new Path();
265 for (int i = 0; i < 3; i++)
266 {
267 if (i == 0)
268 {
269 //System.out.println("" + my_shape[(i + 1) * 2 - 2]);
270 //System.out.println("" + my_shape[(i + 1) * 2 - 1]);
271 p.moveTo((float) (my_shape[(i + 1) * 2 - 2] * size * c1 + this.getWidth() / 2 - my_shape[(i + 1) * 2 - 1] * size * s1 + s1 * radius_x2), (float) (my_shape[(i + 1) * 2 - 1] * size * c1 + this.getHeight() / 2 + my_shape[(i + 1) * 2 - 2] * size * s1 - c1 * radius_y2));
272 }
273 else
274 {
275 //System.out.println(""
276 // + (my_shape[(i + 1) * 2 - 2] * size * c1 + this.getWidth() / 2
277 // - my_shape[(i + 1) * 2 - 1] * size * s1 + s1 * radius));
278 //System.out.println(""
279 // + ((my_shape[(i + 1) * 2 - 1] * size * c1 + this.getHeight() / 2
280 // + my_shape[(i + 1) * 2 - 2] * size * s1 - c1 * radius)));
281 p.lineTo((float) (my_shape[(i + 1) * 2 - 2] * size * c1 + this.getWidth() / 2 - my_shape[(i + 1) * 2 - 1] * size * s1 + s1 * radius_x2), (float) (my_shape[(i + 1) * 2 - 1] * size * c1 + this.getHeight() / 2 + my_shape[(i + 1) * 2 - 2] * size * s1 - c1 * radius_y2));
282 }
283 }
284 p.close();
285 paint_gps.reset();
286 paint_gps.setAntiAlias(true);
287 paint_gps.setStyle(Paint.Style.STROKE);
288 paint_gps.setStrokeWidth(4);
289 paint_gps.setColor(Color.parseColor("#00EE00"));
290 c.drawPath(p, paint_gps);
291 paint_gps.setStrokeWidth(2);
292 paint_gps.setColor(Color.parseColor("#157DEC"));
293 c.drawPath(p, paint_gps);
294
295 }
296 }
297
298 // no gps fix
299 paint_gps.reset();
300 paint_gps.setAntiAlias(true);
301 paint_gps.setColor(Color.parseColor("#EE0000"));
302 paint_gps.setStyle(Paint.Style.STROKE);
303 paint_gps.setTextSize(11);
304 c.drawText("no gps fix (" + this.used_sats + ")", this.getWidth() - 90, this.getHeight() - 17, paint_gps);
305
306 }
307
308 // draw follow
309 c.drawBitmap(this.main_aagtl.follow_current, this.main_aagtl.follow_button_rect.left, this.main_aagtl.follow_button_rect.top, null);
310
311 // draw arrow button
312 c.drawBitmap(this.main_aagtl.arrow_button, this.main_aagtl.arrow_button_rect.left, this.main_aagtl.arrow_button_rect.top, null);
313
314 if (!this.main_aagtl.has_hw_menu_button)
315 {
316 // draw emulated menu button
317 c.drawBitmap(this.main_aagtl.menu_button, this.main_aagtl.menu_button_rect.left, this.main_aagtl.menu_button_rect.top, null);
318
319 // Paint px = new Paint();
320 // px.setColor(Color.RED);
321 // px.setStyle(Style.STROKE);
322 // c.drawRect(this.main_aagtl.menu_button_rect_touch, px);
323
324 //
325 // paint.setAntiAlias(true);
326 // paint.setColor(Color.LTGRAY);
327 // paint.setStrokeWidth(4);
328 // paint.setAlpha(179);
329 // paint.setStyle(Paint.Style.FILL);
330 // c.drawRoundRect(this.main_aagtl.menu_button_rect, (int) 8f * aagtl.Global_dpi_factor, (int) 8f * aagtl.Global_dpi_factor, paint);
331 // paint.setColor(Color.BLACK);
332 // //
333 // paint.setStyle(Paint.Style.STROKE);
334 // paint.setStrokeWidth(1);
335 // paint.setAlpha(255);
336 // c.drawRoundRect(this.main_aagtl.menu_button_rect, (int) 8f * aagtl.Global_dpi_factor, (int) 8f * aagtl.Global_dpi_factor, paint);
337 //
338 // paint.setAntiAlias(true);
339 // paint.setTextSize(23 * aagtl.Global_dpi_factor);
340 // paint.setStrokeWidth(2);
341 // paint.setTextAlign(Paint.Align.CENTER);
342 // paint.setStyle(Paint.Style.FILL);
343 // paint.setAlpha(255);
344 // menu_text_path.reset();
345 // menu_text_path.moveTo(this.main_aagtl.menu_button_rect.left, this.main_aagtl.menu_button_rect.top + (this.main_aagtl.menu_button_rect.bottom - this.main_aagtl.menu_button_rect.top) / 2);
346 // menu_text_path.lineTo(this.main_aagtl.menu_button_rect.right, this.main_aagtl.menu_button_rect.top + (this.main_aagtl.menu_button_rect.bottom - this.main_aagtl.menu_button_rect.top) / 2);
347 // c.drawTextOnPath("MENU", menu_text_path, 0, 0, paint);
348 }
349 }
350 }

   
Visit the aagtl Website