Moved SensorSettingsActivity into SettingsActivity.

This commit is contained in:
Dennis Guse
2019-08-06 20:06:57 +02:00
parent fda95bbec9
commit 4edad610ee
6 changed files with 73 additions and 140 deletions
-1
View File
@@ -130,7 +130,6 @@ limitations under the License.
</activity>
<activity android:name=".io.file.exporter.SaveActivity" />
<activity android:name=".settings.RecordingSettingsActivity" />
<activity android:name=".settings.SensorSettingsActivity" />
<activity android:name=".settings.SettingsActivity" />
<activity android:name=".settings.StatsSettingsActivity" />
<activity
@@ -1,94 +0,0 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package de.dennisguse.opentracks.settings;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
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 de.dennisguse.opentracks.util.BluetoothDeviceUtils;
import de.dennisguse.opentracks.util.PreferencesUtils;
import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
/**
* An activity for accessing sensor settings.
*
* @author Jimmy Shih
*/
public class SensorSettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
addPreferencesFromResource(R.xml.settings_sensors);
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
protected void onResume() {
super.onResume();
// Update each time in case the list of bluetooth sensors has changed
configBluetoothSensor();
}
/**
* 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);
}
}
@@ -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;
@@ -251,7 +251,6 @@ public class PreferencesUtils {
public static void resetPreferences(Context context, boolean readAgain) {
PreferenceManager.setDefaultValues(context, R.xml.settings, readAgain);
PreferenceManager.setDefaultValues(context, R.xml.settings_recording, readAgain);
PreferenceManager.setDefaultValues(context, R.xml.settings_sensors, readAgain);
PreferenceManager.setDefaultValues(context, R.xml.settings_statistics, readAgain);
}
}
+26 -10
View File
@@ -18,10 +18,10 @@ limitations under the License.
<PreferenceScreen android:title="@string/track_detail_chart_tab">
<ListPreference
android:defaultValue="@string/chart_x_axis_distance"
android:entries="@array/chart_x_axis_options"
android:entryValues="@array/chart_x_axis_values"
android:key="@string/chart_x_axis_key"
android:summary="%s"
android:entryValues="@array/chart_x_axis_values"
android:entries="@array/chart_x_axis_options"
android:title="@string/settings_chart_x_axis" />
<PreferenceCategory android:title="@string/settings_show">
<CheckBoxPreference
@@ -48,6 +48,7 @@ limitations under the License.
-->
</PreferenceCategory>
</PreferenceScreen>
<Preference
android:key="@string/settings_stats_key"
android:persistent="false"
@@ -56,10 +57,26 @@ limitations under the License.
android:key="@string/settings_recording_key"
android:persistent="false"
android:title="@string/settings_recording" />
<Preference
android:key="@string/settings_sensor_key"
android:persistent="false"
android:title="@string/settings_sensor" />
<PreferenceScreen
android:key="@string/settings_sensor_root_key"
android:title="@string/settings_sensor">
<PreferenceCategory
android:key="@string/settings_sensor_bluetooth_key"
android:title="@string/settings_sensor_bluetooth">
<Preference
android:key="@string/settings_sensor_bluetooth_pairing_key"
android:persistent="false"
android:summary="@string/settings_sensor_bluetooth_pairing_summary"
android:title="@string/settings_sensor_bluetooth_pairing" />
<ListPreference
android:defaultValue="@string/sensor_type_value_none"
android:key="@string/bluetooth_sensor_key"
android:summary="%s"
android:title="@string/settings_sensor_bluetooth_sensor" />
</PreferenceCategory>
</PreferenceScreen>
<PreferenceCategory android:title="@string/settings_reset">
<de.dennisguse.opentracks.settings.ResetDialogPreference
android:dialogMessage="@string/settings_reset_confirm_message"
@@ -71,11 +88,10 @@ limitations under the License.
android:title="@string/settings_reset" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/about_preference_title">
<Preference
android:title="@string/about_preference_title">
<Preference android:title="@string/about_preference_title">
<intent
android:targetPackage="@string/applicationId"
android:targetClass="de.dennisguse.opentracks.AboutActivity" />
android:targetClass="de.dennisguse.opentracks.AboutActivity"
android:targetPackage="@string/applicationId" />
</Preference>
</PreferenceCategory>
</PreferenceScreen>
-33
View File
@@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2012 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="@string/settings_sensor_root_key"
android:title="@string/settings_sensor">
<PreferenceCategory
android:key="@string/settings_sensor_bluetooth_key"
android:title="@string/settings_sensor_bluetooth">
<Preference
android:key="@string/settings_sensor_bluetooth_pairing_key"
android:persistent="false"
android:summary="@string/settings_sensor_bluetooth_pairing_summary"
android:title="@string/settings_sensor_bluetooth_pairing" />
<ListPreference
android:defaultValue="@string/sensor_type_value_none"
android:key="@string/bluetooth_sensor_key"
android:summary="%s"
android:title="@string/settings_sensor_bluetooth_sensor" />
</PreferenceCategory>
</PreferenceScreen>