diff options
author | Herbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com> | 2010-09-26 02:28:14 +0200 |
---|---|---|
committer | Herbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com> | 2010-09-26 02:28:14 +0200 |
commit | 46bdd0b6f96936da7f531c1fbdbc8f0c34445c8c (patch) | |
tree | 0bee23f921d004dcc2a5c928fecf9a0c59206d2e /src/org/broeuschmeul | |
parent | 21c82b076110b9458616460ea841662aed44a057 (diff) | |
download | BlueGPS-46bdd0b6f96936da7f531c1fbdbc8f0c34445c8c.zip BlueGPS-46bdd0b6f96936da7f531c1fbdbc8f0c34445c8c.tar.gz BlueGPS-46bdd0b6f96936da7f531c1fbdbc8f0c34445c8c.tar.bz2 |
Code cleanup
Diffstat (limited to 'src/org/broeuschmeul')
4 files changed, 201 insertions, 310 deletions
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java index f4cfb92..0a1f67f 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java @@ -52,100 +52,94 @@ 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;
- }
-
- 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();
+ 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;
+ }
+
+ 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();
+ }
+ }
- /**
- * Write to the connected OutStream.
- * @param buffer The bytes to write
- */
- public void write(byte[] buffer) {
- try {
- do {
- Thread.sleep(100);
- } while (! ready);
- out.write(buffer);
- out.flush();
- } catch (IOException e) {
- Log.e("BT test", "Exception during write", e);
- } catch (InterruptedException e) {
- Log.e("BT test", "Exception during write", e);
- }
- }
- /**
- * Write to the connected OutStream.
- * @param buffer The data to write
- */
- public void write(String buffer) {
- try {
- do {
- Thread.sleep(100);
- } while (! ready);
- out2.print(buffer);
- out2.flush();
-// } catch (IOException e) {
-// Log.e("BT test", "Exception during write", e);
- } catch (InterruptedException e) {
- Log.e("BT test", "Exception during write", e);
- }
- }
+ /**
+ * Write to the connected OutStream.
+ * @param buffer The bytes to write
+ */
+ public void write(byte[] buffer) {
+ try {
+ do {
+ Thread.sleep(100);
+ } while (! ready);
+ out.write(buffer);
+ out.flush();
+ } catch (IOException e) {
+ Log.e("BT test", "Exception during write", e);
+ } catch (InterruptedException e) {
+ Log.e("BT test", "Exception during write", e);
+ }
}
+ /**
+ * Write to the connected OutStream.
+ * @param buffer The data to write
+ */
+ public void write(String buffer) {
+ try {
+ do {
+ Thread.sleep(100);
+ } while (! ready);
+ out2.print(buffer);
+ out2.flush();
+ // } catch (IOException e) {
+ // Log.e("BT test", "Exception during write", e);
+ } catch (InterruptedException e) {
+ Log.e("BT test", "Exception during write", e);
+ }
+ }
+ }
private Service callingService;
- private BluetoothDevice gpsDevice;
private BluetoothSocket gpsSocket;
private String gpsDeviceAddress;
private NmeaParser parser = new NmeaParser(10f);
@@ -154,12 +148,7 @@ 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
@@ -178,29 +167,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 {
@@ -232,50 +221,26 @@ public class BlueetoothGpsManager { 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);
-// Thread.sleep(5000);
}
-// } catch (InterruptedException e) {
-// Log.e("BT test", "error while connecting to socket", e);
} 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();
- }
- }
+ // 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;
}
@@ -284,38 +249,26 @@ public class BlueetoothGpsManager { 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();
@@ -342,7 +295,7 @@ public class BlueetoothGpsManager { }
return mockLocationProvider;
}
-
+
private void setMockLocationProviderOutOfService(){
if (parser != null){
parser.setMockLocationProviderOutOfService();
@@ -355,11 +308,11 @@ 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);
@@ -379,7 +332,7 @@ public class BlueetoothGpsManager { }
}
}
-
+
public void sendPackagedNmeaCommand(final String command){
Log.e("BT test", "sending NMEA sentence: "+command);
if (isEnabled()){
@@ -394,7 +347,7 @@ public class BlueetoothGpsManager { });
}
}
-
+
public void sendPackagedSirfCommand(final String commandHexa){
Log.e("BT test", "sending SIRF sentence: "+commandHexa);
if (isEnabled()){
@@ -410,12 +363,12 @@ public class BlueetoothGpsManager { });
}
}
-
+
public void sendNmeaCommand(String sentence){
String command = String.format((Locale)null,"$%s*%X\r\n", sentence, parser.computeChecksum(sentence));
sendPackagedNmeaCommand(command);
}
-
+
public void sendSirfCommand(String payload){
String command = SirfUtils.createSirfCommandFromPayload(payload);
sendPackagedSirfCommand(command);
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java index 5d079a0..d12782e 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,56 @@ 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++; - } - 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(); - } - + 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); + 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 +134,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 +145,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)); } @@ -165,7 +163,7 @@ public class BluetoothGpsActivity extends PreferenceActivity implements OnPrefer || BluetoothGpsProviderService.PREF_SIRF_ENABLE_SBAS.equals(key) || BluetoothGpsProviderService.PREF_SIRF_ENABLE_NMEA.equals(key) || BluetoothGpsProviderService.PREF_SIRF_ENABLE_STATIC_NAVIGATION.equals(key) - ){ + ){ enableSirfFeature(key); } this.updateDevicePreferenceList(); diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java index 37ac056..0d0c30b 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";
@@ -83,19 +82,16 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener public static final String PREF_SIRF_ENABLE_NMEA = "enableNMEA";
public static final String PREF_SIRF_ENABLE_STATIC_NAVIGATION = "enableStaticNavigation";
-
- 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);
}
@Override
@@ -103,12 +99,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())){
@@ -124,21 +116,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener }
gpsManager = new BlueetoothGpsManager(this, deviceAddress);
gpsManager.enableMockLocationProvider(mockProvider);
-// gpsManager.enableMockLocationProvider(LocationManager.GPS_PROVIDER);
boolean enabled = gpsManager.enable();
-// String command1 = this.getString(R.string.sirf_nmea_gga_on);
-// String command2 = this.getString(R.string.sirf_nmea_gsa_off);
-// String command3 = this.getString(R.string.sirf_nmea_gsv_off);
-// String command4 = this.getString(R.string.sirf_nmea_vtg_off);
-// String command5 = this.getString(R.string.sirf_nmea_gll_off);
-// String command6 = this.getString(R.string.sirf_nmea_rmc_on);
-// gpsManager.sendNmeaCommand(command1);
-// gpsManager.sendNmeaCommand(command2);
-// gpsManager.sendNmeaCommand(command3);
-// gpsManager.sendNmeaCommand(command4);
-// gpsManager.sendNmeaCommand(command5);
-// gpsManager.sendNmeaCommand(command6);
-
// Bundle extras = intent.getExtras();
if (sharedPreferences.getBoolean(PREF_START_GPS_PROVIDER, false) != enabled){
edit.putBoolean(PREF_START_GPS_PROVIDER,enabled);
@@ -153,12 +131,6 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener 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 {
@@ -182,8 +154,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));
@@ -213,7 +183,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener }
}
}
-
+
private void enableSirfConfig(Bundle extras){
if (extras.containsKey(PREF_SIRF_ENABLE_GLL)){
enableNmeaGLL(extras.getBoolean(PREF_SIRF_ENABLE_GLL, false));
@@ -266,7 +236,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener gpsManager.sendNmeaCommand(this.getString(R.string.sirf_nmea_gga_on));
gpsManager.sendNmeaCommand(this.getString(R.string.sirf_nmea_rmc_on));
}
-
+
private void enableNmeaGLL(boolean enable){
if (gpsManager != null){
if (enable){
@@ -276,7 +246,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener }
}
}
-
+
private void enableNmeaVTG(boolean enable){
if (gpsManager != null){
if (enable){
@@ -331,7 +301,6 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener if (gpsManager != null){
if (enable){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
-// SharedPreferences.Editor edit = sharedPreferences.edit();
int gll = (sharedPreferences.getBoolean(PREF_SIRF_ENABLE_GLL, false)) ? 1 : 0 ;
int vtg = (sharedPreferences.getBoolean(PREF_SIRF_ENABLE_VTG, false)) ? 1 : 0 ;
int gsa = (sharedPreferences.getBoolean(PREF_SIRF_ENABLE_GSA, false)) ? 5 : 0 ;
@@ -343,7 +312,6 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener int rmc = 1;
String command = getString(R.string.sirf_bin_to_nmea_38400_alt, gga, gll, gsa, gsv, rmc, vtg, mss, epe, zda);
gpsManager.sendSirfCommand(command);
-// gpsManager.sendSirfCommand(getString(R.string.sirf_bin_to_nmea));
} else {
gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_to_binary));
}
@@ -353,7 +321,6 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener private void enableStaticNavigation(boolean enable){
if (gpsManager != null){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
-// SharedPreferences.Editor edit = sharedPreferences.edit();
boolean isInNmeaMode = sharedPreferences.getBoolean(PREF_SIRF_ENABLE_NMEA, true);
if (isInNmeaMode){
enableNMEA(false);
@@ -423,10 +390,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(){
@@ -482,22 +445,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();
-// }
-// }
}
diff --git a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java index b690285..426855f 100644 --- a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java +++ b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java @@ -45,22 +45,22 @@ public class NmeaParser { private float precision = 10f;
private boolean mockGpsEnabled = false;
private String mockLocationProvider = null;
-
+
private int mockStatus = LocationProvider.OUT_OF_SERVICE;
-
+
private Location fix = new Location(mockLocationProvider);
-
+
public NmeaParser(){
this(5f);
}
public NmeaParser(float precision){
this.precision = precision;
}
-
+
public void setLocationManager(LocationManager lm){
this.lm = lm;
}
-
+
public void enableMockLocationProvider(String gpsName){
LocationProvider prov;
if (gpsName != null && gpsName != "" ){
@@ -75,7 +75,6 @@ public class NmeaParser { }
lm.addTestProvider(mockLocationProvider, false, true,false, false, true, true, true, Criteria.POWER_HIGH, Criteria.ACCURACY_FINE);
if (! LocationManager.GPS_PROVIDER.equals(mockLocationProvider)){
- // mockGpsEnabled = locationManager.isProviderEnabled(mockLocationProvider);
lm.setTestProviderEnabled(mockLocationProvider, true);
}
mockGpsEnabled = true;
@@ -88,7 +87,7 @@ public class NmeaParser { }
}
}
-
+
public void disableMockLocationProvider(){
LocationProvider prov;
if (mockLocationProvider != null && mockLocationProvider != "" && mockGpsEnabled){
@@ -98,10 +97,8 @@ public class NmeaParser { }
mockGpsEnabled = false;
if (! LocationManager.GPS_PROVIDER.equals(mockLocationProvider)){
- // mockGpsEnabled = locationManager.isProviderEnabled(mockLocationProvider);
lm.setTestProviderEnabled(mockLocationProvider, false);
}
- // locationManager.setTestProviderEnabled(mockLocationProvider, mockGpsEnabled);
prov = lm.getProvider(mockLocationProvider);
if (prov != null){
Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
@@ -145,7 +142,6 @@ public class NmeaParser { }
private void notifyFix(Location fix){
- //R.drawable.stat
fixTime = null;
hasGGA = false;
hasRMC=false;
@@ -160,7 +156,6 @@ public class NmeaParser { }
private void notifyStatusChanged(int status, Bundle extras, long updateTime){
- //R.drawable.stat
fixTime = null;
hasGGA = false;
hasRMC=false;
@@ -168,8 +163,8 @@ public class NmeaParser { Log.e(this.getClass().getSimpleName(), "New mockStatus: "+System.currentTimeMillis()+" "+status);
if (lm != null && mockGpsEnabled){
lm.setTestProviderStatus(mockLocationProvider, status, extras, updateTime);
-// lm.setTestProviderStatus(mockLocationProvider, status, extras, SystemClock.elapsedRealtime());
-// lm.setTestProviderStatus(mockLocationProvider, status, extras, 50);
+ // lm.setTestProviderStatus(mockLocationProvider, status, extras, SystemClock.elapsedRealtime());
+ // lm.setTestProviderStatus(mockLocationProvider, status, extras, 50);
Log.e(this.getClass().getSimpleName(), "New mockStatus notified to Location Manager: " + status + " "+mockLocationProvider);
}
this.fix = null;
|