aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java')
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java74
1 files changed, 23 insertions, 51 deletions
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
index 0ab972b..ef2410d 100644
--- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
+++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
@@ -35,7 +35,6 @@ import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
-import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.Location;
@@ -56,31 +55,31 @@ import android.widget.Toast;
*
*/
public class BluetoothGpsProviderService extends Service implements NmeaListener, LocationListener {
-
+
public static final String ACTION_START_TRACK_RECORDING = "org.broeuschmeul.android.gps.bluetooth.tracker.nmea.intent.action.START_TRACK_RECORDING";
public static final String ACTION_STOP_TRACK_RECORDING = "org.broeuschmeul.android.gps.bluetooth.tracker.nmea.intent.action.STOP_TRACK_RECORDING";
public static final String ACTION_START_GPS_PROVIDER = "org.broeuschmeul.android.gps.bluetooth.provider.nmea.intent.action.START_GPS_PROVIDER";
public static final String ACTION_STOP_GPS_PROVIDER = "org.broeuschmeul.android.gps.bluetooth.provider.nmea.intent.action.STOP_GPS_PROVIDER";
public static final String PREF_START_GPS_PROVIDER = "startGps";
+ public static final String PREF_GPS_LOCATION_PROVIDER = "gpsLocationProviderKey";
+ public static final String PREF_REPLACE_STD_GPS = "replaceStdtGps";
+ public static final String PREF_MOCK_GPS_NAME = "mockGpsName";
+ public static final String PREF_CONNECTION_RETRIES = "connectionRetries";
public static final String PREF_TRACK_RECORDING = "trackRecording";
- public static final String PREF_TRACK_MIN_DISTANCE = "trackMinDistance";
- public static final String PREF_TRACK_MIN_TIME = "trackMinTime";
public static final String PREF_TRACK_FILE_DIR = "trackFileDirectory";
public static final String PREF_TRACK_FILE_PREFIX = "trackFilePrefix";
public static final String PREF_BLUETOOTH_DEVICE = "bluetoothDevice";
- private LocationManager lm;
- private BlueetoothGpsManager gpsManager = null;
+ private BlueetoothGpsManager gpsManager = null;
private PrintWriter writer;
private File trackFile;
private boolean preludeWritten = false;
private Toast toast ;
-
+
@Override
public void onCreate() {
super.onCreate();
- toast = Toast.makeText(getApplicationContext(), "NMEA track recording... on", Toast.LENGTH_SHORT);
- lm = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
+ toast = Toast.makeText(getApplicationContext(), "NMEA track recording... on", Toast.LENGTH_SHORT);
}
@Override
@@ -88,12 +87,9 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
// super.onStart(intent, startId);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor edit = sharedPreferences.edit();
-// long minTime = Long.parseLong(sharedPreferences.getString(PREF_TRACK_MIN_TIME, this.getString(R.string.defaultTrackMinTime)));
-// float minDistance = Float.parseFloat(sharedPreferences.getString(PREF_TRACK_MIN_DISTANCE, this.getString(R.string.defaultTrackMinDistance)));
String deviceAddress = sharedPreferences.getString(PREF_BLUETOOTH_DEVICE, null);
+ int maxConRetries = Integer.parseInt(sharedPreferences.getString(PREF_CONNECTION_RETRIES, this.getString(R.string.defaultConnectionRetries)));
if (Config.LOGD){
-// Log.d(BluetoothGpsProviderService.class.getName(), "prefs minTime: "+minTime);
-// Log.d(BluetoothGpsProviderService.class.getName(), "prefs minDistance: "+minDistance);
Log.d(BluetoothGpsProviderService.class.getName(), "prefs device addr: "+deviceAddress);
}
if (ACTION_START_GPS_PROVIDER.equals(intent.getAction())){
@@ -102,24 +98,24 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
Intent myIntent = new Intent(this, BluetoothGpsActivity.class);
PendingIntent myPendingIntent = PendingIntent.getActivity(this, 0, myIntent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(getApplicationContext(), this.getString(R.string.foreground_service_started_notification_title), this.getString(R.string.foreground_gps_provider_started_notification), myPendingIntent);
- startForeground(R.string.foreground_gps_provider_started_notification, notification);
if (BluetoothAdapter.checkBluetoothAddress(deviceAddress)){
- gpsManager = new BlueetoothGpsManager(this, deviceAddress);
- gpsManager.enableMockLocationProvider(LocationManager.GPS_PROVIDER);
- gpsManager.enable();
- if (! sharedPreferences.getBoolean(PREF_START_GPS_PROVIDER, false)){
- edit.putBoolean(PREF_START_GPS_PROVIDER,true);
+ String mockProvider = LocationManager.GPS_PROVIDER;
+ if (! sharedPreferences.getBoolean(PREF_REPLACE_STD_GPS, true)){
+ mockProvider = sharedPreferences.getString(PREF_MOCK_GPS_NAME, getString(R.string.defaultMockGpsName));
+ }
+ gpsManager = new BlueetoothGpsManager(this, deviceAddress, maxConRetries);
+ gpsManager.enableMockLocationProvider(mockProvider);
+ boolean enabled = gpsManager.enable();
+ if (sharedPreferences.getBoolean(PREF_START_GPS_PROVIDER, false) != enabled){
+ edit.putBoolean(PREF_START_GPS_PROVIDER,enabled);
edit.commit();
}
- toast.setText(this.getString(R.string.msg_gps_provider_started));
- toast.show();
+ if (enabled) {
+ startForeground(R.string.foreground_gps_provider_started_notification, notification);
+ toast.setText(this.getString(R.string.msg_gps_provider_started));
+ toast.show();
+ }
} else {
-// if (! sharedPreferences.getBoolean(PREF_START_GPS_PROVIDER, true)){
-// edit.putBoolean(PREF_START_GPS_PROVIDER,false);
-// edit.commit();
-// }
-// toast.setText(this.getString(R.string.msg_invalid_device));
-// toast.show();
stopSelf();
}
} else {
@@ -143,8 +139,6 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
edit.putBoolean(PREF_TRACK_RECORDING,false);
edit.commit();
}
-// toast.setText(this.getString(R.string.msg_device_not_started));
-// toast.show();
}
} else {
toast.setText(this.getString(R.string.msg_nmea_recording_already_started));
@@ -224,10 +218,6 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
Log.e(BluetoothGpsProviderService.class.getName(), "Error while writing the prelude of the NMEA file: "+trackFile.getAbsolutePath(), e);
// there was an error while writing the prelude of the NMEA file, stopping the service...
stopSelf();
-// } catch (SecurityException e) {
-// Log.e(BluetoothGpsProviderService.class.getName(), "Error while writing the prelude of the NMEA file: "+trackFile.getAbsolutePath(), e);
-// // there was an error while writing the prelude of the NMEA file, stopping the service...
-// stopSelf();
}
}
private void endTrack(){
@@ -283,22 +273,4 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
public void onNmeaReceived(long timestamp, String data) {
addNMEAString(data);
}
-
-// private void startBluetoothGps(String deviceAddress){
-// Notification notification = new Notification(R.drawable.icon, this.getString(R.string.foreground_service_started_notification), System.currentTimeMillis());
-// Intent myIntent = new Intent(this, BluetoothGpsActivity.class);
-// PendingIntent myPendingIntent = PendingIntent.getActivity(this, 0, myIntent, PendingIntent.FLAG_CANCEL_CURRENT);
-// notification.setLatestEventInfo(getApplicationContext(), this.getString(R.string.foreground_service_started_notification_title), this.getString(R.string.foreground_service_started_notification), myPendingIntent);
-// startForeground(R.string.foreground_service_started_notification, notification);
-// if (BluetoothAdapter.checkBluetoothAddress(deviceAddress)){
-// gpsManager = new BlueetoothGpsManager(this, deviceAddress);
-// gpsManager.enable();
-// gpsManager.enableMockLocationProvider(LocationManager.GPS_PROVIDER);
-// toast.setText(this.getString(R.string.msg_started));
-// toast.show();
-//// } else {
-//// toast.setText(this.getString(R.string.msg_invalid_device));
-//// toast.show();
-// }
-// }
}