aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java')
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java324
1 files changed, 164 insertions, 160 deletions
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();
+ }
+}