forked from upstream-mirrors/OpenTracks
Place sensor settings in SensorSettingsActivity.
This commit is contained in:
@@ -209,6 +209,7 @@ limitations under the License.
|
|||||||
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.UploadServiceChooserActivity" />
|
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.UploadServiceChooserActivity" />
|
||||||
<activity android:name="com.google.android.apps.mytracks.settings.BackupSettingsActivity" />
|
<activity android:name="com.google.android.apps.mytracks.settings.BackupSettingsActivity" />
|
||||||
<activity android:name="com.google.android.apps.mytracks.settings.RecordingSettingsActivity" />
|
<activity android:name="com.google.android.apps.mytracks.settings.RecordingSettingsActivity" />
|
||||||
|
<activity android:name="com.google.android.apps.mytracks.settings.SensorSettingsActivity" />
|
||||||
<activity android:name="com.google.android.apps.mytracks.settings.SettingsActivity" />
|
<activity android:name="com.google.android.apps.mytracks.settings.SettingsActivity" />
|
||||||
<activity android:name="com.google.android.apps.mytracks.settings.SharingSettingsActivity" />
|
<activity android:name="com.google.android.apps.mytracks.settings.SharingSettingsActivity" />
|
||||||
<!-- Services -->
|
<!-- Services -->
|
||||||
|
|||||||
@@ -168,24 +168,30 @@ limitations under the License.
|
|||||||
<item>-50</item>
|
<item>-50</item>
|
||||||
<item>-100</item>
|
<item>-100</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="sensor_type_ant_values">
|
<string-array name="sensor_type_all_options">
|
||||||
<item>@string/sensor_type_value_ant</item>
|
|
||||||
<item>@string/sensor_type_value_srm_ant_bridge</item>
|
|
||||||
</string-array>
|
|
||||||
<string-array name="sensor_type_options">
|
|
||||||
<item>@string/settings_sensor_type_none</item>
|
<item>@string/settings_sensor_type_none</item>
|
||||||
<item>@string/settings_sensor_type_ant</item>
|
<item>@string/settings_sensor_type_ant</item>
|
||||||
<item>@string/settings_sensor_type_srm</item>
|
<item>@string/settings_sensor_type_srm</item>
|
||||||
<item>@string/settings_sensor_type_polar</item>
|
<item>@string/settings_sensor_type_polar</item>
|
||||||
<item>@string/settings_sensor_type_zephyr</item>
|
<item>@string/settings_sensor_type_zephyr</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="sensor_type_values">
|
<string-array name="sensor_type_all_values">
|
||||||
<item>@string/sensor_type_value_none</item>
|
<item>@string/sensor_type_value_none</item>
|
||||||
<item>@string/sensor_type_value_ant</item>
|
<item>@string/sensor_type_value_ant</item>
|
||||||
<item>@string/sensor_type_value_srm_ant_bridge</item>
|
<item>@string/sensor_type_value_srm_ant_bridge</item>
|
||||||
<item>@string/sensor_type_value_polar</item>
|
<item>@string/sensor_type_value_polar</item>
|
||||||
<item>@string/sensor_type_value_zephyr</item>
|
<item>@string/sensor_type_value_zephyr</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
<string-array name="sensor_type_bluetooth_options">
|
||||||
|
<item>@string/settings_sensor_type_none</item>
|
||||||
|
<item>@string/settings_sensor_type_polar</item>
|
||||||
|
<item>@string/settings_sensor_type_zephyr</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="sensor_type_bluetooth_values">
|
||||||
|
<item>@string/sensor_type_value_none</item>
|
||||||
|
<item>@string/sensor_type_value_polar</item>
|
||||||
|
<item>@string/sensor_type_value_zephyr</item>
|
||||||
|
</string-array>
|
||||||
<string-array name="track_name_options">
|
<string-array name="track_name_options">
|
||||||
<item>@string/settings_recording_track_name_date_local_option</item>
|
<item>@string/settings_recording_track_name_date_local_option</item>
|
||||||
<item>@string/settings_recording_track_name_date_iso_8601_option</item>
|
<item>@string/settings_recording_track_name_date_iso_8601_option</item>
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ limitations under the License.
|
|||||||
<string name="ant_srm_bridge_sensor_id_key">antSRMBridgeSensorId</string>
|
<string name="ant_srm_bridge_sensor_id_key">antSRMBridgeSensorId</string>
|
||||||
<string name="auto_resume_track_current_retry_key">autoResumeTrackCurrentRetry</string>
|
<string name="auto_resume_track_current_retry_key">autoResumeTrackCurrentRetry</string>
|
||||||
<string name="auto_resume_track_timeout_key">autoResumeTrackTimeout</string>
|
<string name="auto_resume_track_timeout_key">autoResumeTrackTimeout</string>
|
||||||
<string name="bluetooth_pairing_key">bluetoothPairing</string>
|
|
||||||
<string name="bluetooth_sensor_key">bluetoothSensor</string>
|
<string name="bluetooth_sensor_key">bluetoothSensor</string>
|
||||||
<string name="default_activity_key">defaultActivity</string>
|
<string name="default_activity_key">defaultActivity</string>
|
||||||
<string name="default_map_public_key">defaultMapPublic</string>
|
<string name="default_map_public_key">defaultMapPublic</string>
|
||||||
@@ -60,13 +59,16 @@ limitations under the License.
|
|||||||
<string name="track_name_key">trackName</string>
|
<string name="track_name_key">trackName</string>
|
||||||
|
|
||||||
<!-- Keys for non-persisted preferences. Sorted alphabetically. DO NOT TRANSLATE. -->
|
<!-- Keys for non-persisted preferences. Sorted alphabetically. DO NOT TRANSLATE. -->
|
||||||
<string name="ant_options_key">antOptions</string>
|
|
||||||
<string name="backup_to_sd_key">backupToSd</string>
|
<string name="backup_to_sd_key">backupToSd</string>
|
||||||
<string name="reset_key">resetToDefaults</string>
|
<string name="reset_key">resetToDefaults</string>
|
||||||
<string name="restore_from_sd_key">restoreFromSd</string>
|
<string name="restore_from_sd_key">restoreFromSd</string>
|
||||||
<string name="sensor_options_key">sensorOptions</string>
|
|
||||||
<string name="settings_backup_key">settingsBackup</string>
|
<string name="settings_backup_key">settingsBackup</string>
|
||||||
<string name="settings_recording_key">settingsRecording</string>
|
<string name="settings_recording_key">settingsRecording</string>
|
||||||
|
<string name="settings_sensor_key">settingsSensor</string>
|
||||||
|
<string name="settings_sensor_ant_key">settingsSensorAnt</string>
|
||||||
|
<string name="settings_sensor_bluetooth_key">settingsSensorBluetooth</string>
|
||||||
|
<string name="settings_sensor_bluetooth_pairing_key">settingsSensorBluetoothPairing</string>
|
||||||
|
<string name="settings_sensor_root_key">settingsSensorRoot</string>
|
||||||
<string name="settings_sharing_key">settingsSharing</string>
|
<string name="settings_sharing_key">settingsSharing</string>
|
||||||
<string name="track_color_mode_fixed_speed_options_key">trackColorModeFixedOptions</string>
|
<string name="track_color_mode_fixed_speed_options_key">trackColorModeFixedOptions</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -86,53 +86,18 @@ limitations under the License.
|
|||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
||||||
<!-- Recording -->
|
|
||||||
<Preference
|
<Preference
|
||||||
android:title="@string/settings_recording"
|
android:title="@string/settings_recording"
|
||||||
android:key="@string/settings_recording_key"
|
android:key="@string/settings_recording_key"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
<!-- Sharing -->
|
|
||||||
<Preference
|
<Preference
|
||||||
android:title="@string/settings_sharing"
|
android:title="@string/settings_sharing"
|
||||||
android:key="@string/settings_sharing_key"
|
android:key="@string/settings_sharing_key"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
<Preference
|
||||||
<!-- Sensors -->
|
android:title="@string/settings_sensor"
|
||||||
<PreferenceScreen android:title="@string/settings_sensor"
|
android:key="@string/settings_sensor_key"
|
||||||
android:key="@string/sensor_options_key">
|
android:persistent="false" />
|
||||||
<ListPreference android:key="@string/sensor_type_key"
|
|
||||||
android:title="@string/settings_sensor_type"
|
|
||||||
android:summary="@string/settings_sensor_type_summary"
|
|
||||||
android:entries="@array/sensor_type_options"
|
|
||||||
android:entryValues="@array/sensor_type_values"
|
|
||||||
android:defaultValue="@string/sensor_type_value_none"/>
|
|
||||||
|
|
||||||
<!-- Bluetooth -->
|
|
||||||
<PreferenceCategory android:title="@string/settings_sensor_bluetooth_options">
|
|
||||||
<ListPreference android:key="@string/bluetooth_sensor_key"
|
|
||||||
android:title="@string/settings_sensor_bluetooth_sensor"
|
|
||||||
android:summary="@string/settings_sensor_bluetooth_sensor_summary"
|
|
||||||
android:defaultValue="" />
|
|
||||||
|
|
||||||
<Preference android:key="@string/bluetooth_pairing_key"
|
|
||||||
android:title="@string/settings_sensor_bluetooth_pairing"
|
|
||||||
android:summary="@string/settings_sensor_bluetooth_pairing_summary"
|
|
||||||
android:persistent="false" />
|
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/settings_sensor_ant_options"
|
|
||||||
android:key="@string/ant_options_key">
|
|
||||||
<com.google.android.apps.mytracks.AntPreference
|
|
||||||
android:key="@string/ant_heart_rate_sensor_id_key"
|
|
||||||
android:title="@string/settings_sensor_unpair_ant"/>
|
|
||||||
<com.google.android.apps.mytracks.AntPreference
|
|
||||||
android:key="@string/ant_srm_bridge_sensor_id_key"
|
|
||||||
android:title="@string/settings_sensor_unpair_srm"/>
|
|
||||||
</PreferenceCategory>
|
|
||||||
</PreferenceScreen>
|
|
||||||
|
|
||||||
<!-- Backup -->
|
|
||||||
<Preference
|
<Preference
|
||||||
android:title="@string/settings_backup"
|
android:title="@string/settings_backup"
|
||||||
android:key="@string/settings_backup_key"
|
android:key="@string/settings_backup_key"
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<?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" >
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="@string/sensor_type_value_none"
|
||||||
|
android:key="@string/sensor_type_key"
|
||||||
|
android:summary="@string/settings_sensor_type_summary"
|
||||||
|
android:title="@string/settings_sensor_type" />
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="@string/settings_sensor_bluetooth_key"
|
||||||
|
android:title="@string/settings_sensor_bluetooth_options" >
|
||||||
|
<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=""
|
||||||
|
android:key="@string/bluetooth_sensor_key"
|
||||||
|
android:summary="@string/settings_sensor_bluetooth_sensor_summary"
|
||||||
|
android:title="@string/settings_sensor_bluetooth_sensor" />
|
||||||
|
</PreferenceCategory>
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="@string/settings_sensor_ant_key"
|
||||||
|
android:title="@string/settings_sensor_ant_options" >
|
||||||
|
<com.google.android.apps.mytracks.AntPreference
|
||||||
|
android:defaultValue="0"
|
||||||
|
android:key="@string/ant_heart_rate_sensor_id_key"
|
||||||
|
android:title="@string/settings_sensor_unpair_ant" />
|
||||||
|
<com.google.android.apps.mytracks.AntPreference
|
||||||
|
android:defaultValue="0"
|
||||||
|
android:key="@string/ant_srm_bridge_sensor_id_key"
|
||||||
|
android:title="@string/settings_sensor_unpair_srm" />
|
||||||
|
</PreferenceCategory>
|
||||||
|
</PreferenceScreen>
|
||||||
+11
-7
@@ -19,12 +19,12 @@ import static com.google.android.apps.mytracks.Constants.TAG;
|
|||||||
|
|
||||||
import com.google.android.apps.mytracks.Constants;
|
import com.google.android.apps.mytracks.Constants;
|
||||||
import com.google.android.apps.mytracks.content.Sensor;
|
import com.google.android.apps.mytracks.content.Sensor;
|
||||||
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
@@ -127,16 +127,20 @@ public class BluetoothSensorManager extends SensorManager {
|
|||||||
Log.w(Constants.TAG, "Disabled manager onStartTrack");
|
Log.w(Constants.TAG, "Disabled manager onStartTrack");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SharedPreferences prefs = context.getSharedPreferences(
|
String address = PreferencesUtils.getString(
|
||||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
context, R.string.bluetooth_sensor_key, PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT);
|
||||||
String address =
|
if (PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT.equals(address)) {
|
||||||
prefs.getString(context.getString(R.string.bluetooth_sensor_key), "");
|
|
||||||
if (address == null || address.equals("")) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log.w(Constants.TAG, "Connecting to bluetooth sensor: " + address);
|
Log.w(Constants.TAG, "Connecting to bluetooth sensor: " + address);
|
||||||
// Get the BluetoothDevice object
|
// Get the BluetoothDevice object
|
||||||
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address);
|
BluetoothDevice device;
|
||||||
|
try {
|
||||||
|
device = bluetoothAdapter.getRemoteDevice(address);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
Log.d(Constants.TAG, "Invalid address " + address, e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Attempt to connect to the device
|
// Attempt to connect to the device
|
||||||
connectionManager.connect(device);
|
connectionManager.connect(device);
|
||||||
|
|
||||||
|
|||||||
+12
-10
@@ -61,33 +61,35 @@ public class SensorManagerFactory {
|
|||||||
|
|
||||||
context = context.getApplicationContext();
|
context = context.getApplicationContext();
|
||||||
|
|
||||||
String sensor = prefs.getString(context.getString(R.string.sensor_type_key), null);
|
String sensorTypeValueNone = context.getString(R.string.sensor_type_value_none);
|
||||||
Log.i(Constants.TAG, "Creating sensor of type: " + sensor);
|
String sensorType = prefs.getString(
|
||||||
|
context.getString(R.string.sensor_type_key), sensorTypeValueNone);
|
||||||
|
Log.i(Constants.TAG, "Creating sensor of type: " + sensorType);
|
||||||
|
|
||||||
if (sensor == null) {
|
if (sensorTypeValueNone.equals(sensorType)) {
|
||||||
reset();
|
reset();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (sensor.equals(activeSensorType)) {
|
if (sensorType.equals(activeSensorType)) {
|
||||||
Log.i(Constants.TAG, "Returning existing sensor manager.");
|
Log.i(Constants.TAG, "Returning existing sensor manager.");
|
||||||
refCount++;
|
refCount++;
|
||||||
return activeSensorManager;
|
return activeSensorManager;
|
||||||
}
|
}
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
if (sensor.equals(context.getString(R.string.sensor_type_value_ant))) {
|
if (sensorType.equals(context.getString(R.string.sensor_type_value_ant))) {
|
||||||
activeSensorManager = new AntDirectSensorManager(context);
|
activeSensorManager = new AntDirectSensorManager(context);
|
||||||
} else if (sensor.equals(context.getString(R.string.sensor_type_value_srm_ant_bridge))) {
|
} else if (sensorType.equals(context.getString(R.string.sensor_type_value_srm_ant_bridge))) {
|
||||||
activeSensorManager = new AntSrmBridgeSensorManager(context);
|
activeSensorManager = new AntSrmBridgeSensorManager(context);
|
||||||
} else if (sensor.equals(context.getString(R.string.sensor_type_value_zephyr))) {
|
} else if (sensorType.equals(context.getString(R.string.sensor_type_value_zephyr))) {
|
||||||
activeSensorManager = new ZephyrSensorManager(context);
|
activeSensorManager = new ZephyrSensorManager(context);
|
||||||
} else if (sensor.equals(context.getString(R.string.sensor_type_value_polar))) {
|
} else if (sensorType.equals(context.getString(R.string.sensor_type_value_polar))) {
|
||||||
activeSensorManager = new PolarSensorManager(context);
|
activeSensorManager = new PolarSensorManager(context);
|
||||||
} else {
|
} else {
|
||||||
Log.w(Constants.TAG, "Unable to find sensor type: " + sensor);
|
Log.w(Constants.TAG, "Unable to find sensor type: " + sensorType);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
activeSensorType = sensor;
|
activeSensorType = sensorType;
|
||||||
refCount = 1;
|
refCount = 1;
|
||||||
activeSensorManager.onStartTrack();
|
activeSensorManager.onStartTrack();
|
||||||
return activeSensorManager;
|
return activeSensorManager;
|
||||||
|
|||||||
+4
-14
@@ -20,13 +20,11 @@ import static com.google.android.apps.mytracks.Constants.TAG;
|
|||||||
import com.dsi.ant.AntDefine;
|
import com.dsi.ant.AntDefine;
|
||||||
import com.dsi.ant.AntMesg;
|
import com.dsi.ant.AntMesg;
|
||||||
import com.dsi.ant.exception.AntInterfaceException;
|
import com.dsi.ant.exception.AntInterfaceException;
|
||||||
import com.google.android.apps.mytracks.Constants;
|
|
||||||
import com.google.android.apps.mytracks.content.Sensor;
|
import com.google.android.apps.mytracks.content.Sensor;
|
||||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -107,11 +105,7 @@ public class AntDirectSensorManager extends AntSensorManager
|
|||||||
}
|
}
|
||||||
Log.i(TAG, "Found ANT device id: " + deviceNumber + " on channel: " + channel);
|
Log.i(TAG, "Found ANT device id: " + deviceNumber + " on channel: " + channel);
|
||||||
|
|
||||||
SharedPreferences prefs = context.getSharedPreferences(
|
PreferencesUtils.setInt(context, sensorIdKeys[channel], deviceNumber);
|
||||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
|
||||||
editor.putInt(context.getString(sensorIdKeys[channel]), deviceNumber);
|
|
||||||
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
|
|
||||||
return deviceNumber;
|
return deviceNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,12 +165,8 @@ public class AntDirectSensorManager extends AntSensorManager
|
|||||||
protected void setupAntSensorChannels() {
|
protected void setupAntSensorChannels() {
|
||||||
short devIds[] = new short[sensorIdKeys.length];
|
short devIds[] = new short[sensorIdKeys.length];
|
||||||
|
|
||||||
SharedPreferences prefs = context.getSharedPreferences(
|
for (int i = 0; i < sensorIdKeys.length; ++i) {
|
||||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
devIds[i] = (short) PreferencesUtils.getInt(context, sensorIdKeys[i], WILDCARD);
|
||||||
if (prefs != null) {
|
|
||||||
for (int i = 0; i < sensorIdKeys.length; ++i) {
|
|
||||||
devIds[i] = (short) prefs.getInt(context.getString(sensorIdKeys[i]), WILDCARD);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sensors = new AntSensorBase[] {
|
sensors = new AntSensorBase[] {
|
||||||
|
|||||||
+4
-10
@@ -22,7 +22,7 @@ import com.dsi.ant.AntMesg;
|
|||||||
import com.dsi.ant.exception.AntInterfaceException;
|
import com.dsi.ant.exception.AntInterfaceException;
|
||||||
import com.google.android.apps.mytracks.Constants;
|
import com.google.android.apps.mytracks.Constants;
|
||||||
import com.google.android.apps.mytracks.content.Sensor;
|
import com.google.android.apps.mytracks.content.Sensor;
|
||||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.maps.mytracks.BuildConfig;
|
import com.google.android.maps.mytracks.BuildConfig;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
@@ -71,9 +71,8 @@ public class AntSrmBridgeSensorManager extends AntSensorManager {
|
|||||||
SharedPreferences prefs = context.getSharedPreferences(
|
SharedPreferences prefs = context.getSharedPreferences(
|
||||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||||
if (prefs != null) {
|
if (prefs != null) {
|
||||||
deviceNumber =
|
deviceNumber = (short) PreferencesUtils.getInt(
|
||||||
(short) prefs.getInt(context.getString(
|
context, R.string.ant_srm_bridge_sensor_id_key, WILDCARD);
|
||||||
R.string.ant_srm_bridge_sensor_id_key), 0);
|
|
||||||
}
|
}
|
||||||
Log.i(TAG, "Will pair with device: " + deviceNumber);
|
Log.i(TAG, "Will pair with device: " + deviceNumber);
|
||||||
}
|
}
|
||||||
@@ -194,12 +193,7 @@ public class AntSrmBridgeSensorManager extends AntSensorManager {
|
|||||||
AntChannelIdMessage message = new AntChannelIdMessage(rawMessage);
|
AntChannelIdMessage message = new AntChannelIdMessage(rawMessage);
|
||||||
deviceNumber = message.getDeviceNumber();
|
deviceNumber = message.getDeviceNumber();
|
||||||
Log.d(TAG, "Found device id: " + deviceNumber);
|
Log.d(TAG, "Found device id: " + deviceNumber);
|
||||||
|
PreferencesUtils.setInt(context, R.string.ant_srm_bridge_sensor_id_key, deviceNumber);
|
||||||
SharedPreferences prefs = context.getSharedPreferences(
|
|
||||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
|
||||||
editor.putInt(context.getString(R.string.ant_srm_bridge_sensor_id_key), deviceNumber);
|
|
||||||
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleMessageResponse(byte[] rawMessage) {
|
private void handleMessageResponse(byte[] rawMessage) {
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
/*
|
||||||
|
* 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 com.google.android.apps.mytracks.settings;
|
||||||
|
|
||||||
|
import com.google.android.apps.mytracks.services.sensors.ant.AntUtils;
|
||||||
|
import com.google.android.apps.mytracks.util.BluetoothDeviceUtils;
|
||||||
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.ListPreference;
|
||||||
|
import android.preference.Preference;
|
||||||
|
import android.preference.Preference.OnPreferenceChangeListener;
|
||||||
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
|
import android.preference.PreferenceScreen;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An activity for accessing sensor settings.
|
||||||
|
*
|
||||||
|
* @author Jimmy Shih
|
||||||
|
*/
|
||||||
|
public class SensorSettingsActivity extends AbstractSettingsActivity {
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle bundle) {
|
||||||
|
super.onCreate(bundle);
|
||||||
|
addPreferencesFromResource(R.xml.sensor_settings);
|
||||||
|
|
||||||
|
ListPreference sensorTypeListPreference = (ListPreference) findPreference(
|
||||||
|
getString(R.string.sensor_type_key));
|
||||||
|
List<String> sensorTypeEntries = Arrays.asList(getResources().getStringArray(
|
||||||
|
AntUtils.hasAntSupport(this) ? R.array.sensor_type_all_options
|
||||||
|
: R.array.sensor_type_bluetooth_options));
|
||||||
|
List<String> sensorTypeEntryValues = Arrays.asList(getResources().getStringArray(
|
||||||
|
AntUtils.hasAntSupport(this) ? R.array.sensor_type_all_values
|
||||||
|
: R.array.sensor_type_bluetooth_values));
|
||||||
|
sensorTypeListPreference.setEntries(sensorTypeEntries.toArray(
|
||||||
|
new CharSequence[sensorTypeEntries.size()]));
|
||||||
|
sensorTypeListPreference.setEntryValues(
|
||||||
|
sensorTypeEntryValues.toArray(new CharSequence[sensorTypeEntryValues.size()]));
|
||||||
|
sensorTypeListPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
updateUiBySensorType((String) newValue);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
updateUiBySensorType(sensorTypeListPreference.getValue());
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!AntUtils.hasAntSupport(this)) {
|
||||||
|
PreferenceScreen rootPreferenceScreen = (PreferenceScreen) findPreference(
|
||||||
|
getString(R.string.settings_sensor_root_key));
|
||||||
|
rootPreferenceScreen.removePreference(
|
||||||
|
findPreference(getString(R.string.settings_sensor_ant_key)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the UI based on the sensor type.
|
||||||
|
*
|
||||||
|
* @param sensorType the sensor type
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private void updateUiBySensorType(String sensorType) {
|
||||||
|
boolean isBluetooth = getString(R.string.sensor_type_value_polar).equals(sensorType)
|
||||||
|
|| getString(R.string.sensor_type_value_zephyr).equals(sensorType);
|
||||||
|
findPreference(getString(R.string.settings_sensor_bluetooth_key)).setEnabled(isBluetooth);
|
||||||
|
|
||||||
|
Preference antHeartRateSensorId = findPreference(
|
||||||
|
getString(R.string.ant_heart_rate_sensor_id_key));
|
||||||
|
if (antHeartRateSensorId != null) {
|
||||||
|
antHeartRateSensorId.setEnabled(getString(R.string.sensor_type_value_ant).equals(sensorType));
|
||||||
|
}
|
||||||
|
|
||||||
|
Preference antSrmBridgetSensorId = findPreference(
|
||||||
|
getString(R.string.ant_srm_bridge_sensor_id_key));
|
||||||
|
if (antSrmBridgetSensorId != null) {
|
||||||
|
antSrmBridgetSensorId.setEnabled(
|
||||||
|
getString(R.string.sensor_type_value_srm_ant_bridge).equals(sensorType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
updateBluetoothSensorListPreference();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the bluetooth sensor list preference.
|
||||||
|
*/
|
||||||
|
private void updateBluetoothSensorListPreference() {
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
ListPreference bluetoothSensorListPreference = (ListPreference) findPreference(
|
||||||
|
getString(R.string.bluetooth_sensor_key));
|
||||||
|
List<String> entries = new ArrayList<String>();
|
||||||
|
List<String> entryValues = new ArrayList<String>();
|
||||||
|
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
|
||||||
|
if (bluetoothAdapter != null) {
|
||||||
|
BluetoothDeviceUtils.populateDeviceLists(bluetoothAdapter, entries, entryValues);
|
||||||
|
}
|
||||||
|
bluetoothSensorListPreference.setEntries(entries.toArray(new CharSequence[entries.size()]));
|
||||||
|
bluetoothSensorListPreference.setEntryValues(entryValues.toArray(
|
||||||
|
new CharSequence[entryValues.size()]));
|
||||||
|
if (entries.size() == 1) {
|
||||||
|
bluetoothSensorListPreference.setValueIndex(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,9 +19,7 @@ package com.google.android.apps.mytracks.settings;
|
|||||||
import static com.google.android.apps.mytracks.Constants.TAG;
|
import static com.google.android.apps.mytracks.Constants.TAG;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.Constants;
|
import com.google.android.apps.mytracks.Constants;
|
||||||
import com.google.android.apps.mytracks.services.sensors.ant.AntUtils;
|
|
||||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||||
import com.google.android.apps.mytracks.util.BluetoothDeviceUtils;
|
|
||||||
import com.google.android.apps.mytracks.util.DialogUtils;
|
import com.google.android.apps.mytracks.util.DialogUtils;
|
||||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
@@ -29,7 +27,6 @@ import com.google.android.apps.mytracks.util.UnitConversions;
|
|||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -42,16 +39,9 @@ import android.preference.Preference;
|
|||||||
import android.preference.Preference.OnPreferenceChangeListener;
|
import android.preference.Preference.OnPreferenceChangeListener;
|
||||||
import android.preference.Preference.OnPreferenceClickListener;
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
import android.preference.PreferenceCategory;
|
import android.preference.PreferenceCategory;
|
||||||
import android.preference.PreferenceScreen;
|
|
||||||
import android.provider.Settings;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An activity for accessing settings.
|
* An activity for accessing settings.
|
||||||
*
|
*
|
||||||
@@ -67,7 +57,6 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
|||||||
super.onCreate(bundle);
|
super.onCreate(bundle);
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
|
||||||
customizeSensorOptionsPreferences();
|
|
||||||
customizeTrackColorModePreferences();
|
customizeTrackColorModePreferences();
|
||||||
|
|
||||||
Preference recordingPreference = findPreference(getString(R.string.settings_recording_key));
|
Preference recordingPreference = findPreference(getString(R.string.settings_recording_key));
|
||||||
@@ -90,6 +79,16 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Preference sensorPreference = findPreference(getString(R.string.settings_sensor_key));
|
||||||
|
sensorPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
|
Intent intent = IntentUtils.newIntent(SettingsActivity.this, SensorSettingsActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Preference backupPreference = findPreference(getString(R.string.settings_backup_key));
|
Preference backupPreference = findPreference(getString(R.string.settings_backup_key));
|
||||||
backupPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
backupPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
@@ -128,53 +127,6 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void customizeSensorOptionsPreferences() {
|
|
||||||
ListPreference sensorTypePreference =
|
|
||||||
(ListPreference) findPreference(getString(R.string.sensor_type_key));
|
|
||||||
sensorTypePreference.setOnPreferenceChangeListener(
|
|
||||||
new OnPreferenceChangeListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceChange(Preference preference,
|
|
||||||
Object newValue) {
|
|
||||||
updateSensorSettings((String) newValue);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
updateSensorSettings(sensorTypePreference.getValue());
|
|
||||||
|
|
||||||
if (!AntUtils.hasAntSupport(this)) {
|
|
||||||
// The sensor options screen has a few ANT-specific options which we
|
|
||||||
// need to remove. First, we need to remove the ANT sensor types.
|
|
||||||
// Second, we need to remove the ANT unpairing options.
|
|
||||||
|
|
||||||
Set<Integer> toRemove = new HashSet<Integer>();
|
|
||||||
|
|
||||||
String[] antValues = getResources().getStringArray(R.array.sensor_type_ant_values);
|
|
||||||
for (String antValue : antValues) {
|
|
||||||
toRemove.add(sensorTypePreference.findIndexOfValue(antValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
CharSequence[] entries = sensorTypePreference.getEntries();
|
|
||||||
CharSequence[] entryValues = sensorTypePreference.getEntryValues();
|
|
||||||
|
|
||||||
CharSequence[] filteredEntries = new CharSequence[entries.length - toRemove.size()];
|
|
||||||
CharSequence[] filteredEntryValues = new CharSequence[filteredEntries.length];
|
|
||||||
for (int i = 0, last = 0; i < entries.length; i++) {
|
|
||||||
if (!toRemove.contains(i)) {
|
|
||||||
filteredEntries[last] = entries[i];
|
|
||||||
filteredEntryValues[last++] = entryValues[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sensorTypePreference.setEntries(filteredEntries);
|
|
||||||
sensorTypePreference.setEntryValues(filteredEntryValues);
|
|
||||||
|
|
||||||
PreferenceScreen sensorOptionsScreen =
|
|
||||||
(PreferenceScreen) findPreference(getString(R.string.sensor_options_key));
|
|
||||||
sensorOptionsScreen.removePreference(findPreference(getString(R.string.ant_options_key)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void customizeTrackColorModePreferences() {
|
private void customizeTrackColorModePreferences() {
|
||||||
ListPreference trackColorModePreference =
|
ListPreference trackColorModePreference =
|
||||||
(ListPreference) findPreference(getString(R.string.track_color_mode_key));
|
(ListPreference) findPreference(getString(R.string.track_color_mode_key));
|
||||||
@@ -203,7 +155,6 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
configureBluetoothPreferences();
|
|
||||||
Preference resetPreference = findPreference(getString(R.string.reset_key));
|
Preference resetPreference = findPreference(getString(R.string.reset_key));
|
||||||
boolean recording = PreferencesUtils.getLong(this, R.string.recording_track_id_key) != -1;
|
boolean recording = PreferencesUtils.getLong(this, R.string.recording_track_id_key) != -1;
|
||||||
resetPreference.setEnabled(!recording);
|
resetPreference.setEnabled(!recording);
|
||||||
@@ -212,27 +163,6 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
|||||||
: R.string.settings_reset_summary);
|
: R.string.settings_reset_summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSensorSettings(String sensorType) {
|
|
||||||
boolean usesBluetooth =
|
|
||||||
getString(R.string.sensor_type_value_zephyr).equals(sensorType)
|
|
||||||
|| getString(R.string.sensor_type_value_polar).equals(sensorType);
|
|
||||||
findPreference(
|
|
||||||
getString(R.string.bluetooth_sensor_key)).setEnabled(usesBluetooth);
|
|
||||||
findPreference(
|
|
||||||
getString(R.string.bluetooth_pairing_key)).setEnabled(usesBluetooth);
|
|
||||||
|
|
||||||
// Update the ANT+ sensors.
|
|
||||||
// TODO: Only enable on phones that have ANT+.
|
|
||||||
Preference antHrm = findPreference(getString(R.string.ant_heart_rate_sensor_id_key));
|
|
||||||
Preference antSrm = findPreference(getString(R.string.ant_srm_bridge_sensor_id_key));
|
|
||||||
if (antHrm != null && antSrm != null) {
|
|
||||||
antHrm
|
|
||||||
.setEnabled(getString(R.string.sensor_type_value_ant).equals(sensorType));
|
|
||||||
antSrm
|
|
||||||
.setEnabled(getString(R.string.sensor_type_value_srm_ant_bridge).equals(sensorType));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateTrackColorModeSettings(String trackColorMode) {
|
private void updateTrackColorModeSettings(String trackColorMode) {
|
||||||
boolean usesFixedSpeed =
|
boolean usesFixedSpeed =
|
||||||
trackColorMode.equals(getString(R.string.display_track_color_value_fixed));
|
trackColorMode.equals(getString(R.string.display_track_color_value_fixed));
|
||||||
@@ -247,45 +177,6 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
|||||||
.setEnabled(usesDynamicSpeed);
|
.setEnabled(usesDynamicSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures preference actions related to bluetooth.
|
|
||||||
*/
|
|
||||||
private void configureBluetoothPreferences() {
|
|
||||||
// Populate the list of bluetooth devices
|
|
||||||
populateBluetoothDeviceList();
|
|
||||||
// Make the pair devices preference go to the system preferences
|
|
||||||
findPreference(getString(R.string.bluetooth_pairing_key)).setOnPreferenceClickListener(
|
|
||||||
new OnPreferenceClickListener() {
|
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
|
||||||
Intent settingsIntent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS);
|
|
||||||
startActivity(settingsIntent);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Populates the list preference with all available bluetooth devices.
|
|
||||||
*/
|
|
||||||
private void populateBluetoothDeviceList() {
|
|
||||||
// Build the list of entries and their values
|
|
||||||
List<String> entries = new ArrayList<String>();
|
|
||||||
List<String> entryValues = new ArrayList<String>();
|
|
||||||
|
|
||||||
// The actual devices
|
|
||||||
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
|
||||||
if (bluetoothAdapter != null) {
|
|
||||||
BluetoothDeviceUtils.populateDeviceLists(bluetoothAdapter, entries, entryValues);
|
|
||||||
}
|
|
||||||
|
|
||||||
CharSequence[] entriesArray = entries.toArray(new CharSequence[entries.size()]);
|
|
||||||
CharSequence[] entryValuesArray = entryValues.toArray(new CharSequence[entryValues.size()]);
|
|
||||||
ListPreference devicesPreference =
|
|
||||||
(ListPreference) findPreference(getString(R.string.bluetooth_sensor_key));
|
|
||||||
devicesPreference.setEntryValues(entryValuesArray);
|
|
||||||
devicesPreference.setEntries(entriesArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Callback for when user confirms resetting all settings. */
|
/** Callback for when user confirms resetting all settings. */
|
||||||
private void onResetPreferencesConfirmed() {
|
private void onResetPreferencesConfirmed() {
|
||||||
// Change preferences in a separate thread.
|
// Change preferences in a separate thread.
|
||||||
|
|||||||
@@ -24,17 +24,17 @@ import java.util.Set;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities for dealing with bluetooth devices.
|
* Utilities for dealing with bluetooth devices.
|
||||||
*
|
*
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class BluetoothDeviceUtils {
|
public class BluetoothDeviceUtils {
|
||||||
|
|
||||||
private BluetoothDeviceUtils() {}
|
private BluetoothDeviceUtils() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Populates the device names and the device addresses with all the suitable
|
* Populates the device names and the device addresses with all the suitable
|
||||||
* bluetooth devices.
|
* bluetooth devices.
|
||||||
*
|
*
|
||||||
* @param bluetoothAdapter the bluetooth adapter
|
* @param bluetoothAdapter the bluetooth adapter
|
||||||
* @param deviceNames list of device names
|
* @param deviceNames list of device names
|
||||||
* @param deviceAddresses list of device addresses
|
* @param deviceAddresses list of device addresses
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public class PreferencesUtils {
|
|||||||
public static final int AUTO_RESUME_TRACK_TIMEOUT_DEFAULT = 10;
|
public static final int AUTO_RESUME_TRACK_TIMEOUT_DEFAULT = 10;
|
||||||
public static final int AUTO_RESUME_TRACK_TIMEOUT_NEVER = 0;
|
public static final int AUTO_RESUME_TRACK_TIMEOUT_NEVER = 0;
|
||||||
|
|
||||||
|
public static final String BLUETOOTH_SENSOR_DEFAULT = "";
|
||||||
public static final String DEFAULT_ACTIVITY_DEFAULT = "";
|
public static final String DEFAULT_ACTIVITY_DEFAULT = "";
|
||||||
public static final boolean DEFAULT_MAP_PUBLIC_DEFAULT = true;
|
public static final boolean DEFAULT_MAP_PUBLIC_DEFAULT = true;
|
||||||
public static final int MAX_RECORDING_DISTANCE_DEFAULT = 200;
|
public static final int MAX_RECORDING_DISTANCE_DEFAULT = 200;
|
||||||
@@ -168,4 +169,19 @@ public class PreferencesUtils {
|
|||||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||||
return sharedPreferences.getString(getKey(context, keyId), defaultValue);
|
return sharedPreferences.getString(getKey(context, keyId), defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a string preference value.
|
||||||
|
*
|
||||||
|
* @param context the context
|
||||||
|
* @param keyId the key id
|
||||||
|
* @param value the value
|
||||||
|
*/
|
||||||
|
public static void setString(Context context, int keyId, String value) {
|
||||||
|
SharedPreferences sharedPreferences = context.getSharedPreferences(
|
||||||
|
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||||
|
Editor editor = sharedPreferences.edit();
|
||||||
|
editor.putString(getKey(context, keyId), value);
|
||||||
|
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-5
@@ -647,14 +647,17 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
|||||||
}
|
}
|
||||||
|
|
||||||
@MediumTest
|
@MediumTest
|
||||||
public void testWithProperties_noSensorType() throws Exception {
|
public void testWithProperties_sensorTypeDefault() throws Exception {
|
||||||
functionalTest(R.string.sensor_type_key, (Object) null);
|
PreferencesUtils.setString(
|
||||||
|
context, R.string.sensor_type_key, context.getString(R.string.sensor_type_value_none));
|
||||||
|
fullRecordingSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
@MediumTest
|
@MediumTest
|
||||||
public void testWithProperties_zephyrSensorType() throws Exception {
|
public void testWithProperties_sensorTypeZephyr() throws Exception {
|
||||||
functionalTest(R.string.sensor_type_key,
|
PreferencesUtils.setString(
|
||||||
context.getString(R.string.sensor_type_value_zephyr));
|
context, R.string.sensor_type_key, context.getString(R.string.sensor_type_value_zephyr));
|
||||||
|
fullRecordingSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ITrackRecordingService bindAndGetService(Intent intent) {
|
private ITrackRecordingService bindAndGetService(Intent intent) {
|
||||||
|
|||||||
+2
-4
@@ -1,6 +1,7 @@
|
|||||||
package com.google.android.apps.mytracks.services.sensors;
|
package com.google.android.apps.mytracks.services.sensors;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.Constants;
|
import com.google.android.apps.mytracks.Constants;
|
||||||
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -38,10 +39,7 @@ public class SensorManagerFactoryTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void assertClassForName(Class<?> c, int i) {
|
private void assertClassForName(Class<?> c, int i) {
|
||||||
sharedPreferences.edit()
|
PreferencesUtils.setString(getContext(), R.string.sensor_type_key, getContext().getString(i));
|
||||||
.putString(getContext().getString(R.string.sensor_type_key),
|
|
||||||
getContext().getString(i))
|
|
||||||
.apply();
|
|
||||||
SensorManager sm = SensorManagerFactory.getInstance().getSensorManager(getContext());
|
SensorManager sm = SensorManagerFactory.getInstance().getSensorManager(getContext());
|
||||||
assertNotNull(sm);
|
assertNotNull(sm);
|
||||||
assertTrue(c.isInstance(sm));
|
assertTrue(c.isInstance(sm));
|
||||||
|
|||||||
+3
-3
@@ -18,6 +18,7 @@ package com.google.android.apps.mytracks.services.sensors.ant;
|
|||||||
import com.dsi.ant.AntMesg;
|
import com.dsi.ant.AntMesg;
|
||||||
import com.google.android.apps.mytracks.Constants;
|
import com.google.android.apps.mytracks.Constants;
|
||||||
import com.google.android.apps.mytracks.content.Sensor;
|
import com.google.android.apps.mytracks.content.Sensor;
|
||||||
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -87,9 +88,8 @@ public class AntDirectSensorManagerTest extends AndroidTestCase {
|
|||||||
manager.handleMessage(AntMesg.MESG_CHANNEL_ID_ID, buff);
|
manager.handleMessage(AntMesg.MESG_CHANNEL_ID_ID, buff);
|
||||||
|
|
||||||
assertEquals(43, heartRateSensor.getDeviceNumber());
|
assertEquals(43, heartRateSensor.getDeviceNumber());
|
||||||
assertEquals(43,
|
assertEquals(43, PreferencesUtils.getInt(
|
||||||
sharedPreferences.getInt(
|
getContext(), R.string.ant_heart_rate_sensor_id_key, AntSensorManager.WILDCARD));
|
||||||
getContext().getString(R.string.ant_heart_rate_sensor_id_key), -1));
|
|
||||||
assertNull(manager.getSensorDataSet());
|
assertNull(manager.getSensorDataSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user