mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 17:43:06 +02:00
Moved SensorSettingsActivity into SettingsActivity.
This commit is contained in:
@@ -16,14 +16,21 @@
|
||||
|
||||
package de.dennisguse.opentracks.settings;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceClickListener;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.provider.Settings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.util.BluetoothDeviceUtils;
|
||||
import de.dennisguse.opentracks.util.IntentUtils;
|
||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||
|
||||
@@ -65,7 +72,15 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
|
||||
configPreference(R.string.settings_stats_key, StatsSettingsActivity.class);
|
||||
configPreference(R.string.settings_recording_key, RecordingSettingsActivity.class);
|
||||
configPreference(R.string.settings_sensor_key, SensorSettingsActivity.class);
|
||||
|
||||
findPreference(getString(R.string.settings_sensor_bluetooth_pairing_key))
|
||||
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Intent settingsIntent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS);
|
||||
startActivity(settingsIntent);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,6 +89,8 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
PreferencesUtils.getSharedPreferences(this).registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
||||
recordingTrackId = PreferencesUtils.getLong(this, R.string.recording_track_id_key);
|
||||
updateUI();
|
||||
|
||||
configBluetoothSensor();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,6 +117,35 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the bluetooth sensor.
|
||||
*/
|
||||
private void configBluetoothSensor() {
|
||||
ListPreference preference = (ListPreference) findPreference(getString(R.string.bluetooth_sensor_key));
|
||||
String value = PreferencesUtils.getString(this, R.string.bluetooth_sensor_key, PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT);
|
||||
List<String> devicesNameList = new ArrayList<>();
|
||||
List<String> devicesAddressList = new ArrayList<>();
|
||||
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (bluetoothAdapter != null) {
|
||||
BluetoothDeviceUtils.populateDeviceLists(bluetoothAdapter, devicesNameList, devicesAddressList);
|
||||
}
|
||||
|
||||
// Was the previously configured device unpaired? Then forget it.
|
||||
if (!devicesAddressList.contains(value)) {
|
||||
value = PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT;
|
||||
PreferencesUtils.setString(this, R.string.bluetooth_sensor_key, value);
|
||||
}
|
||||
|
||||
devicesNameList.add(0, getString(R.string.value_none));
|
||||
devicesAddressList.add(0, PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT);
|
||||
|
||||
String[] values = devicesAddressList.toArray(new String[0]);
|
||||
preference.setEntryValues(values);
|
||||
|
||||
String[] options = devicesNameList.toArray(new String[0]);
|
||||
preference.setEntries(options);
|
||||
}
|
||||
|
||||
private void updateUI() {
|
||||
//TODO Remove the following if recordingTrackId is replaced by direct communication rather than via preferences.
|
||||
boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
||||
|
||||
Reference in New Issue
Block a user