diff options
author | Herbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com> | 2010-09-26 02:30:14 +0200 |
---|---|---|
committer | Herbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com> | 2010-09-26 02:30:14 +0200 |
commit | 79add8afa37d4e125a0eec577a1f3e10f92b2a07 (patch) | |
tree | 1a1a9d6970488dc31c193d27d1779aaba14396d9 /src/org/broeuschmeul/android/gps/bluetooth | |
parent | 73845df38038160c4eb9696cccc5babcce6dc216 (diff) | |
download | BlueGPS-79add8afa37d4e125a0eec577a1f3e10f92b2a07.zip BlueGPS-79add8afa37d4e125a0eec577a1f3e10f92b2a07.tar.gz BlueGPS-79add8afa37d4e125a0eec577a1f3e10f92b2a07.tar.bz2 |
Code cleanup
Diffstat (limited to 'src/org/broeuschmeul/android/gps/bluetooth')
3 files changed, 153 insertions, 253 deletions
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java index 12e6c97..a1d3480 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java @@ -24,8 +24,6 @@ import java.io.BufferedReader; import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.PrintStream;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -50,65 +48,47 @@ import android.util.Log; public class BlueetoothGpsManager {
private class ConnectedGps extends Thread {
- private final InputStream in;
- private final OutputStream out;
- private final PrintStream out2;
- private boolean ready = false;
-
- public ConnectedGps(BluetoothSocket socket) {
- InputStream tmpIn = null;
- OutputStream tmpOut = null;
- PrintStream tmpOut2 = null;
- try {
- tmpIn = socket.getInputStream();
- tmpOut = socket.getOutputStream();
- if (tmpOut != null){
- tmpOut2 = new PrintStream(tmpOut, false, "US-ASCII");
- }
- } catch (IOException e) {
- Log.e("BT test", "error while getting socket streams", e);
- }
- in = tmpIn;
- out = tmpOut;
- out2 = tmpOut2;
- }
+ private final InputStream in;
+
+ public ConnectedGps(BluetoothSocket socket) {
+ InputStream tmpIn = null;
+ try {
+ tmpIn = socket.getInputStream();
+ } catch (IOException e) {
+ Log.e("BT test", "error while getting socket streams", e);
+ }
+ in = tmpIn;
+ }
- public void run() {
- try {
- BufferedReader reader = new BufferedReader(new InputStreamReader(in,"US-ASCII"));
- String s;
- long now = SystemClock.uptimeMillis();
- long lastRead = now;
-// while((enabled && (s = reader.readLine()) != null)){
- while((enabled) && (now < lastRead+5000 )){
- if (reader.ready()){
- s = reader.readLine();
+ public void run() {
+ try {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in,"US-ASCII"));
+ String s;
+ long now = SystemClock.uptimeMillis();
+ long lastRead = now;
+ while((enabled) && (now < lastRead+5000 )){
+ if (reader.ready()){
+ s = reader.readLine();
Log.e("BT test", "data: "+System.currentTimeMillis()+" "+s + "xxx");
notifyNmeaSentence(s+"\r\n");
- ready = true;
lastRead = SystemClock.uptimeMillis();
-// parser.parseNmeaSentence(s);
-// // writer.println(s);
-// addNMEAString(s);
-// nmeaSentenceHandler.ob
- } else {
- Log.e("BT test", "data: not ready "+System.currentTimeMillis());
- SystemClock.sleep(500);
- }
- now = SystemClock.uptimeMillis();
+ } else {
+ Log.e("BT test", "data: not ready "+System.currentTimeMillis());
+ SystemClock.sleep(500);
}
- } catch (IOException e) {
- Log.e("BT test", "error while getting data", e);
- setMockLocationProviderOutOfService();
- } finally {
- // remove because we want to retry...
-// disable();
+ now = SystemClock.uptimeMillis();
}
- }
+ } catch (IOException e) {
+ Log.e("BT test", "error while getting data", e);
+ setMockLocationProviderOutOfService();
+ } finally {
+ // remove because we want to retry...
+ // disable();
+ }
}
+ }
private Service callingService;
- private BluetoothDevice gpsDevice;
private BluetoothSocket gpsSocket;
private String gpsDeviceAddress;
private NmeaParser parser = new NmeaParser(10f);
@@ -117,13 +97,8 @@ public class BlueetoothGpsManager { private ScheduledExecutorService connectionAndReadingPool;
private List<NmeaListener> nmeaListeners = Collections.synchronizedList(new LinkedList<NmeaListener>());
private LocationManager locationManager;
-// private boolean mockGpsEnabled = true;
-// private String mockLocationProvider = LocationManager.GPS_PROVIDER;
private ConnectedGps connectedGps;
-// private Handler nmeaSentenceHandler = new Handler();
-
-
/**
* @return true if the bluetooth GPS is enabled
*/
@@ -141,29 +116,29 @@ public class BlueetoothGpsManager { public synchronized boolean enable() {
if (! enabled){
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
- if (bluetoothAdapter == null) {
- // Device does not support Bluetooth
- Log.e("BT test", "Device does not support Bluetooth");
- } else if (!bluetoothAdapter.isEnabled()) {
-// Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
-// startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
- Log.e("BT test", "Bluetooth is not enabled");
- } else {
- final BluetoothDevice gpsDevice = bluetoothAdapter.getRemoteDevice(gpsDeviceAddress);
- if (gpsDevice == null){
- Log.e("BT test", "GPS device not found");
- } else {
- Log.e("BT test", "current device: "+gpsDevice.getName() + " -- " + gpsDevice.getAddress());
- try {
- gpsSocket = gpsDevice.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
- } catch (IOException e) {
- Log.e("BT test", "Error during connection", e);
- }
- if (gpsSocket == null){
- Log.e("BT test", "Error while establishing connection: no socket");
- } else {
- Runnable connectThread = new Runnable() {
- private int connectionTry=0;
+ if (bluetoothAdapter == null) {
+ // Device does not support Bluetooth
+ Log.e("BT test", "Device does not support Bluetooth");
+ } else if (!bluetoothAdapter.isEnabled()) {
+ // Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
+ // startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
+ Log.e("BT test", "Bluetooth is not enabled");
+ } else {
+ final BluetoothDevice gpsDevice = bluetoothAdapter.getRemoteDevice(gpsDeviceAddress);
+ if (gpsDevice == null){
+ Log.e("BT test", "GPS device not found");
+ } else {
+ Log.e("BT test", "current device: "+gpsDevice.getName() + " -- " + gpsDevice.getAddress());
+ try {
+ gpsSocket = gpsDevice.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
+ } catch (IOException e) {
+ Log.e("BT test", "Error during connection", e);
+ }
+ if (gpsSocket == null){
+ Log.e("BT test", "Error while establishing connection: no socket");
+ } else {
+ Runnable connectThread = new Runnable() {
+ private int connectionTry=0;
@Override
public void run() {
try {
@@ -185,97 +160,63 @@ public class BlueetoothGpsManager { if (gpsSocket == null){
Log.e("BT test", "Error while establishing connection: no socket");
} else {
- // Cancel discovery because it will slow down the connection
- bluetoothAdapter.cancelDiscovery();
+ // Cancel discovery because it will slow down the connection
+ bluetoothAdapter.cancelDiscovery();
// we increment the number of connection try
- // Connect the device through the socket. This will block
- // until it succeeds or throws an exception
- gpsSocket.connect();
+ // Connect the device through the socket. This will block
+ // until it succeeds or throws an exception
+ gpsSocket.connect();
// connection obtained so reset the number of connection try
connectionTry=0;
connectedGps = new ConnectedGps(gpsSocket);
connectionAndReadingPool.execute(connectedGps);
-// connectedGps.start();
-// String command = callingService.getString(R.string.sirf_gll_on);
-// String sentence = String.format((Locale)null,"$%s*%X\r\n", command, parser.computeChecksum(command));
-// String command1 = callingService.getString(R.string.sirf_gll_off);
-// String sentence1 = String.format((Locale)null,"$%s*%X\r\n", command1, parser.computeChecksum(command1));
-// String command2 = callingService.getString(R.string.sirf_vtg_off);
-// String sentence2 = String.format((Locale)null,"$%s*%X\r\n", command2, parser.computeChecksum(command2));
-// try {
-// Thread.sleep(5000);
-// } catch (InterruptedException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
-// Log.e("BT test", "sending NMEA sentence: "+"$PSRF105,1*3E\r\n");
-// connectedGps.write("$PSRF105,1*3E\r\n");
-// Log.e("BT test", "sending NMEA sentence: "+sentence1);
-// connectedGps.write(sentence1);
-// Log.e("BT test", "sending NMEA sentence: "+sentence2);
-// connectedGps.write(sentence2);
}
- } catch (IOException connectException) {
- // Unable to connect; close everything and get out
- Log.e("BT test", "error while connecting to socket", connectException);
-// callingService.stopSelf();
- } finally {
- // if bluetooth has bean disabled or
- // if two much tries consider that we are enable to connect. So close everything and get out
- if ((!bluetoothAdapter.isEnabled()) || (connectionTry > 5 )){
- disable();
- }
- }
+ } catch (IOException connectException) {
+ // Unable to connect; close everything and get out
+ Log.e("BT test", "error while connecting to socket", connectException);
+ } finally {
+ // if bluetooth has bean disabled or
+ // if two much tries consider that we are enable to connect. So close everything and get out
+ if ((!bluetoothAdapter.isEnabled()) || (connectionTry > 5 )){
+ disable();
+ }
+ }
}
};
this.enabled = true;
notificationPool = Executors.newSingleThreadExecutor();
connectionAndReadingPool = Executors.newSingleThreadScheduledExecutor();
connectionAndReadingPool.scheduleWithFixedDelay(connectThread, 100, 60000, TimeUnit.MILLISECONDS);
-// enableMockLocationProvider(LocationManager.GPS_PROVIDER);
- }
- }
- }
+ }
+ }
+ }
}
return this.enabled;
}
-
+
public synchronized void disable() {
if (enabled){
enabled = false;
if (gpsSocket != null){
- try {
- gpsSocket.close();
- } catch (IOException closeException) {
- Log.e("BT test", "error while closing socket", closeException);
- }
+ try {
+ gpsSocket.close();
+ } catch (IOException closeException) {
+ Log.e("BT test", "error while closing socket", closeException);
+ }
}
nmeaListeners.clear();
disableMockLocationProvider();
notificationPool.shutdown();
-//// locationManager.setTestProviderEnabled(mockLocationProvider, mockGpsEnabled);
-// LocationProvider prov = locationManager.getProvider(mockLocationProvider);
-// Log.e("BT test", "Mock power: "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+locationManager.isProviderEnabled(mockLocationProvider));
-// locationManager.clearTestProviderEnabled(mockLocationProvider);
-// prov = locationManager.getProvider(mockLocationProvider);
-// Log.e("BT test", "Mock power: "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+locationManager.isProviderEnabled(mockLocationProvider));
-// locationManager.clearTestProviderStatus(mockLocationProvider);
-// locationManager.removeTestProvider(mockLocationProvider);
-// prov = locationManager.getProvider(mockLocationProvider);
-// Log.e("BT test", "Mock power: "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+locationManager.isProviderEnabled(mockLocationProvider));
-// Log.e("BT test", "removed mock GPS");
-
callingService.stopSelf();
}
}
-
public void enableMockLocationProvider(String gpsName){
if (parser != null){
parser.enableMockLocationProvider(gpsName);
}
}
-
+
public void disableMockLocationProvider(){
if (parser != null){
parser.disableMockLocationProvider();
@@ -302,7 +243,7 @@ public class BlueetoothGpsManager { }
return mockLocationProvider;
}
-
+
private void setMockLocationProviderOutOfService(){
if (parser != null){
parser.setMockLocationProviderOutOfService();
@@ -315,28 +256,28 @@ public class BlueetoothGpsManager { }
return true;
}
-
+
public void removeNmeaListener(NmeaListener listener){
- nmeaListeners.remove(listener);
+ nmeaListeners.remove(listener);
}
-
+
private void notifyNmeaSentence(final String nmeaSentence){
if (enabled){
final String recognizedSentence = parser.parseNmeaSentence(nmeaSentence);
final long timestamp = System.currentTimeMillis();
if (recognizedSentence != null){
Log.e("BT test", "NMEA : "+timestamp+" "+recognizedSentence);
- synchronized(nmeaListeners) {
- for(final NmeaListener listener : nmeaListeners){
- notificationPool.execute(new Runnable(){
- @Override
- public void run() {
- listener.onNmeaReceived(timestamp, nmeaSentence);
- }
- });
+ synchronized(nmeaListeners) {
+ for(final NmeaListener listener : nmeaListeners){
+ notificationPool.execute(new Runnable(){
+ @Override
+ public void run() {
+ listener.onNmeaReceived(timestamp, nmeaSentence);
+ }
+ });
+ }
}
}
}
- }
}
}
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java index 176508b..85d63ef 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java @@ -45,18 +45,18 @@ import android.util.Log; public class BluetoothGpsActivity extends PreferenceActivity implements OnPreferenceChangeListener, OnSharedPreferenceChangeListener { private SharedPreferences sharedPref ; private BluetoothAdapter bluetoothAdapter = null; - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.pref); - sharedPref = PreferenceManager.getDefaultSharedPreferences(this); - sharedPref.registerOnSharedPreferenceChangeListener(this); - bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); - } - /* (non-Javadoc) + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.pref); + sharedPref = PreferenceManager.getDefaultSharedPreferences(this); + sharedPref.registerOnSharedPreferenceChangeListener(this); + bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); + } + + /* (non-Javadoc) * @see android.app.Activity#onResume() */ @Override @@ -66,58 +66,55 @@ public class BluetoothGpsActivity extends PreferenceActivity implements OnPrefer } private void updateDevicePreferenceSummary(){ - // update bluetooth device summary + // update bluetooth device summary String deviceName = ""; - ListPreference prefDevices = (ListPreference)findPreference(BluetoothGpsProviderService.PREF_BLUETOOTH_DEVICE); - String deviceAddress = sharedPref.getString(BluetoothGpsProviderService.PREF_BLUETOOTH_DEVICE, null); - if (BluetoothAdapter.checkBluetoothAddress(deviceAddress)){ - deviceName = bluetoothAdapter.getRemoteDevice(deviceAddress).getName(); - } - prefDevices.setSummary(getString(R.string.pref_bluetooth_device_summary, deviceName)); - } + ListPreference prefDevices = (ListPreference)findPreference(BluetoothGpsProviderService.PREF_BLUETOOTH_DEVICE); + String deviceAddress = sharedPref.getString(BluetoothGpsProviderService.PREF_BLUETOOTH_DEVICE, null); + if (BluetoothAdapter.checkBluetoothAddress(deviceAddress)){ + deviceName = bluetoothAdapter.getRemoteDevice(deviceAddress).getName(); + } + prefDevices.setSummary(getString(R.string.pref_bluetooth_device_summary, deviceName)); + } private void updateDevicePreferenceList(){ - // update bluetooth device summary + // update bluetooth device summary updateDevicePreferenceSummary(); // update bluetooth device list - ListPreference prefDevices = (ListPreference)findPreference(BluetoothGpsProviderService.PREF_BLUETOOTH_DEVICE); - Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices(); - String[] entryValues = new String[pairedDevices.size()]; - String[] entries = new String[pairedDevices.size()]; - int i = 0; - // Loop through paired devices - for (BluetoothDevice device : pairedDevices) { - // Add the name and address to the ListPreference enties and entyValues - Log.e("BT test", "device: "+device.getName() + " -- " + device.getAddress()); - entryValues[i] = device.getAddress(); - entries[i] = device.getName(); - i++; - } + ListPreference prefDevices = (ListPreference)findPreference(BluetoothGpsProviderService.PREF_BLUETOOTH_DEVICE); + Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices(); + String[] entryValues = new String[pairedDevices.size()]; + String[] entries = new String[pairedDevices.size()]; + int i = 0; + // Loop through paired devices + for (BluetoothDevice device : pairedDevices) { + // Add the name and address to the ListPreference enties and entyValues + Log.e("BT test", "device: "+device.getName() + " -- " + device.getAddress()); + entryValues[i] = device.getAddress(); + entries[i] = device.getName(); + i++; + } prefDevices.setEntryValues(entryValues); prefDevices.setEntries(entries); -// if (sharedPref.getBoolean(BluetoothGpsProviderService.PREF_START_GPS_PROVIDER, false)){ - Preference pref = (Preference)findPreference(BluetoothGpsProviderService.PREF_TRACK_RECORDING); - pref.setEnabled(sharedPref.getBoolean(BluetoothGpsProviderService.PREF_START_GPS_PROVIDER, false)); -// } - pref = (Preference)findPreference(BluetoothGpsProviderService.PREF_MOCK_GPS_NAME); - String mockProvider = sharedPref.getString(BluetoothGpsProviderService.PREF_MOCK_GPS_NAME, getString(R.string.defaultMockGpsName)); - pref.setSummary(getString(R.string.pref_mock_gps_name_summary,mockProvider)); - - pref = (Preference)findPreference(BluetoothGpsProviderService.PREF_GPS_LOCATION_PROVIDER); - if (sharedPref.getBoolean(BluetoothGpsProviderService.PREF_REPLACE_STD_GPS, true)){ - String s = getString(R.string.pref_gps_location_provider_summary); - pref.setSummary(s); - Log.e("BT test", "loc. provider: "+s); - Log.e("BT test", "loc. provider: "+pref.getSummary()); - } else { - String s = getString(R.string.pref_mock_gps_name_summary, mockProvider); - pref.setSummary(s); - Log.e("BT test", "loc. provider: "+s); - Log.e("BT test", "loc. provider: "+pref.getSummary()); - } - this.onContentChanged(); + Preference pref = (Preference)findPreference(BluetoothGpsProviderService.PREF_TRACK_RECORDING); + pref.setEnabled(sharedPref.getBoolean(BluetoothGpsProviderService.PREF_START_GPS_PROVIDER, false)); + pref = (Preference)findPreference(BluetoothGpsProviderService.PREF_MOCK_GPS_NAME); + String mockProvider = sharedPref.getString(BluetoothGpsProviderService.PREF_MOCK_GPS_NAME, getString(R.string.defaultMockGpsName)); + pref.setSummary(getString(R.string.pref_mock_gps_name_summary,mockProvider)); + pref = (Preference)findPreference(BluetoothGpsProviderService.PREF_GPS_LOCATION_PROVIDER); + if (sharedPref.getBoolean(BluetoothGpsProviderService.PREF_REPLACE_STD_GPS, true)){ + String s = getString(R.string.pref_gps_location_provider_summary); + pref.setSummary(s); + Log.e("BT test", "loc. provider: "+s); + Log.e("BT test", "loc. provider: "+pref.getSummary()); + } else { + String s = getString(R.string.pref_mock_gps_name_summary, mockProvider); + pref.setSummary(s); + Log.e("BT test", "loc. provider: "+s); + Log.e("BT test", "loc. provider: "+pref.getSummary()); + } + this.onContentChanged(); } - + @Override protected void onDestroy() { super.onDestroy(); @@ -136,7 +133,7 @@ public class BluetoothGpsActivity extends PreferenceActivity implements OnPrefer if (BluetoothGpsProviderService.PREF_START_GPS_PROVIDER.equals(key)){ boolean val = false; if (val = sharedPreferences.getBoolean(key, false)){ - startService(new Intent(BluetoothGpsProviderService.ACTION_START_GPS_PROVIDER)); + startService(new Intent(BluetoothGpsProviderService.ACTION_START_GPS_PROVIDER)); } else { startService(new Intent(BluetoothGpsProviderService.ACTION_STOP_GPS_PROVIDER)); } @@ -147,7 +144,7 @@ public class BluetoothGpsActivity extends PreferenceActivity implements OnPrefer } else if (BluetoothGpsProviderService.PREF_TRACK_RECORDING.equals(key)){ boolean val = false; if (val = sharedPreferences.getBoolean(key, false)){ - startService(new Intent(BluetoothGpsProviderService.ACTION_START_TRACK_RECORDING)); + startService(new Intent(BluetoothGpsProviderService.ACTION_START_TRACK_RECORDING)); } else { startService(new Intent(BluetoothGpsProviderService.ACTION_STOP_TRACK_RECORDING)); } diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java index 9ac1b07..3fc43e9 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,7 +55,7 @@ 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";
@@ -72,18 +71,16 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener 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
@@ -91,12 +88,8 @@ 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);
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())){
@@ -112,7 +105,6 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener }
gpsManager = new BlueetoothGpsManager(this, deviceAddress);
gpsManager.enableMockLocationProvider(mockProvider);
-// gpsManager.enableMockLocationProvider(LocationManager.GPS_PROVIDER);
boolean enabled = gpsManager.enable();
if (sharedPreferences.getBoolean(PREF_START_GPS_PROVIDER, false) != enabled){
edit.putBoolean(PREF_START_GPS_PROVIDER,enabled);
@@ -120,16 +112,10 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener }
if (enabled) {
startForeground(R.string.foreground_gps_provider_started_notification, notification);
- toast.setText(this.getString(R.string.msg_gps_provider_started));
- toast.show();
+ 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 {
@@ -153,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));
@@ -234,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(){
@@ -293,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();
-// }
-// }
}
|