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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 50 - (show annotations) (download)
Wed Jun 22 07:33:35 2016 UTC (7 years, 9 months ago) by zoff99
File size: 43589 byte(s)
v2.0.51
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011 - 2014 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 /**
21 * Navit, a modular navigation system.
22 * Copyright (C) 2005-2008 Navit Team
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * version 2 as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the
35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36 * Boston, MA 02110-1301, USA.
37 */
38
39 package com.zoffcc.applications.zanavi;
40
41 import java.io.BufferedWriter;
42 import java.io.File;
43 import java.io.FileWriter;
44 import java.text.DecimalFormat;
45 import java.text.DecimalFormatSymbols;
46 import java.text.SimpleDateFormat;
47 import java.util.Date;
48 import java.util.Iterator;
49 import java.util.Locale;
50
51 import android.content.Context;
52 import android.location.Criteria;
53 import android.location.GpsSatellite;
54 import android.location.GpsStatus;
55 import android.location.Location;
56 import android.location.LocationListener;
57 import android.location.LocationManager;
58 import android.location.LocationProvider;
59 import android.os.Bundle;
60 import android.os.Handler;
61 import android.os.Message;
62 import android.os.SystemClock;
63 import android.text.format.DateFormat;
64 import android.util.Log;
65
66 public class NavitVehicle
67 {
68 private LocationManager locationManager = null;
69 private static LocationManager locationManager_s = null;
70 private String preciseProvider = null;
71 private String fastProvider = null;
72 private static LocationListener fastLocationListener_s = null;
73 private static LocationListener preciseLocationListener_s = null;
74 private static GpsStatus.Listener gps_status_listener_s = null;
75 private static float compass_heading;
76 private static float current_accuracy = 99999999F;
77 private static long last_real_gps_update = -1;
78 static boolean sat_status_enabled = false;
79 static boolean sat_status_icon_updated = false;
80 static int sat_status_icon_last = -1;
81 static int sat_status_icon_now = -1;
82 static float gps_last_bearing = 0.0f;
83 static double gps_last_lat = 0.0d;
84 static double gps_last_lon = 0.0d;
85 static int gps_last_lat_1000 = 0;
86 static int gps_last_lon_1000 = 0;
87 static int fast_provider_status = 0;
88 static int disregard_first_fast_location = 0;
89 static String[] cmd_name = new String[4];
90
91 static long MILLIS_AFTER_GPS_FIX_IS_LOST = 2000;
92
93 static TunnelExtrapolationThread te_thread = null;
94
95 static boolean is_pos_recording = false;
96 static File pos_recording_file;
97 // static File pos_recording_file_gpx;
98 static File speech_recording_file_gpx;
99 static BufferedWriter pos_recording_writer;
100 // static BufferedWriter pos_recording_writer_gpx;
101 static BufferedWriter speech_recording_writer_gpx;
102 static boolean speech_recording_started = false;
103 // DateFormat sdf = new DateFormat();
104
105 int sats1_old = -1;
106 int satsInFix1_old = -1;
107
108 public static Handler vehicle_handler_ = null;
109 public static long lastcompass_update_timestamp = 0L;
110
111 public static final float GPS_SPEED_ABOVE_USE_FOR_HEADING = (float) (9 / 3.6f); // (9 km/h) / (3.6) ~= m/s
112
113 private static String preciseProvider_s = null;
114 static String fastProvider_s = null;
115
116 public static long last_p_fix = 0;
117 public static long last_f_fix = 0;
118 public Bundle gps_extras = null;
119 public static GpsStatus gps_status = null;
120 public static Boolean update_location_in_progress = false;
121
122 static long last_gps_status_update = 0L;
123
124 static DecimalFormat df2 = new DecimalFormat("#.####");
125
126 public static Location last_location = null;
127
128 public static native void VehicleCallback(double lat, double lon, float speed, float direction, double height, float radius, long gpstime);
129
130 public static void VehicleCallback2(Location location)
131 {
132 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
133 String dd_text = "";
134
135 if (Navit.Global_Init_Finished != 0)
136 {
137 if (Navit.Global_Location_update_not_allowed == 0)
138 {
139 if (NavitGraphics.DEBUG_SMOOTH_DRIVING) System.out.println("DEBUG_SMOOTH_DRIVING:TMG-DEBUG:Gps");
140
141 // change bearing/direction to last good bearing -------------------
142 // change bearing/direction to last good bearing -------------------
143 // change bearing/direction to last good bearing -------------------
144 if ((location.getSpeed() < 5f) && (location.getBearing() == 0.0f) && (gps_last_bearing != 0.0f))
145 {
146 //if ((gps_last_lat_1000 == (int) (location.getLatitude() * 1000)) && (gps_last_lon_1000 == (int) (location.getLongitude() * 1000)))
147 //{
148 dd_text = dd_text + "a:";
149 location.setBearing(gps_last_bearing);
150 //}
151 }
152
153 if (location.getBearing() != 0.0f)
154 {
155 dd_text = dd_text + "n:";
156 gps_last_bearing = location.getBearing();
157 }
158 // change bearing/direction to last good bearing -------------------
159 // change bearing/direction to last good bearing -------------------
160 // change bearing/direction to last good bearing -------------------
161
162 if (Navit.p.PREF_enable_debug_write_gpx)
163 {
164 pos_recording_add(1, location.getLatitude(), location.getLongitude(), location.getSpeed(), location.getBearing(), location.getTime());
165 }
166
167 if (Navit.NAVIT_DEBUG_TEXT_VIEW) ZANaviOSDDebug01.add_text(dd_text + "b=" + location.getBearing() + " lb=" + gps_last_bearing);
168
169 Navit.cwthr.VehicleCallback3(location);
170 gps_last_lat = location.getLatitude();
171 gps_last_lon = location.getLongitude();
172 gps_last_lat_1000 = (int) (gps_last_lat * 1000);
173 gps_last_lon_1000 = (int) (gps_last_lon * 1000);
174 }
175 }
176 else
177 {
178 System.out.println("VehicleCallback2:Global_Init_Finished == 0 !!!!!!!");
179 }
180
181 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
182
183 }
184
185 // private static SatStatusThread st = null;
186
187 private class SatStatusThread extends Thread
188 {
189 // get new gpsstatus --------
190 int sats1 = 0;
191 int satsInFix1 = 0;
192 Boolean running = true;
193
194 public void run()
195 {
196 this.running = true;
197
198 while (this.running)
199 {
200 try
201 {
202 if (!Navit.DemoVehicle)
203 {
204 GpsStatus stat = locationManager.getGpsStatus(gps_status);
205 gps_status = stat;
206 Iterator<GpsSatellite> localIterator = stat.getSatellites().iterator();
207 while (localIterator.hasNext())
208 {
209 GpsSatellite localGpsSatellite = (GpsSatellite) localIterator.next();
210 sats1++;
211 if (localGpsSatellite.usedInFix())
212 {
213 satsInFix1++;
214 }
215 }
216 }
217 }
218 catch (Exception e)
219 {
220 e.printStackTrace();
221 }
222 // System.out.println("Statellites (Thread): " + satsInFix1 + "/" + sats1);
223 // Navit.set_debug_messages3_wrapper("sat: " + satsInFix1 + "/" + sats1);
224 // get new gpsstatus --------
225
226 try
227 {
228 Thread.sleep(2000);
229 }
230 catch (InterruptedException e)
231 {
232 }
233 }
234 }
235
236 public void stop_me()
237 {
238 this.running = false;
239 }
240 }
241
242 NavitVehicle(Context context)
243 {
244 // ---------------------
245 // ---------------------
246 // ------- DEBUG: test #ifdef equivalent --------
247 // ---------------------
248 // final long ccccc = 2000000000L; // 2.000.000.000 (2 billion) iterations!
249 // // ---------------------
250 // final boolean flag1 = true;
251 // final boolean flag2 = false;
252 // // ---------------------
253 // long aa1 = System.currentTimeMillis();
254 // long j = 0;
255 // while (j < ccccc)
256 // {
257 // if (flag1)
258 // {
259 // if (flag2)
260 // {
261 // j++;
262 // }
263 // else
264 // {
265 // j++;
266 // }
267 // }
268 // }
269 // long aa2 = System.currentTimeMillis();
270 // System.out.println("NVVVVV:3a:" + ((float) (aa2 - aa1) / 1000f));
271 // // ---------------------
272 // boolean flag1b = true;
273 // boolean flag2b = false;
274 // // ---------------------
275 // aa1 = System.currentTimeMillis();
276 // j = 0;
277 // while (j < ccccc)
278 // {
279 // if (flag1b)
280 // {
281 // if (flag2b)
282 // {
283 // j++;
284 // }
285 // else
286 // {
287 // j++;
288 // }
289 // }
290 // }
291 // aa2 = System.currentTimeMillis();
292 // System.out.println("NVVVVV:3b:" + ((float) (aa2 - aa1) / 1000f));
293 // // ---------------------
294 // // ---------------------
295 // aa1 = System.currentTimeMillis();
296 // j = 0;
297 // while (j < ccccc)
298 // {
299 // j++;
300 // }
301 // aa2 = System.currentTimeMillis();
302 // System.out.println("NVVVVV:3c:" + ((float) (aa2 - aa1) / 1000f));
303 // ---------------------
304 // ---------------------
305 // ------- DEBUG test #ifdef equivalent --------
306 // ---------------------
307 // ---------------------
308
309 vehicle_handler_ = Navit.vehicle_handler;
310
311 cmd_name[0] = "-";
312 cmd_name[1] = "POS";
313 cmd_name[2] = "CLR";
314 cmd_name[3] = "DST";
315
316 locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
317 locationManager_s = locationManager;
318
319 LocationListener fastLocationListener = new LocationListener()
320 {
321 public void onLocationChanged(Location location)
322 {
323 if (disregard_first_fast_location > 0)
324 {
325 Log.e("NavitVehicle", "LocationChanged provider=fast" + " disregard_first_fast_location=" + disregard_first_fast_location);
326
327 disregard_first_fast_location--;
328 return;
329 }
330
331 last_f_fix = location.getTime();
332 // if last gps fix was longer than 8 secs. ago, use this fix
333 // and we dont have a GPS lock
334 if ((last_p_fix + 8000 < last_f_fix) && (Navit.satsInFix < 3))
335 {
336 if (Navit.p.PREF_follow_gps)
337 {
338 if (Navit.p.PREF_use_compass_heading_base)
339 {
340 if ((Navit.p.PREF_use_compass_heading_always) || (location.getSpeed() < GPS_SPEED_ABOVE_USE_FOR_HEADING))
341 {
342 // use compass heading
343 location.setBearing(compass_heading);
344 }
345 }
346
347 //System.out.println("send values 1");
348 // Log.e("NavitVehicle", "LocationChanged provider=fast Latitude " + location.getLatitude() + " Longitude " + location.getLongitude());
349 last_location = location;
350 if (!Navit.DemoVehicle)
351 {
352 //Log.e("NavitVehicle", "call VehicleCallback 001");
353 VehicleCallback2(location);
354 }
355 }
356 }
357 }
358
359 public void onProviderDisabled(String provider)
360 {
361 //Log.e("NavitVehicle", "onProviderDisabled -> provider=" + provider);
362 }
363
364 public void onProviderEnabled(String provider)
365 {
366 //Log.e("NavitVehicle", "onProviderEnabled -> provider=" + provider);
367 }
368
369 public void onStatusChanged(String provider, int status, Bundle extras)
370 {
371 //Log.e("NavitVehicle", "onStatusChanged -> provider=" + provider + " status=" + status);
372 try
373 {
374 switch (status)
375 {
376 case LocationProvider.OUT_OF_SERVICE:
377 System.out.println("*** No Service ***");
378 break;
379 case LocationProvider.TEMPORARILY_UNAVAILABLE:
380 System.out.println("*** No Fix ***");
381 break;
382 case LocationProvider.AVAILABLE:
383 System.out.println("@@@ Fix @@@");
384 break;
385 }
386 }
387 catch (Exception e)
388 {
389
390 }
391 }
392 };
393 fastLocationListener_s = fastLocationListener;
394
395 LocationListener preciseLocationListener = new LocationListener()
396 {
397 public void onLocationChanged(Location location)
398 {
399 last_p_fix = location.getTime();
400 current_accuracy = location.getAccuracy();
401
402 if (location != null)
403 {
404 Navit.mLastLocationMillis = SystemClock.elapsedRealtime();
405 Navit.mLastLocation = location;
406 }
407
408 if (Navit.p.PREF_follow_gps)
409 {
410 if (Navit.p.PREF_use_compass_heading_base)
411 {
412 if ((Navit.p.PREF_use_compass_heading_always) || (location.getSpeed() < GPS_SPEED_ABOVE_USE_FOR_HEADING))
413 {
414 // use compass heading
415 location.setBearing(compass_heading);
416 }
417 }
418 //System.out.println("send values 2");
419 //Log.e("NavitVehicle", "LocationChanged provider=precise Latitude " + location.getLatitude() + " Longitude " + location.getLongitude());
420 last_location = location;
421 //Log.e("NavitVehicle", "call VehicleCallback 002");
422 if (NavitGraphics.DEBUG_SMOOTH_DRIVING)
423 {
424 if (last_real_gps_update > -1)
425 {
426 Log.e("NavitVehicle", "gps-gap:" + (System.currentTimeMillis() - last_real_gps_update));
427 }
428 last_real_gps_update = System.currentTimeMillis();
429 }
430 VehicleCallback2(location);
431 }
432 }
433
434 public void onProviderDisabled(String provider)
435 {
436 //Log.e("NavitVehicle", "onProviderDisabled -> provider=" + provider);
437 }
438
439 public void onProviderEnabled(String provider)
440 {
441 //Log.e("NavitVehicle", "onProviderEnabled -> provider=" + provider);
442 }
443
444 public void onStatusChanged(String provider, int status, Bundle extras)
445 {
446 //Log.e("NavitVehicle", "onStatusChanged -> provider=" + provider + " status=" + status);
447
448 try
449 {
450 if (status == GpsStatus.GPS_EVENT_FIRST_FIX)
451 {
452 System.out.println("*** GPS first fix ***");
453 }
454 switch (status)
455 {
456 case LocationProvider.OUT_OF_SERVICE:
457 System.out.println("*** No Service ***");
458 break;
459 case LocationProvider.TEMPORARILY_UNAVAILABLE:
460 System.out.println("*** No Fix ***");
461 break;
462 case LocationProvider.AVAILABLE:
463 System.out.println("@@@ Fix @@@");
464 break;
465 }
466 }
467 catch (Exception e)
468 {
469
470 }
471 }
472 };
473 preciseLocationListener_s = preciseLocationListener;
474
475 /*
476 * Use 2 LocationProviders, one precise (usually GPS), and one
477 * not so precise, but possible faster.
478 */
479 Criteria highCriteria = null;
480 Criteria lowCriteria = null;
481 try
482 {
483 // Selection criterias for the precise provider
484 highCriteria = new Criteria();
485 highCriteria.setAccuracy(Criteria.ACCURACY_FINE);
486 highCriteria.setAltitudeRequired(false);
487 highCriteria.setBearingRequired(true);
488 //highCriteria.setCostAllowed(true);
489 //highCriteria.setPowerRequirement(Criteria.POWER_HIGH);
490
491 // Selection criterias for the fast provider
492 lowCriteria = new Criteria();
493 lowCriteria.setAccuracy(Criteria.ACCURACY_COARSE);
494 lowCriteria.setAltitudeRequired(false);
495 lowCriteria.setBearingRequired(false);
496 lowCriteria.setCostAllowed(true);
497 lowCriteria.setPowerRequirement(Criteria.POWER_LOW);
498 }
499 catch (Exception e)
500 {
501 e.printStackTrace();
502 }
503
504 try
505 {
506 Log.e("NavitVehicle", "Providers " + locationManager.getAllProviders());
507 //
508 preciseProvider = locationManager.getBestProvider(highCriteria, false);
509 preciseProvider_s = preciseProvider;
510 Log.e("NavitVehicle", "Precise Provider " + preciseProvider);
511 fastProvider = locationManager.getBestProvider(lowCriteria, false);
512 fastProvider_s = fastProvider;
513 Log.e("NavitVehicle", "Fast Provider " + fastProvider);
514 }
515 catch (Exception e)
516 {
517 e.printStackTrace();
518 }
519
520 try
521 {
522 //*in onresume()*// locationManager.requestLocationUpdates(preciseProvider, 0, 0, preciseLocationListener);
523 }
524 catch (Exception e)
525 {
526 e.printStackTrace();
527 }
528
529 try
530 {
531 // If the 2 providers are the same, only activate one listener
532 if (fastProvider == null || preciseProvider.compareTo(fastProvider) == 0)
533 {
534 fastProvider = null;
535 }
536 else
537 {
538 if (Navit.p.PREF_use_fast_provider)
539 {
540 //*in onresume()*//locationManager.requestLocationUpdates(fastProvider, 30000L, 8.0f, fastLocationListener); // (long)time [milliseconds], (float)minDistance [meters]
541 }
542 }
543 }
544 catch (Exception e)
545 {
546 e.printStackTrace();
547 }
548
549 gps_status_listener_s = new GpsStatus.Listener()
550 {
551 public void onGpsStatusChanged(int event)
552 {
553 if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS)
554 {
555
556 boolean old_fix = Navit.isGPSFix;
557 // ------------------------------
558 // thanks to: http://stackoverflow.com/questions/2021176/how-can-i-check-the-current-status-of-the-gps-receiver
559 // ------------------------------
560 if (Navit.mLastLocation != null)
561 {
562 Navit.isGPSFix = (SystemClock.elapsedRealtime() - Navit.mLastLocationMillis) < MILLIS_AFTER_GPS_FIX_IS_LOST;
563 }
564 // if (Navit.isGPSFix)
565 // {
566 // // A fix has been acquired.
567 // }
568 // else
569 // {
570 // // The fix has been lost.
571 // }
572 if (old_fix != Navit.isGPSFix)
573 {
574 try
575 {
576 Message msg = new Message();
577 Bundle b = new Bundle();
578 b.putInt("Callback", 102);
579 if (Navit.isGPSFix)
580 {
581 b.putString("s", "1");
582 }
583 else
584 {
585 b.putString("s", "0");
586 }
587 msg.setData(b);
588 NavitGraphics.callback_handler.sendMessage(msg);
589 }
590 catch (Exception e)
591 {
592 }
593
594 if (Navit.p.PREF_show_sat_status)
595 {
596 // redraw NavitOSDJava
597 // System.out.println("onDraw:show_sat_status:1");
598 NavitGraphics.OSD_new.postInvalidate();
599 }
600
601 if (Navit.want_tunnel_extrapolation())
602 {
603 turn_on_tunnel_extrapolation();
604 }
605 else
606 {
607 turn_off_tunnel_extrapolation();
608 }
609 }
610
611 // ------------------------------
612
613 if (last_gps_status_update + 4000 < System.currentTimeMillis())
614 {
615 last_gps_status_update = System.currentTimeMillis();
616
617 // get new gpsstatus --------
618
619 sats1_old = Navit.sats;
620 satsInFix1_old = Navit.satsInFix;
621
622 GpsStatus stat = locationManager.getGpsStatus(null);
623
624 Navit.sats = 0;
625 Navit.satsInFix = 0;
626
627 try
628 {
629 Iterator<GpsSatellite> localIterator = stat.getSatellites().iterator();
630 while (localIterator.hasNext())
631 {
632 GpsSatellite localGpsSatellite = (GpsSatellite) localIterator.next();
633 Navit.sats++;
634 if (localGpsSatellite.usedInFix())
635 {
636 Navit.satsInFix++;
637 }
638 }
639
640 // System.out.println("checking sat status update");
641
642 if ((sats1_old != Navit.sats) || (satsInFix1_old != Navit.satsInFix))
643 {
644 //System.out.println("sat status update -> changed");
645 if (Navit.p.PREF_show_sat_status)
646 {
647 // redraw NavitOSDJava
648 // System.out.println("onDraw:show_sat_status:2");
649 NavitGraphics.OSD_new.postInvalidate();
650 }
651 }
652 }
653 catch (Exception e)
654 {
655 e.printStackTrace();
656 }
657 }
658
659 // Navit.set_debug_messages3_wrapper("sat: " + Navit.satsInFix + "/" + Navit.sats);
660 // System.out.println("Statellites: " + Navit.satsInFix + "/" + Navit.sats);
661 // get new gpsstatus --------
662 }
663 else if (event == GpsStatus.GPS_EVENT_FIRST_FIX)
664 {
665 Navit.isGPSFix = true;
666 turn_off_tunnel_extrapolation();
667
668 try
669 {
670 Message msg = new Message();
671 Bundle b = new Bundle();
672 b.putInt("Callback", 102);
673 b.putString("s", "1");
674 msg.setData(b);
675 NavitGraphics.callback_handler.sendMessage(msg);
676 }
677 catch (Exception e)
678 {
679 }
680
681 if (Navit.p.PREF_show_sat_status)
682 {
683 // redraw NavitOSDJava
684 // System.out.println("onDraw:show_sat_status:3");
685 NavitGraphics.OSD_new.postInvalidate();
686 }
687 }
688 else if (event == GpsStatus.GPS_EVENT_STOPPED)
689 {
690 Navit.isGPSFix = false;
691
692 if (Navit.want_tunnel_extrapolation())
693 {
694 turn_on_tunnel_extrapolation();
695 }
696
697 try
698 {
699 Message msg = new Message();
700 Bundle b = new Bundle();
701 b.putInt("Callback", 102);
702 b.putString("s", "0");
703 msg.setData(b);
704 NavitGraphics.callback_handler.sendMessage(msg);
705 }
706 catch (Exception e)
707 {
708 }
709
710 if (Navit.p.PREF_show_sat_status)
711 {
712 // redraw NavitOSDJava
713 // System.out.println("onDraw:show_sat_status:4");
714 NavitGraphics.OSD_new.postInvalidate();
715 }
716 }
717 }
718 };
719
720 }
721
722 public static void set_mock_location__fast(Location mock_location)
723 {
724 float save_speed;
725
726 try
727 {
728 //locationManager_s.setTestProviderLocation("ZANavi_mock", mock_location);
729 // mock_location;
730 // System.out.println("llllllll" + mock_location.getLatitude() + " " + mock_location.getLongitude());
731 if (mock_location != null)
732 {
733 if (mock_location.getSpeed() == 0.0f)
734 {
735 if (last_location != null)
736 {
737 save_speed = last_location.getSpeed();
738 }
739 else
740 {
741 save_speed = 0.0f;
742 last_location = mock_location;
743 }
744 mock_location.setSpeed(0.2f);
745 //Log.e("NavitVehicle", "call VehicleCallback 003");
746 VehicleCallback2(mock_location);
747 mock_location.setSpeed(save_speed);
748 }
749 else
750 {
751 //Log.e("NavitVehicle", "call VehicleCallback 004");
752 VehicleCallback2(mock_location);
753 }
754 }
755 }
756 catch (Exception e)
757 {
758 e.printStackTrace();
759 }
760 }
761
762 public static void set_mock_location__fast_no_speed(Location mock_location)
763 {
764 try
765 {
766 //locationManager_s.setTestProviderLocation("ZANavi_mock", mock_location);
767 // mock_location;
768 // System.out.println("llllllll" + mock_location.getLatitude() + " " + mock_location.getLongitude());
769 if (mock_location != null)
770 {
771 //Log.e("NavitVehicle", "call VehicleCallback 004");
772 VehicleCallback2(mock_location);
773 }
774 }
775 catch (Exception e)
776 {
777 e.printStackTrace();
778 }
779 }
780
781 public static class location_coords
782 {
783 double lat;
784 double lon;
785 }
786
787 public static location_coords get_last_known_pos()
788 {
789 location_coords ret = new location_coords();
790
791 try
792 {
793 Location l = locationManager_s.getLastKnownLocation(preciseProvider_s);
794 if (l != null)
795 {
796 if (l.getAccuracy() > 0)
797 {
798 if ((l.getLatitude() != 0) && (l.getLongitude() != 0))
799 {
800 ret.lat = l.getLatitude();
801 ret.lon = l.getLongitude();
802 return ret;
803 }
804 }
805 }
806 }
807 catch (Exception e)
808 {
809 }
810
811 try
812 {
813 // If the 2 providers are the same, only activate one listener
814 if (fastProvider_s != null)
815 {
816 if (Navit.p.PREF_use_fast_provider)
817 {
818 if (!Navit.DemoVehicle)
819 {
820 Location l = locationManager_s.getLastKnownLocation(fastProvider_s);
821 //System.out.println("ZANAVI:getLastKnownLocation=" + l);
822 if (l != null)
823 {
824 if (l.getAccuracy() > 0)
825 {
826 if ((l.getLatitude() != 0) && (l.getLongitude() != 0))
827 {
828 ret.lat = l.getLatitude();
829 ret.lon = l.getLongitude();
830 return ret;
831 }
832 }
833 }
834 }
835 }
836 }
837 }
838 catch (Exception e)
839 {
840 }
841
842 return null;
843 }
844
845 public static void set_last_known_pos_precise_provider()
846 {
847 try
848 {
849 Location l = locationManager_s.getLastKnownLocation(preciseProvider_s);
850 if (l != null)
851 {
852 if (l.getAccuracy() > 0)
853 {
854 if ((l.getLatitude() != 0) && (l.getLongitude() != 0))
855 {
856 if (Navit.p.PREF_follow_gps)
857 {
858 // Log.e("NavitVehicle", "getLastKnownLocation precise (2) l=" + l.toString());
859 last_location = l;
860 //Log.e("NavitVehicle", "call VehicleCallback 005");
861 VehicleCallback2(l);
862 }
863 }
864 }
865 }
866 }
867 catch (Exception e)
868 {
869 e.printStackTrace();
870 }
871 }
872
873 public static void set_last_known_pos_fast_provider()
874 {
875 // System.out.println("fast_provider_status=" + fast_provider_status);
876
877 if (fast_provider_status == 0)
878 {
879 return;
880 }
881
882 try
883 {
884 // If the 2 providers are the same, only activate one listener
885 if (fastProvider_s != null)
886 {
887 if (Navit.p.PREF_use_fast_provider)
888 {
889 if (!Navit.DemoVehicle)
890 {
891 Location l = locationManager_s.getLastKnownLocation(fastProvider_s);
892 //System.out.println("ZANAVI:getLastKnownLocation=" + l);
893 if (l != null)
894 {
895 if (l.getAccuracy() > 0)
896 {
897 if ((l.getLatitude() != 0) && (l.getLongitude() != 0))
898 {
899 if (Navit.p.PREF_follow_gps)
900 {
901 // Log.e("NavitVehicle", "getLastKnownLocation fast (3) l=" + l.toString());
902 last_location = l;
903 //Log.e("NavitVehicle", "call VehicleCallback 006");
904 //System.out.println("ZANAVI:set_last_known_pos_fast_provider");
905 VehicleCallback2(l);
906 }
907 }
908 }
909 }
910 }
911 }
912 }
913 }
914 catch (Exception e)
915 {
916 e.printStackTrace();
917 }
918
919 }
920
921 public static void turn_on_fast_provider()
922 {
923 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
924
925 try
926 {
927 // If the 2 providers are the same, only activate one listener
928 if (fastProvider_s != null)
929 {
930 if (Navit.p.PREF_use_fast_provider)
931 {
932 if (!Navit.DemoVehicle)
933 {
934 disregard_first_fast_location = 2;
935 locationManager_s.requestLocationUpdates(fastProvider_s, 30000L, 8.0f, fastLocationListener_s); // (long)time [milliseconds], (float)minDistance [meters]
936
937 fast_provider_status = 1;
938 //System.out.println("ZANAVI:turn on fast provider");
939 }
940 }
941 }
942 }
943 catch (Exception e)
944 {
945 e.printStackTrace();
946 }
947
948 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
949 }
950
951 public static void turn_on_precise_provider()
952 {
953 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
954
955 try
956 {
957 locationManager_s.requestLocationUpdates(preciseProvider_s, 0, 0, preciseLocationListener_s);
958 }
959 catch (Exception e)
960 {
961 e.printStackTrace();
962 }
963
964 turn_on_sat_status();
965
966 try
967 {
968 // try to download aGPS data!!
969 if (Navit.p.PREF_use_agps)
970 {
971 Navit.downloadGPSXtra(Navit.getBaseContext_);
972 }
973 }
974 catch (Exception e)
975 {
976 e.printStackTrace();
977 }
978
979 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
980
981 }
982
983 public static void turn_off_precise_provider()
984 {
985 try
986 {
987 if (preciseProvider_s != null)
988 {
989 locationManager_s.removeUpdates(preciseLocationListener_s);
990 }
991 }
992 catch (Exception e)
993 {
994 e.printStackTrace();
995 }
996
997 turn_off_sat_status();
998 }
999
1000 public static void turn_on_sat_status()
1001 {
1002 try
1003 {
1004 Navit.sats = 0;
1005 Navit.satsInFix = 0;
1006 if (preciseProvider_s != null)
1007 {
1008 try
1009 {
1010 locationManager_s.removeGpsStatusListener(gps_status_listener_s);
1011 }
1012 catch (Exception e3)
1013 {
1014 e3.printStackTrace();
1015 }
1016 locationManager_s.addGpsStatusListener(gps_status_listener_s);
1017 sat_status_enabled = true;
1018 }
1019 }
1020 catch (Exception e)
1021 {
1022 e.printStackTrace();
1023 }
1024 //System.out.println("turn_ON_sat_status");
1025 }
1026
1027 public static void turn_off_sat_status()
1028 {
1029 try
1030 {
1031 Navit.sats = 0;
1032 Navit.satsInFix = 0;
1033 sat_status_enabled = true;
1034
1035 if (preciseProvider_s != null)
1036 {
1037 locationManager_s.removeGpsStatusListener(gps_status_listener_s);
1038 }
1039 }
1040 catch (Exception e)
1041 {
1042 e.printStackTrace();
1043 }
1044 //System.out.println("turn_off_sat_status");
1045 }
1046
1047 public static void turn_off_fast_provider()
1048 {
1049 try
1050 {
1051 fast_provider_status = 0;
1052 if (fastProvider_s != null)
1053 {
1054 locationManager_s.removeUpdates(fastLocationListener_s);
1055 }
1056 }
1057 catch (Exception e)
1058 {
1059 e.printStackTrace();
1060 }
1061 }
1062
1063 public static class TunnelExtrapolationThread extends Thread
1064 {
1065 private Boolean running;
1066 private static int interval_millis = 990;
1067
1068 TunnelExtrapolationThread()
1069 {
1070 this.running = true;
1071 }
1072
1073 public void run()
1074 {
1075 System.out.println("TunnelExtrapolationThread -- started --");
1076 while (this.running)
1077 {
1078 // request tunnel extrapolation from C code ------------------
1079 // request tunnel extrapolation from C code ------------------
1080
1081 String extrapolated_post_string = NavitGraphics.CallbackGeoCalc(12, 1, interval_millis);
1082
1083 if (extrapolated_post_string == null)
1084 {
1085 System.out.println("extrapolated pos:*ERROR.1*");
1086 }
1087 else if (extrapolated_post_string.equals("*ERROR*"))
1088 {
1089 System.out.println("extrapolated pos:*ERROR.2*");
1090 }
1091 else
1092 {
1093 try
1094 {
1095 // System.out.println("extrapolated pos:" + extrapolated_post_string);
1096 String tmp[] = extrapolated_post_string.split(":", 3);
1097 float lat = Float.parseFloat(tmp[0]);
1098 float lon = Float.parseFloat(tmp[1]);
1099 float dir = Float.parseFloat(tmp[2]);
1100 // System.out.println("extrapolated pos:" + lat + " " + lon + " " + dir);
1101
1102 Location l = new Location("ZANavi Tunnel Extrapolation");
1103 l.setLatitude(lat);
1104 l.setLongitude(lon);
1105 l.setBearing(dir);
1106 l.setSpeed(50.0f / 3.6f); // in m/s
1107 l.setAccuracy(4.0f); // accuracy 4 meters
1108 // NavitVehicle.update_compass_heading(dir);
1109 NavitVehicle.set_mock_location__fast(l);
1110 }
1111 catch (Exception e)
1112 {
1113 e.printStackTrace();
1114 }
1115 }
1116
1117 try
1118 {
1119 Thread.sleep(interval_millis);
1120 }
1121 catch (InterruptedException e)
1122 {
1123 }
1124 }
1125 }
1126
1127 public void stop_me()
1128 {
1129 this.running = false;
1130 this.interrupt();
1131 }
1132 }
1133
1134 static synchronized void turn_on_tunnel_extrapolation()
1135 {
1136 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
1137
1138 if (Navit.CIDEBUG == 0)
1139 {
1140
1141 if (!Navit.tunnel_extrapolation)
1142 {
1143 if (te_thread != null)
1144 {
1145 try
1146 {
1147 // try to clean up old thread
1148 te_thread.stop_me();
1149 te_thread = null;
1150 }
1151 catch (Exception e)
1152 {
1153 e.printStackTrace();
1154 }
1155 }
1156
1157 te_thread = new TunnelExtrapolationThread();
1158 te_thread.start();
1159 }
1160 Navit.tunnel_extrapolation = true;
1161
1162 }
1163
1164 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
1165 }
1166
1167 static synchronized void turn_off_tunnel_extrapolation()
1168 {
1169 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
1170
1171 if (Navit.CIDEBUG == 0)
1172 {
1173
1174 if (Navit.tunnel_extrapolation)
1175 {
1176 if (te_thread != null)
1177 {
1178 try
1179 {
1180 // try to stop thread
1181 te_thread.stop_me();
1182 te_thread = null;
1183 }
1184 catch (Exception e)
1185 {
1186 e.printStackTrace();
1187 }
1188 }
1189 }
1190 Navit.tunnel_extrapolation = false;
1191
1192 }
1193
1194 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
1195 }
1196
1197 public static void turn_off_all_providers()
1198 {
1199 turn_off_precise_provider();
1200 turn_off_fast_provider();
1201 }
1202
1203 public static void update_compass_heading_force(float heading)
1204 {
1205 try
1206 {
1207 Location l = new Location("ZANavi Dummy");
1208 l.setLatitude(0.0);
1209 l.setLongitude(0.0);
1210 l.setAccuracy(4.0f); // accuracy 4 meters
1211 l.setBearing(heading);
1212 l.setSpeed(4.0f);
1213 VehicleCallback2(l);
1214 }
1215 catch (Exception e)
1216 {
1217 //e.printStackTrace();
1218 }
1219 }
1220
1221 public static void update_compass_heading(float heading)
1222 {
1223 compass_heading = heading;
1224 // use compass heading
1225 try
1226 {
1227 if (Navit.p.PREF_use_compass_heading_base)
1228 {
1229 if ((Navit.p.PREF_use_compass_heading_always) || (last_location.getSpeed() < GPS_SPEED_ABOVE_USE_FOR_HEADING))
1230 {
1231 if ((lastcompass_update_timestamp + 400) > System.currentTimeMillis())
1232 {
1233 //Log.e("NavitVehicle", "compass update to fast!");
1234 return;
1235 }
1236 lastcompass_update_timestamp = System.currentTimeMillis();
1237
1238 last_location.setBearing(compass_heading);
1239 // !! ugly hack to make map redraw !!
1240 // !! ugly hack to make map redraw !!
1241 // !! ugly hack to make map redraw !!
1242 if (last_location.getSpeed() == 0.0f)
1243 {
1244 float save_speed = last_location.getSpeed();
1245 last_location.setSpeed(0.2f);
1246 if (!Navit.DemoVehicle)
1247 {
1248 //Log.e("NavitVehicle", "call VehicleCallback 007:start");
1249 VehicleCallback2(last_location);
1250 /*
1251 * Message m2 = new Message();
1252 * m2.what = 2;
1253 * vehicle_handler_.handleMessage(m2);
1254 */
1255 //Log.e("NavitVehicle", "call VehicleCallback 007:end");
1256 }
1257 last_location.setSpeed(save_speed);
1258 }
1259 else
1260 {
1261 if (!Navit.DemoVehicle)
1262 {
1263 //Log.e("NavitVehicle", "call VehicleCallback 008");
1264 VehicleCallback2(last_location);
1265 }
1266 }
1267 // !! ugly hack to make map redraw !!
1268 // !! ugly hack to make map redraw !!
1269 // !! ugly hack to make map redraw !!
1270 }
1271 }
1272 }
1273 catch (Exception e)
1274 {
1275 //e.printStackTrace();
1276 }
1277 }
1278
1279 static void speech_recording_start()
1280 {
1281 speech_recording_started = true;
1282
1283 String pos_recording_filename_gpx_base = Navit.NAVIT_DATA_DEBUG_DIR + "zanavi_speech_recording";
1284 String pos_recording_filename_gpx = pos_recording_filename_gpx_base + ".gpx";
1285 String date = new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.GERMAN).format(new Date());
1286 String pos_recording_filename_gpx_archive = pos_recording_filename_gpx_base + "_" + date + ".gpx";
1287
1288 String gpx_header_1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>" + "<gpx version=\"1.1\" creator=\"ZANavi http://zanavi.cc\"\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xmlns=\"http://www.topografix.com/GPX/1/1\"\n" + " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n" + "<metadata>\n" + " <name>ZANavi Debug log</name>\n" + " <desc>ZANavi</desc>\n" + " <author>\n"
1289 + " <name>ZANavi</name>\n" + " </author>\n" + "</metadata>\n";
1290
1291 speech_recording_file_gpx = new File(pos_recording_filename_gpx);
1292
1293 try
1294 {
1295 if (speech_recording_file_gpx.exists())
1296 {
1297 // archive old GPX file
1298 speech_recording_file_gpx.renameTo(new File(pos_recording_filename_gpx_archive));
1299 }
1300 }
1301 catch (Exception e)
1302 {
1303 }
1304
1305 try
1306 {
1307 speech_recording_file_gpx = new File(pos_recording_filename_gpx);
1308 }
1309 catch (Exception e)
1310 {
1311 }
1312
1313 try
1314 {
1315 speech_recording_writer_gpx = new BufferedWriter(new FileWriter(speech_recording_file_gpx, true));
1316 speech_recording_writer_gpx.write(gpx_header_1);
1317 // speech_recording_writer_gpx.write("<rte>\n");
1318 }
1319 catch (Exception e)
1320 {
1321 }
1322 }
1323
1324 static void speech_recording_end()
1325 {
1326
1327 String gpx_trailer_1 = "</gpx>\n";
1328
1329 try
1330 {
1331 // speech_recording_writer_gpx.write("</rte>\n");
1332 speech_recording_writer_gpx.write(gpx_trailer_1);
1333 speech_recording_writer_gpx.flush();
1334 speech_recording_writer_gpx.close();
1335 }
1336 catch (Exception e)
1337 {
1338 }
1339 }
1340
1341 static void pos_recording_start()
1342 {
1343 is_pos_recording = true;
1344
1345 String date = new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.GERMAN).format(new Date());
1346 String pos_recording_filename_base = Navit.NAVIT_DATA_DEBUG_DIR + date + "-" + "zanavi_pos_recording";
1347 String pos_recording_filename = pos_recording_filename_base + ".txt";
1348 // String pos_recording_filename_gpx_base = Navit.NAVIT_DATA_DEBUG_DIR + "zanavi_pos_recording";
1349 //String pos_recording_filename_gpx = pos_recording_filename_gpx_base + ".gpx";
1350 // String date = new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.GERMAN).format(new Date());
1351 //String pos_recording_filename_gpx_archive = pos_recording_filename_gpx_base + "_" + date + ".gpx";
1352 //String pos_recording_filename_archive = pos_recording_filename_base + "_" + date + ".txt";
1353
1354 // String gpx_header_1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>" + "<gpx version=\"1.1\" creator=\"ZANavi http://zanavi.cc\"\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xmlns=\"http://www.topografix.com/GPX/1/1\"\n" + " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n" + "<metadata>\n" + " <name>ZANavi Debug log</name>\n" + " <desc>ZANavi</desc>\n" + " <author>\n"
1355 // + " <name>ZANavi</name>\n" + " </author>\n" + "</metadata>\n" + "<trk>\n" + "<trkseg>\n" + " <name>ACTIVE LOG</name>\n";
1356
1357 pos_recording_file = new File(pos_recording_filename);
1358 //pos_recording_file_gpx = new File(pos_recording_filename_gpx);
1359
1360 // try
1361 // {
1362 // if (pos_recording_file_gpx.exists())
1363 // {
1364 // // archive old GPX file
1365 // pos_recording_file_gpx.renameTo(new File(pos_recording_filename_gpx_archive));
1366 // }
1367 // }
1368 // catch (Exception e)
1369 // {
1370 // }
1371
1372 try
1373 {
1374 pos_recording_writer = new BufferedWriter(new FileWriter(pos_recording_file, true));
1375 // pos_recording_file_gpx = new File(pos_recording_filename_gpx);
1376 }
1377 catch (Exception e)
1378 {
1379 }
1380 }
1381
1382 static void pos_recording_end()
1383 {
1384 is_pos_recording = false;
1385
1386 // String gpx_trailer_1 = "</trkseg>\n" + "</trk>\n" + "</gpx>\n";
1387
1388 try
1389 {
1390 //pos_recording_writer_gpx.write(gpx_trailer_1);
1391
1392 pos_recording_writer.close();
1393 // pos_recording_writer_gpx.close();
1394 }
1395 catch (Exception e)
1396 {
1397 }
1398 }
1399
1400 static public String customNumberFormat_(String pattern, double value)
1401 {
1402 // NumberFormat myFormatter = DecimalFormat.getInstance(Locale.US);
1403
1404 DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US);
1405 otherSymbols.setDecimalSeparator('.');
1406 DecimalFormat df = new DecimalFormat(pattern, otherSymbols);
1407
1408 String output = df.format(value);
1409 return (output);
1410 }
1411
1412 static void speech_recording_add(double lat, double lon, String text, long time)
1413 {
1414 try
1415 {
1416 String date_time_gpx = (String) DateFormat.format("yyyy-MM-dd'T'HH:mm:ss'Z'", time);
1417 // System.out.println("33XX"+date_time_gpx+"YY");
1418
1419 // speech_recording_writer_gpx.write(" <trkpt lat=\"" + customNumberFormat_("####.######", lat) + "\" lon=\"" + customNumberFormat_("####.######", lon) + "\"><time>2014-10-02T09:30:10Z</time><speed>" + customNumberFormat_("####.##", speed) + "</speed><course>" + customNumberFormat_("####.#", bearing) + "</course></trkpt>\n");
1420 // speech_recording_writer_gpx.write(" <rtept lat=\"" + customNumberFormat_("####.######", lat) + "\" lon=\"" + customNumberFormat_("####.######", lon) + "\"><name>" + text + "</name></rtept>" + "\n");
1421 speech_recording_writer_gpx.write(" <wpt lat=\"" + customNumberFormat_("####.######", lat) + "\" lon=\"" + customNumberFormat_("####.######", lon) + "\"><time>" + date_time_gpx + "</time>" + "<name>" + text + "</name><sym>Dot</sym><type>Dot</type></wpt>" + "\n");
1422 }
1423 catch (Exception e)
1424 {
1425 }
1426 }
1427
1428 static void pos_recording_add(int cmd, double lat, double lon, double speed, double bearing, long time)
1429 {
1430 if (ZANaviDebugReceiver.dont_save_loc == true)
1431 {
1432 // dont save (already saved) log
1433 return;
1434 }
1435
1436 //System.out.println("PRF:CMD=" + cmd_name[cmd] + " dst=" + Navit.global_last_destination_name);
1437
1438 if (cmd == 0) // empty lines
1439 {
1440 try
1441 {
1442 pos_recording_writer.write("\n");
1443 pos_recording_writer.write("\n");
1444 pos_recording_writer.write("\n");
1445 pos_recording_writer.write("\n");
1446 }
1447 catch (Exception e)
1448 {
1449 }
1450 }
1451 else if (cmd == 1) // POS
1452 {
1453
1454 // try
1455 // {
1456 // pos_recording_writer_gpx.write(" <trkpt lat=\"" + customNumberFormat_("####.######", lat) + "\" lon=\"" + customNumberFormat_("####.######", lon) + "\"><time>2014-10-02T09:30:10Z</time><speed>" + customNumberFormat_("####.##", speed) + "</speed><course>" + customNumberFormat_("####.#", bearing) + "</course></trkpt>\n");
1457 // }
1458 // catch (Exception e)
1459 // {
1460 // }
1461
1462 try
1463 {
1464 pos_recording_writer.write("POS:" + "\"" + customNumberFormat_("####.######", lat) + "," + customNumberFormat_("####.######", lon) + "," + customNumberFormat_("####.##", speed) + "," + customNumberFormat_("####.##", bearing) + "\"" + "\n");
1465 if (Navit.OSD_route_001.arriving_time_valid)
1466 {
1467 pos_recording_writer.write("REM:" + "\"ETA:" + Navit.OSD_route_001.arriving_time + "\"" + "\n");
1468 }
1469 }
1470 catch (Exception e)
1471 {
1472 }
1473 }
1474 else if (cmd == 2) // CLR
1475 {
1476 try
1477 {
1478 if (time == 111)
1479 {
1480 pos_recording_writer.write("CLR:" + "\"\"" + "\n");
1481 }
1482
1483 if (time == 111)
1484 {
1485
1486 // before "CLR" rotate recording file --------------------------
1487 // before "CLR" rotate recording file --------------------------
1488 String date = new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.GERMAN).format(new Date());
1489 String pos_recording_filename_base = Navit.NAVIT_DATA_DEBUG_DIR + date + "-" + "zanavi_pos_recording";
1490 String pos_recording_filename = pos_recording_filename_base + ".txt";
1491 String pos_recording_filename_archive = pos_recording_filename_base + "_" + date + ".txt";
1492
1493 //System.out.println("PRF:CLR:" + pos_recording_file.getName() + " " + pos_recording_filename_archive);
1494 pos_recording_filename_archive = Navit.NAVIT_DATA_DEBUG_DIR + "arch_" + pos_recording_file.getName();
1495
1496 //System.out.println("PRF:CLR:004:" + pos_recording_filename_archive);
1497
1498 try
1499 {
1500 if (pos_recording_file.exists())
1501 {
1502 //System.out.println("PRF:CLR:005");
1503
1504 try
1505 {
1506 pos_recording_writer.close();
1507 }
1508 catch (Exception cl001)
1509 {
1510 }
1511
1512 // archive old GPX file
1513 pos_recording_file.renameTo(new File(pos_recording_filename_archive));
1514 pos_recording_file = new File(pos_recording_filename);
1515 pos_recording_writer = new BufferedWriter(new FileWriter(pos_recording_file, true));
1516
1517 //System.out.println("PRF:CLR:006");
1518 }
1519 }
1520 catch (Exception e)
1521 {
1522 }
1523 // before "CLR" rotate recording file --------------------------
1524 // before "CLR" rotate recording file --------------------------
1525
1526 //System.out.println("PRF:CLR:007");
1527 }
1528
1529 if (time == 0)
1530 {
1531 pos_recording_writer.write("CLR:" + "\"\"" + "\n");
1532 }
1533
1534 }
1535 catch (Exception e)
1536 {
1537 }
1538 }
1539 else if (cmd == 3) // DST
1540 {
1541 try
1542 {
1543 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.GERMAN);
1544 String currentDateandTime = sdf.format(new Date());
1545
1546 try
1547 {
1548 //System.out.println("PRF:X01:" + Navit.global_last_destination_name + " " + pos_recording_file.getName());
1549
1550 if ((Navit.global_last_destination_name.compareTo("") != 0) && (pos_recording_file.getName().contains("zanavi_pos_recording")))
1551 {
1552 String date = new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.GERMAN).format(new Date());
1553 String pos_recording_filename_newname = Navit.NAVIT_DATA_DEBUG_DIR + "route-" + date + "-" + Navit.global_last_destination_name + ".txt";
1554
1555 //System.out.println("PRF:X02:" + pos_recording_filename_newname);
1556
1557 if (pos_recording_file.exists())
1558 {
1559 pos_recording_writer.close();
1560 pos_recording_file.renameTo(new File(pos_recording_filename_newname));
1561 pos_recording_file = new File(pos_recording_filename_newname);
1562 pos_recording_writer = new BufferedWriter(new FileWriter(pos_recording_file, true));
1563 }
1564 }
1565 }
1566 catch (Exception e)
1567 {
1568 }
1569
1570 pos_recording_writer.write("REM:" + "\"Date:" + currentDateandTime + "\"" + "\n");
1571 pos_recording_writer.write("DST:" + "\"" + customNumberFormat_("####.######", lat) + "," + customNumberFormat_("####.######", lon) + "\"" + "\n");
1572 if (Navit.global_last_destination_name.compareTo("") != 0)
1573 {
1574 pos_recording_writer.write("REM:" + "\"TO:" + Navit.global_last_destination_name + "\"" + "\n");
1575 }
1576
1577 }
1578 catch (Exception e)
1579 {
1580 }
1581 }
1582 }
1583
1584 static int distanceBetween(float lat1, float lon1, float lat2, float lon2)
1585 {
1586 int ret = -1;
1587
1588 float[] res = new float[3];
1589
1590 try
1591 {
1592 android.location.Location.distanceBetween(lat1, lon1, lat2, lon2, res);
1593 ret = (int) (res[0]);
1594 }
1595 catch (Exception e)
1596 {
1597 }
1598
1599 return ret;
1600 }
1601
1602 static int distanceBetween(double lat1, double lon1, double lat2, double lon2)
1603 {
1604 int ret = -1;
1605
1606 float[] res = new float[3];
1607
1608 try
1609 {
1610 android.location.Location.distanceBetween(lat1, lon1, lat2, lon2, res);
1611 ret = (int) (res[0]);
1612 }
1613 catch (Exception e)
1614 {
1615 }
1616
1617 return ret;
1618 }
1619
1620 }

   
Visit the ZANavi Wiki