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

Diff of /src/com/zoffcc/applications/aagtl/ArrowView.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 3 Revision 4
40import com.luckycatlabs.sunrisesunset.dto.Location2; 40import com.luckycatlabs.sunrisesunset.dto.Location2;
41 41
42public class ArrowView extends ImageView 42public class ArrowView extends ImageView
43{ 43{
44 44
45 Paint arrow_paint = new Paint(0); 45 Paint arrow_paint = new Paint(0);
46 Paint text_paint = new Paint(0); 46 Paint text_paint = new Paint(0);
47 47
48 aagtl main_aagtl; 48 aagtl main_aagtl;
49 49
50 long mLastCalcSunMillis = -1; 50 long mLastCalcSunMillis = -1;
51 public double azmiuth_cache = -1; 51 public double azmiuth_cache = -1;
52 public double zenith_cache = -1; 52 public double zenith_cache = -1;
53 public String sunrise_cache = ""; 53 public String sunrise_cache = "";
54 public String sunset_cache = ""; 54 public String sunset_cache = "";
55 public double elevation = 0; 55 public double elevation = 0;
56 56
57 public double moon_azimuth_cache = -1; 57 public double moon_azimuth_cache = -1;
58 public double moon_evelation_cache = -1; 58 public double moon_evelation_cache = -1;
59 59
60 Boolean must_calc_new = true; 60 Boolean must_calc_new = true;
61 SunriseSunsetCalculator calc = null; 61 SunriseSunsetCalculator calc = null;
62 Calendar cx = null; 62 Calendar cx = null;
63 SolarPosition.SunCoordinates sc = null; 63 SolarPosition.SunCoordinates sc = null;
64 64
65 int COLOR_QUALITY_INNER = Color.parseColor("#348017"); 65 int COLOR_QUALITY_INNER = Color.parseColor("#348017");
66 int COLOR_QUALITY_OUTER = Color.parseColor("#150517"); 66 int COLOR_QUALITY_OUTER = Color.parseColor("#150517");
67 int COLOR_ARROW_ATTARGET = Color.parseColor("#C11B17"); 67 int COLOR_ARROW_ATTARGET = Color.parseColor("#C11B17");
68 int COLOR_ARROW_NEAR = Color.parseColor("#F87217"); 68 int COLOR_ARROW_NEAR = Color.parseColor("#F87217");
69 int COLOR_ARROW_DEFAULT = Color.parseColor("#348017"); 69 int COLOR_ARROW_DEFAULT = Color.parseColor("#348017");
70 int COLOR_ARROW_OUTER_LINE = Color.parseColor("#150517"); 70 int COLOR_ARROW_OUTER_LINE = Color.parseColor("#150517");
71 int COLOR_CIRCLE_OUTLINE = Color.parseColor("#424242"); 71 int COLOR_CIRCLE_OUTLINE = Color.parseColor("#424242");
72 int DISTANCE_DISABLE_ARROW = 2; // 2 meters 72 int DISTANCE_DISABLE_ARROW = 2; // 2 meters
73 int NORTH_INDICATOR_SIZE = 20; // 20 pixels 73 int NORTH_INDICATOR_SIZE = 20; // 20 pixels
74 74
75 double ARROW_OFFSET = 1.0 / 3.0; // Offset to center of arrow, calculated as 2-x = sqrt(1^2+(x+1)^2) 75 double ARROW_OFFSET = 1.0 / 3.0; // Offset to center of arrow, calculated as 2-x = sqrt(1^2+(x+1)^2)
76 76
77 public ArrowView(Context context, aagtl main_aagtl) 77 public ArrowView(Context context, aagtl main_aagtl)
78 { 78 {
79 super(context); 79 super(context);
80 80
81 text_paint.setColor(Color.WHITE); 81 text_paint.setColor(Color.WHITE);
82 //text_paint.setStyle(Paint.Style.FILL); 82 //text_paint.setStyle(Paint.Style.FILL);
83 text_paint.setTextSize(19); 83 text_paint.setTextSize(19 * aagtl.Global_dpi_factor);
84 text_paint.setTypeface(Typeface.DEFAULT_BOLD); 84 text_paint.setTypeface(Typeface.DEFAULT_BOLD);
85 text_paint.setAntiAlias(true); 85 text_paint.setAntiAlias(true);
86 86
87 this.main_aagtl = main_aagtl; 87 this.main_aagtl = main_aagtl;
88 this.clear_stuff(); 88 this.clear_stuff();
105 if ((this.must_calc_new) || (this.azmiuth_cache == -1)) 105 if ((this.must_calc_new) || (this.azmiuth_cache == -1))
106 { 106 {
107 this.mLastCalcSunMillis = SystemClock.elapsedRealtime(); 107 this.mLastCalcSunMillis = SystemClock.elapsedRealtime();
108 TimeZone t = TimeZone.getDefault(); 108 TimeZone t = TimeZone.getDefault();
109 //System.out.println(t.getID()); 109 //System.out.println(t.getID());
110 calc = new SunriseSunsetCalculator(new Location2(String 110 calc = new SunriseSunsetCalculator(new Location2(String.valueOf(this.main_aagtl.global_settings.map_position_lat), String.valueOf(this.main_aagtl.global_settings.map_position_lon)), t.getID());
111 .valueOf(this.main_aagtl.global_settings.map_position_lat), String
112 .valueOf(this.main_aagtl.global_settings.map_position_lon)), t.getID());
113 cx = Calendar.getInstance(); 111 cx = Calendar.getInstance();
114 sc = SolarPosition.getSunPosition(new Date(), 112 sc = SolarPosition.getSunPosition(new Date(), this.main_aagtl.global_settings.map_position_lat, this.main_aagtl.global_settings.map_position_lon);
115 this.main_aagtl.global_settings.map_position_lat,
116 this.main_aagtl.global_settings.map_position_lon);
117 113
118 this.azmiuth_cache = sc.azimuth; 114 this.azmiuth_cache = sc.azimuth;
119 this.zenith_cache = sc.zenithAngle; 115 this.zenith_cache = sc.zenithAngle;
120 this.sunrise_cache = calc.getOfficialSunriseForDate(cx); 116 this.sunrise_cache = calc.getOfficialSunriseForDate(cx);
121 this.sunset_cache = calc.getOfficialSunsetForDate(cx); 117 this.sunset_cache = calc.getOfficialSunsetForDate(cx);
134 130
135 public void onDraw(Canvas c) 131 public void onDraw(Canvas c)
136 { 132 {
137 //System.out.println("ArrowView: onDraw"); 133 //System.out.println("ArrowView: onDraw");
138 134
135 // clear bg with color black
136 c.drawColor(Color.BLACK);
139 137
140 // draw grey circle around the arrow 138 // draw grey circle around the arrow
141 // draw grey circle around the arrow 139 // draw grey circle around the arrow
142 int indicator_radius = (int) ((Math.min(this.getWidth(), this.getHeight()) / 4) * 1.1f); 140 int indicator_radius = (int) ((Math.min(this.getWidth(), this.getHeight()) / 4) * 1.1f);
143 int indicator_dist = (Math.min(this.getHeight(), this.getWidth()) / 2) - indicator_radius / 2; 141 int indicator_dist = (Math.min(this.getHeight(), this.getWidth()) / 2) - indicator_radius / 2;
144 int[] center = new int[2]; 142 int[] center = new int[2];
145 center[0] = this.getWidth() / 2; 143 center[0] = this.getWidth() / 2;
146 center[1] = this.getHeight() / 2; 144 center[1] = this.getHeight() / 2;
147 145
148 RectF coord_rect = new RectF(center[0] - indicator_dist, center[1] - indicator_dist, 146 RectF coord_rect = new RectF(center[0] - indicator_dist, center[1] - indicator_dist, center[0] - indicator_dist + indicator_dist * 2, center[1] - indicator_dist + indicator_dist * 2);
149 center[0] - indicator_dist + indicator_dist * 2, center[1] - indicator_dist
150 + indicator_dist * 2);
151 147
152 int start = 0; // 0 148 int start = 0; // 0
153 int end = 360; // 360 149 int end = 360; // 360
154 arrow_paint.setAntiAlias(true); 150 arrow_paint.setAntiAlias(true);
155 arrow_paint.setColor(COLOR_CIRCLE_OUTLINE); 151 arrow_paint.setColor(COLOR_CIRCLE_OUTLINE);
156 arrow_paint.setStyle(Paint.Style.STROKE); 152 arrow_paint.setStyle(Paint.Style.STROKE);
157 arrow_paint.setStrokeWidth(3); 153 arrow_paint.setStrokeWidth(3 * aagtl.Global_dpi_factor);
158 c.drawArc(coord_rect, start, end, false, arrow_paint); 154 c.drawArc(coord_rect, start, end, false, arrow_paint);
159 // draw grey circle around the arrow 155 // draw grey circle around the arrow
160 // draw grey circle around the arrow 156 // draw grey circle around the arrow
161 157
162
163 Coordinate my_pos = new Coordinate(this.main_aagtl.global_settings.map_position_lat, 158 Coordinate my_pos = new Coordinate(this.main_aagtl.global_settings.map_position_lat, this.main_aagtl.global_settings.map_position_lon);
164 this.main_aagtl.global_settings.map_position_lon);
165 159
166 double display_distance = 0; 160 double display_distance = 0;
167 double display_bearing = 0; 161 double display_bearing = 0;
168 if (this.main_aagtl.rose.current_target != null) 162 if (this.main_aagtl.rose.current_target != null)
169 { 163 {
170 display_distance = my_pos.distance_to((Coordinate) (this.main_aagtl.rose.current_target)); 164 display_distance = my_pos.distance_to((Coordinate) (this.main_aagtl.rose.current_target));
171 165
172 display_bearing = my_pos.bearing_to((Coordinate) (this.main_aagtl.rose.current_target)) 166 display_bearing = my_pos.bearing_to((Coordinate) (this.main_aagtl.rose.current_target)) - this.main_aagtl.cross.gps_heading;
173 - this.main_aagtl.cross.gps_heading;
174 } 167 }
175 168
176 //if ((this.main_aagtl.cross.gps_heading != -1) && (this.main_aagtl.isGPSFix)) 169 //if ((this.main_aagtl.cross.gps_heading != -1) && (this.main_aagtl.isGPSFix))
177 if (this.main_aagtl.cross.gps_heading != -1) 170 if (this.main_aagtl.cross.gps_heading != -1)
178 { 171 {
179 double display_north = Math.toRadians(this.main_aagtl.cross.gps_heading); 172 double display_north = Math.toRadians(this.main_aagtl.cross.gps_heading);
180 int position_x = (int) (this.getWidth() / 2 - Math.sin(display_north) 173 int position_x = (int) (this.getWidth() / 2 - Math.sin(display_north) * (indicator_dist * 1.15));
181 * (indicator_dist * 1.15));
182 int position_y = (int) (this.getHeight() / 2 - Math.cos(display_north) 174 int position_y = (int) (this.getHeight() / 2 - Math.cos(display_north) * (indicator_dist * 1.15));
183 * (indicator_dist * 1.15));
184 175
185 text_paint.setColor(Color.WHITE); 176 text_paint.setColor(Color.WHITE);
186 c.drawText("N", position_x, position_y, text_paint); 177 c.drawText("N", position_x, position_y, text_paint);
187 } 178 }
188 179
189 text_paint.setColor(Color.WHITE); 180 text_paint.setColor(Color.WHITE);
190 c.drawText( 181 c.drawText("distance to target: " + String.valueOf(roundTwoDecimals(display_distance)) + " m", 10 * aagtl.Global_dpi_factor, 34 * aagtl.Global_dpi_factor, text_paint);
191 "distance to target: " + String.valueOf(roundTwoDecimals(display_distance)) + " m", 10,
192 34, text_paint);
193 182
194 c.drawText("target: " + String.valueOf((int) display_bearing) + " ", 10, 2 * 34, text_paint); 183 c.drawText("target: " + String.valueOf((int) display_bearing) + " ", 10 * aagtl.Global_dpi_factor, 2 * 34 * aagtl.Global_dpi_factor, text_paint);
195 184
196 c.drawText("my heading: " + String.valueOf((int) this.main_aagtl.cross.gps_heading) + " ", 185 c.drawText("my heading: " + String.valueOf((int) this.main_aagtl.cross.gps_heading) + " ", this.getWidth() / 2, 2 * 34 * aagtl.Global_dpi_factor, text_paint);
197 this.getWidth() / 2, 2 * 34, text_paint);
198 186
199 c.drawText("gps accuracy: " + String.valueOf(roundTwoDecimals(this.main_aagtl.cross.gps_acc)) 187 c.drawText("gps accuracy: " + String.valueOf(roundTwoDecimals(this.main_aagtl.cross.gps_acc)) + " m", 10 * aagtl.Global_dpi_factor, 3 * 34 * aagtl.Global_dpi_factor, text_paint);
200 + " m", 10, 3 * 34, text_paint); 188 c.drawText("gps Sats.: " + String.valueOf((int) this.main_aagtl.cross.used_sats), 10 * aagtl.Global_dpi_factor, 4 * 34 * aagtl.Global_dpi_factor, text_paint);
201 c.drawText("gps Sats.: " + String.valueOf((int) this.main_aagtl.cross.used_sats), 10, 4 * 34,
202 text_paint);
203
204 189
205 // 190 //
206 // 191 //
207 // SUN ---------------- 192 // SUN ----------------
208 // 193 //
209 // 194 //
210 this.calc_sun_stats(); 195 this.calc_sun_stats();
211 c.drawText("sunrise: " + this.sunrise_cache, 10, this.getHeight() - 34 * 4, text_paint); 196 c.drawText("sunrise: " + this.sunrise_cache, 10 * aagtl.Global_dpi_factor, this.getHeight() - 34 * 4 * aagtl.Global_dpi_factor, text_paint);
212 c.drawText("sunset: " + this.sunset_cache, 10, this.getHeight() - 34 * 3, text_paint); 197 c.drawText("sunset: " + this.sunset_cache, 10 * aagtl.Global_dpi_factor, this.getHeight() - 34 * 3 * aagtl.Global_dpi_factor, text_paint);
213
214 198
215 if (elevation < -0.83) 199 if (elevation < -0.83)
216 { 200 {
217 c.drawText("elevation: *night*", this.getWidth() / 2, this.getHeight() - 34 * 4, 201 c.drawText("elevation: *night*", this.getWidth() / 2, this.getHeight() - 34 * 4 * aagtl.Global_dpi_factor, text_paint);
218 text_paint);
219 } 202 }
220 else 203 else
221 { 204 {
222 c.drawText("elevation: " + roundTwoDecimals(elevation), this.getWidth() / 2, this 205 c.drawText("elevation: " + roundTwoDecimals(elevation), this.getWidth() / 2, this.getHeight() - 34 * 4 * aagtl.Global_dpi_factor, text_paint);
223 .getHeight() - 34 * 4, text_paint);
224 } 206 }
225 207
226 c.drawText("azimuth: " + roundTwoDecimals(this.azmiuth_cache), this.getWidth() / 2, this 208 c.drawText("azimuth: " + roundTwoDecimals(this.azmiuth_cache), this.getWidth() / 2, this.getHeight() - 34 * 3 * aagtl.Global_dpi_factor, text_paint);
227 .getHeight() - 34 * 3, text_paint);
228 // 209 //
229 // 210 //
230 // SUN ---------------- 211 // SUN ----------------
231 // 212 //
232 // 213 //
233 214
234
235 if (this.main_aagtl.rose.current_target != null) 215 if (this.main_aagtl.rose.current_target != null)
236 { 216 {
237 // gc-code 217 // gc-code
238 c.drawText("Geocache: " + this.main_aagtl.rose.current_target.name, 10, 218 c.drawText("Geocache: " + this.main_aagtl.rose.current_target.name, 10 * aagtl.Global_dpi_factor, this.getHeight() - 34 * 2 * aagtl.Global_dpi_factor, text_paint);
239 this.getHeight() - 34 * 2, text_paint);
240 // cache name 219 // cache name
241 c.drawText(this.main_aagtl.rose.current_target.title, 10, this.getHeight() - 34, 220 c.drawText(this.main_aagtl.rose.current_target.title, 10 * aagtl.Global_dpi_factor, this.getHeight() - 34 * aagtl.Global_dpi_factor, text_paint);
242 text_paint);
243 } 221 }
244 222
245 // draw signal indicator , part 1 223 // draw signal indicator , part 1
246 int signal_width = 15; 224 int signal_width = 15;
247 RectF coord_rect3 = new RectF(this.getWidth() - signal_width - 2, 0, this.getWidth(), this 225 RectF coord_rect3 = new RectF(this.getWidth() - signal_width - 2, 0, this.getWidth(), this.getHeight());
248 .getHeight());
249 arrow_paint.setColor(COLOR_QUALITY_OUTER); 226 arrow_paint.setColor(COLOR_QUALITY_OUTER);
250 arrow_paint.setStyle(Paint.Style.STROKE); 227 arrow_paint.setStyle(Paint.Style.STROKE);
251 arrow_paint.setStrokeWidth(3); 228 arrow_paint.setStrokeWidth(3);
252 c.drawRect(coord_rect3, arrow_paint); 229 c.drawRect(coord_rect3, arrow_paint);
253 230
254 // draw signal indicator , part 2 231 // draw signal indicator , part 2
255 int usable_height = this.getHeight() - 1; 232 int usable_height = this.getHeight() - 1;
256 int target_height = (int) (usable_height * ((float) (this.main_aagtl.cross.used_sats) / (float) (13))); 233 int target_height = (int) (usable_height * ((float) (this.main_aagtl.cross.used_sats) / (float) (13)));
257 RectF coord_rect7 = new RectF(this.getWidth() - signal_width - 1, usable_height 234 RectF coord_rect7 = new RectF(this.getWidth() - signal_width - 1, usable_height - target_height, this.getWidth() - 1, usable_height);
258 - target_height, this.getWidth() - 1, usable_height);
259 arrow_paint.setColor(COLOR_QUALITY_INNER); 235 arrow_paint.setColor(COLOR_QUALITY_INNER);
260 arrow_paint.setStyle(Paint.Style.FILL); 236 arrow_paint.setStyle(Paint.Style.FILL);
261 c.drawRect(coord_rect7, arrow_paint); 237 c.drawRect(coord_rect7, arrow_paint);
262 238
263
264 if (this.main_aagtl.rose.current_target != null) 239 if (this.main_aagtl.rose.current_target != null)
265 { 240 {
266 arrow_paint.setStrokeWidth(1); 241 arrow_paint.setStrokeWidth(1 * aagtl.Global_dpi_factor);
267 int arrow_color; 242 int arrow_color;
268 if (display_distance < 50) 243 if (display_distance < 50)
269 { 244 {
270 arrow_color = COLOR_ARROW_ATTARGET; 245 arrow_color = COLOR_ARROW_ATTARGET;
271 } 246 }
280 255
281 if (display_distance > DISTANCE_DISABLE_ARROW) 256 if (display_distance > DISTANCE_DISABLE_ARROW)
282 { 257 {
283 //c.drawLines(pts, paint) ; 258 //c.drawLines(pts, paint) ;
284 double[] arrow_transformed = new double[8]; 259 double[] arrow_transformed = new double[8];
285 arrow_transformed = this.__get_arrow_transformed(0, 0, this.getWidth(), this 260 arrow_transformed = this.__get_arrow_transformed(0, 0, this.getWidth(), this.getHeight(), display_bearing, 0.22);
286 .getHeight(), display_bearing, 0.22);
287 Path p = new Path(); 261 Path p = new Path();
288 for (int i = 0; i < 4; i++) 262 for (int i = 0; i < 4; i++)
289 { 263 {
290 if (i == 0) 264 if (i == 0)
291 { 265 {
292 p.moveTo((float) arrow_transformed[(i + 1) * 2 - 2], 266 p.moveTo((float) arrow_transformed[(i + 1) * 2 - 2], (float) arrow_transformed[(i + 1) * 2 - 1]);
293 (float) arrow_transformed[(i + 1) * 2 - 1]);
294 } 267 }
295 else 268 else
296 { 269 {
297 p.lineTo((float) arrow_transformed[(i + 1) * 2 - 2], 270 p.lineTo((float) arrow_transformed[(i + 1) * 2 - 2], (float) arrow_transformed[(i + 1) * 2 - 1]);
298 (float) arrow_transformed[(i + 1) * 2 - 1]);
299 } 271 }
300 } 272 }
301 p.close(); 273 p.close();
302 arrow_paint.setStyle(Paint.Style.FILL); 274 arrow_paint.setStyle(Paint.Style.FILL);
303 arrow_paint.setAntiAlias(true); 275 arrow_paint.setAntiAlias(true);
305 c.drawPath(p, arrow_paint); 277 c.drawPath(p, arrow_paint);
306 } 278 }
307 else 279 else
308 { 280 {
309 double circle_size = Math.max(this.getHeight() / 2.5, this.getWidth() / 2.5); 281 double circle_size = Math.max(this.getHeight() / 2.5, this.getWidth() / 2.5);
310 RectF coord_rect2 = new RectF((int) (this.getWidth() / 2 - circle_size / 2), 282 RectF coord_rect2 = new RectF((int) (this.getWidth() / 2 - circle_size / 2), (int) (this.getHeight() / 2 - circle_size / 2), (int) (this.getWidth() / 2 + circle_size / 2), (int) (this.getHeight() / 2 + circle_size / 2));
311 (int) (this.getHeight() / 2 - circle_size / 2),
312 (int) (this.getWidth() / 2 + circle_size / 2),
313 (int) (this.getHeight() / 2 + circle_size / 2));
314 arrow_paint.setStyle(Paint.Style.FILL); 283 arrow_paint.setStyle(Paint.Style.FILL);
315 arrow_paint.setAntiAlias(true); 284 arrow_paint.setAntiAlias(true);
316 arrow_paint.setColor(arrow_color); 285 arrow_paint.setColor(arrow_color);
317 c.drawArc(coord_rect2, 0, 360, false, arrow_paint); 286 c.drawArc(coord_rect2, 0, 360, false, arrow_paint);
318 } 287 }
319 } 288 }
320 } 289 }
321 290
322 public double[] __get_arrow_transformed(int x1, int y1, int width, int height, double angle, 291 public double[] __get_arrow_transformed(int x1, int y1, int width, int height, double angle, double size_offset)
323 double size_offset)
324 { 292 {
325 293
326 double[] ARROW_SHAPE = new double[8]; 294 double[] ARROW_SHAPE = new double[8];
327 ARROW_SHAPE[0] = 0; 295 ARROW_SHAPE[0] = 0;
328 ARROW_SHAPE[1] = -2 + this.ARROW_OFFSET; 296 ARROW_SHAPE[1] = -2 + this.ARROW_OFFSET;
334 ARROW_SHAPE[7] = 1 + this.ARROW_OFFSET; 302 ARROW_SHAPE[7] = 1 + this.ARROW_OFFSET;
335 // ARROW_SHAPE[0]=1.1; 303 // ARROW_SHAPE[0]=1.1;
336 // // ARROW_SHAPE=(0, -2 + this.ARROW_OFFSET, 1, + 1 + this.ARROW_OFFSET 304 // // ARROW_SHAPE=(0, -2 + this.ARROW_OFFSET, 1, + 1 + this.ARROW_OFFSET
337 // , 0, 0 + this.ARROW_OFFSET, -1, 1 + this.ARROW_OFFSET); 305 // , 0, 0 + this.ARROW_OFFSET, -1, 1 + this.ARROW_OFFSET);
338 306
339
340 double multiply = (Math.min(width, height) * 0.7) / (2 * (this.ARROW_OFFSET)) * size_offset; 307 double multiply = (Math.min(width, height) * 0.7) / (2 * (this.ARROW_OFFSET)) * size_offset;
341 double offset_x = width / 2; 308 double offset_x = width / 2;
342 double offset_y = height / 2; 309 double offset_y = height / 2;
343 310
344 double s = Math.sin(Math.toRadians(angle)); 311 double s = Math.sin(Math.toRadians(angle));

Legend:
Removed from v.3  
changed lines
  Added in v.4

   
Visit the aagtl Website