/[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 3 - (show annotations) (download)
Sun Aug 5 14:00:28 2012 UTC (11 years, 7 months ago) by zoffadmin
File size: 12044 byte(s)
license text correction
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
38 aagtl main_aagtl;
39
40 public CrossHair(Context context, aagtl main)
41 {
42 super(context);
43 this.main_aagtl = main;
44 }
45
46 public void set_used_sats(int count)
47 {
48 this.used_sats = count;
49 }
50
51 public void set_gps_heading(double degrees)
52 {
53 this.gps_heading = degrees;
54 if (this.main_aagtl.global_settings.options_turn_map_on_heading)
55 {
56 // user wants map to turn with heading
57 // so draw map
58 //this.main_aagtl.rose.invalidate();
59 //System.out.println("iigcYYYYY");
60 this.main_aagtl.rose.draw_view();
61 }
62 }
63
64 public double get_gps_heading()
65 {
66 return this.gps_heading;
67 }
68
69 public void set_gps_acc(double meters)
70 {
71 this.gps_acc = meters;
72 }
73
74 public void onDraw(Canvas c)
75 {
76 //System.out.println("CrossHair: onDraw");
77
78 Paint paint = new Paint(0);
79 paint.setAntiAlias(false);
80 paint.setColor(Color.GRAY);
81 c.drawLine(this.getWidth() / 2, 0, this.getWidth() / 2, this.getHeight() / 2 - middle_size,
82 paint);
83 c.drawLine(this.getWidth() / 2, this.getHeight() / 2 + middle_size, this.getWidth() / 2, this
84 .getHeight(), paint);
85
86 c.drawLine(0, this.getHeight() / 2, this.getWidth() / 2 - middle_size, this.getHeight() / 2,
87 paint);
88 c.drawLine(this.getWidth() / 2 + middle_size, this.getHeight() / 2, this.getWidth(), this
89 .getHeight() / 2, paint);
90
91
92 // -- SUN --
93 // -- SUN --
94 // -- SUN --
95 // set correct sun values
96 this.main_aagtl.arrowview.calc_sun_stats();
97
98 //c.drawText("sunrise: " + this.sunrise_cache, 10, this.getHeight() - 34 * 4, text_paint);
99 //c.drawText("sunset: " + this.sunset_cache, 10, this.getHeight() - 34 * 3, text_paint);
100
101 if (this.main_aagtl.arrowview.moon_evelation_cache < -0.83)
102 {
103 // moon not visible
104 }
105 else
106 {
107 // moon is visible!!
108 double x1 = this.getWidth() / 2
109 + Math.sin(Math.toRadians(this.main_aagtl.arrowview.moon_azimuth_cache))
110 * (this.getWidth() / 2) * 0.9;
111 double y1 = this.getHeight() / 2
112 - Math.cos(Math.toRadians(this.main_aagtl.arrowview.moon_azimuth_cache))
113 * (this.getHeight() / 2) * 0.9;
114
115 int radius_x = 6;
116 int radius_y = 6;
117 RectF sun_oval = null;
118 // day
119
120 // draw yellow sun
121 Paint paint_gps = new Paint(0);
122 paint_gps.setColor(Color.parseColor("#EBEBEB"));
123 paint_gps.setStyle(Paint.Style.FILL);
124 paint_gps.setAntiAlias(true);
125 radius_x = 6;
126 radius_y = 6;
127 sun_oval = new RectF((int) (x1 - radius_x), (int) (y1 - radius_y), (int) (x1 + radius_x),
128 (int) (y1 + radius_y));
129 c.drawArc(sun_oval, 0, 360, false, paint_gps);
130 //
131 // draw black circle
132 paint_gps.setColor(Color.parseColor("#000000"));
133 paint_gps.setStyle(Paint.Style.STROKE);
134 paint_gps.setAntiAlias(true);
135 paint_gps.setStrokeWidth(1);
136 radius_x = 6;
137 radius_y = 6;
138 sun_oval = new RectF((int) (x1 - radius_x), (int) (y1 - radius_y), (int) (x1 + radius_x),
139 (int) (y1 + radius_y));
140 c.drawArc(sun_oval, 0, 360, false, paint_gps);
141
142 }
143
144 if (this.main_aagtl.arrowview.elevation < -0.83)
145 {
146 // night
147 }
148 else
149 {
150 double x1 = this.getWidth() / 2
151 + Math.sin(Math.toRadians(this.main_aagtl.arrowview.azmiuth_cache))
152 * (this.getWidth() / 2) * 0.9;
153 double y1 = this.getHeight() / 2
154 - Math.cos(Math.toRadians(this.main_aagtl.arrowview.azmiuth_cache))
155 * (this.getHeight() / 2) * 0.9;
156
157 int radius_x = 6;
158 int radius_y = 6;
159 RectF sun_oval = null;
160 // day
161
162 // draw yellow sun
163 Paint paint_gps = new Paint(0);
164 paint_gps.setColor(Color.parseColor("#FFFF66"));
165 paint_gps.setStyle(Paint.Style.FILL);
166 paint_gps.setAntiAlias(true);
167 radius_x = 6;
168 radius_y = 6;
169 sun_oval = new RectF((int) (x1 - radius_x), (int) (y1 - radius_y), (int) (x1 + radius_x),
170 (int) (y1 + radius_y));
171 c.drawArc(sun_oval, 0, 360, false, paint_gps);
172 //
173 // draw black circle
174 paint_gps.setColor(Color.parseColor("#000000"));
175 paint_gps.setStyle(Paint.Style.STROKE);
176 paint_gps.setAntiAlias(true);
177 paint_gps.setStrokeWidth(1);
178 radius_x = 6;
179 radius_y = 6;
180 sun_oval = new RectF((int) (x1 - radius_x), (int) (y1 - radius_y), (int) (x1 + radius_x),
181 (int) (y1 + radius_y));
182 c.drawArc(sun_oval, 0, 360, false, paint_gps);
183 }
184
185 // -- SUN --
186 // -- SUN --
187 // -- SUN --
188
189
190 if (this.main_aagtl.isGPSFix)
191 {
192 if (!this.main_aagtl.global_settings.options_turn_map_on_heading)
193 {
194 // have gps fix
195 if (this.gps_acc != -1)
196 {
197 Paint paint_gps = new Paint(0);
198 paint_gps.setColor(Color.parseColor("#0000AA"));
199 paint_gps.setStyle(Paint.Style.STROKE);
200 paint_gps.setAntiAlias(true);
201
202 // calc gps_acc (in meters) into pixels (in current zoomlevel)
203 // zoom = 19 -> tile_size = 100/2m =50*1m
204 // zoom = 18 -> tile_size = 100m =50*2m
205 // zoom = 17 -> tile_size = 100*2m =50*4m
206 int temp = 19 - this.main_aagtl.rose.zoom;
207 double n = (1 << temp);
208 int radius_x = (int) (gps_acc * (this.main_aagtl.rose.tile_size_x / (50 * n)));
209 int radius_y = (int) (gps_acc * (this.main_aagtl.rose.tile_size_y / (50 * n)));
210
211 //System.out.println("acc radius x=" + radius_x);
212 //System.out.println("acc radius y=" + radius_y);
213 //System.out.println("zoom=" + this.main_aagtl.rose.zoom);
214 //System.out.println("gps acc=" + gps_acc);
215 //System.out.println("n=" + n);
216
217
218 RectF gps_oval = new RectF(this.getWidth() / 2 - (int) radius_x, this.getHeight()
219 / 2 - (int) radius_y, this.getWidth() / 2 + (int) radius_x, this.getHeight()
220 / 2 + (int) radius_y);
221 c.drawArc(gps_oval, 0, 360, false, paint_gps);
222
223
224 // show the heading on map
225 //System.out.println("-> heading=" + this.gps_heading);
226 int size = 16;
227 double s1 = Math.sin(Math.toRadians(this.gps_heading));
228 double c1 = Math.cos(Math.toRadians(this.gps_heading));
229 double radius_x2 = (this.getWidth() / 2) - 34;
230 double radius_y2 = (this.getHeight() / 2) - 34;
231 double[] my_shape = {0.7, +0, 0, -1, -0.7, 0};
232
233 Path p = new Path();
234 for (int i = 0; i < 3; i++)
235 {
236 if (i == 0)
237 {
238 //System.out.println("" + my_shape[(i + 1) * 2 - 2]);
239 //System.out.println("" + my_shape[(i + 1) * 2 - 1]);
240 p.moveTo((float) (my_shape[(i + 1) * 2 - 2] * size * c1 + this.getWidth() / 2
241 - my_shape[(i + 1) * 2 - 1] * size * s1 + s1 * radius_x2),
242 (float) (my_shape[(i + 1) * 2 - 1] * size * c1 + this.getHeight() / 2
243 + my_shape[(i + 1) * 2 - 2] * size * s1 - c1 * radius_y2));
244 }
245 else
246 {
247 //System.out.println(""
248 // + (my_shape[(i + 1) * 2 - 2] * size * c1 + this.getWidth() / 2
249 // - my_shape[(i + 1) * 2 - 1] * size * s1 + s1 * radius));
250 //System.out.println(""
251 // + ((my_shape[(i + 1) * 2 - 1] * size * c1 + this.getHeight() / 2
252 // + my_shape[(i + 1) * 2 - 2] * size * s1 - c1 * radius)));
253 p.lineTo((float) (my_shape[(i + 1) * 2 - 2] * size * c1 + this.getWidth() / 2
254 - my_shape[(i + 1) * 2 - 1] * size * s1 + s1 * radius_x2),
255 (float) (my_shape[(i + 1) * 2 - 1] * size * c1 + this.getHeight() / 2
256 + my_shape[(i + 1) * 2 - 2] * size * s1 - c1 * radius_y2));
257 }
258 }
259 p.close();
260 paint_gps.setStyle(Paint.Style.STROKE);
261 paint_gps.setStrokeWidth(4);
262 paint_gps.setColor(Color.parseColor("#00EE00"));
263 c.drawPath(p, paint_gps);
264 paint_gps.setStrokeWidth(2);
265 paint_gps.setColor(Color.parseColor("#157DEC"));
266 c.drawPath(p, paint_gps);
267
268 paint_gps.setTextSize(14);
269 paint_gps.setStrokeWidth(1);
270 paint_gps.setColor(Color.parseColor("#00EE00"));
271 c.drawText("*gps fix* (" + this.used_sats + ")", this.getWidth() - 90, this
272 .getHeight() - 17, paint_gps);
273 }
274 }
275 }
276 else
277 {
278 if (!this.main_aagtl.global_settings.options_turn_map_on_heading)
279 {
280 if (this.main_aagtl.global_settings.options_use_compass_heading)
281 {
282 // show the heading on map
283 //System.out.println("-> heading=" + this.gps_heading);
284 int size = 16;
285 double s1 = Math.sin(Math.toRadians(this.gps_heading));
286 double c1 = Math.cos(Math.toRadians(this.gps_heading));
287 double radius_x2 = (this.getWidth() / 2) - 34;
288 double radius_y2 = (this.getHeight() / 2) - 34;
289 double[] my_shape = {0.7, +0, 0, -1, -0.7, 0};
290
291 Path p = new Path();
292 for (int i = 0; i < 3; i++)
293 {
294 if (i == 0)
295 {
296 //System.out.println("" + my_shape[(i + 1) * 2 - 2]);
297 //System.out.println("" + my_shape[(i + 1) * 2 - 1]);
298 p.moveTo((float) (my_shape[(i + 1) * 2 - 2] * size * c1 + this.getWidth() / 2
299 - my_shape[(i + 1) * 2 - 1] * size * s1 + s1 * radius_x2),
300 (float) (my_shape[(i + 1) * 2 - 1] * size * c1 + this.getHeight() / 2
301 + my_shape[(i + 1) * 2 - 2] * size * s1 - c1 * radius_y2));
302 }
303 else
304 {
305 //System.out.println(""
306 // + (my_shape[(i + 1) * 2 - 2] * size * c1 + this.getWidth() / 2
307 // - my_shape[(i + 1) * 2 - 1] * size * s1 + s1 * radius));
308 //System.out.println(""
309 // + ((my_shape[(i + 1) * 2 - 1] * size * c1 + this.getHeight() / 2
310 // + my_shape[(i + 1) * 2 - 2] * size * s1 - c1 * radius)));
311 p.lineTo((float) (my_shape[(i + 1) * 2 - 2] * size * c1 + this.getWidth() / 2
312 - my_shape[(i + 1) * 2 - 1] * size * s1 + s1 * radius_x2),
313 (float) (my_shape[(i + 1) * 2 - 1] * size * c1 + this.getHeight() / 2
314 + my_shape[(i + 1) * 2 - 2] * size * s1 - c1 * radius_y2));
315 }
316 }
317 p.close();
318 Paint paint_gps = new Paint(0);
319 paint_gps.setAntiAlias(true);
320 paint_gps.setStyle(Paint.Style.STROKE);
321 paint_gps.setStrokeWidth(4);
322 paint_gps.setColor(Color.parseColor("#00EE00"));
323 c.drawPath(p, paint_gps);
324 paint_gps.setStrokeWidth(2);
325 paint_gps.setColor(Color.parseColor("#157DEC"));
326 c.drawPath(p, paint_gps);
327
328 }
329 }
330
331 // no gps fix
332 Paint paint_gps = new Paint(0);
333 paint_gps.setAntiAlias(true);
334 paint_gps.setColor(Color.parseColor("#EE0000"));
335 paint_gps.setStyle(Paint.Style.STROKE);
336 paint_gps.setTextSize(11);
337 c.drawText("no gps fix (" + this.used_sats + ")", this.getWidth() - 90,
338 this.getHeight() - 17, paint_gps);
339
340 }
341
342 // draw follow
343 c.drawBitmap(this.main_aagtl.follow_current, this.main_aagtl.follow_button_rect.left,
344 this.main_aagtl.follow_button_rect.top, null);
345
346 // draw arrow button
347 c.drawBitmap(this.main_aagtl.arrow_button, this.main_aagtl.arrow_button_rect.left,
348 this.main_aagtl.arrow_button_rect.top, null);
349
350 }
351
352 }

   
Visit the aagtl Website