summaryrefslogtreecommitdiff
path: root/navit/android/src/org/navitproject/navit/NavitVehicle.java
diff options
context:
space:
mode:
Diffstat (limited to 'navit/android/src/org/navitproject/navit/NavitVehicle.java')
-rw-r--r--navit/android/src/org/navitproject/navit/NavitVehicle.java126
1 files changed, 63 insertions, 63 deletions
diff --git a/navit/android/src/org/navitproject/navit/NavitVehicle.java b/navit/android/src/org/navitproject/navit/NavitVehicle.java
index 200fc3eec..e8c43e474 100644
--- a/navit/android/src/org/navitproject/navit/NavitVehicle.java
+++ b/navit/android/src/org/navitproject/navit/NavitVehicle.java
@@ -1,4 +1,4 @@
-/**
+/*
* Navit, a modular navigation system.
* Copyright (C) 2005-2008 Navit Team
*
@@ -41,52 +41,53 @@ import java.util.List;
public class NavitVehicle {
private static final String GPS_FIX_CHANGE = "android.location.GPS_FIX_CHANGE";
+ static Location sLastLocation;
+ private static LocationManager sLocationManager;
+ private Context mContext;
+ private long mVehiclePcbid;
+ private long mVehicleScbid;
+ private long mVehicleFcbid;
+ private String mFastProvider;
- public static Location lastLocation = null;
+ private static NavitLocationListener sPreciseLocationListener;
+ private static NavitLocationListener sFastLocationListener;
- private static LocationManager sLocationManager = null;
- private static Context context = null;
- private int vehicle_pcbid;
- private int vehicle_scbid;
- private int vehicle_fcbid;
- private String preciseProvider;
- private String fastProvider;
+ public native void vehicleCallback(long id, Location location);
- private static NavitLocationListener preciseLocationListener = null;
- private static NavitLocationListener fastLocationListener = null;
+ public native void vehicleCallback(long id, int satsInView, int satsUsed);
- public native void VehicleCallback(int id, Location location);
-
- public native void VehicleCallback(int id, int satsInView, int satsUsed);
-
- public native void VehicleCallback(int id, int enabled);
+ public native void vehicleCallback(long id, int enabled);
private class NavitLocationListener extends BroadcastReceiver implements GpsStatus.Listener, LocationListener {
- public boolean precise = false;
+ boolean mPrecise = false;
public void onLocationChanged(Location location) {
- lastLocation = location;
// Disable the fast provider if still active
- if (precise && fastProvider != null) {
- sLocationManager.removeUpdates(fastLocationListener);
- fastProvider = null;
+ if (mPrecise && mFastProvider != null) {
+ sLocationManager.removeUpdates(sFastLocationListener);
+ mFastProvider = null;
}
-
- VehicleCallback(vehicle_pcbid, location);
- VehicleCallback(vehicle_fcbid, 1);
+ vehicleCallback(mVehiclePcbid, location);
+ vehicleCallback(mVehicleFcbid, 1);
}
- public void onProviderDisabled(String provider) {}
+ public void onProviderDisabled(String provider) {
+ //unhandled
+ }
- public void onProviderEnabled(String provider) {}
+ public void onProviderEnabled(String provider) {
+ //unhandled
+ }
- public void onStatusChanged(String provider, int status, Bundle extras) {}
+ public void onStatusChanged(String provider, int status, Bundle extras) {
+ //unhandled
+ }
/**
* Called when the status of the GPS changes.
*/
public void onGpsStatusChanged(int event) {
- if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION)
+ if (ContextCompat.checkSelfPermission(mContext, android.Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
return;
@@ -101,17 +102,17 @@ public class NavitVehicle {
satsUsed++;
}
}
- VehicleCallback(vehicle_scbid, satsInView, satsUsed);
+ vehicleCallback(mVehicleScbid, satsInView, satsUsed);
}
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(GPS_FIX_CHANGE)) {
if (intent.getBooleanExtra("enabled", false)) {
- VehicleCallback(vehicle_fcbid, 1);
+ vehicleCallback(mVehicleFcbid, 1);
} else {
if (!intent.getBooleanExtra("enabled", true)) {
- VehicleCallback(vehicle_fcbid, 0);
+ vehicleCallback(mVehicleFcbid, 0);
}
}
}
@@ -119,25 +120,25 @@ public class NavitVehicle {
}
/**
- * @brief Creates a new {@code NavitVehicle}
+ * Creates a new {@code NavitVehicle}.
*
- * @param context
+ * @param context the context
* @param pcbid The address of the position callback function called when a location update is received
* @param scbid The address of the status callback function called when a status update is received
* @param fcbid The address of the fix callback function called when a
* {@code android.location.GPS_FIX_CHANGE} is received, indicating a change in GPS fix status
*/
- NavitVehicle(Context context, int pcbid, int scbid, int fcbid) {
+ NavitVehicle(Context context, long pcbid, long scbid, long fcbid) {
if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
return;
}
- this.context = context;
+ this.mContext = context;
sLocationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
- preciseLocationListener = new NavitLocationListener();
- preciseLocationListener.precise = true;
- fastLocationListener = new NavitLocationListener();
+ sPreciseLocationListener = new NavitLocationListener();
+ sPreciseLocationListener.mPrecise = true;
+ sFastLocationListener = new NavitLocationListener();
/* Use 2 LocationProviders, one precise (usually GPS), and one
not so precise, but possible faster. The fast provider is
@@ -159,19 +160,19 @@ public class NavitVehicle {
lowCriteria.setCostAllowed(true);
lowCriteria.setPowerRequirement(Criteria.POWER_HIGH);
- Log.e("NavitVehicle", "Providers " + sLocationManager.getAllProviders());
+ Log.d("NavitVehicle", "Providers " + sLocationManager.getAllProviders());
- preciseProvider = sLocationManager.getBestProvider(highCriteria, false);
- Log.e("NavitVehicle", "Precise Provider " + preciseProvider);
- fastProvider = sLocationManager.getBestProvider(lowCriteria, false);
- Log.e("NavitVehicle", "Fast Provider " + fastProvider);
- vehicle_pcbid = pcbid;
- vehicle_scbid = scbid;
- vehicle_fcbid = fcbid;
+ String mPreciseProvider = sLocationManager.getBestProvider(highCriteria, false);
+ Log.d("NavitVehicle", "Precise Provider " + mPreciseProvider);
+ mFastProvider = sLocationManager.getBestProvider(lowCriteria, false);
+ Log.d("NavitVehicle", "Fast Provider " + mFastProvider);
+ mVehiclePcbid = pcbid;
+ mVehicleScbid = scbid;
+ mVehicleFcbid = fcbid;
- context.registerReceiver(preciseLocationListener, new IntentFilter(GPS_FIX_CHANGE));
- sLocationManager.requestLocationUpdates(preciseProvider, 0, 0, preciseLocationListener);
- sLocationManager.addGpsStatusListener(preciseLocationListener);
+ context.registerReceiver(sPreciseLocationListener, new IntentFilter(GPS_FIX_CHANGE));
+ sLocationManager.requestLocationUpdates(mPreciseProvider, 0, 0, sPreciseLocationListener);
+ sLocationManager.addGpsStatusListener(sPreciseLocationListener);
/*
* Since Android criteria have no way to specify "fast fix", lowCriteria may return the same
@@ -179,32 +180,31 @@ public class NavitVehicle {
* listeners for the same provider but pick the fast provider manually. (Usually there will
* only be two providers in total, which makes the choice easy.)
*/
- if (fastProvider == null || preciseProvider.compareTo(fastProvider) == 0) {
+ if (mFastProvider == null || mPreciseProvider.compareTo(mFastProvider) == 0) {
List<String> fastProviderList = sLocationManager.getProviders(lowCriteria, false);
- fastProvider = null;
+ mFastProvider = null;
for (String fastCandidate: fastProviderList) {
- if (preciseProvider.compareTo(fastCandidate) != 0) {
- fastProvider = fastCandidate;
+ if (mPreciseProvider.compareTo(fastCandidate) != 0) {
+ mFastProvider = fastCandidate;
break;
}
}
}
- if (fastProvider != null) {
- sLocationManager.requestLocationUpdates(fastProvider, 0, 0, fastLocationListener);
+ if (mFastProvider != null) {
+ sLocationManager.requestLocationUpdates(mFastProvider, 0, 0, sFastLocationListener);
}
}
- public static void removeListener() {
+ static void removeListeners(Navit navit) {
if (sLocationManager != null) {
- if (preciseLocationListener != null) {
- sLocationManager.removeUpdates(preciseLocationListener);
- sLocationManager.removeGpsStatusListener(preciseLocationListener);
- context.unregisterReceiver(preciseLocationListener);
+ if (sPreciseLocationListener != null) {
+ sLocationManager.removeUpdates(sPreciseLocationListener);
+ sLocationManager.removeGpsStatusListener(sPreciseLocationListener);
+ navit.unregisterReceiver(sPreciseLocationListener);
}
- if (fastLocationListener != null) {
- sLocationManager.removeUpdates(fastLocationListener);
+ if (sFastLocationListener != null) {
+ sLocationManager.removeUpdates(sFastLocationListener);
}
}
-
}
}