aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHerbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com>2010-11-07 19:27:30 +0100
committerHerbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com>2010-11-07 19:27:30 +0100
commit17f8164913422da101be1c667207608c5c6c1003 (patch)
tree5e06f77edb74aa239f0e5fa2c18062eb814ac7c0 /src
parent2293d7015ea93e1e910610a3c41508f1d83b1c2a (diff)
parente8944d1d6b26492359c03f32dcf79476ff85a4dc (diff)
downloadBlueGPS-17f8164913422da101be1c667207608c5c6c1003.zip
BlueGPS-17f8164913422da101be1c667207608c5c6c1003.tar.gz
BlueGPS-17f8164913422da101be1c667207608c5c6c1003.tar.bz2
Merge log rewrite from 1.0.x into branch 1.1.x
Diffstat (limited to 'src')
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java87
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java324
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java19
-rw-r--r--src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java52
4 files changed, 256 insertions, 226 deletions
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java
index 5f1860b..335539a 100644
--- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java
+++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java
@@ -54,6 +54,9 @@ import android.util.Log;
public class BlueetoothGpsManager {
+ private static final String LOG_TAG = "BlueGPS";
+// private static final String LOG_TAG = BlueetoothGpsManager.class.getSimpleName();
+
private class ConnectedGps extends Thread {
private final InputStream in;
@@ -62,7 +65,7 @@ public class BlueetoothGpsManager {
try {
tmpIn = socket.getInputStream();
} catch (IOException e) {
- Log.e("BT test", "error while getting socket streams", e);
+ Log.e(LOG_TAG, "error while getting socket streams", e);
}
in = tmpIn;
}
@@ -76,17 +79,17 @@ public class BlueetoothGpsManager {
while((enabled) && (now < lastRead+5000 )){
if (reader.ready()){
s = reader.readLine();
- Log.e("BT test", "data: "+System.currentTimeMillis()+" "+s + "xxx");
+ Log.v(LOG_TAG, "data: "+System.currentTimeMillis()+" "+s);
notifyNmeaSentence(s+"\r\n");
lastRead = SystemClock.uptimeMillis();
} else {
- Log.e("BT test", "data: not ready "+System.currentTimeMillis());
+ Log.d(LOG_TAG, "data: not ready "+System.currentTimeMillis());
SystemClock.sleep(500);
}
now = SystemClock.uptimeMillis();
}
} catch (IOException e) {
- Log.e("BT test", "error while getting data", e);
+ Log.e(LOG_TAG, "error while getting data", e);
setMockLocationProviderOutOfService();
} finally {
disableIfNeeded();
@@ -160,39 +163,40 @@ public class BlueetoothGpsManager {
public synchronized boolean enable() {
notificationManager.cancel(R.string.service_closed_because_connection_problem_notification_title);
if (! enabled){
+ Log.d(LOG_TAG, "enabling Bluetooth GPS manager");
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
// Device does not support Bluetooth
- Log.e("BT test", "Device does not support Bluetooth");
+ Log.e(LOG_TAG, "Device does not support Bluetooth");
disable(R.string.msg_bluetooth_unsupported);
} 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");
+ Log.e(LOG_TAG, "Bluetooth is not enabled");
disable(R.string.msg_bluetooth_disabled);
} else if (Settings.Secure.getInt(callingService.getContentResolver(),Settings.Secure.ALLOW_MOCK_LOCATION, 0)==0){
- Log.e("BT test", "Mock location provider OFF");
+ Log.e(LOG_TAG, "Mock location provider OFF");
disable(R.string.msg_mock_location_disabled);
// } else if ( (! locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
// && (sharedPreferences.getBoolean(BluetoothGpsProviderService.PREF_REPLACE_STD_GPS, true))
// ) {
-// Log.e("BT test", "GPS location provider OFF");
+// Log.e(LOG_TAG, "GPS location provider OFF");
// disable(R.string.msg_gps_provider_disabled);
} else {
final BluetoothDevice gpsDevice = bluetoothAdapter.getRemoteDevice(gpsDeviceAddress);
if (gpsDevice == null){
- Log.e("BT test", "GPS device not found");
+ Log.e(LOG_TAG, "GPS device not found");
disable(R.string.msg_bluetooth_gps_unavaible);
- } 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);
+ } else {
+ Log.e(LOG_TAG, "current device: "+gpsDevice.getName() + " -- " + gpsDevice.getAddress());
+ try {
+ gpsSocket = gpsDevice.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
+ } catch (IOException e) {
+ Log.e(LOG_TAG, "Error during connection", e);
gpsSocket = null;
- }
- if (gpsSocket == null){
- Log.e("BT test", "Error while establishing connection: no socket");
+ }
+ if (gpsSocket == null){
+ Log.e(LOG_TAG, "Error while establishing connection: no socket");
disable(R.string.msg_bluetooth_gps_unavaible);
} else {
Runnable connectThread = new Runnable() {
@@ -200,24 +204,24 @@ public class BlueetoothGpsManager {
public void run() {
try {
connected = false;
- Log.e("BT test", "current device: "+gpsDevice.getName() + " -- " + gpsDevice.getAddress());
+ Log.v(LOG_TAG, "current device: "+gpsDevice.getName() + " -- " + gpsDevice.getAddress());
if ((bluetoothAdapter.isEnabled()) && (nbRetriesRemaining > 0 )){
try {
if (gpsSocket != null){
- Log.e("BT test", "trying to close old socket");
+ Log.d(LOG_TAG, "trying to close old socket");
gpsSocket.close();
}
} catch (IOException e) {
- Log.e("BT test", "Error during disconnection", e);
+ Log.e(LOG_TAG, "Error during disconnection", e);
}
try {
gpsSocket = gpsDevice.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
} catch (IOException e) {
- Log.e("BT test", "Error during connection", e);
+ Log.e(LOG_TAG, "Error during connection", e);
gpsSocket = null;
}
if (gpsSocket == null){
- Log.e("BT test", "Error while establishing connection: no socket");
+ Log.e(LOG_TAG, "Error while establishing connection: no socket");
disable(R.string.msg_bluetooth_gps_unavaible);
} else {
// Cancel discovery because it will slow down the connection
@@ -225,22 +229,26 @@ public class BlueetoothGpsManager {
// we increment the number of connection try
// Connect the device through the socket. This will block
// until it succeeds or throws an exception
+ Log.v(LOG_TAG, "connecting to socket");
gpsSocket.connect();
- // connection obtained so reset the number of connection try
+ Log.d(LOG_TAG, "connected to socket");
connected = true;
// reset eventual disabling cause
// setDisableReason(0);
+ // connection obtained so reset the number of connection try
nbRetriesRemaining = 1+maxConnectionRetries ;
notificationManager.cancel(R.string.connection_problem_notification_title);
+ Log.v(LOG_TAG, "starting socket reading task");
connectedGps = new ConnectedGps(gpsSocket);
connectionAndReadingPool.execute(connectedGps);
+ Log.v(LOG_TAG, "socket reading thread started");
}
// } else if (! bluetoothAdapter.isEnabled()) {
// setDisableReason(R.string.msg_bluetooth_disabled);
}
} catch (IOException connectException) {
// Unable to connect
- Log.e("BT test", "error while connecting to socket", connectException);
+ Log.e(LOG_TAG, "error while connecting to socket", connectException);
// disable(R.string.msg_bluetooth_gps_unavaible);
} finally {
nbRetriesRemaining--;
@@ -251,8 +259,12 @@ public class BlueetoothGpsManager {
}
};
this.enabled = true;
+ Log.d(LOG_TAG, "Bluetooth GPS manager enabled");
+ Log.v(LOG_TAG, "starting notification thread");
notificationPool = Executors.newSingleThreadExecutor();
+ Log.v(LOG_TAG, "starting connection and reading thread");
connectionAndReadingPool = Executors.newSingleThreadScheduledExecutor();
+ Log.v(LOG_TAG, "starting connection to socket task");
connectionAndReadingPool.scheduleWithFixedDelay(connectThread, 5000, 60000, TimeUnit.MILLISECONDS);
}
}
@@ -265,7 +277,7 @@ public class BlueetoothGpsManager {
if (enabled){
if (nbRetriesRemaining > 0){
// Unable to connect
- Log.e("BT test", "Unable to establish connection");
+ Log.e(LOG_TAG, "Unable to establish connection");
connectionProblemNotification.when = System.currentTimeMillis();
String pbMessage = appContext.getResources().getQuantityString(R.plurals.connection_problem_notification, nbRetriesRemaining, nbRetriesRemaining);
connectionProblemNotification.setLatestEventInfo(appContext,
@@ -284,6 +296,7 @@ public class BlueetoothGpsManager {
}
public synchronized void disable(int reasonId) {
+ Log.d(LOG_TAG, "disabling Bluetooth GPS manager reason: "+callingService.getString(reasonId));
setDisableReason(reasonId);
disable();
}
@@ -299,30 +312,34 @@ public class BlueetoothGpsManager {
notificationManager.notify(R.string.service_closed_because_connection_problem_notification_title, serviceStoppedNotification);
}
if (enabled){
+ Log.d(LOG_TAG, "disabling Bluetooth GPS manager");
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(LOG_TAG, "error while closing socket", closeException);
+ }
}
nmeaListeners.clear();
disableMockLocationProvider();
notificationPool.shutdown();
connectionAndReadingPool.shutdown();
callingService.stopSelf();
+ Log.d(LOG_TAG, "Bluetooth GPS manager disabled");
}
}
public void enableMockLocationProvider(String gpsName){
if (parser != null){
+ Log.d(LOG_TAG, "enabling mock locations provider: "+gpsName);
parser.enableMockLocationProvider(gpsName);
}
}
public void disableMockLocationProvider(){
if (parser != null){
+ Log.d(LOG_TAG, "disabling mock locations provider");
parser.disableMockLocationProvider();
}
}
@@ -356,21 +373,25 @@ public class BlueetoothGpsManager {
public boolean addNmeaListener(NmeaListener listener){
if (!nmeaListeners.contains(listener)){
+ Log.d(LOG_TAG, "adding new NMEA listener");
nmeaListeners.add(listener);
}
return true;
}
public void removeNmeaListener(NmeaListener listener){
+ Log.d(LOG_TAG, "removing NMEA listener");
nmeaListeners.remove(listener);
}
private void notifyNmeaSentence(final String nmeaSentence){
if (enabled){
+ Log.v(LOG_TAG, "parsing and notifying NMEA sentence: "+nmeaSentence);
String sentence = null;
try {
sentence = parser.parseNmeaSentence(nmeaSentence);
} catch (SecurityException e){
+ Log.e(LOG_TAG, "error while parsing NMEA sentence: "+nmeaSentence, e);
// a priori Mock Location is disabled
sentence = null;
disable(R.string.msg_mock_location_disabled);
@@ -378,7 +399,7 @@ public class BlueetoothGpsManager {
final String recognizedSentence = sentence;
final long timestamp = System.currentTimeMillis();
if (recognizedSentence != null){
- Log.e("BT test", "NMEA : "+timestamp+" "+recognizedSentence);
+ Log.v(LOG_TAG, "notifying NMEA sentence: "+recognizedSentence);
synchronized(nmeaListeners) {
for(final NmeaListener listener : nmeaListeners){
notificationPool.execute(new Runnable(){
@@ -391,5 +412,5 @@ public class BlueetoothGpsManager {
}
}
}
- }
+ }
}
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java
index e09ae34..742a3d4 100644
--- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java
+++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java
@@ -1,160 +1,164 @@
-/*
- * Copyright (C) 2010 Herbert von Broeuschmeul
- * Copyright (C) 2010 BluetoothGPS4Droid Project
- *
- * This file is part of BluetoothGPS4Droid.
- *
- * BluetoothGPS4Droid is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * BluetoothGPS4Droid is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with BluetoothGPS4Droid. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.broeuschmeul.android.gps.bluetooth.provider;
-
-import java.util.Set;
-
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothDevice;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
-import android.os.Bundle;
-import android.preference.CheckBoxPreference;
-import android.preference.ListPreference;
-import android.preference.Preference;
-import android.preference.PreferenceActivity;
-import android.preference.PreferenceManager;
-import android.preference.Preference.OnPreferenceChangeListener;
-import android.util.Log;
-
-/**
- * A PreferenceActivity Class used to configure, start and stop the NMEA tracker service.
- *
- * @author Herbert von Broeuschmeul
- *
- */
-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)
- * @see android.app.Activity#onResume()
- */
- @Override
- protected void onResume() {
- this.updateDevicePreferenceList();
- super.onResume();
- }
-
- private void updateDevicePreferenceSummary(){
- // 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));
- }
-
- private void updateDevicePreferenceList(){
- // 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);
- 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_CONNECTION_RETRIES);
- String maxConnRetries = sharedPref.getString(BluetoothGpsProviderService.PREF_CONNECTION_RETRIES, getString(R.string.defaultConnectionRetries));
- pref.setSummary(getString(R.string.pref_connection_retries_summary,maxConnRetries));
- 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();
- sharedPref.unregisterOnSharedPreferenceChangeListener(this);
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
- if (BluetoothGpsProviderService.PREF_START_GPS_PROVIDER.equals(key)){
- boolean val = sharedPreferences.getBoolean(key, false);
- CheckBoxPreference pref = (CheckBoxPreference)findPreference(key);
- if (pref.isChecked() != val){
- pref.setChecked(val);
- } else if (val){
- startService(new Intent(BluetoothGpsProviderService.ACTION_START_GPS_PROVIDER));
- } else {
- startService(new Intent(BluetoothGpsProviderService.ACTION_STOP_GPS_PROVIDER));
- }
- } else if (BluetoothGpsProviderService.PREF_TRACK_RECORDING.equals(key)){
- boolean val = sharedPreferences.getBoolean(key, false);
- CheckBoxPreference pref = (CheckBoxPreference)findPreference(key);
- if (pref.isChecked() != val){
- pref.setChecked(val);
- } else if (val){
- startService(new Intent(BluetoothGpsProviderService.ACTION_START_TRACK_RECORDING));
- } else {
- startService(new Intent(BluetoothGpsProviderService.ACTION_STOP_TRACK_RECORDING));
- }
- } else if (BluetoothGpsProviderService.PREF_BLUETOOTH_DEVICE.equals(key)){
- updateDevicePreferenceSummary();
- }
- this.updateDevicePreferenceList();
- }
-} \ No newline at end of file
+/*
+ * Copyright (C) 2010 Herbert von Broeuschmeul
+ * Copyright (C) 2010 BluetoothGPS4Droid Project
+ *
+ * This file is part of BluetoothGPS4Droid.
+ *
+ * BluetoothGPS4Droid is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * BluetoothGPS4Droid is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with BluetoothGPS4Droid. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.broeuschmeul.android.gps.bluetooth.provider;
+
+import java.util.Set;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceManager;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.util.Log;
+
+/**
+ * A PreferenceActivity Class used to configure, start and stop the NMEA tracker service.
+ *
+ * @author Herbert von Broeuschmeul
+ *
+ */
+public class BluetoothGpsActivity extends PreferenceActivity implements OnPreferenceChangeListener, OnSharedPreferenceChangeListener {
+
+ private static final String LOG_TAG = "BlueGPS";
+// private static final String LOG_TAG = BluetoothGpsActivity.class.getSimpleName();
+
+ 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)
+ * @see android.app.Activity#onResume()
+ */
+ @Override
+ protected void onResume() {
+ this.updateDevicePreferenceList();
+ super.onResume();
+ }
+
+ private void updateDevicePreferenceSummary(){
+ // 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));
+ }
+
+ private void updateDevicePreferenceList(){
+ // 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.v(LOG_TAG, "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_CONNECTION_RETRIES);
+ String maxConnRetries = sharedPref.getString(BluetoothGpsProviderService.PREF_CONNECTION_RETRIES, getString(R.string.defaultConnectionRetries));
+ pref.setSummary(getString(R.string.pref_connection_retries_summary,maxConnRetries));
+ 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.v(LOG_TAG, "loc. provider: "+s);
+ Log.v(LOG_TAG, "loc. provider: "+pref.getSummary());
+ } else {
+ String s = getString(R.string.pref_mock_gps_name_summary, mockProvider);
+ pref.setSummary(s);
+ Log.v(LOG_TAG, "loc. provider: "+s);
+ Log.v(LOG_TAG, "loc. provider: "+pref.getSummary());
+ }
+ this.onContentChanged();
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ sharedPref.unregisterOnSharedPreferenceChangeListener(this);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ if (BluetoothGpsProviderService.PREF_START_GPS_PROVIDER.equals(key)){
+ boolean val = sharedPreferences.getBoolean(key, false);
+ CheckBoxPreference pref = (CheckBoxPreference)findPreference(key);
+ if (pref.isChecked() != val){
+ pref.setChecked(val);
+ } else if (val){
+ startService(new Intent(BluetoothGpsProviderService.ACTION_START_GPS_PROVIDER));
+ } else {
+ startService(new Intent(BluetoothGpsProviderService.ACTION_STOP_GPS_PROVIDER));
+ }
+ } else if (BluetoothGpsProviderService.PREF_TRACK_RECORDING.equals(key)){
+ boolean val = sharedPreferences.getBoolean(key, false);
+ CheckBoxPreference pref = (CheckBoxPreference)findPreference(key);
+ if (pref.isChecked() != val){
+ pref.setChecked(val);
+ } else if (val){
+ startService(new Intent(BluetoothGpsProviderService.ACTION_START_TRACK_RECORDING));
+ } else {
+ startService(new Intent(BluetoothGpsProviderService.ACTION_STOP_TRACK_RECORDING));
+ }
+ } else if (BluetoothGpsProviderService.PREF_BLUETOOTH_DEVICE.equals(key)){
+ updateDevicePreferenceSummary();
+ }
+ 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 5146d1d..8eccd7f 100644
--- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
+++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
@@ -69,6 +69,9 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
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 static final String LOG_TAG = "BlueGPS";
+// private static final String LOG_TAG = BluetoothGpsProviderService.class.getSimpleName();
private BlueetoothGpsManager gpsManager = null;
private PrintWriter writer;
@@ -90,7 +93,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
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 device addr: "+deviceAddress);
+ Log.d(LOG_TAG, "prefs device addr: "+deviceAddress);
}
if (ACTION_START_GPS_PROVIDER.equals(intent.getAction())){
if (gpsManager == null){
@@ -211,23 +214,23 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
String trackDirName = sharedPreferences.getString(PREF_TRACK_FILE_DIR, this.getString(R.string.defaultTrackFileDirectory));
String trackFilePrefix = sharedPreferences.getString(PREF_TRACK_FILE_PREFIX, this.getString(R.string.defaultTrackFilePrefix));
trackFile = new File(trackDirName,trackFilePrefix+fmt.format(new Date()));
- Log.i(BluetoothGpsProviderService.class.getName(), "Writing the prelude of the NMEA file: "+trackFile.getAbsolutePath());
+ Log.d(LOG_TAG, "Writing the prelude of the NMEA file: "+trackFile.getAbsolutePath());
File trackDir = trackFile.getParentFile();
try {
if ((! trackDir.mkdirs()) && (! trackDir.isDirectory())){
- Log.e(BluetoothGpsProviderService.class.getName(), "Error while creating parent dir of NMEA file: "+trackDir.getAbsolutePath());
+ Log.e(LOG_TAG, "Error while creating parent dir of NMEA file: "+trackDir.getAbsolutePath());
}
writer = new PrintWriter(new BufferedWriter(new FileWriter(trackFile)));
preludeWritten = true;
} catch (IOException e) {
- Log.e(BluetoothGpsProviderService.class.getName(), "Error while writing the prelude of the NMEA file: "+trackFile.getAbsolutePath(), e);
+ Log.e(LOG_TAG, "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(){
if (trackFile != null && writer != null){
- Log.i(BluetoothGpsProviderService.class.getName(), "Ending the NMEA file: "+trackFile.getAbsolutePath());
+ Log.d(LOG_TAG, "Ending the NMEA file: "+trackFile.getAbsolutePath());
preludeWritten = false;
writer.close();
trackFile = null;
@@ -237,7 +240,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
if (! preludeWritten){
beginTrack();
}
- Log.d(BluetoothGpsProviderService.class.getName(), "Adding data in the NMEA file: "+ data);
+ Log.v(LOG_TAG, "Adding data in the NMEA file: "+ data);
if (trackFile != null && writer != null){
writer.print(data);
}
@@ -248,7 +251,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
@Override
public IBinder onBind(Intent intent) {
if (Config.LOGD){
- Log.d(BluetoothGpsProviderService.class.getName(), "trying access IBinder");
+ Log.d(LOG_TAG, "trying access IBinder");
}
return null;
}
@@ -260,7 +263,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
@Override
public void onProviderDisabled(String provider) {
- Log.e(BluetoothGpsProviderService.class.getName(), "The GPS has been disabled.....stopping the NMEA tracker service.");
+ Log.i(LOG_TAG, "The GPS has been disabled.....stopping the NMEA tracker service.");
stopSelf();
}
diff --git a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
index 5b06c62..21df4ce 100644
--- a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
+++ b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
@@ -36,6 +36,9 @@ import android.text.TextUtils.SimpleStringSplitter;
import android.util.Log;
public class NmeaParser {
+ private static final String LOG_TAG = "BlueGPS";
+// private static final String LOG_TAG = NmeaParser.class.getSimpleName();
+
private String fixTime = null;
private long fixTimestamp;
@@ -73,27 +76,27 @@ public class NmeaParser {
if (! mockGpsEnabled){
prov = lm.getProvider(mockLocationProvider);
if (prov != null){
- Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ Log.v(LOG_TAG, "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
}
lm.addTestProvider(mockLocationProvider, false, true,false, false, true, true, true, Criteria.POWER_HIGH, Criteria.ACCURACY_FINE);
if ((prov == null)
// || (! LocationManager.GPS_PROVIDER.equals(mockLocationProvider))
){
- Log.e("BT test", "enabling Mock provider: "+mockLocationProvider);
+ Log.d(LOG_TAG, "enabling Mock provider: "+mockLocationProvider);
lm.setTestProviderEnabled(mockLocationProvider, true);
mockGpsAutoEnabled = true;
}
mockGpsEnabled = true;
} else {
- Log.e("BT test", "Mock provider already enabled: "+mockLocationProvider);
+ Log.d(LOG_TAG, "Mock provider already enabled: "+mockLocationProvider);
}
prov = lm.getProvider(mockLocationProvider);
if (prov != null){
- Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ Log.e(LOG_TAG, "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
}
}
} catch (SecurityException e){
- Log.e("BT test", "Error while enabling Mock Mocations Provider", e);
+ Log.e(LOG_TAG, "Error while enabling Mock Mocations Provider", e);
disableMockLocationProvider();
}
}
@@ -104,34 +107,34 @@ public class NmeaParser {
if (mockLocationProvider != null && mockLocationProvider != "" && mockGpsEnabled){
prov = lm.getProvider(mockLocationProvider);
if (prov != null){
- Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ Log.v(LOG_TAG, "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
}
mockGpsEnabled = false;
if ( mockGpsAutoEnabled ) {
- Log.e("BT test", "disabling Mock provider: "+mockLocationProvider);
+ Log.d(LOG_TAG, "disabling Mock provider: "+mockLocationProvider);
lm.setTestProviderEnabled(mockLocationProvider, false);
}
prov = lm.getProvider(mockLocationProvider);
if (prov != null){
- Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ Log.v(LOG_TAG, "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
}
lm.clearTestProviderEnabled(mockLocationProvider);
prov = lm.getProvider(mockLocationProvider);
if (prov != null){
- Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ Log.v(LOG_TAG, "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
}
lm.clearTestProviderStatus(mockLocationProvider);
lm.removeTestProvider(mockLocationProvider);
prov = lm.getProvider(mockLocationProvider);
if (prov != null){
- Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ Log.v(LOG_TAG, "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
}
- Log.e("BT test", "removed mock GPS");
+ Log.d(LOG_TAG, "removed mock GPS");
} else {
- Log.e("BT test", "Mock provider already disabled: "+mockLocationProvider);
+ Log.d(LOG_TAG, "Mock provider already disabled: "+mockLocationProvider);
}
} catch (SecurityException e){
- Log.e("BT test", "Error while enabling Mock Mocations Provider", e);
+ Log.e(LOG_TAG, "Error while enabling Mock Mocations Provider", e);
} finally {
mockLocationProvider = null;
mockGpsEnabled = false;
@@ -163,10 +166,10 @@ public class NmeaParser {
hasGGA = false;
hasRMC=false;
if (fix != null){
- Log.e(this.getClass().getSimpleName(), "New Fix: "+System.currentTimeMillis()+" "+fix);
+ Log.v(LOG_TAG, "New Fix: "+System.currentTimeMillis()+" "+fix);
if (lm != null && mockGpsEnabled){
lm.setTestProviderLocation(mockLocationProvider, fix);
- Log.e(this.getClass().getSimpleName(), "New Fix notified to Location Manager: "+mockLocationProvider);
+ Log.v(LOG_TAG, "New Fix notified to Location Manager: "+mockLocationProvider);
}
this.fix = null;
}
@@ -177,12 +180,12 @@ public class NmeaParser {
hasGGA = false;
hasRMC=false;
if (this.mockStatus != status){
- Log.e(this.getClass().getSimpleName(), "New mockStatus: "+System.currentTimeMillis()+" "+status);
+ Log.d(LOG_TAG, "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);
- Log.e(this.getClass().getSimpleName(), "New mockStatus notified to Location Manager: " + status + " "+mockLocationProvider);
+ Log.v(LOG_TAG, "New mockStatus notified to Location Manager: " + status + " "+mockLocationProvider);
}
this.fix = null;
this.mockStatus = status;
@@ -192,14 +195,14 @@ public class NmeaParser {
// parse NMEA Sentence
public String parseNmeaSentence(String gpsSentence) throws SecurityException {
String nmeaSentence = null;
- Log.e("BT test", "data: "+System.currentTimeMillis()+" "+gpsSentence);
+ Log.v(LOG_TAG, "data: "+System.currentTimeMillis()+" "+gpsSentence);
Pattern xx = Pattern.compile("\\$([^*$]*)\\*([0-9A-F][0-9A-F])?\r\n");
Matcher m = xx.matcher(gpsSentence);
if (m.matches()){
nmeaSentence = m.group(0);
String sentence = m.group(1);
String checkSum = m.group(2);
- Log.e("BT test", "data: "+System.currentTimeMillis()+" "+sentence+" cheksum; "+checkSum +" control: "+String.format("%X",computeChecksum(sentence)));
+ Log.v(LOG_TAG, "data: "+System.currentTimeMillis()+" "+sentence+" cheksum; "+checkSum +" control: "+String.format("%X",computeChecksum(sentence)));
SimpleStringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
splitter.setString(sentence);
String command = splitter.next();
@@ -272,7 +275,7 @@ public class NmeaParser {
fixTime = time;
fixTimestamp = parseNmeaTime(time);
fix.setTime(fixTimestamp);
- Log.e(this.getClass().getSimpleName(), "Fix: "+fix);
+ Log.v(LOG_TAG, "Fix: "+fix);
}
if (lat != null && !lat.equals("")){
fix.setLatitude(parseNmeaLatitude(lat,latDir));
@@ -291,7 +294,7 @@ public class NmeaParser {
extras.putInt("satellites", Integer.parseInt(nbSat));
fix.setExtras(extras);
}
- Log.e(this.getClass().getSimpleName(), "Fix: "+System.currentTimeMillis()+" "+fix);
+ Log.v(LOG_TAG, "Fix: "+System.currentTimeMillis()+" "+fix);
hasGGA = true;
if (hasGGA && hasRMC){
notifyFix(fix);
@@ -352,7 +355,7 @@ public class NmeaParser {
fixTime = time;
fixTimestamp = parseNmeaTime(time);
fix.setTime(fixTimestamp);
- Log.e(this.getClass().getSimpleName(), "Fix: "+fix);
+ Log.v(LOG_TAG, "Fix: "+fix);
}
if (lat != null && !lat.equals("")){
fix.setLatitude(parseNmeaLatitude(lat,latDir));
@@ -366,7 +369,7 @@ public class NmeaParser {
if (bearing != null && !bearing.equals("")){
fix.setBearing(Float.parseFloat(bearing));
}
- Log.e(this.getClass().getSimpleName(), "Fix: "+System.currentTimeMillis()+" "+fix);
+ Log.v(LOG_TAG, "Fix: "+System.currentTimeMillis()+" "+fix);
hasRMC = true;
if (hasGGA && hasRMC){
notifyFix(fix);
@@ -526,8 +529,7 @@ public class NmeaParser {
}
}
} catch (ParseException e) {
- // TODO Auto-generated catch block
- Log.e(this.getClass().getSimpleName(), "Error while parsing NMEA time", e);
+ Log.e(LOG_TAG, "Error while parsing NMEA time", e);
}
return timestamp;
}