Move recording settings to RecordingSettingsActivity.

This commit is contained in:
Jimmy Shih
2012-05-04 13:10:51 -07:00
parent f8460fb76f
commit 3008b335a7
17 changed files with 617 additions and 598 deletions
+1
View File
@@ -208,6 +208,7 @@ limitations under the License.
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity" />
<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.RecordingSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.SettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.SharingSettingsActivity" />
<!-- Services -->
+48 -64
View File
@@ -16,7 +16,6 @@ limitations under the License.
-->
<resources>
<!-- Do not translate any arrays in this file. -->
<string-array name="activity_types">
<item>@string/activity_type_airplane</item>
<item>@string/activity_type_atv</item>
@@ -84,35 +83,38 @@ limitations under the License.
<item>@string/activity_type_water_skiing</item>
<item>@string/activity_type_wind_surfing</item>
</string-array>
<string-array name="display_track_color_options">
<item>@string/settings_display_track_color_single</item>
<item>@string/settings_display_track_color_fixed</item>
<item>@string/settings_display_track_color_dynamic</item>
</string-array>
<string-array name="display_track_color_values">
<item>@string/display_track_color_value_none</item>
<item>@string/display_track_color_value_fixed</item>
<item>@string/display_track_color_value_dynamic</item>
</string-array>
<string-array name="file_types">
<item>GPX</item>
<item>KML</item>
<item>CSV</item>
<item>TCX</item>
</string-array>
<string-array name="recording_auto_resume_timeout_values">
<string-array name="auto_resume_track_timeout_values">
<item>0</item>
<item>5</item>
<item>10</item>
<item>15</item>
<item>-1</item>
</string-array>
<string-array name="recording_distance_values">
<string-array name="display_track_color_options">
<item>@string/settings_display_track_color_single</item>
<item>@string/settings_display_track_color_fixed</item>
<item>@string/settings_display_track_color_dynamic</item>
</string-array>
<string-array name="display_track_color_values">
<item>@string/display_track_color_value_none</item>
<item>@string/display_track_color_value_fixed</item>
<item>@string/display_track_color_value_dynamic</item>
</string-array>
<string-array name="file_types">
<item>GPX</item>
<item>KML</item>
<item>CSV</item>
<item>TCX</item>
</string-array>
<string-array name="max_recording_distance_values">
<item>50</item>
<item>100</item>
<item>200</item>
<item>500</item>
<item>1000</item>
<item>5000</item>
</string-array>
<string-array name="min_recording_distance_values">
<item>1</item>
<item>2</item>
<item>3</item>
@@ -121,20 +123,7 @@ limitations under the License.
<item>10</item>
<item>100</item>
</string-array>
<string-array name="recording_gps_accuracy_values">
<item>10</item>
<item>20</item>
<item>50</item>
<item>100</item>
<item>200</item>
<item>500</item>
<item>1000</item>
<item>2000</item>
<item>5000</item>
</string-array>
<string-array name="recording_interval_values">
<string-array name="min_recording_interval_values">
<item>-2</item>
<item>-1</item>
<item>0</item>
@@ -152,38 +141,37 @@ limitations under the License.
<item>900</item>
<item>1800</item>
</string-array>
<string-array name="recording_task_frequency_values">
<item>0</item>
<item>-100</item>
<item>-50</item>
<item>-25</item>
<item>-10</item>
<item>-5</item>
<item>-1</item>
<item>60</item>
<item>30</item>
<item>15</item>
<string-array name="min_required_accuracy_values">
<item>10</item>
<item>5</item>
<item>2</item>
<item>1</item>
</string-array>
<string-array name="recording_track_distance_values">
<item>20</item>
<item>50</item>
<item>100</item>
<item>200</item>
<item>500</item>
<item>1000</item>
<item>2000</item>
<item>5000</item>
</string-array>
<string-array name="periodic_task_values">
<item>0</item>
<item>1</item>
<item>2</item>
<item>5</item>
<item>10</item>
<item>15</item>
<item>30</item>
<item>60</item>
<item>-1</item>
<item>-5</item>
<item>-10</item>
<item>-25</item>
<item>-50</item>
<item>-100</item>
</string-array>
<string-array name="sensor_type_ant_values">
<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_ant</item>
@@ -191,7 +179,6 @@ limitations under the License.
<item>@string/settings_sensor_type_polar</item>
<item>@string/settings_sensor_type_zephyr</item>
</string-array>
<string-array name="sensor_type_values">
<item>@string/sensor_type_value_none</item>
<item>@string/sensor_type_value_ant</item>
@@ -199,19 +186,16 @@ limitations under the License.
<item>@string/sensor_type_value_polar</item>
<item>@string/sensor_type_value_zephyr</item>
</string-array>
<string-array name="settings_recording_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_iso_8601_option</item>
<item>@string/settings_recording_track_name_number_option</item>
</string-array>
<string-array name="settings_recording_track_name_values">
<string-array name="track_name_values">
<item>@string/settings_recording_track_name_date_local_value</item>
<item>@string/settings_recording_track_name_date_iso_8601_value</item>
<item>@string/settings_recording_track_name_number_value</item>
</string-array>
<string-array name="waypoint_types">
<item>@string/waypoint_type_atm</item>
<item>@string/waypoint_type_bank</item>
+1
View File
@@ -66,6 +66,7 @@ limitations under the License.
<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_recording_key">settingsRecording</string>
<string name="settings_sharing_key">settingsSharing</string>
<string name="track_color_mode_fixed_speed_options_key">trackColorModeFixedOptions</string>
</resources>
+6 -66
View File
@@ -86,72 +86,12 @@ limitations under the License.
</PreferenceCategory>
</PreferenceScreen>
<!-- Recording settings -->
<PreferenceScreen android:title="@string/settings_recording">
<com.google.android.apps.mytracks.IntegerListPreference
android:key="@string/announcement_frequency_key"
android:title="@string/settings_recording_voice"
android:summary="@string/settings_recording_voice_summary"
android:entryValues="@array/recording_task_frequency_values"
android:defaultValue="0" />
<com.google.android.apps.mytracks.IntegerListPreference
android:key="@string/split_frequency_key"
android:title="@string/settings_recording_marker"
android:summary="@string/settings_recording_marker_summary"
android:entryValues="@array/recording_task_frequency_values"
android:defaultValue="0" />
<com.google.android.apps.mytracks.IntegerListPreference
android:key="@string/min_recording_interval_key"
android:title="@string/settings_recording_interval"
android:summary="@string/settings_recording_interval_summary"
android:entryValues="@array/recording_interval_values"
android:defaultValue="0" />
<com.google.android.apps.mytracks.IntegerListPreference
android:key="@string/min_recording_distance_key"
android:title="@string/settings_recording_distance"
android:summary="@string/settings_recording_distance_summary"
android:entryValues="@array/recording_distance_values"
android:defaultValue="5" />
<com.google.android.apps.mytracks.IntegerListPreference
android:key="@string/max_recording_distance_key"
android:title="@string/settings_recording_track_distance"
android:summary="@string/settings_recording_track_distance_summary"
android:entryValues="@array/recording_track_distance_values"
android:defaultValue="200" />
<com.google.android.apps.mytracks.IntegerListPreference
android:key="@string/min_required_accuracy_key"
android:title="@string/settings_recording_gps_accuracy"
android:summary="@string/settings_recording_gps_accuracy_summary"
android:entryValues="@array/recording_gps_accuracy_values"
android:defaultValue="200" />
<com.google.android.apps.mytracks.IntegerListPreference
android:key="@string/auto_resume_track_timeout_key"
android:title="@string/settings_recording_auto_resume"
android:summary="@string/settings_recording_auto_resume_summary"
android:entryValues="@array/recording_auto_resume_timeout_values"
android:defaultValue="10" />
<ListPreference android:key="@string/track_name_key"
android:title="@string/settings_recording_track_name"
android:summary="@string/settings_recording_track_name_summary"
android:entries="@array/settings_recording_track_name_options"
android:entryValues="@array/settings_recording_track_name_values"
android:defaultValue="@string/settings_recording_track_name_date_local_value"/>
<com.google.android.apps.mytracks.AutoCompleteTextPreference
android:key="@string/default_activity_key"
android:title="@string/settings_recording_default_activity"
android:summary="@string/settings_recording_default_activity_summary"
android:defaultValue="" />
</PreferenceScreen>
<!-- Recording -->
<Preference
android:title="@string/settings_recording"
android:key="@string/settings_recording_key"
android:persistent="false" />
<!-- Sharing -->
<Preference
android:title="@string/settings_sharing"
+73
View File
@@ -0,0 +1,73 @@
<?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:title="@string/settings_recording" >
<com.google.android.apps.mytracks.IntegerListPreference
android:defaultValue="0"
android:entryValues="@array/periodic_task_values"
android:key="@string/announcement_frequency_key"
android:summary="@string/settings_recording_voice_summary"
android:title="@string/settings_recording_voice" />
<com.google.android.apps.mytracks.IntegerListPreference
android:defaultValue="0"
android:entryValues="@array/periodic_task_values"
android:key="@string/split_frequency_key"
android:summary="@string/settings_recording_marker_summary"
android:title="@string/settings_recording_marker" />
<ListPreference
android:defaultValue="@string/settings_recording_track_name_date_local_value"
android:entries="@array/track_name_options"
android:entryValues="@array/track_name_values"
android:key="@string/track_name_key"
android:summary="@string/settings_recording_track_name_summary"
android:title="@string/settings_recording_track_name" />
<com.google.android.apps.mytracks.AutoCompleteTextPreference
android:defaultValue=""
android:key="@string/default_activity_key"
android:summary="@string/settings_recording_default_activity_summary"
android:title="@string/settings_recording_default_activity" />
<com.google.android.apps.mytracks.IntegerListPreference
android:defaultValue="0"
android:entryValues="@array/min_recording_interval_values"
android:key="@string/min_recording_interval_key"
android:summary="@string/settings_recording_interval_summary"
android:title="@string/settings_recording_interval" />
<com.google.android.apps.mytracks.IntegerListPreference
android:defaultValue="5"
android:entryValues="@array/min_recording_distance_values"
android:key="@string/min_recording_distance_key"
android:summary="@string/settings_recording_distance_summary"
android:title="@string/settings_recording_distance" />
<com.google.android.apps.mytracks.IntegerListPreference
android:defaultValue="200"
android:entryValues="@array/max_recording_distance_values"
android:key="@string/max_recording_distance_key"
android:summary="@string/settings_recording_track_distance_summary"
android:title="@string/settings_recording_track_distance" />
<com.google.android.apps.mytracks.IntegerListPreference
android:defaultValue="200"
android:entryValues="@array/min_required_accuracy_values"
android:key="@string/min_required_accuracy_key"
android:summary="@string/settings_recording_gps_accuracy_summary"
android:title="@string/settings_recording_gps_accuracy" />
<com.google.android.apps.mytracks.IntegerListPreference
android:defaultValue="10"
android:entryValues="@array/auto_resume_track_timeout_values"
android:key="@string/auto_resume_track_timeout_key"
android:summary="@string/settings_recording_auto_resume_summary"
android:title="@string/settings_recording_auto_resume" />
</PreferenceScreen>
@@ -1,5 +1,6 @@
package com.google.android.apps.mytracks;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
import android.content.Context;
@@ -31,9 +32,9 @@ public class AutoCompleteTextPreference extends EditTextPreference {
mEditText.setThreshold(0);
// Gets autocomplete values for 'Default Activity' preference
if (getKey().equals(context.getString(R.string.default_activity_key))) {
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(context,
R.array.activity_types, android.R.layout.simple_dropdown_item_1line);
if (PreferencesUtils.getKey(context, R.string.default_activity_key).equals(getKey())) {
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
context, R.array.activity_types, android.R.layout.simple_dropdown_item_1line);
mEditText.setAdapter(adapter);
}
}
@@ -121,23 +121,10 @@ public abstract class Constants {
* The name of extra intent property to indicate whether we want to resume
* a previously recorded track.
*/
public static final String RESUME_TRACK_EXTRA_NAME =
"com.google.android.apps.mytracks.RESUME_TRACK";
public static final String
RESUME_TRACK_EXTRA_NAME = "com.google.android.apps.mytracks.RESUME_TRACK";
public static final String MAPSHOP_BASE_URL =
"https://maps.google.com/maps/ms";
/*
* Default values - keep in sync with those in preferences.xml.
*/
public static final int DEFAULT_ANNOUNCEMENT_FREQUENCY = -1;
public static final int DEFAULT_AUTO_RESUME_TRACK_TIMEOUT = 10; // In min.
public static final int DEFAULT_MAX_RECORDING_DISTANCE = 200;
public static final int DEFAULT_MIN_RECORDING_DISTANCE = 5;
public static final int DEFAULT_MIN_RECORDING_INTERVAL = 0;
public static final int DEFAULT_MIN_REQUIRED_ACCURACY = 200;
public static final int DEFAULT_SPLIT_FREQUENCY = 0;
public static final String MAPSHOP_BASE_URL = "https://maps.google.com/maps/ms";
public static final String SETTINGS_NAME = "SettingsActivity";
@@ -15,7 +15,6 @@
*/
package com.google.android.apps.mytracks.content;
import static com.google.android.apps.mytracks.Constants.DEFAULT_MIN_REQUIRED_ACCURACY;
import static com.google.android.apps.mytracks.Constants.MAX_DISPLAYED_WAYPOINTS_POINTS;
import static com.google.android.apps.mytracks.Constants.MAX_LOCATION_AGE_MS;
import static com.google.android.apps.mytracks.Constants.MAX_NETWORK_AGE_MS;
@@ -58,9 +57,6 @@ import java.util.Set;
*/
public class TrackDataHub {
// Preference keys
private final String MIN_REQUIRED_ACCURACY_KEY;
// Overridable constants
private final int targetNumPoints;
@@ -219,8 +215,6 @@ public class TrackDataHub {
this.targetNumPoints = targetNumPoints;
this.locationFactory = new DoubleBufferedLocationFactory();
MIN_REQUIRED_ACCURACY_KEY = context.getString(R.string.min_required_accuracy_key);
resetState();
}
@@ -297,8 +291,8 @@ public class TrackDataHub {
selectedTrackId = PreferencesUtils.getLong(context, R.string.selected_track_id_key);
metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
reportSpeed = PreferencesUtils.getBoolean(context, R.string.report_speed_key, true);
minRequiredAccuracy = preferences.getInt(MIN_REQUIRED_ACCURACY_KEY,
DEFAULT_MIN_REQUIRED_ACCURACY);
minRequiredAccuracy = PreferencesUtils.getInt(context, R.string.min_required_accuracy_key,
PreferencesUtils.MIN_REQUIRED_ACCURACY_DEFAULT);
}
/** Updates known magnetic declination if needed. */
@@ -605,13 +599,13 @@ public class TrackDataHub {
/**
* Called when a preference changes.
*
*
* @param key the key to the preference that changed
*/
private void notifyPreferenceChanged(String key) {
if (MIN_REQUIRED_ACCURACY_KEY.equals(key)) {
minRequiredAccuracy = preferences.getInt(MIN_REQUIRED_ACCURACY_KEY,
DEFAULT_MIN_REQUIRED_ACCURACY);
if (PreferencesUtils.getKey(context, R.string.min_required_accuracy_key).equals(key)) {
minRequiredAccuracy = PreferencesUtils.getInt(context, R.string.min_required_accuracy_key,
PreferencesUtils.MIN_REQUIRED_ACCURACY_DEFAULT);
} else if (PreferencesUtils.getKey(context, R.string.metric_units_key).equals(key)) {
metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
notifyUnitsChanged();
@@ -15,13 +15,12 @@
*/
package com.google.android.apps.mytracks.services;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.maps.mytracks.R;
import com.google.common.annotations.VisibleForTesting;
import android.content.Context;
import android.content.SharedPreferences;
import java.text.SimpleDateFormat;
@@ -59,7 +58,7 @@ public class DefaultTrackNameFactory {
} else {
// trackNameSetting equals
// R.string.settings_recording_track_name_number_value
return String.format(context.getString(R.string.track_name_format), trackId);
return context.getString(R.string.track_name_format, trackId);
}
}
@@ -68,10 +67,7 @@ public class DefaultTrackNameFactory {
*/
@VisibleForTesting
String getTrackNameSetting() {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getString(
context.getString(R.string.track_name_key),
return PreferencesUtils.getString(context, R.string.track_name_key,
context.getString(R.string.settings_recording_track_name_date_local_value));
}
}
@@ -16,156 +16,119 @@
package com.google.android.apps.mytracks.services;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.util.Log;
/**
* A class that manages reading the shared preferences for the service.
*
*
* @author Sandor Dornbush
*/
public class PreferenceManager implements OnSharedPreferenceChangeListener {
private TrackRecordingService service;
private SharedPreferences sharedPreferences;
private final String announcementFrequencyKey;
private final String autoResumeTrackCurrentRetryKey;
private final String autoResumeTrackTimeoutKey;
private final String maxRecordingDistanceKey;
private final String minRecordingDistanceKey;
private final String minRecordingIntervalKey;
private final String minRequiredAccuracyKey;
private final String splitFrequencyKey;
public PreferenceManager(TrackRecordingService service) {
this.service = service;
this.sharedPreferences = service.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
if (sharedPreferences == null) {
Log.w(Constants.TAG,
"TrackRecordingService: Couldn't get shared preferences.");
throw new IllegalStateException("Couldn't get shared preferences");
}
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
announcementFrequencyKey =
service.getString(R.string.announcement_frequency_key);
autoResumeTrackCurrentRetryKey =
service.getString(R.string.auto_resume_track_current_retry_key);
autoResumeTrackTimeoutKey =
service.getString(R.string.auto_resume_track_timeout_key);
maxRecordingDistanceKey =
service.getString(R.string.max_recording_distance_key);
minRecordingDistanceKey =
service.getString(R.string.min_recording_distance_key);
minRecordingIntervalKey =
service.getString(R.string.min_recording_interval_key);
minRequiredAccuracyKey =
service.getString(R.string.min_required_accuracy_key);
splitFrequencyKey =
service.getString(R.string.split_frequency_key);
// Refresh all properties.
onSharedPreferenceChanged(sharedPreferences, null);
}
/**
* Notifies that preferences have changed.
* Call this with key == null to update all preferences in one call.
*
* Notifies that preferences have changed. Call this with key == null to
* update all preferences in one call.
*
* @param key the key that changed (may be null to update all preferences)
*/
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences,
String key) {
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (service == null) {
Log.w(Constants.TAG,
"onSharedPreferenceChanged: a preference change (key = " + key
Log.w(Constants.TAG, "onSharedPreferenceChanged: a preference change (key = " + key
+ ") after a call to shutdown()");
return;
}
if (key == null || key.equals(minRecordingDistanceKey)) {
int minRecordingDistance = sharedPreferences.getInt(
minRecordingDistanceKey,
Constants.DEFAULT_MIN_RECORDING_DISTANCE);
service.setMinRecordingDistance(minRecordingDistance);
Log.d(Constants.TAG,
"TrackRecordingService: minRecordingDistance = "
+ minRecordingDistance);
if (key == null
|| PreferencesUtils.getKey(service, R.string.recording_track_id_key).equals(key)) {
long recordingTrackId = PreferencesUtils.getLong(service, R.string.recording_track_id_key);
/*
* Only set the id if it is valid. Setting it to -1L should only happen
* in TrackRecordingService.endCurrentTrack()
*/
if (recordingTrackId != -1L) {
service.setRecordingTrackId(recordingTrackId);
}
}
if (key == null || key.equals(maxRecordingDistanceKey)) {
service.setMaxRecordingDistance(sharedPreferences.getInt(
maxRecordingDistanceKey,
Constants.DEFAULT_MAX_RECORDING_DISTANCE));
if (key == null || PreferencesUtils.getKey(service, R.string.metric_units_key).equals(key)) {
service.setMetricUnits(PreferencesUtils.getBoolean(service, R.string.metric_units_key, true));
}
if (key == null || key.equals(minRecordingIntervalKey)) {
int minRecordingInterval = sharedPreferences.getInt(
minRecordingIntervalKey,
Constants.DEFAULT_MIN_RECORDING_INTERVAL);
if (key == null
|| PreferencesUtils.getKey(service, R.string.announcement_frequency_key).equals(key)) {
service.setAnnouncementFrequency(PreferencesUtils.getInt(
service, R.string.announcement_frequency_key,
PreferencesUtils.ANNOUNCEMENT_FREQUENCY_DEFAULT));
}
if (key == null || PreferencesUtils.getKey(service, R.string.split_frequency_key).equals(key)) {
service.setSplitFrequency(PreferencesUtils.getInt(
service, R.string.split_frequency_key, PreferencesUtils.SPLIT_FREQUENCY_DEFAULT));
}
if (key == null
|| PreferencesUtils.getKey(service, R.string.min_recording_interval_key).equals(key)) {
int minRecordingInterval = PreferencesUtils.getInt(service,
R.string.min_recording_interval_key, PreferencesUtils.MIN_RECORDING_INTERVAL_DEFAULT);
switch (minRecordingInterval) {
case -2:
// Battery Miser
// min: 30 seconds
// max: 5 minutes
// minDist: 5 meters Choose battery life over moving time accuracy.
service.setLocationListenerPolicy(
new AdaptiveLocationListenerPolicy(30000, 300000, 5));
case PreferencesUtils.MIN_RECORDING_INTERVAL_ADAPT_BATTERY_LIFE:
/*
* Choose battery life over moving time accuracy. min: 30 seconds,
* max: 5 minutes, inDist: 5 meters.
*/
service.setLocationListenerPolicy(new AdaptiveLocationListenerPolicy(30000, 300000, 5));
break;
case -1:
// High Accuracy
// min: 1 second
// max: 30 seconds
// minDist: 0 meters get all updates to properly measure moving time.
service.setLocationListenerPolicy(
new AdaptiveLocationListenerPolicy(1000, 30000, 0));
case PreferencesUtils.MIN_RECORDING_INTERVAL_ADAPT_ACCURACY:
/*
* Get all the updates. min: 1 second, max: 30 seconds, minDist: 0
* meter.
*/
service.setLocationListenerPolicy(new AdaptiveLocationListenerPolicy(1000, 30000, 0));
break;
default:
service.setLocationListenerPolicy(
new AbsoluteLocationListenerPolicy(minRecordingInterval * 1000));
}
}
if (key == null || key.equals(minRequiredAccuracyKey)) {
service.setMinRequiredAccuracy(sharedPreferences.getInt(
minRequiredAccuracyKey,
Constants.DEFAULT_MIN_REQUIRED_ACCURACY));
if (key == null
|| PreferencesUtils.getKey(service, R.string.min_recording_distance_key).equals(key)) {
service.setMinRecordingDistance(PreferencesUtils.getInt(
service, R.string.min_recording_distance_key,
PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT));
}
if (key == null || key.equals(announcementFrequencyKey)) {
service.setAnnouncementFrequency(
sharedPreferences.getInt(announcementFrequencyKey, -1));
if (key == null
|| PreferencesUtils.getKey(service, R.string.max_recording_distance_key).equals(key)) {
service.setMaxRecordingDistance(PreferencesUtils.getInt(
service, R.string.max_recording_distance_key,
PreferencesUtils.MAX_RECORDING_DISTANCE_DEFAULT));
}
if (key == null || key.equals(autoResumeTrackTimeoutKey)) {
service.setAutoResumeTrackTimeout(sharedPreferences.getInt(
autoResumeTrackTimeoutKey,
Constants.DEFAULT_AUTO_RESUME_TRACK_TIMEOUT));
}
if (key == null || key.equals(PreferencesUtils.getKey(service, R.string.recording_track_id_key))) {
long recordingTrackId = PreferencesUtils.getLong(service, R.string.recording_track_id_key);
// Only read the id if it is valid.
// Setting it to -1 should only happen in
// TrackRecordingService.endCurrentTrack()
if (recordingTrackId != -1L) {
service.setRecordingTrackId(recordingTrackId);
}
}
if (key == null || key.equals(splitFrequencyKey)) {
service.setSplitFrequency(
sharedPreferences.getInt(splitFrequencyKey, 0));
}
if (key == null || key.equals(PreferencesUtils.getKey(service, R.string.metric_units_key))) {
service.setMetricUnits(PreferencesUtils.getBoolean(service, R.string.metric_units_key, true));
}
}
public void setAutoResumeTrackCurrentRetry(int retryAttempts) {
Editor editor = sharedPreferences.edit();
editor.putInt(autoResumeTrackCurrentRetryKey, retryAttempts);
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
if (key == null
|| PreferencesUtils.getKey(service, R.string.min_required_accuracy_key).equals(key)) {
service.setMinRequiredAccuracy(PreferencesUtils.getInt(
service, R.string.min_required_accuracy_key,
PreferencesUtils.MIN_REQUIRED_ACCURACY_DEFAULT));
}
if (key == null
|| PreferencesUtils.getKey(service, R.string.auto_resume_track_timeout_key).equals(key)) {
service.setAutoResumeTrackTimeout(PreferencesUtils.getInt(
service, R.string.auto_resume_track_timeout_key,
PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT));
}
}
public void shutdown() {
@@ -50,7 +50,6 @@ import android.app.Service;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.location.Location;
@@ -84,14 +83,10 @@ public class TrackRecordingService extends Service {
private LocationManager locationManager;
private WakeLock wakeLock;
private int minRecordingDistance =
Constants.DEFAULT_MIN_RECORDING_DISTANCE;
private int maxRecordingDistance =
Constants.DEFAULT_MAX_RECORDING_DISTANCE;
private int minRequiredAccuracy =
Constants.DEFAULT_MIN_REQUIRED_ACCURACY;
private int autoResumeTrackTimeout =
Constants.DEFAULT_AUTO_RESUME_TRACK_TIMEOUT;
private int minRecordingDistance = PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT;
private int maxRecordingDistance = PreferencesUtils.MAX_RECORDING_DISTANCE_DEFAULT;
private int minRequiredAccuracy = PreferencesUtils.MIN_REQUIRED_ACCURACY_DEFAULT;
private int autoResumeTrackTimeout = PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT;
private long recordingTrackId = -1;
@@ -123,7 +118,7 @@ public class TrackRecordingService extends Service {
private SensorManager sensorManager;
private PreferenceManager prefManager;
private PreferenceManager prefereceManager;
/**
* The interval in milliseconds that we have requested to be notified of gps
@@ -248,7 +243,7 @@ public class TrackRecordingService extends Service {
setUpTaskExecutors();
executorService = Executors.newSingleThreadExecutor();
prefManager = new PreferenceManager(this);
prefereceManager = new PreferenceManager(this);
registerLocationListener();
@@ -354,8 +349,7 @@ public class TrackRecordingService extends Service {
isRecording = false;
showNotification();
prefManager.shutdown();
prefManager = null;
prefereceManager.shutdown();
checkLocationListener.cancel();
checkLocationListener = null;
timer.cancel();
@@ -383,7 +377,7 @@ public class TrackRecordingService extends Service {
private void setAutoResumeTrackRetries(int retryAttempts) {
Log.d(TAG, "Updating auto-resume retry attempts to: " + retryAttempts);
prefManager.setAutoResumeTrackCurrentRetry(retryAttempts);
PreferencesUtils.setInt(this, R.string.auto_resume_track_current_retry_key, retryAttempts);
}
private boolean shouldResumeTrack(Track track) {
@@ -391,10 +385,8 @@ public class TrackRecordingService extends Service {
+ autoResumeTrackTimeout);
// Check if we haven't exceeded the maximum number of retry attempts.
SharedPreferences sharedPreferences = getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
int retries = sharedPreferences.getInt(
getString(R.string.auto_resume_track_current_retry_key), 0);
int retries = PreferencesUtils.getInt(this, R.string.auto_resume_track_current_retry_key,
PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT);
Log.d(TAG,
"shouldResumeTrack: Attempting to auto-resume the track ("
+ (retries + 1) + "/" + MAX_AUTO_RESUME_TRACK_RETRY_ATTEMPTS + ")");
@@ -409,12 +401,12 @@ public class TrackRecordingService extends Service {
setAutoResumeTrackRetries(retries + 1);
// Check for special cases.
if (autoResumeTrackTimeout == 0) {
if (autoResumeTrackTimeout == PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_NEVER) {
// Never resume.
Log.d(TAG,
"shouldResumeTrack: Auto-resume disabled (never resume)");
return false;
} else if (autoResumeTrackTimeout == -1) {
} else if (autoResumeTrackTimeout == PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_ALWAYS) {
// Always resume.
Log.d(TAG,
"shouldResumeTrack: Auto-resume forced (always resume)");
@@ -565,12 +557,6 @@ public class TrackRecordingService extends Service {
"Location listener now unregistered w/ TrackRecordingService.");
}
private String getDefaultActivityType(Context context) {
SharedPreferences prefs = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
return prefs.getString(context.getString(R.string.default_activity_key), "");
}
/*
* Recording lifecycle.
*/
@@ -593,7 +579,8 @@ public class TrackRecordingService extends Service {
track.setId(recordingTrackId);
track.setName(new DefaultTrackNameFactory(this).getDefaultTrackName(
recordingTrackId, startTime));
track.setCategory(getDefaultActivityType(this));
track.setCategory(PreferencesUtils.getString(
this, R.string.default_activity_key, PreferencesUtils.DEFAULT_ACTIVITY_DEFAULT));
isRecording = true;
isMoving = true;
@@ -18,6 +18,7 @@ package com.google.android.apps.mytracks.services.tasks;
import static com.google.android.apps.mytracks.Constants.TAG;
import com.google.android.apps.mytracks.services.TrackRecordingService;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.UnitConversions;
import android.util.Log;
@@ -34,7 +35,7 @@ public class PeriodicTaskExecutor {
* A value greater than zero is a frequency in time.
* A value less than zero is considered a frequency in distance.
*/
private int taskFrequency = 0;
private int taskFrequency = PreferencesUtils.PERIODIC_TASK_OFF;
/**
* The next distance when the task should execute.
@@ -74,7 +75,7 @@ public class PeriodicTaskExecutor {
timerExecutor = null;
}
}
if (taskFrequency == 0) {
if (taskFrequency == PreferencesUtils.PERIODIC_TASK_OFF) {
return;
}
@@ -0,0 +1,243 @@
/*
* 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.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.UnitConversions;
import com.google.android.maps.mytracks.R;
import android.os.Bundle;
import android.preference.ListPreference;
/**
* An activity for accessing recording settings.
*
* @author Jimmy Shih
*/
public class RecordingSettingsActivity extends AbstractSettingsActivity {
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
addPreferencesFromResource(R.xml.recording_settings);
boolean metricUnits = PreferencesUtils.getBoolean(
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
ListPreference announcementFrequencyListPreference = (ListPreference) findPreference(
getString(R.string.announcement_frequency_key));
announcementFrequencyListPreference.setEntries(getPeriodicTaskDisplayOptions(metricUnits));
ListPreference splitFrequencyListPreference = (ListPreference) findPreference(
getString(R.string.split_frequency_key));
splitFrequencyListPreference.setEntries(getPeriodicTaskDisplayOptions(metricUnits));
ListPreference minRecordingIntervalListPreference = (ListPreference) findPreference(
getString(R.string.min_recording_interval_key));
minRecordingIntervalListPreference.setEntries(getMinRecordingIntervalDisplayOptions());
ListPreference minRecordingDistanceListPreference = (ListPreference) findPreference(
getString(R.string.min_recording_distance_key));
minRecordingDistanceListPreference.setEntries(
getMinRecordingDistanceDisplayOptions(metricUnits));
ListPreference maxRecordingDistanceListPreference = (ListPreference) findPreference(
getString(R.string.max_recording_distance_key));
maxRecordingDistanceListPreference.setEntries(
getMaxRecordingDistanceDisplayOptions(metricUnits));
ListPreference minRequiredAccuracyListPreference = (ListPreference) findPreference(
getString(R.string.min_required_accuracy_key));
minRequiredAccuracyListPreference.setEntries(getMinRequiredAccuracyDisplayOptions(metricUnits));
ListPreference autoResumeTrackTimeoutListPreference = (ListPreference) findPreference(
getString(R.string.auto_resume_track_timeout_key));
autoResumeTrackTimeoutListPreference.setEntries(getAutoResumeTrackTimeoutDisplayOptions());
}
/**
* Gets the periodic task display options.
*
* @param metricUnits true to display metric units
*/
private String[] getPeriodicTaskDisplayOptions(boolean metricUnits) {
String[] values = getResources().getStringArray(R.array.periodic_task_values);
String[] options = new String[values.length];
for (int i = 0; i < values.length; i++) {
int value = Integer.parseInt(values[i]);
if (value == PreferencesUtils.PERIODIC_TASK_OFF) {
options[i] = getString(R.string.value_off);
} else if (value < 0) {
options[i] = getString(metricUnits ? R.string.value_integer_kilometer
: R.string.value_integer_mile, Math.abs(value));
} else {
options[i] = getString(R.string.value_integer_minute, value);
}
}
return options;
}
/**
* Gets the min recording interval display options.
*/
private String[] getMinRecordingIntervalDisplayOptions() {
String[] values = getResources().getStringArray(R.array.min_recording_interval_values);
String[] options = new String[values.length];
for (int i = 0; i < values.length; i++) {
int value = Integer.parseInt(values[i]);
switch (value) {
case PreferencesUtils.MIN_RECORDING_INTERVAL_ADAPT_BATTERY_LIFE:
options[i] = getString(R.string.value_adapt_battery_life);
break;
case PreferencesUtils.MIN_RECORDING_INTERVAL_ADAPT_ACCURACY:
options[i] = getString(R.string.value_adapt_accuracy);
break;
case PreferencesUtils.MIN_RECORDING_INTERVAL_DEFAULT:
options[i] = getString(R.string.value_smallest_recommended);
break;
default:
options[i] = value < 60 ? getString(R.string.value_integer_second, value)
: getString(R.string.value_integer_minute, value / 60);
}
}
return options;
}
/**
* Gets the min recording distance display options.
*
* @param metricUnits true to display metric units
*/
private String[] getMinRecordingDistanceDisplayOptions(boolean metricUnits) {
String[] values = getResources().getStringArray(R.array.min_recording_distance_values);
String[] options = new String[values.length];
for (int i = 0; i < values.length; i++) {
int value = Integer.parseInt(values[i]);
if (metricUnits) {
options[i] = getString(value == PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT
? R.string.value_integer_meter_recommended
: R.string.value_integer_meter, value);
} else {
int feet = (int) (value * UnitConversions.M_TO_FT);
options[i] = getString(value == PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT
? R.string.value_integer_feet_recommended
: R.string.value_integer_feet, feet);
}
}
return options;
}
/**
* Gets the max recording distance display options.
*
* @param metricUnits true to display metric units
*/
private String[] getMaxRecordingDistanceDisplayOptions(boolean metricUnits) {
String[] values = getResources().getStringArray(R.array.max_recording_distance_values);
String[] options = new String[values.length];
for (int i = 0; i < values.length; i++) {
int value = Integer.parseInt(values[i]);
if (metricUnits) {
options[i] = getString(value == PreferencesUtils.MAX_RECORDING_DISTANCE_DEFAULT
? R.string.value_integer_meter_recommended
: R.string.value_integer_meter, value);
} else {
int feet = (int) (value * UnitConversions.M_TO_FT);
if (feet < 2000) {
options[i] = getString(value == PreferencesUtils.MAX_RECORDING_DISTANCE_DEFAULT
? R.string.value_integer_feet_recommended
: R.string.value_integer_feet, feet);
} else {
double mile = feet * UnitConversions.FT_TO_MI;
options[i] = getString(R.string.value_float_mile, mile);
}
}
}
return options;
}
/**
* Gets the min required accuracy display options.
*
* @param metricUnits true to display metric units
*/
private String[] getMinRequiredAccuracyDisplayOptions(boolean metricUnits) {
String[] values = getResources().getStringArray(R.array.min_required_accuracy_values);
String[] options = new String[values.length];
for (int i = 0; i < values.length; i++) {
int value = Integer.parseInt(values[i]);
if (metricUnits) {
switch (value) {
case PreferencesUtils.MIN_REQUIRED_ACCURACY_DEFAULT:
options[i] = getString(R.string.value_integer_meter_recommended, value);
break;
case PreferencesUtils.MIN_REQUIRED_ACCURACY_EXCELLENT:
options[i] = getString(R.string.value_integer_meter_excellent_gps, value);
break;
case PreferencesUtils.MIN_REQUIRED_ACCURACY_POOR:
options[i] = getString(R.string.value_integer_meter_poor_gps, value);
break;
default:
options[i] = getString(R.string.value_integer_meter, value);
}
} else {
int feet = (int) (value * UnitConversions.M_TO_FT);
if (feet < 2000) {
switch (value) {
case PreferencesUtils.MIN_REQUIRED_ACCURACY_DEFAULT:
options[i] = getString(R.string.value_integer_feet_recommended, feet);
break;
case PreferencesUtils.MIN_REQUIRED_ACCURACY_EXCELLENT:
options[i] = getString(R.string.value_integer_feet_excellent_gps, feet);
break;
default:
options[i] = getString(R.string.value_integer_feet, feet);
}
} else {
double mile = feet * UnitConversions.FT_TO_MI;
options[i] = getString(value == PreferencesUtils.MIN_REQUIRED_ACCURACY_POOR
? R.string.value_float_mile_poor_gps
: R.string.value_float_mile, mile);
}
}
}
return options;
}
/**
* Gets the auto resume track timeout display options.
*/
private String[] getAutoResumeTrackTimeoutDisplayOptions() {
String[] values = getResources().getStringArray(R.array.auto_resume_track_timeout_values);
String[] options = new String[values.length];
for (int i = 0; i < values.length; i++) {
int value = Integer.parseInt(values[i]);
switch (value) {
case PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_NEVER:
options[i] = getString(R.string.value_never);
break;
case PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_ALWAYS:
options[i] = getString(R.string.value_always);
break;
default:
options[i] = getString(R.string.value_integer_minute, value);
}
}
return options;
}
}
@@ -36,7 +36,6 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
@@ -63,69 +62,25 @@ public class SettingsActivity extends AbstractSettingsActivity {
private static final int DIALOG_CONFIRM_RESET_ID = 0;
// Value when the task frequency is off.
private static final String TASK_FREQUENCY_OFF = "0";
// Value when the recording interval is 'Adapt battery life'.
private static final String RECORDING_INTERVAL_ADAPT_BATTERY_LIFE = "-2";
// Value when the recording interval is 'Adapt accuracy'.
private static final String RECORDING_INTERVAL_ADAPT_ACCURACY = "-1";
// Value for the recommended recording interval.
private static final String RECORDING_INTERVAL_RECOMMENDED = "0";
// Value when the auto resume timeout is never.
private static final String AUTO_RESUME_TIMEOUT_NEVER = "0";
// Value when the auto resume timeout is always.
private static final String AUTO_RESUME_TIMEOUT_ALWAYS = "-1";
// Value for the recommended recording distance.
private static final String RECORDING_DISTANCE_RECOMMENDED = "5";
// Value for the recommended track distance.
private static final String TRACK_DISTANCE_RECOMMENDED = "200";
// Value for the recommended GPS accuracy.
private static final String GPS_ACCURACY_RECOMMENDED = "200";
// Value when the GPS accuracy is for excellent GPS signal.
private static final String GPS_ACCURACY_EXCELLENT = "10";
// Value when the GPS accuracy is for poor GPS signal.
private static final String GPS_ACCURACY_POOR = "5000";
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Load the preferences to be displayed
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
addPreferencesFromResource(R.xml.preferences);
setRecordingIntervalOptions();
setAutoResumeTimeoutOptions();
// Hook up switching of displayed list entries between metric and imperial
// units
CheckBoxPreference metricUnitsPreference =
(CheckBoxPreference) findPreference(PreferencesUtils.getKey(this, R.string.metric_units_key));
metricUnitsPreference.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
boolean isMetric = (Boolean) newValue;
updateDisplayOptions(isMetric);
return true;
}
});
updateDisplayOptions(metricUnitsPreference.isChecked());
customizeSensorOptionsPreferences();
customizeTrackColorModePreferences();
Preference recordingPreference = findPreference(getString(R.string.settings_recording_key));
recordingPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = IntentUtils.newIntent(
SettingsActivity.this, RecordingSettingsActivity.class);
startActivity(intent);
return true;
}
});
Preference sharingPreference = findPreference(getString(R.string.settings_sharing_key));
sharingPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
@@ -173,58 +128,6 @@ public class SettingsActivity extends AbstractSettingsActivity {
}
}
/**
* Sets the display options for the 'Time between points' option.
*/
private void setRecordingIntervalOptions() {
String[] values = getResources().getStringArray(R.array.recording_interval_values);
String[] options = new String[values.length];
for (int i = 0; i < values.length; i++) {
if (values[i].equals(RECORDING_INTERVAL_ADAPT_BATTERY_LIFE)) {
options[i] = getString(R.string.value_adapt_battery_life);
} else if (values[i].equals(RECORDING_INTERVAL_ADAPT_ACCURACY)) {
options[i] = getString(R.string.value_adapt_accuracy);
} else if (values[i].equals(RECORDING_INTERVAL_RECOMMENDED)) {
options[i] = getString(R.string.value_smallest_recommended);
} else {
int value = Integer.parseInt(values[i]);
String format;
if (value < 60) {
format = getString(R.string.value_integer_second);
} else {
value = value / 60;
format = getString(R.string.value_integer_minute);
}
options[i] = String.format(format, value);
}
}
ListPreference list = (ListPreference) findPreference(
getString(R.string.min_recording_interval_key));
list.setEntries(options);
}
/**
* Sets the display options for the 'Auto-resume timeout' option.
*/
private void setAutoResumeTimeoutOptions() {
String[] values = getResources().getStringArray(R.array.recording_auto_resume_timeout_values);
String[] options = new String[values.length];
for (int i = 0; i < values.length; i++) {
if (values[i].equals(AUTO_RESUME_TIMEOUT_NEVER)) {
options[i] = getString(R.string.value_never);
} else if (values[i].equals(AUTO_RESUME_TIMEOUT_ALWAYS)) {
options[i] = getString(R.string.value_always);
} else {
int value = Integer.parseInt(values[i]);
String format = getString(R.string.value_integer_minute);
options[i] = String.format(format, value);
}
}
ListPreference list = (ListPreference) findPreference(
getString(R.string.auto_resume_track_timeout_key));
list.setEntries(options);
}
private void customizeSensorOptionsPreferences() {
ListPreference sensorTypePreference =
(ListPreference) findPreference(getString(R.string.sensor_type_key));
@@ -343,150 +246,6 @@ public class SettingsActivity extends AbstractSettingsActivity {
findPreference(getString(R.string.track_color_mode_dynamic_speed_variation_key))
.setEnabled(usesDynamicSpeed);
}
/**
* Updates display options that depends on the preferred distance units, metric or imperial.
*
* @param isMetric true to use metric units, false to use imperial
*/
private void updateDisplayOptions(boolean isMetric) {
setTaskOptions(isMetric, R.string.announcement_frequency_key);
setTaskOptions(isMetric, R.string.split_frequency_key);
setRecordingDistanceOptions(isMetric, R.string.min_recording_distance_key);
setTrackDistanceOptions(isMetric, R.string.max_recording_distance_key);
setGpsAccuracyOptions(isMetric, R.string.min_required_accuracy_key);
}
/**
* Sets the display options for a periodic task.
*/
private void setTaskOptions(boolean isMetric, int listId) {
String[] values = getResources().getStringArray(R.array.recording_task_frequency_values);
String[] options = new String[values.length];
for (int i = 0; i < values.length; i++) {
if (values[i].equals(TASK_FREQUENCY_OFF)) {
options[i] = getString(R.string.value_off);
} else if (values[i].startsWith("-")) {
int value = Integer.parseInt(values[i].substring(1));
int stringId = isMetric ? R.string.value_integer_kilometer : R.string.value_integer_mile;
String format = getString(stringId);
options[i] = String.format(format, value);
} else {
int value = Integer.parseInt(values[i]);
String format = getString(R.string.value_integer_minute);
options[i] = String.format(format, value);
}
}
ListPreference list = (ListPreference) findPreference(getString(listId));
list.setEntries(options);
}
/**
* Sets the display options for 'Distance between points' option.
*/
private void setRecordingDistanceOptions(boolean isMetric, int listId) {
String[] values = getResources().getStringArray(R.array.recording_distance_values);
String[] options = new String[values.length];
for (int i = 0; i < values.length; i++) {
int value = Integer.parseInt(values[i]);
if (!isMetric) {
value = (int) (value * UnitConversions.M_TO_FT);
}
String format;
if (values[i].equals(RECORDING_DISTANCE_RECOMMENDED)) {
int stringId = isMetric ? R.string.value_integer_meter_recommended
: R.string.value_integer_feet_recommended;
format = getString(stringId);
} else {
int stringId = isMetric ? R.string.value_integer_meter : R.string.value_integer_feet;
format = getString(stringId);
}
options[i] = String.format(format, value);
}
ListPreference list = (ListPreference) findPreference(getString(listId));
list.setEntries(options);
}
/**
* Sets the display options for 'Distance between Tracks'.
*/
private void setTrackDistanceOptions(boolean isMetric, int listId) {
String[] values = getResources().getStringArray(R.array.recording_track_distance_values);
String[] options = new String[values.length];
for (int i = 0; i < values.length; i++) {
int value = Integer.parseInt(values[i]);
String format;
if (isMetric) {
int stringId = values[i].equals(TRACK_DISTANCE_RECOMMENDED)
? R.string.value_integer_meter_recommended : R.string.value_integer_meter;
format = getString(stringId);
options[i] = String.format(format, value);
} else {
value = (int) (value * UnitConversions.M_TO_FT);
if (value < 2000) {
int stringId = values[i].equals(TRACK_DISTANCE_RECOMMENDED)
? R.string.value_integer_feet_recommended : R.string.value_integer_feet;
format = getString(stringId);
options[i] = String.format(format, value);
} else {
double mile = value * UnitConversions.FT_TO_MI;
format = getString(R.string.value_float_mile);
options[i] = String.format(format, mile);
}
}
}
ListPreference list = (ListPreference) findPreference(getString(listId));
list.setEntries(options);
}
/**
* Sets the display options for 'GPS accuracy'.
*/
private void setGpsAccuracyOptions(boolean isMetric, int listId) {
String[] values = getResources().getStringArray(R.array.recording_gps_accuracy_values);
String[] options = new String[values.length];
for (int i = 0; i < values.length; i++) {
int value = Integer.parseInt(values[i]);
String format;
if (isMetric) {
if (values[i].equals(GPS_ACCURACY_RECOMMENDED)) {
format = getString(R.string.value_integer_meter_recommended);
} else if (values[i].equals(GPS_ACCURACY_EXCELLENT)) {
format = getString(R.string.value_integer_meter_excellent_gps);
} else if (values[i].equals(GPS_ACCURACY_POOR)) {
format = getString(R.string.value_integer_meter_poor_gps);
} else {
format = getString(R.string.value_integer_meter);
}
options[i] = String.format(format, value);
} else {
value = (int) (value * UnitConversions.M_TO_FT);
if (value < 2000) {
if (values[i].equals(GPS_ACCURACY_RECOMMENDED)) {
format = getString(R.string.value_integer_feet_recommended);
} else if (values[i].equals(GPS_ACCURACY_EXCELLENT)) {
format = getString(R.string.value_integer_feet_excellent_gps);
} else {
format = getString(R.string.value_integer_feet);
}
options[i] = String.format(format, value);
} else {
double mile = value * UnitConversions.FT_TO_MI;
if (values[i].equals(GPS_ACCURACY_POOR)) {
format = getString(R.string.value_float_mile_poor_gps);
} else {
format = getString(R.string.value_float_mile);
}
options[i] = String.format(format, mile);
}
}
}
ListPreference list = (ListPreference) findPreference(getString(listId));
list.setEntries(options);
}
/**
* Configures preference actions related to bluetooth.
@@ -19,6 +19,7 @@ package com.google.android.apps.mytracks.stats;
import static com.google.android.apps.mytracks.Constants.TAG;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import android.location.Location;
import android.util.Log;
@@ -91,8 +92,7 @@ public class TripStatisticsBuilder {
*/
private long totalLocations = 0;
private int minRecordingDistance =
Constants.DEFAULT_MIN_RECORDING_DISTANCE;
private int minRecordingDistance = PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT;
/**
* Creates a new trip starting at the given time.
@@ -30,13 +30,36 @@ import android.content.SharedPreferences.Editor;
public class PreferencesUtils {
/*
* Preferences defaults, need to match the android:defaultValue in the xml
* Preferences values. The defaults need to match the defaults in the xml
* files.
*/
public static final boolean ALLOW_ACCESS_DEFAULT = false;
public static final int ANNOUNCEMENT_FREQUENCY_DEFAULT = 0;
public static final int AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT = 0;
public static final int AUTO_RESUME_TRACK_TIMEOUT_ALWAYS = -1;
public static final int AUTO_RESUME_TRACK_TIMEOUT_DEFAULT = 10;
public static final int AUTO_RESUME_TRACK_TIMEOUT_NEVER = 0;
public static final String DEFAULT_ACTIVITY_DEFAULT = "";
public static final boolean DEFAULT_MAP_PUBLIC_DEFAULT = true;
public static final int MAX_RECORDING_DISTANCE_DEFAULT = 200;
public static final boolean METRIC_UNITS_DEFAULT = true;
public static final int MIN_RECORDING_DISTANCE_DEFAULT = 5;
public static final int MIN_RECORDING_INTERVAL_ADAPT_ACCURACY = -1;
public static final int MIN_RECORDING_INTERVAL_ADAPT_BATTERY_LIFE = -2;
public static final int MIN_RECORDING_INTERVAL_DEFAULT = 0;
public static final int MIN_REQUIRED_ACCURACY_DEFAULT = 200;
public static final int MIN_REQUIRED_ACCURACY_EXCELLENT = 10;
public static final int MIN_REQUIRED_ACCURACY_POOR = 5000;
public static final int PERIODIC_TASK_OFF = 0;
public static final long RECORDING_TRACK_ID_DEFAULT = -1L;
public static final boolean SHARE_URL_ONLY_DEFAULT = false;
public static final int SPLIT_FREQUENCY_DEFAULT = 0;
private PreferencesUtils() {}
@@ -78,6 +101,34 @@ public class PreferencesUtils {
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
}
/**
* Gets an integer preference value.
*
* @param context the context
* @param keyId the key id
* @param defaultValue the default value
*/
public static int getInt(Context context, int keyId, int defaultValue) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getInt(getKey(context, keyId), defaultValue);
}
/**
* Sets an integer preference value.
*
* @param context the context
* @param keyId the key id
* @param value the value
*/
public static void setInt(Context context, int keyId, int value) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
Editor editor = sharedPreferences.edit();
editor.putInt(getKey(context, keyId), value);
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
}
/**
* Gets a long preference value.
*
@@ -104,4 +155,17 @@ public class PreferencesUtils {
editor.putLong(getKey(context, keyId), value);
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
}
/**
* Gets a string preference value.
*
* @param context the context
* @param keyId the key id
* @param defaultValue default value
*/
public static String getString(Context context, int keyId, String defaultValue) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getString(getKey(context, keyId), defaultValue);
}
}
@@ -165,7 +165,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
sharedPreferences.edit().clear().apply();
// Disable auto resume by default.
updateAutoResumePrefs(0, -1);
updateAutoResumePrefs(PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT, 0);
// No recording track.
PreferencesUtils.setLong(context, R.string.recording_track_id_key, -1L);
}
@@ -188,7 +188,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
createDummyTrack(123L, System.currentTimeMillis(), true);
// Clear the number of attempts and set the timeout to 10 min.
updateAutoResumePrefs(0, 10);
updateAutoResumePrefs(PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT,
PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT);
// Start the service in "resume" mode (simulates the on-reboot action).
Intent startIntent = createStartIntent();
@@ -210,7 +211,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
// TODO: If fixed, remove "disabled" prefix from the test name.
@MediumTest
public void disabledTestResumeAfterReboot_simulateReboot() throws Exception {
updateAutoResumePrefs(0, 10);
updateAutoResumePrefs(PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT,
PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT);
ITrackRecordingService service = bindAndGetService(createStartIntent());
assertFalse(service.isRecording());
@@ -236,7 +238,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
createDummyTrack(123L, System.currentTimeMillis(), false);
// Clear the number of attempts and set the timeout to 10 min.
updateAutoResumePrefs(0, 10);
updateAutoResumePrefs(PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT,
PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT);
// Start the service in "resume" mode (simulates the on-reboot action).
Intent startIntent = createStartIntent();
@@ -256,7 +259,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
createDummyTrack(123L, System.currentTimeMillis() - 20 * 60 * 1000, true);
// Clear the number of attempts and set the timeout to 10 min.
updateAutoResumePrefs(0, 10);
updateAutoResumePrefs(PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT,
PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT);
// Start the service in "resume" mode (simulates the on-reboot action).
Intent startIntent = createStartIntent();
@@ -276,8 +280,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
createDummyTrack(123L, System.currentTimeMillis(), true);
// Set the number of attempts to max.
updateAutoResumePrefs(
TrackRecordingService.MAX_AUTO_RESUME_TRACK_RETRY_ATTEMPTS, 10);
updateAutoResumePrefs(TrackRecordingService.MAX_AUTO_RESUME_TRACK_RETRY_ATTEMPTS,
PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT);
// Start the service in "resume" mode (simulates the on-reboot action).
Intent startIntent = createStartIntent();
@@ -387,7 +391,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
Track track = providerUtils.getTrack(id);
assertNotNull(track);
assertEquals(id, track.getId());
assertEquals(sharedPreferences.getString(context.getString(R.string.default_activity_key), ""),
assertEquals(PreferencesUtils.getString(
context, R.string.default_activity_key, PreferencesUtils.DEFAULT_ACTIVITY_DEFAULT),
track.getCategory());
assertEquals(id, PreferencesUtils.getLong(context, R.string.recording_track_id_key));
assertEquals(id, service.getRecordingTrackId());
@@ -537,48 +542,67 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
}
@MediumTest
public void testWithProperties_noAnnouncementFreq() throws Exception {
functionalTest(R.string.announcement_frequency_key, (Object) null);
public void testWithProperties_announcementFrequencyDefault() throws Exception {
PreferencesUtils.setInt(context, R.string.announcement_frequency_key,
PreferencesUtils.ANNOUNCEMENT_FREQUENCY_DEFAULT);
fullRecordingSession();
}
@MediumTest
public void testWithProperties_defaultAnnouncementFreq() throws Exception {
functionalTest(R.string.announcement_frequency_key, 1);
public void testWithProperties_announcementFrequencyByDistance() throws Exception {
PreferencesUtils.setInt(context, R.string.announcement_frequency_key, -1);
fullRecordingSession();
}
@MediumTest
public void testWithProperties_noMaxRecordingDist() throws Exception {
functionalTest(R.string.max_recording_distance_key, (Object) null);
public void testWithProperties_announcementFrequencyByTime() throws Exception {
PreferencesUtils.setInt(context, R.string.announcement_frequency_key, 1);
fullRecordingSession();
}
@MediumTest
public void testWithProperties_maxRecordingDistanceDefault() throws Exception {
PreferencesUtils.setInt(context, R.string.max_recording_distance_key,
PreferencesUtils.MAX_RECORDING_DISTANCE_DEFAULT);
fullRecordingSession();
}
@MediumTest
public void testWithProperties_defaultMaxRecordingDist() throws Exception {
functionalTest(R.string.max_recording_distance_key, 5);
public void testWithProperties_maxRecordingDistance() throws Exception {
PreferencesUtils.setInt(context, R.string.max_recording_distance_key, 50);
fullRecordingSession();
}
@MediumTest
public void testWithProperties_noMinRecordingDist() throws Exception {
functionalTest(R.string.min_recording_distance_key, (Object) null);
public void testWithProperties_minRecordingDistanceDefault() throws Exception {
PreferencesUtils.setInt(context, R.string.min_recording_distance_key,
PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT);
fullRecordingSession();
}
@MediumTest
public void testWithProperties_defaultMinRecordingDist() throws Exception {
functionalTest(R.string.min_recording_distance_key, 2);
public void testWithProperties_minRecordingDistance() throws Exception {
PreferencesUtils.setInt(context, R.string.min_recording_distance_key, 2);
fullRecordingSession();
}
@MediumTest
public void testWithProperties_noSplitFreq() throws Exception {
functionalTest(R.string.split_frequency_key, (Object) null);
public void testWithProperties_splitFrequencyDefault() throws Exception {
PreferencesUtils.setInt(context, R.string.split_frequency_key,
PreferencesUtils.SPLIT_FREQUENCY_DEFAULT);
fullRecordingSession();
}
@MediumTest
public void testWithProperties_defaultSplitFreqByDist() throws Exception {
functionalTest(R.string.split_frequency_key, 5);
public void testWithProperties_splitFrequencyByDistance() throws Exception {
PreferencesUtils.setInt(context, R.string.split_frequency_key, -1);
fullRecordingSession();
}
@MediumTest
public void testWithProperties_defaultSplitFreqByTime() throws Exception {
functionalTest(R.string.split_frequency_key, -2);
public void testWithProperties_splitFrequencyByTime() throws Exception {
PreferencesUtils.setInt(context, R.string.split_frequency_key, 1);
fullRecordingSession();
}
@MediumTest
@@ -597,24 +621,29 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
}
@MediumTest
public void testWithProperties_noMinRecordingInterval() throws Exception {
functionalTest(R.string.min_recording_interval_key, (Object) null);
public void testWithProperties_minRecordingIntervalDefault() throws Exception {
PreferencesUtils.setInt(context, R.string.min_recording_interval_key,
PreferencesUtils.MIN_RECORDING_INTERVAL_DEFAULT);
fullRecordingSession();
}
@MediumTest
public void testWithProperties_defaultMinRecordingInterval()
throws Exception {
functionalTest(R.string.min_recording_interval_key, 3);
public void testWithProperties_minRecordingInterval() throws Exception {
PreferencesUtils.setInt(context, R.string.min_recording_interval_key, 2);
fullRecordingSession();
}
@MediumTest
public void testWithProperties_noMinRequiredAccuracy() throws Exception {
functionalTest(R.string.min_required_accuracy_key, (Object) null);
public void testWithProperties_minRequiredAccuracyDefault() throws Exception {
PreferencesUtils.setInt(context, R.string.min_required_accuracy_key,
PreferencesUtils.MIN_REQUIRED_ACCURACY_DEFAULT);
fullRecordingSession();
}
@MediumTest
public void testWithProperties_defaultMinRequiredAccuracy() throws Exception {
functionalTest(R.string.min_required_accuracy_key, 500);
public void testWithProperties_minRequiredAccuracy() throws Exception {
PreferencesUtils.setInt(context, R.string.min_required_accuracy_key, 500);
fullRecordingSession();
}
@MediumTest
@@ -647,12 +676,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
}
private void updateAutoResumePrefs(int attempts, int timeoutMins) {
Editor editor = sharedPreferences.edit();
editor.putInt(context.getString(
R.string.auto_resume_track_current_retry_key), attempts);
editor.putInt(context.getString(
R.string.auto_resume_track_timeout_key), timeoutMins);
editor.apply();
PreferencesUtils.setInt(context, R.string.auto_resume_track_current_retry_key, attempts);
PreferencesUtils.setInt(context, R.string.auto_resume_track_timeout_key, timeoutMins);
}
private Intent createStartIntent() {