… | |
… | |
81 | |
81 | |
82 | private static Location last_location = null; |
82 | private static Location last_location = null; |
83 | |
83 | |
84 | public static native void VehicleCallback(int id, Location location); |
84 | public static native void VehicleCallback(int id, Location location); |
85 | |
85 | |
86 | private static SatStatusThread st = null; |
86 | // private static SatStatusThread st = null; |
87 | |
87 | |
88 | private class SatStatusThread extends Thread |
88 | private class SatStatusThread extends Thread |
89 | { |
89 | { |
90 | // get new gpsstatus -------- |
90 | // get new gpsstatus -------- |
91 | int sats1 = 0; |
91 | int sats1 = 0; |
… | |
… | |
98 | |
98 | |
99 | while (this.running) |
99 | while (this.running) |
100 | { |
100 | { |
101 | try |
101 | try |
102 | { |
102 | { |
|
|
103 | if (!Navit.DemoVehicle) |
|
|
104 | { |
103 | GpsStatus stat = locationManager.getGpsStatus(gps_status); |
105 | GpsStatus stat = locationManager.getGpsStatus(gps_status); |
104 | gps_status = stat; |
106 | gps_status = stat; |
105 | Iterator<GpsSatellite> localIterator = stat.getSatellites().iterator(); |
107 | Iterator<GpsSatellite> localIterator = stat.getSatellites().iterator(); |
106 | while (localIterator.hasNext()) |
108 | while (localIterator.hasNext()) |
107 | { |
109 | { |
108 | GpsSatellite localGpsSatellite = (GpsSatellite) localIterator.next(); |
110 | GpsSatellite localGpsSatellite = (GpsSatellite) localIterator.next(); |
109 | sats1++; |
111 | sats1++; |
110 | if (localGpsSatellite.usedInFix()) |
112 | if (localGpsSatellite.usedInFix()) |
111 | { |
113 | { |
112 | satsInFix1++; |
114 | satsInFix1++; |
|
|
115 | } |
113 | } |
116 | } |
114 | } |
117 | } |
115 | } |
118 | } |
116 | catch (Exception e) |
119 | catch (Exception e) |
117 | { |
120 | { |
… | |
… | |
151 | { |
154 | { |
152 | public void onLocationChanged(Location location) |
155 | public void onLocationChanged(Location location) |
153 | { |
156 | { |
154 | last_f_fix = location.getTime(); |
157 | last_f_fix = location.getTime(); |
155 | // if last gps fix was longer than 4 secs. ago, use this fix |
158 | // if last gps fix was longer than 4 secs. ago, use this fix |
156 | if (last_p_fix + 4000 < last_f_fix) |
159 | // and we dont have a GPS lock |
|
|
160 | if ((last_p_fix + 4000 < last_f_fix) && (Navit.satsInFix < 3)) |
157 | { |
161 | { |
158 | if (Navit.PREF_follow_gps) |
162 | if (Navit.PREF_follow_gps) |
159 | { |
163 | { |
160 | if (Navit.PREF_use_compass_heading_base) |
164 | if (Navit.PREF_use_compass_heading_base) |
161 | { |
165 | { |
… | |
… | |
167 | } |
171 | } |
168 | |
172 | |
169 | //System.out.println("send values 1"); |
173 | //System.out.println("send values 1"); |
170 | //Log.e("NavitVehicle", "LocationChanged provider=fast Latitude " + location.getLatitude() + " Longitude " + location.getLongitude()); |
174 | //Log.e("NavitVehicle", "LocationChanged provider=fast Latitude " + location.getLatitude() + " Longitude " + location.getLongitude()); |
171 | last_location = location; |
175 | last_location = location; |
|
|
176 | if (!Navit.DemoVehicle) |
|
|
177 | { |
172 | VehicleCallback(vehicle_callbackid, location); |
178 | VehicleCallback(vehicle_callbackid, location); |
|
|
179 | } |
173 | } |
180 | } |
174 | } |
181 | } |
175 | } |
182 | } |
176 | |
183 | |
177 | public void onProviderDisabled(String provider) |
184 | public void onProviderDisabled(String provider) |
… | |
… | |
214 | { |
221 | { |
215 | public void onLocationChanged(Location location) |
222 | public void onLocationChanged(Location location) |
216 | { |
223 | { |
217 | last_p_fix = location.getTime(); |
224 | last_p_fix = location.getTime(); |
218 | current_accuracy = location.getAccuracy(); |
225 | current_accuracy = location.getAccuracy(); |
219 | /* |
|
|
220 | * gps_extras = location.getExtras(); |
|
|
221 | * Log.e("NavitVehicle", "getExtras 1 size=" + gps_extras.keySet().size()); |
|
|
222 | * if (gps_extras.containsKey("satellites")) |
|
|
223 | * { |
|
|
224 | * Bundle b = null; |
|
|
225 | * try |
|
|
226 | * { |
|
|
227 | * Log.e("NavitVehicle", "getExtras 2"); |
|
|
228 | * b = gps_extras.getBundle("satellites"); |
|
|
229 | * Log.e("NavitVehicle", "getExtras 3 size=" + b.keySet().size()); |
|
|
230 | * } |
|
|
231 | * catch (Exception e) |
|
|
232 | * { |
|
|
233 | * |
|
|
234 | * } |
|
|
235 | * String s = ""; |
|
|
236 | * while (s != null) |
|
|
237 | * { |
|
|
238 | * try |
|
|
239 | * { |
|
|
240 | * s = b.keySet().iterator().next(); |
|
|
241 | * } |
|
|
242 | * catch (Exception e) |
|
|
243 | * { |
|
|
244 | * s = null; |
|
|
245 | * } |
|
|
246 | * System.out.println("s=" + s); |
|
|
247 | * } |
|
|
248 | * } |
|
|
249 | */ |
|
|
250 | |
226 | |
251 | if (Navit.PREF_follow_gps) |
227 | if (Navit.PREF_follow_gps) |
252 | { |
228 | { |
253 | if (Navit.PREF_use_compass_heading_base) |
229 | if (Navit.PREF_use_compass_heading_base) |
254 | { |
230 | { |
… | |
… | |
306 | }; |
282 | }; |
307 | preciseLocationListener_s = preciseLocationListener; |
283 | preciseLocationListener_s = preciseLocationListener; |
308 | |
284 | |
309 | /* |
285 | /* |
310 | * Use 2 LocationProviders, one precise (usually GPS), and one |
286 | * Use 2 LocationProviders, one precise (usually GPS), and one |
311 | * not so precise, but possible faster. The fast provider is |
287 | * not so precise, but possible faster. |
312 | * disabled when the precise provider gets its first fix. |
|
|
313 | */ |
288 | */ |
314 | Criteria highCriteria = null; |
289 | Criteria highCriteria = null; |
315 | Criteria lowCriteria = null; |
290 | Criteria lowCriteria = null; |
316 | try |
291 | try |
317 | { |
292 | { |
… | |
… | |
379 | catch (Exception e) |
354 | catch (Exception e) |
380 | { |
355 | { |
381 | e.printStackTrace(); |
356 | e.printStackTrace(); |
382 | } |
357 | } |
383 | |
358 | |
384 | // if (Navit.PREF_use_fast_provider) |
|
|
385 | // { |
|
|
386 | // try |
|
|
387 | // { |
|
|
388 | // // use last know location for startup |
|
|
389 | // //Log.e("NavitVehicle", "getLastKnownLocation startup (fast)"); |
|
|
390 | // Location l = locationManager.getLastKnownLocation(fastProvider); |
|
|
391 | // if (l != null) |
|
|
392 | // { |
|
|
393 | // if (Navit.PREF_follow_gps) |
|
|
394 | // { |
|
|
395 | // Log.e("NavitVehicle", "getLastKnownLocation startup (+2) l=" + l.toString()); |
|
|
396 | // last_location = l; |
|
|
397 | // VehicleCallback(vehicle_callbackid, l); |
|
|
398 | // } |
|
|
399 | // } |
|
|
400 | // } |
|
|
401 | // catch (Exception e) |
|
|
402 | // { |
|
|
403 | // e.printStackTrace(); |
|
|
404 | // } |
|
|
405 | // } |
|
|
406 | // else |
|
|
407 | // { |
|
|
408 | // Log.e("NavitVehicle", "pref not set"); |
|
|
409 | // } |
|
|
410 | |
|
|
411 | // try |
|
|
412 | // { |
|
|
413 | // // use last know location for startup |
|
|
414 | // //Log.e("NavitVehicle", "getLastKnownLocation startup (precise)"); |
|
|
415 | // Location l = locationManager.getLastKnownLocation(preciseProvider); |
|
|
416 | // if (l != null) |
|
|
417 | // { |
|
|
418 | // //Log.e("NavitVehicle", "getLastKnownLocation startup (2) l=" + l.toString()); |
|
|
419 | // if (Navit.PREF_follow_gps) |
|
|
420 | // { |
|
|
421 | // last_location = l; |
|
|
422 | // VehicleCallback(vehicle_callbackid, l); |
|
|
423 | // } |
|
|
424 | // } |
|
|
425 | // } |
|
|
426 | // catch (Exception e) |
|
|
427 | // { |
|
|
428 | // e.printStackTrace(); |
|
|
429 | // } |
|
|
430 | //Log.e("NavitVehicle", "getLastKnownLocation ready"); |
|
|
431 | |
|
|
432 | gps_status_listener_s = new GpsStatus.Listener() |
359 | gps_status_listener_s = new GpsStatus.Listener() |
433 | { |
360 | { |
434 | public void onGpsStatusChanged(int event) |
361 | public void onGpsStatusChanged(int event) |
435 | { |
362 | { |
436 | if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) |
363 | if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) |
… | |
… | |
462 | catch (Exception e) |
389 | catch (Exception e) |
463 | { |
390 | { |
464 | e.printStackTrace(); |
391 | e.printStackTrace(); |
465 | } |
392 | } |
466 | // Navit.set_debug_messages3_wrapper("sat: " + Navit.satsInFix + "/" + Navit.sats); |
393 | // Navit.set_debug_messages3_wrapper("sat: " + Navit.satsInFix + "/" + Navit.sats); |
467 | // System.out.println("Statellites: " + satsInFix + "/" + sats); |
394 | // System.out.println("Statellites: " + Navit.satsInFix + "/" + Navit.sats); |
468 | // get new gpsstatus -------- |
395 | // get new gpsstatus -------- |
469 | } |
396 | } |
470 | } |
397 | } |
471 | }; |
398 | }; |
472 | |
|
|
473 | // try |
|
|
474 | // { |
|
|
475 | // st.stop_me(); |
|
|
476 | // } |
|
|
477 | // catch (Exception e) |
|
|
478 | // { |
|
|
479 | // |
|
|
480 | // } |
|
|
481 | // st = new SatStatusThread(); |
|
|
482 | // st.start(); |
|
|
483 | |
|
|
484 | } |
399 | } |
485 | |
400 | |
486 | public static void set_mock_location__fast(Location mock_location) |
401 | public static void set_mock_location__fast(Location mock_location) |
487 | { |
402 | { |
488 | try |
403 | try |
… | |
… | |
545 | // If the 2 providers is the same, only activate one listener |
460 | // If the 2 providers is the same, only activate one listener |
546 | if (fastProvider_s != null) |
461 | if (fastProvider_s != null) |
547 | { |
462 | { |
548 | if (Navit.PREF_use_fast_provider) |
463 | if (Navit.PREF_use_fast_provider) |
549 | { |
464 | { |
|
|
465 | if (!Navit.DemoVehicle) |
|
|
466 | { |
550 | Location l = locationManager_s.getLastKnownLocation(fastProvider_s); |
467 | Location l = locationManager_s.getLastKnownLocation(fastProvider_s); |
551 | if (l != null) |
468 | if (l != null) |
552 | { |
469 | { |
553 | if (l.getAccuracy() > 0) |
470 | if (l.getAccuracy() > 0) |
554 | { |
|
|
555 | if ((l.getLatitude() != 0) && (l.getLongitude() != 0)) |
|
|
556 | { |
471 | { |
557 | if (Navit.PREF_follow_gps) |
472 | if ((l.getLatitude() != 0) && (l.getLongitude() != 0)) |
558 | { |
473 | { |
|
|
474 | if (Navit.PREF_follow_gps) |
|
|
475 | { |
559 | Log.e("NavitVehicle", "getLastKnownLocation fast (3) l=" + l.toString()); |
476 | Log.e("NavitVehicle", "getLastKnownLocation fast (3) l=" + l.toString()); |
560 | last_location = l; |
477 | last_location = l; |
561 | VehicleCallback(vehicle_callbackid_, l); |
478 | VehicleCallback(vehicle_callbackid_, l); |
|
|
479 | } |
562 | } |
480 | } |
563 | } |
481 | } |
564 | } |
482 | } |
565 | } |
483 | } |
566 | } |
484 | } |
… | |
… | |
580 | // If the 2 providers is the same, only activate one listener |
498 | // If the 2 providers is the same, only activate one listener |
581 | if (fastProvider_s != null) |
499 | if (fastProvider_s != null) |
582 | { |
500 | { |
583 | if (Navit.PREF_use_fast_provider) |
501 | if (Navit.PREF_use_fast_provider) |
584 | { |
502 | { |
|
|
503 | if (!Navit.DemoVehicle) |
|
|
504 | { |
585 | locationManager_s.requestLocationUpdates(fastProvider_s, 0, 0, fastLocationListener_s); |
505 | locationManager_s.requestLocationUpdates(fastProvider_s, 0, 0, fastLocationListener_s); |
|
|
506 | } |
586 | } |
507 | } |
587 | } |
508 | } |
588 | } |
509 | } |
589 | catch (Exception e) |
510 | catch (Exception e) |
590 | { |
511 | { |
… | |
… | |
643 | { |
564 | { |
644 | Navit.sats = 0; |
565 | Navit.sats = 0; |
645 | Navit.satsInFix = 0; |
566 | Navit.satsInFix = 0; |
646 | if (preciseProvider_s != null) |
567 | if (preciseProvider_s != null) |
647 | { |
568 | { |
|
|
569 | try |
|
|
570 | { |
|
|
571 | locationManager_s.removeGpsStatusListener(gps_status_listener_s); |
|
|
572 | } |
|
|
573 | catch (Exception e3) |
|
|
574 | { |
|
|
575 | e3.printStackTrace(); |
|
|
576 | } |
648 | locationManager_s.addGpsStatusListener(gps_status_listener_s); |
577 | locationManager_s.addGpsStatusListener(gps_status_listener_s); |
649 | } |
578 | } |
650 | } |
579 | } |
651 | catch (Exception e) |
580 | catch (Exception e) |
652 | { |
581 | { |
653 | e.printStackTrace(); |
582 | e.printStackTrace(); |
654 | } |
583 | } |
|
|
584 | System.out.println("turn_ON_sat_status"); |
655 | } |
585 | } |
656 | |
586 | |
657 | public static void turn_off_sat_status() |
587 | public static void turn_off_sat_status() |
658 | { |
588 | { |
659 | try |
589 | try |
… | |
… | |
667 | } |
597 | } |
668 | catch (Exception e) |
598 | catch (Exception e) |
669 | { |
599 | { |
670 | e.printStackTrace(); |
600 | e.printStackTrace(); |
671 | } |
601 | } |
|
|
602 | System.out.println("turn_off_sat_status"); |
672 | } |
603 | } |
673 | |
604 | |
674 | public static void turn_off_fast_provider() |
605 | public static void turn_off_fast_provider() |
675 | { |
606 | { |
676 | try |
607 | try |
… | |
… | |
728 | // !! ugly hack to make map redraw !! |
659 | // !! ugly hack to make map redraw !! |
729 | if (last_location.getSpeed() == 0.0f) |
660 | if (last_location.getSpeed() == 0.0f) |
730 | { |
661 | { |
731 | float save_speed = last_location.getSpeed(); |
662 | float save_speed = last_location.getSpeed(); |
732 | last_location.setSpeed(0.2f); |
663 | last_location.setSpeed(0.2f); |
|
|
664 | if (!Navit.DemoVehicle) |
|
|
665 | { |
733 | VehicleCallback(vehicle_callbackid_, last_location); |
666 | VehicleCallback(vehicle_callbackid_, last_location); |
|
|
667 | } |
734 | last_location.setSpeed(save_speed); |
668 | last_location.setSpeed(save_speed); |
735 | } |
669 | } |
736 | else |
670 | else |
737 | { |
671 | { |
|
|
672 | if (!Navit.DemoVehicle) |
|
|
673 | { |
738 | VehicleCallback(vehicle_callbackid_, last_location); |
674 | VehicleCallback(vehicle_callbackid_, last_location); |
|
|
675 | } |
739 | } |
676 | } |
740 | // !! ugly hack to make map redraw !! |
677 | // !! ugly hack to make map redraw !! |
741 | // !! ugly hack to make map redraw !! |
678 | // !! ugly hack to make map redraw !! |
742 | // !! ugly hack to make map redraw !! |
679 | // !! ugly hack to make map redraw !! |
743 | } |
680 | } |