/[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 47 - (show annotations) (download)
Sat Sep 12 11:02:16 2015 UTC (8 years, 6 months ago) by zoff99
File size: 43015 byte(s)
v2.0.48
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.equals("*ERROR*"))
1084 {
1085 System.out.println("extrapolated pos:*ERROR*");
1086 }
1087 else
1088 {
1089 try
1090 {
1091 // System.out.println("extrapolated pos:" + extrapolated_post_string);
1092 String tmp[] = extrapolated_post_string.split(":", 3);
1093 float lat = Float.parseFloat(tmp[0]);
1094 float lon = Float.parseFloat(tmp[1]);
1095 float dir = Float.parseFloat(tmp[2]);
1096 // System.out.println("extrapolated pos:" + lat + " " + lon + " " + dir);
1097
1098 Location l = new Location("ZANavi Tunnel Extrapolation");
1099 l.setLatitude(lat);
1100 l.setLongitude(lon);
1101 l.setBearing(dir);
1102 l.setSpeed(50.0f / 3.6f); // in m/s
1103 l.setAccuracy(4.0f); // accuracy 4 meters
1104 // NavitVehicle.update_compass_heading(dir);
1105 NavitVehicle.set_mock_location__fast(l);
1106 }
1107 catch (Exception e)
1108 {
1109 e.printStackTrace();
1110 }
1111 }
1112
1113 try
1114 {
1115 Thread.sleep(interval_millis);
1116 }
1117 catch (InterruptedException e)
1118 {
1119 }
1120 }
1121 }
1122
1123 public void stop_me()
1124 {
1125 this.running = false;
1126 this.interrupt();
1127 }
1128 }
1129
1130 static synchronized void turn_on_tunnel_extrapolation()
1131 {
1132 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
1133
1134 if (!Navit.tunnel_extrapolation)
1135 {
1136 if (te_thread != null)
1137 {
1138 try
1139 {
1140 // try to clean up old thread
1141 te_thread.stop_me();
1142 te_thread = null;
1143 }
1144 catch (Exception e)
1145 {
1146 e.printStackTrace();
1147 }
1148 }
1149
1150 te_thread = new TunnelExtrapolationThread();
1151 te_thread.start();
1152 }
1153 Navit.tunnel_extrapolation = true;
1154
1155 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
1156 }
1157
1158 static synchronized void turn_off_tunnel_extrapolation()
1159 {
1160 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
1161
1162 if (Navit.tunnel_extrapolation)
1163 {
1164 if (te_thread != null)
1165 {
1166 try
1167 {
1168 // try to stop thread
1169 te_thread.stop_me();
1170 te_thread = null;
1171 }
1172 catch (Exception e)
1173 {
1174 e.printStackTrace();
1175 }
1176 }
1177 }
1178 Navit.tunnel_extrapolation = false;
1179
1180 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
1181 }
1182
1183 public static void turn_off_all_providers()
1184 {
1185 turn_off_precise_provider();
1186 turn_off_fast_provider();
1187 }
1188
1189 public static void update_compass_heading(float heading)
1190 {
1191 compass_heading = heading;
1192 // use compass heading
1193 try
1194 {
1195 if (Navit.p.PREF_use_compass_heading_base)
1196 {
1197 if ((Navit.p.PREF_use_compass_heading_always) || (last_location.getSpeed() < GPS_SPEED_ABOVE_USE_FOR_HEADING))
1198 {
1199 if ((lastcompass_update_timestamp + 400) > System.currentTimeMillis())
1200 {
1201 //Log.e("NavitVehicle", "compass update to fast!");
1202 return;
1203 }
1204 lastcompass_update_timestamp = System.currentTimeMillis();
1205
1206 last_location.setBearing(compass_heading);
1207 // !! ugly hack to make map redraw !!
1208 // !! ugly hack to make map redraw !!
1209 // !! ugly hack to make map redraw !!
1210 if (last_location.getSpeed() == 0.0f)
1211 {
1212 float save_speed = last_location.getSpeed();
1213 last_location.setSpeed(0.2f);
1214 if (!Navit.DemoVehicle)
1215 {
1216 //Log.e("NavitVehicle", "call VehicleCallback 007:start");
1217 VehicleCallback2(last_location);
1218 /*
1219 * Message m2 = new Message();
1220 * m2.what = 2;
1221 * vehicle_handler_.handleMessage(m2);
1222 */
1223 //Log.e("NavitVehicle", "call VehicleCallback 007:end");
1224 }
1225 last_location.setSpeed(save_speed);
1226 }
1227 else
1228 {
1229 if (!Navit.DemoVehicle)
1230 {
1231 //Log.e("NavitVehicle", "call VehicleCallback 008");
1232 VehicleCallback2(last_location);
1233 }
1234 }
1235 // !! ugly hack to make map redraw !!
1236 // !! ugly hack to make map redraw !!
1237 // !! ugly hack to make map redraw !!
1238 }
1239 }
1240 }
1241 catch (Exception e)
1242 {
1243 //e.printStackTrace();
1244 }
1245 }
1246
1247 static void speech_recording_start()
1248 {
1249 speech_recording_started = true;
1250
1251 String pos_recording_filename_gpx_base = Navit.NAVIT_DATA_DEBUG_DIR + "zanavi_speech_recording";
1252 String pos_recording_filename_gpx = pos_recording_filename_gpx_base + ".gpx";
1253 String date = new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.GERMAN).format(new Date());
1254 String pos_recording_filename_gpx_archive = pos_recording_filename_gpx_base + "_" + date + ".gpx";
1255
1256 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"
1257 + " <name>ZANavi</name>\n" + " </author>\n" + "</metadata>\n";
1258
1259 speech_recording_file_gpx = new File(pos_recording_filename_gpx);
1260
1261 try
1262 {
1263 if (speech_recording_file_gpx.exists())
1264 {
1265 // archive old GPX file
1266 speech_recording_file_gpx.renameTo(new File(pos_recording_filename_gpx_archive));
1267 }
1268 }
1269 catch (Exception e)
1270 {
1271 }
1272
1273 try
1274 {
1275 speech_recording_file_gpx = new File(pos_recording_filename_gpx);
1276 }
1277 catch (Exception e)
1278 {
1279 }
1280
1281 try
1282 {
1283 speech_recording_writer_gpx = new BufferedWriter(new FileWriter(speech_recording_file_gpx, true));
1284 speech_recording_writer_gpx.write(gpx_header_1);
1285 // speech_recording_writer_gpx.write("<rte>\n");
1286 }
1287 catch (Exception e)
1288 {
1289 }
1290 }
1291
1292 static void speech_recording_end()
1293 {
1294
1295 String gpx_trailer_1 = "</gpx>\n";
1296
1297 try
1298 {
1299 // speech_recording_writer_gpx.write("</rte>\n");
1300 speech_recording_writer_gpx.write(gpx_trailer_1);
1301 speech_recording_writer_gpx.flush();
1302 speech_recording_writer_gpx.close();
1303 }
1304 catch (Exception e)
1305 {
1306 }
1307 }
1308
1309 static void pos_recording_start()
1310 {
1311 is_pos_recording = true;
1312
1313 String date = new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.GERMAN).format(new Date());
1314 String pos_recording_filename_base = Navit.NAVIT_DATA_DEBUG_DIR + date + "-" + "zanavi_pos_recording";
1315 String pos_recording_filename = pos_recording_filename_base + ".txt";
1316 // String pos_recording_filename_gpx_base = Navit.NAVIT_DATA_DEBUG_DIR + "zanavi_pos_recording";
1317 //String pos_recording_filename_gpx = pos_recording_filename_gpx_base + ".gpx";
1318 // String date = new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.GERMAN).format(new Date());
1319 //String pos_recording_filename_gpx_archive = pos_recording_filename_gpx_base + "_" + date + ".gpx";
1320 //String pos_recording_filename_archive = pos_recording_filename_base + "_" + date + ".txt";
1321
1322 // 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"
1323 // + " <name>ZANavi</name>\n" + " </author>\n" + "</metadata>\n" + "<trk>\n" + "<trkseg>\n" + " <name>ACTIVE LOG</name>\n";
1324
1325 pos_recording_file = new File(pos_recording_filename);
1326 //pos_recording_file_gpx = new File(pos_recording_filename_gpx);
1327
1328 // try
1329 // {
1330 // if (pos_recording_file_gpx.exists())
1331 // {
1332 // // archive old GPX file
1333 // pos_recording_file_gpx.renameTo(new File(pos_recording_filename_gpx_archive));
1334 // }
1335 // }
1336 // catch (Exception e)
1337 // {
1338 // }
1339
1340 try
1341 {
1342 pos_recording_writer = new BufferedWriter(new FileWriter(pos_recording_file, true));
1343 // pos_recording_file_gpx = new File(pos_recording_filename_gpx);
1344 }
1345 catch (Exception e)
1346 {
1347 }
1348 }
1349
1350 static void pos_recording_end()
1351 {
1352 is_pos_recording = false;
1353
1354 // String gpx_trailer_1 = "</trkseg>\n" + "</trk>\n" + "</gpx>\n";
1355
1356 try
1357 {
1358 //pos_recording_writer_gpx.write(gpx_trailer_1);
1359
1360 pos_recording_writer.close();
1361 // pos_recording_writer_gpx.close();
1362 }
1363 catch (Exception e)
1364 {
1365 }
1366 }
1367
1368 static public String customNumberFormat_(String pattern, double value)
1369 {
1370 // NumberFormat myFormatter = DecimalFormat.getInstance(Locale.US);
1371
1372 DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US);
1373 otherSymbols.setDecimalSeparator('.');
1374 DecimalFormat df = new DecimalFormat(pattern, otherSymbols);
1375
1376 String output = df.format(value);
1377 return (output);
1378 }
1379
1380 static void speech_recording_add(double lat, double lon, String text, long time)
1381 {
1382 try
1383 {
1384 String date_time_gpx = (String) DateFormat.format("yyyy-MM-dd'T'HH:mm:ss'Z'", time);
1385 // System.out.println("33XX"+date_time_gpx+"YY");
1386
1387 // 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");
1388 // speech_recording_writer_gpx.write(" <rtept lat=\"" + customNumberFormat_("####.######", lat) + "\" lon=\"" + customNumberFormat_("####.######", lon) + "\"><name>" + text + "</name></rtept>" + "\n");
1389 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");
1390 }
1391 catch (Exception e)
1392 {
1393 }
1394 }
1395
1396 static void pos_recording_add(int cmd, double lat, double lon, double speed, double bearing, long time)
1397 {
1398 if (ZANaviDebugReceiver.dont_save_loc == true)
1399 {
1400 // dont save (already saved) log
1401 return;
1402 }
1403
1404 //System.out.println("PRF:CMD=" + cmd_name[cmd] + " dst=" + Navit.global_last_destination_name);
1405
1406 if (cmd == 0) // empty lines
1407 {
1408 try
1409 {
1410 pos_recording_writer.write("\n");
1411 pos_recording_writer.write("\n");
1412 pos_recording_writer.write("\n");
1413 pos_recording_writer.write("\n");
1414 }
1415 catch (Exception e)
1416 {
1417 }
1418 }
1419 else if (cmd == 1) // POS
1420 {
1421
1422 // try
1423 // {
1424 // 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");
1425 // }
1426 // catch (Exception e)
1427 // {
1428 // }
1429
1430 try
1431 {
1432 pos_recording_writer.write("POS:" + "\"" + customNumberFormat_("####.######", lat) + "," + customNumberFormat_("####.######", lon) + "," + customNumberFormat_("####.##", speed) + "," + customNumberFormat_("####.##", bearing) + "\"" + "\n");
1433 if (Navit.OSD_route_001.arriving_time_valid)
1434 {
1435 pos_recording_writer.write("REM:" + "\"ETA:" + Navit.OSD_route_001.arriving_time + "\"" + "\n");
1436 }
1437 }
1438 catch (Exception e)
1439 {
1440 }
1441 }
1442 else if (cmd == 2) // CLR
1443 {
1444 try
1445 {
1446 if (time == 111)
1447 {
1448 pos_recording_writer.write("CLR:" + "\"\"" + "\n");
1449 }
1450
1451 if (time == 111)
1452 {
1453
1454 // before "CLR" rotate recording file --------------------------
1455 // before "CLR" rotate recording file --------------------------
1456 String date = new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.GERMAN).format(new Date());
1457 String pos_recording_filename_base = Navit.NAVIT_DATA_DEBUG_DIR + date + "-" + "zanavi_pos_recording";
1458 String pos_recording_filename = pos_recording_filename_base + ".txt";
1459 String pos_recording_filename_archive = pos_recording_filename_base + "_" + date + ".txt";
1460
1461 //System.out.println("PRF:CLR:" + pos_recording_file.getName() + " " + pos_recording_filename_archive);
1462 pos_recording_filename_archive = Navit.NAVIT_DATA_DEBUG_DIR + "arch_" + pos_recording_file.getName();
1463
1464 //System.out.println("PRF:CLR:004:" + pos_recording_filename_archive);
1465
1466 try
1467 {
1468 if (pos_recording_file.exists())
1469 {
1470 //System.out.println("PRF:CLR:005");
1471
1472 try
1473 {
1474 pos_recording_writer.close();
1475 }
1476 catch (Exception cl001)
1477 {
1478 }
1479
1480 // archive old GPX file
1481 pos_recording_file.renameTo(new File(pos_recording_filename_archive));
1482 pos_recording_file = new File(pos_recording_filename);
1483 pos_recording_writer = new BufferedWriter(new FileWriter(pos_recording_file, true));
1484
1485 //System.out.println("PRF:CLR:006");
1486 }
1487 }
1488 catch (Exception e)
1489 {
1490 }
1491 // before "CLR" rotate recording file --------------------------
1492 // before "CLR" rotate recording file --------------------------
1493
1494 //System.out.println("PRF:CLR:007");
1495 }
1496
1497 if (time == 0)
1498 {
1499 pos_recording_writer.write("CLR:" + "\"\"" + "\n");
1500 }
1501
1502 }
1503 catch (Exception e)
1504 {
1505 }
1506 }
1507 else if (cmd == 3) // DST
1508 {
1509 try
1510 {
1511 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.GERMAN);
1512 String currentDateandTime = sdf.format(new Date());
1513
1514 try
1515 {
1516 //System.out.println("PRF:X01:" + Navit.global_last_destination_name + " " + pos_recording_file.getName());
1517
1518 if ((Navit.global_last_destination_name.compareTo("") != 0) && (pos_recording_file.getName().contains("zanavi_pos_recording")))
1519 {
1520 String date = new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.GERMAN).format(new Date());
1521 String pos_recording_filename_newname = Navit.NAVIT_DATA_DEBUG_DIR + "route-" + date + "-" + Navit.global_last_destination_name + ".txt";
1522
1523 //System.out.println("PRF:X02:" + pos_recording_filename_newname);
1524
1525 if (pos_recording_file.exists())
1526 {
1527 pos_recording_writer.close();
1528 pos_recording_file.renameTo(new File(pos_recording_filename_newname));
1529 pos_recording_file = new File(pos_recording_filename_newname);
1530 pos_recording_writer = new BufferedWriter(new FileWriter(pos_recording_file, true));
1531 }
1532 }
1533 }
1534 catch (Exception e)
1535 {
1536 }
1537
1538 pos_recording_writer.write("REM:" + "\"Date:" + currentDateandTime + "\"" + "\n");
1539 pos_recording_writer.write("DST:" + "\"" + customNumberFormat_("####.######", lat) + "," + customNumberFormat_("####.######", lon) + "\"" + "\n");
1540 if (Navit.global_last_destination_name.compareTo("") != 0)
1541 {
1542 pos_recording_writer.write("REM:" + "\"TO:" + Navit.global_last_destination_name + "\"" + "\n");
1543 }
1544
1545 }
1546 catch (Exception e)
1547 {
1548 }
1549 }
1550 }
1551
1552 static int distanceBetween(float lat1, float lon1, float lat2, float lon2)
1553 {
1554 int ret = -1;
1555
1556 float[] res = new float[3];
1557
1558 try
1559 {
1560 android.location.Location.distanceBetween(lat1, lon1, lat2, lon2, res);
1561 ret = (int) (res[0]);
1562 }
1563 catch (Exception e)
1564 {
1565 }
1566
1567 return ret;
1568 }
1569
1570 static int distanceBetween(double lat1, double lon1, double lat2, double lon2)
1571 {
1572 int ret = -1;
1573
1574 float[] res = new float[3];
1575
1576 try
1577 {
1578 android.location.Location.distanceBetween(lat1, lon1, lat2, lon2, res);
1579 ret = (int) (res[0]);
1580 }
1581 catch (Exception e)
1582 {
1583 }
1584
1585 return ret;
1586 }
1587
1588 }

   
Visit the ZANavi Wiki