… | |
… | |
63 | private static LocationListener preciseLocationListener_s = null; |
63 | private static LocationListener preciseLocationListener_s = null; |
64 | private static GpsStatus.Listener gps_status_listener_s = null; |
64 | private static GpsStatus.Listener gps_status_listener_s = null; |
65 | private static float compass_heading; |
65 | private static float compass_heading; |
66 | private static float current_accuracy = 99999999F; |
66 | private static float current_accuracy = 99999999F; |
67 | |
67 | |
|
|
68 | int sats1_old = -1; |
|
|
69 | int satsInFix1_old = -1; |
|
|
70 | |
68 | public static Handler vehicle_handler_ = null; |
71 | public static Handler vehicle_handler_ = null; |
69 | public static long lastcompass_update_timestamp = 0L; |
72 | public static long lastcompass_update_timestamp = 0L; |
70 | |
73 | |
71 | public static final float GPS_SPEED_ABOVE_USE_FOR_HEADING = (float) (9 / 3.6f); // (9 km/h) / (3.6) ~= m/s |
74 | public static final float GPS_SPEED_ABOVE_USE_FOR_HEADING = (float) (9 / 3.6f); // (9 km/h) / (3.6) ~= m/s |
72 | |
75 | |
… | |
… | |
77 | public static long last_f_fix = 0; |
80 | public static long last_f_fix = 0; |
78 | public Bundle gps_extras = null; |
81 | public Bundle gps_extras = null; |
79 | public static GpsStatus gps_status = null; |
82 | public static GpsStatus gps_status = null; |
80 | public static Boolean update_location_in_progress = false; |
83 | public static Boolean update_location_in_progress = false; |
81 | |
84 | |
82 | private static Location last_location = null; |
85 | public static Location last_location = null; |
83 | |
86 | |
84 | public static native void VehicleCallback(Location location); |
87 | public static native void VehicleCallback(Location location); |
|
|
88 | |
|
|
89 | public static void VehicleCallback2(Location location) |
|
|
90 | { |
|
|
91 | if (Navit.Global_Init_Finished != 0) |
|
|
92 | { |
|
|
93 | Navit.cwthr.VehicleCallback3(location); |
|
|
94 | } |
|
|
95 | else |
|
|
96 | { |
|
|
97 | System.out.println("VehicleCallback2:Global_Init_Finished == 0 !!!!!!!"); |
|
|
98 | } |
|
|
99 | } |
85 | |
100 | |
86 | // private static SatStatusThread st = null; |
101 | // private static SatStatusThread st = null; |
87 | |
102 | |
88 | private class SatStatusThread extends Thread |
103 | private class SatStatusThread extends Thread |
89 | { |
104 | { |
… | |
… | |
124 | // Navit.set_debug_messages3_wrapper("sat: " + satsInFix1 + "/" + sats1); |
139 | // Navit.set_debug_messages3_wrapper("sat: " + satsInFix1 + "/" + sats1); |
125 | // get new gpsstatus -------- |
140 | // get new gpsstatus -------- |
126 | |
141 | |
127 | try |
142 | try |
128 | { |
143 | { |
129 | Thread.sleep(1000); |
144 | Thread.sleep(3000); |
130 | } |
145 | } |
131 | catch (InterruptedException e) |
146 | catch (InterruptedException e) |
132 | { |
147 | { |
133 | } |
148 | } |
134 | } |
149 | } |
… | |
… | |
138 | { |
153 | { |
139 | this.running = false; |
154 | this.running = false; |
140 | } |
155 | } |
141 | } |
156 | } |
142 | |
157 | |
143 | NavitVehicle(Context context, int callbackid) |
158 | NavitVehicle(Context context) |
144 | { |
159 | { |
145 | vehicle_handler_ = vehicle_handler; |
160 | vehicle_handler_ = Navit.vehicle_handler; |
146 | |
161 | |
147 | locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); |
162 | locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); |
148 | locationManager_s = locationManager; |
163 | locationManager_s = locationManager; |
149 | |
164 | |
150 | LocationListener fastLocationListener = new LocationListener() |
165 | LocationListener fastLocationListener = new LocationListener() |
… | |
… | |
171 | //Log.e("NavitVehicle", "LocationChanged provider=fast Latitude " + location.getLatitude() + " Longitude " + location.getLongitude()); |
186 | //Log.e("NavitVehicle", "LocationChanged provider=fast Latitude " + location.getLatitude() + " Longitude " + location.getLongitude()); |
172 | last_location = location; |
187 | last_location = location; |
173 | if (!Navit.DemoVehicle) |
188 | if (!Navit.DemoVehicle) |
174 | { |
189 | { |
175 | //Log.e("NavitVehicle", "call VehicleCallback 001"); |
190 | //Log.e("NavitVehicle", "call VehicleCallback 001"); |
176 | VehicleCallback(location); |
191 | VehicleCallback2(location); |
177 | } |
192 | } |
178 | } |
193 | } |
179 | } |
194 | } |
180 | } |
195 | } |
181 | |
196 | |
… | |
… | |
234 | } |
249 | } |
235 | //System.out.println("send values 2"); |
250 | //System.out.println("send values 2"); |
236 | //Log.e("NavitVehicle", "LocationChanged provider=precise Latitude " + location.getLatitude() + " Longitude " + location.getLongitude()); |
251 | //Log.e("NavitVehicle", "LocationChanged provider=precise Latitude " + location.getLatitude() + " Longitude " + location.getLongitude()); |
237 | last_location = location; |
252 | last_location = location; |
238 | //Log.e("NavitVehicle", "call VehicleCallback 002"); |
253 | //Log.e("NavitVehicle", "call VehicleCallback 002"); |
239 | VehicleCallback(location); |
254 | VehicleCallback2(location); |
240 | } |
255 | } |
241 | } |
256 | } |
242 | |
257 | |
243 | public void onProviderDisabled(String provider) |
258 | public void onProviderDisabled(String provider) |
244 | { |
259 | { |
… | |
… | |
360 | public void onGpsStatusChanged(int event) |
375 | public void onGpsStatusChanged(int event) |
361 | { |
376 | { |
362 | if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) |
377 | if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) |
363 | { |
378 | { |
364 | // get new gpsstatus -------- |
379 | // get new gpsstatus -------- |
|
|
380 | |
|
|
381 | sats1_old = Navit.sats; |
|
|
382 | satsInFix1_old = Navit.satsInFix; |
|
|
383 | |
365 | GpsStatus stat = locationManager.getGpsStatus(null); |
384 | GpsStatus stat = locationManager.getGpsStatus(null); |
|
|
385 | |
366 | Navit.sats = 0; |
386 | Navit.sats = 0; |
367 | Navit.satsInFix = 0; |
387 | Navit.satsInFix = 0; |
368 | |
388 | |
369 | try |
389 | try |
370 | { |
390 | { |
… | |
… | |
376 | if (localGpsSatellite.usedInFix()) |
396 | if (localGpsSatellite.usedInFix()) |
377 | { |
397 | { |
378 | Navit.satsInFix++; |
398 | Navit.satsInFix++; |
379 | } |
399 | } |
380 | } |
400 | } |
|
|
401 | |
|
|
402 | System.out.println("checking sat status update"); |
|
|
403 | |
|
|
404 | if ((sats1_old != Navit.sats) || (satsInFix1_old != Navit.satsInFix)) |
|
|
405 | { |
|
|
406 | System.out.println("sat status update -> changed"); |
|
|
407 | if (Navit.PREF_show_sat_status) |
|
|
408 | { |
381 | // redraw NavitOSDJava |
409 | // redraw NavitOSDJava |
382 | Message msg = NavitOSDJava.progress_handler_.obtainMessage(); |
410 | Message msg = NavitOSDJava.progress_handler_.obtainMessage(); |
383 | Bundle b = new Bundle(); |
411 | Bundle b = new Bundle(); |
384 | msg.what = 1; |
412 | msg.what = 1; |
385 | msg.setData(b); |
413 | msg.setData(b); |
386 | NavitOSDJava.progress_handler_.sendMessage(msg); |
414 | NavitOSDJava.progress_handler_.sendMessage(msg); |
|
|
415 | } |
|
|
416 | } |
387 | } |
417 | } |
388 | catch (Exception e) |
418 | catch (Exception e) |
389 | { |
419 | { |
390 | e.printStackTrace(); |
420 | e.printStackTrace(); |
391 | } |
421 | } |
… | |
… | |
409 | if (mock_location.getSpeed() == 0.0f) |
439 | if (mock_location.getSpeed() == 0.0f) |
410 | { |
440 | { |
411 | float save_speed = last_location.getSpeed(); |
441 | float save_speed = last_location.getSpeed(); |
412 | mock_location.setSpeed(0.2f); |
442 | mock_location.setSpeed(0.2f); |
413 | //Log.e("NavitVehicle", "call VehicleCallback 003"); |
443 | //Log.e("NavitVehicle", "call VehicleCallback 003"); |
414 | VehicleCallback(mock_location); |
444 | VehicleCallback2(mock_location); |
415 | mock_location.setSpeed(save_speed); |
445 | mock_location.setSpeed(save_speed); |
416 | } |
446 | } |
417 | else |
447 | else |
418 | { |
448 | { |
419 | //Log.e("NavitVehicle", "call VehicleCallback 004"); |
449 | //Log.e("NavitVehicle", "call VehicleCallback 004"); |
420 | VehicleCallback(mock_location); |
450 | VehicleCallback2(mock_location); |
421 | } |
451 | } |
422 | } |
452 | } |
423 | } |
453 | } |
424 | catch (Exception e) |
454 | catch (Exception e) |
425 | { |
455 | { |
… | |
… | |
441 | if (Navit.PREF_follow_gps) |
471 | if (Navit.PREF_follow_gps) |
442 | { |
472 | { |
443 | Log.e("NavitVehicle", "getLastKnownLocation precise (2) l=" + l.toString()); |
473 | Log.e("NavitVehicle", "getLastKnownLocation precise (2) l=" + l.toString()); |
444 | last_location = l; |
474 | last_location = l; |
445 | //Log.e("NavitVehicle", "call VehicleCallback 005"); |
475 | //Log.e("NavitVehicle", "call VehicleCallback 005"); |
446 | VehicleCallback(l); |
476 | VehicleCallback2(l); |
447 | } |
477 | } |
448 | } |
478 | } |
449 | } |
479 | } |
450 | } |
480 | } |
451 | } |
481 | } |
… | |
… | |
476 | if (Navit.PREF_follow_gps) |
506 | if (Navit.PREF_follow_gps) |
477 | { |
507 | { |
478 | Log.e("NavitVehicle", "getLastKnownLocation fast (3) l=" + l.toString()); |
508 | Log.e("NavitVehicle", "getLastKnownLocation fast (3) l=" + l.toString()); |
479 | last_location = l; |
509 | last_location = l; |
480 | //Log.e("NavitVehicle", "call VehicleCallback 006"); |
510 | //Log.e("NavitVehicle", "call VehicleCallback 006"); |
481 | VehicleCallback(l); |
511 | VehicleCallback2(l); |
482 | } |
512 | } |
483 | } |
513 | } |
484 | } |
514 | } |
485 | } |
515 | } |
486 | } |
516 | } |
… | |
… | |
582 | } |
612 | } |
583 | catch (Exception e) |
613 | catch (Exception e) |
584 | { |
614 | { |
585 | e.printStackTrace(); |
615 | e.printStackTrace(); |
586 | } |
616 | } |
587 | System.out.println("turn_ON_sat_status"); |
617 | //System.out.println("turn_ON_sat_status"); |
588 | } |
618 | } |
589 | |
619 | |
590 | public static void turn_off_sat_status() |
620 | public static void turn_off_sat_status() |
591 | { |
621 | { |
592 | try |
622 | try |
… | |
… | |
600 | } |
630 | } |
601 | catch (Exception e) |
631 | catch (Exception e) |
602 | { |
632 | { |
603 | e.printStackTrace(); |
633 | e.printStackTrace(); |
604 | } |
634 | } |
605 | System.out.println("turn_off_sat_status"); |
635 | //System.out.println("turn_off_sat_status"); |
606 | } |
636 | } |
607 | |
637 | |
608 | public static void turn_off_fast_provider() |
638 | public static void turn_off_fast_provider() |
609 | { |
639 | { |
610 | try |
640 | try |
… | |
… | |
624 | { |
654 | { |
625 | turn_off_precise_provider(); |
655 | turn_off_precise_provider(); |
626 | turn_off_fast_provider(); |
656 | turn_off_fast_provider(); |
627 | } |
657 | } |
628 | |
658 | |
|
|
659 | /* |
629 | public Handler vehicle_handler = new Handler() |
660 | * public Handler vehicle_handler = new Handler() |
630 | { |
661 | * { |
631 | public void handleMessage(Message msg) |
662 | * public void handleMessage(Message msg) |
632 | { |
663 | * { |
633 | switch (msg.what) |
664 | * switch (msg.what) |
634 | { |
665 | * { |
635 | case 1: |
666 | * case 1: |
636 | // dismissDialog(msg.getData().getInt("dialog_num")); |
667 | * // dismissDialog(msg.getData().getInt("dialog_num")); |
637 | // removeDialog(msg.getData().getInt("dialog_num")); |
668 | * // removeDialog(msg.getData().getInt("dialog_num")); |
638 | Location l = new Location("Network"); |
669 | * Location l = new Location("Network"); |
639 | l.setLatitude(msg.getData().getFloat("lat")); |
670 | * l.setLatitude(msg.getData().getFloat("lat")); |
640 | l.setLongitude(msg.getData().getFloat("lng")); |
671 | * l.setLongitude(msg.getData().getFloat("lng")); |
641 | l.setBearing(msg.getData().getFloat("b")); |
672 | * l.setBearing(msg.getData().getFloat("b")); |
642 | l.setSpeed(0.8f); |
673 | * l.setSpeed(0.8f); |
643 | NavitVehicle.set_mock_location__fast(l); |
674 | * NavitVehicle.set_mock_location__fast(l); |
644 | break; |
675 | * break; |
645 | case 2: |
676 | * case 2: |
646 | if (update_location_in_progress) |
677 | * if (update_location_in_progress) |
647 | { |
678 | * { |
648 | } |
679 | * } |
649 | else |
680 | * else |
650 | { |
681 | * { |
651 | update_location_in_progress = true; |
682 | * update_location_in_progress = true; |
652 | VehicleCallback(last_location); |
683 | * VehicleCallback(last_location); |
653 | update_location_in_progress = false; |
684 | * update_location_in_progress = false; |
654 | } |
685 | * } |
655 | break; |
686 | * break; |
656 | } |
687 | * } |
657 | } |
688 | * } |
658 | }; |
689 | * }; |
|
|
690 | */ |
659 | |
691 | |
660 | public static void update_compass_heading(float heading) |
692 | public static void update_compass_heading(float heading) |
661 | { |
693 | { |
662 | compass_heading = heading; |
694 | compass_heading = heading; |
663 | // use compass heading |
695 | // use compass heading |
… | |
… | |
683 | float save_speed = last_location.getSpeed(); |
715 | float save_speed = last_location.getSpeed(); |
684 | last_location.setSpeed(0.2f); |
716 | last_location.setSpeed(0.2f); |
685 | if (!Navit.DemoVehicle) |
717 | if (!Navit.DemoVehicle) |
686 | { |
718 | { |
687 | //Log.e("NavitVehicle", "call VehicleCallback 007:start"); |
719 | //Log.e("NavitVehicle", "call VehicleCallback 007:start"); |
688 | VehicleCallback(last_location); |
720 | VehicleCallback2(last_location); |
689 | /* |
721 | /* |
690 | Message m2 = new Message(); |
722 | * Message m2 = new Message(); |
691 | m2.what = 2; |
723 | * m2.what = 2; |
692 | vehicle_handler_.handleMessage(m2); |
724 | * vehicle_handler_.handleMessage(m2); |
693 | */ |
725 | */ |
694 | //Log.e("NavitVehicle", "call VehicleCallback 007:end"); |
726 | //Log.e("NavitVehicle", "call VehicleCallback 007:end"); |
695 | } |
727 | } |
696 | last_location.setSpeed(save_speed); |
728 | last_location.setSpeed(save_speed); |
697 | } |
729 | } |
698 | else |
730 | else |
699 | { |
731 | { |
700 | if (!Navit.DemoVehicle) |
732 | if (!Navit.DemoVehicle) |
701 | { |
733 | { |
702 | //Log.e("NavitVehicle", "call VehicleCallback 008"); |
734 | //Log.e("NavitVehicle", "call VehicleCallback 008"); |
703 | VehicleCallback(last_location); |
735 | VehicleCallback2(last_location); |
704 | } |
736 | } |
705 | } |
737 | } |
706 | // !! ugly hack to make map redraw !! |
738 | // !! ugly hack to make map redraw !! |
707 | // !! ugly hack to make map redraw !! |
739 | // !! ugly hack to make map redraw !! |
708 | // !! ugly hack to make map redraw !! |
740 | // !! ugly hack to make map redraw !! |