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

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

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

Revision 27 Revision 28
55 55
56public class NavitVehicle 56public class NavitVehicle
57{ 57{
58 private LocationManager locationManager = null; 58 private LocationManager locationManager = null;
59 private static LocationManager locationManager_s = null; 59 private static LocationManager locationManager_s = null;
60 private int vehicle_callbackid;
61 private static int vehicle_callbackid_ = 0;
62 private String preciseProvider = null; 60 private String preciseProvider = null;
63 private String fastProvider = null; 61 private String fastProvider = null;
64 private static LocationListener fastLocationListener_s = null; 62 private static LocationListener fastLocationListener_s = null;
65 private static LocationListener preciseLocationListener_s = null; 63 private static LocationListener preciseLocationListener_s = null;
66 private static GpsStatus.Listener gps_status_listener_s = null; 64 private static GpsStatus.Listener gps_status_listener_s = null;
67 private static float compass_heading; 65 private static float compass_heading;
68 private static float current_accuracy = 99999999F; 66 private static float current_accuracy = 99999999F;
69 67
70 public static Handler vehicle_handler_ = null; 68 public static Handler vehicle_handler_ = null;
69 public static long lastcompass_update_timestamp = 0L;
71 70
72 public static final float GPS_SPEED_ABOVE_USE_FOR_HEADING = (float) (9 / 3.6f); // (9 km/h) / (3.6) ~= m/s 71 public static final float GPS_SPEED_ABOVE_USE_FOR_HEADING = (float) (9 / 3.6f); // (9 km/h) / (3.6) ~= m/s
73 72
74 private static String preciseProvider_s = null; 73 private static String preciseProvider_s = null;
75 private static String fastProvider_s = null; 74 private static String fastProvider_s = null;
76 75
77 public static long last_p_fix = 0; 76 public static long last_p_fix = 0;
78 public static long last_f_fix = 0; 77 public static long last_f_fix = 0;
79 public Bundle gps_extras = null; 78 public Bundle gps_extras = null;
80 public static GpsStatus gps_status = null; 79 public static GpsStatus gps_status = null;
80 public static Boolean update_location_in_progress = false;
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(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 {
142 142
143 NavitVehicle(Context context, int callbackid) 143 NavitVehicle(Context context, int callbackid)
144 { 144 {
145 vehicle_handler_ = vehicle_handler; 145 vehicle_handler_ = vehicle_handler;
146 146
147 vehicle_callbackid = callbackid;
148 vehicle_callbackid_ = callbackid;
149
150 locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); 147 locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
151 locationManager_s = locationManager; 148 locationManager_s = locationManager;
152 149
153 LocationListener fastLocationListener = new LocationListener() 150 LocationListener fastLocationListener = new LocationListener()
154 { 151 {
173 //System.out.println("send values 1"); 170 //System.out.println("send values 1");
174 //Log.e("NavitVehicle", "LocationChanged provider=fast Latitude " + location.getLatitude() + " Longitude " + location.getLongitude()); 171 //Log.e("NavitVehicle", "LocationChanged provider=fast Latitude " + location.getLatitude() + " Longitude " + location.getLongitude());
175 last_location = location; 172 last_location = location;
176 if (!Navit.DemoVehicle) 173 if (!Navit.DemoVehicle)
177 { 174 {
175 //Log.e("NavitVehicle", "call VehicleCallback 001");
178 VehicleCallback(vehicle_callbackid, location); 176 VehicleCallback(location);
179 } 177 }
180 } 178 }
181 } 179 }
182 } 180 }
183 181
235 } 233 }
236 } 234 }
237 //System.out.println("send values 2"); 235 //System.out.println("send values 2");
238 //Log.e("NavitVehicle", "LocationChanged provider=precise Latitude " + location.getLatitude() + " Longitude " + location.getLongitude()); 236 //Log.e("NavitVehicle", "LocationChanged provider=precise Latitude " + location.getLatitude() + " Longitude " + location.getLongitude());
239 last_location = location; 237 last_location = location;
238 //Log.e("NavitVehicle", "call VehicleCallback 002");
240 VehicleCallback(vehicle_callbackid, location); 239 VehicleCallback(location);
241 } 240 }
242 } 241 }
243 242
244 public void onProviderDisabled(String provider) 243 public void onProviderDisabled(String provider)
245 { 244 {
251 //Log.e("NavitVehicle", "onProviderEnabled -> provider=" + provider); 250 //Log.e("NavitVehicle", "onProviderEnabled -> provider=" + provider);
252 } 251 }
253 252
254 public void onStatusChanged(String provider, int status, Bundle extras) 253 public void onStatusChanged(String provider, int status, Bundle extras)
255 { 254 {
256 Log.e("NavitVehicle", "onStatusChanged -> provider=" + provider + " status=" + status); 255 //Log.e("NavitVehicle", "onStatusChanged -> provider=" + provider + " status=" + status);
257 256
258 try 257 try
259 { 258 {
260 if (status == GpsStatus.GPS_EVENT_FIRST_FIX) 259 if (status == GpsStatus.GPS_EVENT_FIRST_FIX)
261 { 260 {
291 try 290 try
292 { 291 {
293 // Selection criterias for the precise provider 292 // Selection criterias for the precise provider
294 highCriteria = new Criteria(); 293 highCriteria = new Criteria();
295 highCriteria.setAccuracy(Criteria.ACCURACY_FINE); 294 highCriteria.setAccuracy(Criteria.ACCURACY_FINE);
296 highCriteria.setAltitudeRequired(true); 295 highCriteria.setAltitudeRequired(false);
297 highCriteria.setBearingRequired(true); 296 highCriteria.setBearingRequired(true);
298 //highCriteria.setCostAllowed(true); 297 //highCriteria.setCostAllowed(true);
299 //highCriteria.setPowerRequirement(Criteria.POWER_HIGH); 298 //highCriteria.setPowerRequirement(Criteria.POWER_HIGH);
300 299
301 // Selection criterias for the fast provider 300 // Selection criterias for the fast provider
403 try 402 try
404 { 403 {
405 //locationManager_s.setTestProviderLocation("ZANavi_mock", mock_location); 404 //locationManager_s.setTestProviderLocation("ZANavi_mock", mock_location);
406 // mock_location; 405 // mock_location;
407 // System.out.println("llllllll" + mock_location.getLatitude() + " " + mock_location.getLongitude()); 406 // System.out.println("llllllll" + mock_location.getLatitude() + " " + mock_location.getLongitude());
408 if ((vehicle_callbackid_ != 0) && (mock_location != null)) 407 if (mock_location != null)
409 { 408 {
410 if (mock_location.getSpeed() == 0.0f) 409 if (mock_location.getSpeed() == 0.0f)
411 { 410 {
412 float save_speed = last_location.getSpeed(); 411 float save_speed = last_location.getSpeed();
413 mock_location.setSpeed(0.2f); 412 mock_location.setSpeed(0.2f);
413 //Log.e("NavitVehicle", "call VehicleCallback 003");
414 VehicleCallback(vehicle_callbackid_, mock_location); 414 VehicleCallback(mock_location);
415 mock_location.setSpeed(save_speed); 415 mock_location.setSpeed(save_speed);
416 } 416 }
417 else 417 else
418 { 418 {
419 //Log.e("NavitVehicle", "call VehicleCallback 004");
419 VehicleCallback(vehicle_callbackid_, mock_location); 420 VehicleCallback(mock_location);
420 } 421 }
421 } 422 }
422 } 423 }
423 catch (Exception e) 424 catch (Exception e)
424 { 425 {
439 { 440 {
440 if (Navit.PREF_follow_gps) 441 if (Navit.PREF_follow_gps)
441 { 442 {
442 Log.e("NavitVehicle", "getLastKnownLocation precise (2) l=" + l.toString()); 443 Log.e("NavitVehicle", "getLastKnownLocation precise (2) l=" + l.toString());
443 last_location = l; 444 last_location = l;
444 VehicleCallback(vehicle_callbackid_, l); 445 //Log.e("NavitVehicle", "call VehicleCallback 005");
446 VehicleCallback(l);
445 } 447 }
446 } 448 }
447 } 449 }
448 } 450 }
449 } 451 }
473 { 475 {
474 if (Navit.PREF_follow_gps) 476 if (Navit.PREF_follow_gps)
475 { 477 {
476 Log.e("NavitVehicle", "getLastKnownLocation fast (3) l=" + l.toString()); 478 Log.e("NavitVehicle", "getLastKnownLocation fast (3) l=" + l.toString());
477 last_location = l; 479 last_location = l;
478 VehicleCallback(vehicle_callbackid_, l); 480 //Log.e("NavitVehicle", "call VehicleCallback 006");
481 VehicleCallback(l);
479 } 482 }
480 } 483 }
481 } 484 }
482 } 485 }
483 } 486 }
637 l.setLongitude(msg.getData().getFloat("lng")); 640 l.setLongitude(msg.getData().getFloat("lng"));
638 l.setBearing(msg.getData().getFloat("b")); 641 l.setBearing(msg.getData().getFloat("b"));
639 l.setSpeed(0.8f); 642 l.setSpeed(0.8f);
640 NavitVehicle.set_mock_location__fast(l); 643 NavitVehicle.set_mock_location__fast(l);
641 break; 644 break;
645 case 2:
646 if (update_location_in_progress)
647 {
648 }
649 else
650 {
651 update_location_in_progress = true;
652 VehicleCallback(last_location);
653 update_location_in_progress = false;
654 }
655 break;
642 } 656 }
643 } 657 }
644 }; 658 };
645 659
646 public static void update_compass_heading(float heading) 660 public static void update_compass_heading(float heading)
651 { 665 {
652 if (Navit.PREF_use_compass_heading_base) 666 if (Navit.PREF_use_compass_heading_base)
653 { 667 {
654 if ((Navit.PREF_use_compass_heading_always) || (last_location.getSpeed() < GPS_SPEED_ABOVE_USE_FOR_HEADING)) 668 if ((Navit.PREF_use_compass_heading_always) || (last_location.getSpeed() < GPS_SPEED_ABOVE_USE_FOR_HEADING))
655 { 669 {
670 if ((lastcompass_update_timestamp + 400) > System.currentTimeMillis())
671 {
672 //Log.e("NavitVehicle", "compass update to fast!");
673 return;
674 }
675 lastcompass_update_timestamp = System.currentTimeMillis();
676
656 last_location.setBearing(compass_heading); 677 last_location.setBearing(compass_heading);
657 // !! ugly hack to make map redraw !! 678 // !! ugly hack to make map redraw !!
658 // !! ugly hack to make map redraw !! 679 // !! ugly hack to make map redraw !!
659 // !! ugly hack to make map redraw !! 680 // !! ugly hack to make map redraw !!
660 if (last_location.getSpeed() == 0.0f) 681 if (last_location.getSpeed() == 0.0f)
661 { 682 {
662 float save_speed = last_location.getSpeed(); 683 float save_speed = last_location.getSpeed();
663 last_location.setSpeed(0.2f); 684 last_location.setSpeed(0.2f);
664 if (!Navit.DemoVehicle) 685 if (!Navit.DemoVehicle)
665 { 686 {
687 //Log.e("NavitVehicle", "call VehicleCallback 007:start");
666 VehicleCallback(vehicle_callbackid_, last_location); 688 VehicleCallback(last_location);
689 /*
690 Message m2 = new Message();
691 m2.what = 2;
692 vehicle_handler_.handleMessage(m2);
693 */
694 //Log.e("NavitVehicle", "call VehicleCallback 007:end");
667 } 695 }
668 last_location.setSpeed(save_speed); 696 last_location.setSpeed(save_speed);
669 } 697 }
670 else 698 else
671 { 699 {
672 if (!Navit.DemoVehicle) 700 if (!Navit.DemoVehicle)
673 { 701 {
702 //Log.e("NavitVehicle", "call VehicleCallback 008");
674 VehicleCallback(vehicle_callbackid_, last_location); 703 VehicleCallback(last_location);
675 } 704 }
676 } 705 }
677 // !! ugly hack to make map redraw !! 706 // !! ugly hack to make map redraw !!
678 // !! ugly hack to make map redraw !! 707 // !! ugly hack to make map redraw !!
679 // !! ugly hack to make map redraw !! 708 // !! ugly hack to make map redraw !!

Legend:
Removed from v.27  
changed lines
  Added in v.28

   
Visit the ZANavi Wiki