forked from upstream-mirrors/OpenTracks
Combine b2f2f9e9e9 and 8774b3663c
Allow users to choose the default track name policy. By default, we'll switch to a new, timestamp-based name. If they change the pref, they'll get the old-style 'track n' style.
This commit is contained in:
@@ -38,6 +38,7 @@ limitations under the License.
|
|||||||
<string name="share_url_only_key">shareUrlOnly</string>
|
<string name="share_url_only_key">shareUrlOnly</string>
|
||||||
<string name="signal_sampling_frequency_key">signalSamplingFrequency</string>
|
<string name="signal_sampling_frequency_key">signalSamplingFrequency</string>
|
||||||
<string name="split_frequency_key">splitFrequency</string>
|
<string name="split_frequency_key">splitFrequency</string>
|
||||||
|
<string name="timestamp_track_name_key">timestampTrackName</string>
|
||||||
|
|
||||||
<!-- Preference keys which keep transient state (not user preferences) - DO NOT TRANSLATE -->
|
<!-- Preference keys which keep transient state (not user preferences) - DO NOT TRANSLATE -->
|
||||||
<string name="auto_resume_track_current_retry_key">autoResumeTrackCurrentRetry</string>
|
<string name="auto_resume_track_current_retry_key">autoResumeTrackCurrentRetry</string>
|
||||||
@@ -47,4 +48,4 @@ limitations under the License.
|
|||||||
<!-- Keys for non-persisted preferences - DO NOT TRANSLATE -->
|
<!-- Keys for non-persisted preferences - DO NOT TRANSLATE -->
|
||||||
<string name="backup_to_sd_key">backupToSd</string>
|
<string name="backup_to_sd_key">backupToSd</string>
|
||||||
<string name="restore_from_sd_key">restoreFromSd</string>
|
<string name="restore_from_sd_key">restoreFromSd</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -210,6 +210,10 @@ limitations under the License.
|
|||||||
<string name="settings_auto_resume_track_timeout">Auto-resume track timeout</string>
|
<string name="settings_auto_resume_track_timeout">Auto-resume track timeout</string>
|
||||||
<string name="settings_auto_resume_track_timeout_summary">Maximum time in minutes after which a previously recording track will not be resumed on phone reboot</string>
|
<string name="settings_auto_resume_track_timeout_summary">Maximum time in minutes after which a previously recording track will not be resumed on phone reboot</string>
|
||||||
|
|
||||||
|
<string name="settings_timestamp_track_name">Timestamp as track name</string>
|
||||||
|
<string name="settings_timestamp_track_name_on">The default track name will be the date and time at the start of the track</string>
|
||||||
|
<string name="settings_timestamp_track_name_off">Track names will have numbers which increment for each new track.</string>
|
||||||
|
|
||||||
<string name="pace_label">Pace</string>
|
<string name="pace_label">Pace</string>
|
||||||
|
|
||||||
<string name="eclair_required">Only supported in Android 2.0 or above</string>
|
<string name="eclair_required">Only supported in Android 2.0 or above</string>
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ limitations under the License.
|
|||||||
android:entries="@array/task_frequency_options"
|
android:entries="@array/task_frequency_options"
|
||||||
android:entryValues="@array/task_frequency_values"
|
android:entryValues="@array/task_frequency_values"
|
||||||
android:defaultValue="-1" />
|
android:defaultValue="-1" />
|
||||||
|
|
||||||
<com.google.android.apps.mytracks.IntegerListPreference
|
<com.google.android.apps.mytracks.IntegerListPreference
|
||||||
android:key="@string/auto_resume_track_timeout_key"
|
android:key="@string/auto_resume_track_timeout_key"
|
||||||
android:title="@string/settings_auto_resume_track_timeout"
|
android:title="@string/settings_auto_resume_track_timeout"
|
||||||
@@ -99,6 +99,14 @@ limitations under the License.
|
|||||||
android:entries="@array/auto_resume_track_timeout_options"
|
android:entries="@array/auto_resume_track_timeout_options"
|
||||||
android:entryValues="@array/auto_resume_track_timeout_values"
|
android:entryValues="@array/auto_resume_track_timeout_values"
|
||||||
android:defaultValue="10" />
|
android:defaultValue="10" />
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="@string/timestamp_track_name_key"
|
||||||
|
android:title="@string/settings_timestamp_track_name"
|
||||||
|
android:summaryOn="@string/settings_timestamp_track_name_on"
|
||||||
|
android:summaryOff="@string/settings_timestamp_track_name_off"
|
||||||
|
android:defaultValue="true" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
||||||
<!-- Sharing settings -->
|
<!-- Sharing settings -->
|
||||||
@@ -126,7 +134,7 @@ limitations under the License.
|
|||||||
android:title="@string/settings_backup_to_sd"
|
android:title="@string/settings_backup_to_sd"
|
||||||
android:summary="@string/settings_backup_to_sd_summary"
|
android:summary="@string/settings_backup_to_sd_summary"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
<Preference
|
<Preference
|
||||||
android:key="@string/restore_from_sd_key"
|
android:key="@string/restore_from_sd_key"
|
||||||
android:title="@string/settings_restore_from_sd"
|
android:title="@string/settings_restore_from_sd"
|
||||||
android:summary="@string/settings_restore_from_sd_summary"
|
android:summary="@string/settings_restore_from_sd_summary"
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010 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.services;
|
||||||
|
|
||||||
|
import com.google.android.apps.mytracks.MyTracksSettings;
|
||||||
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.text.format.Time;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a default track name based on the current default track name policy.
|
||||||
|
*
|
||||||
|
* @author simmonmt@google.com (Matthew Simmons)
|
||||||
|
*/
|
||||||
|
class DefaultTrackNameFactory {
|
||||||
|
private static final String TIMESTAMP_DATE_FORMAT = "yyyy-MM-dd HH:mm";
|
||||||
|
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
|
DefaultTrackNameFactory(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new track name.
|
||||||
|
*
|
||||||
|
* @param trackId The ID for the current track.
|
||||||
|
* @param startTime The start time, in milliseconds since the epoch, of the
|
||||||
|
* current track.
|
||||||
|
* @return The new track name.
|
||||||
|
*/
|
||||||
|
String newTrackName(long trackId, long startTime) {
|
||||||
|
if (useTimestampTrackName()) {
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat(TIMESTAMP_DATE_FORMAT);
|
||||||
|
return formatter.format(new Date(startTime));
|
||||||
|
} else {
|
||||||
|
return String.format(context.getString(R.string.new_track), trackId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Determines whether the preferences allow a timestamp-based track name */
|
||||||
|
protected boolean useTimestampTrackName() {
|
||||||
|
SharedPreferences prefs =
|
||||||
|
context.getSharedPreferences(MyTracksSettings.SETTINGS_NAME, 0);
|
||||||
|
|
||||||
|
boolean useTimestamp = false;
|
||||||
|
if (prefs != null) {
|
||||||
|
useTimestamp = prefs.getBoolean(
|
||||||
|
context.getString(R.string.timestamp_track_name_key), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return useTimestamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -962,7 +962,8 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
Uri trackUri = providerUtils.insertTrack(track);
|
Uri trackUri = providerUtils.insertTrack(track);
|
||||||
recordingTrackId = Long.parseLong(trackUri.getLastPathSegment());
|
recordingTrackId = Long.parseLong(trackUri.getLastPathSegment());
|
||||||
track.setId(recordingTrackId);
|
track.setId(recordingTrackId);
|
||||||
track.setName(getNewTrackName(this, recordingTrackId, startTime));
|
track.setName(new DefaultTrackNameFactory(this).newTrackName(
|
||||||
|
recordingTrackId, startTime));
|
||||||
providerUtils.updateTrack(track);
|
providerUtils.updateTrack(track);
|
||||||
|
|
||||||
currentWaypointId = insertStatisticsMarker(null);
|
currentWaypointId = insertStatisticsMarker(null);
|
||||||
@@ -982,14 +983,6 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
setAutoResumeTrackRetries(sharedPreferences, 0);
|
setAutoResumeTrackRetries(sharedPreferences, 0);
|
||||||
return recordingTrackId;
|
return recordingTrackId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getNewTrackName(Context context, long trackId,
|
|
||||||
long startTime) {
|
|
||||||
Date startDate = new Date(startTime);
|
|
||||||
return String.format("%s %s",
|
|
||||||
DateFormat.getDateFormat(context).format(startDate),
|
|
||||||
DateFormat.getTimeFormat(context).format(startDate));
|
|
||||||
}
|
|
||||||
|
|
||||||
TripStatistics getTripStatistics() {
|
TripStatistics getTripStatistics() {
|
||||||
return statsBuilder.getStatistics();
|
return statsBuilder.getStatistics();
|
||||||
|
|||||||
+57
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010 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.services;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.test.AndroidTestCase;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class DefaultTrackNameFactoryTest extends AndroidTestCase {
|
||||||
|
private static class MockDefaultTrackNameFactory
|
||||||
|
extends DefaultTrackNameFactory {
|
||||||
|
private final boolean useTimestamp;
|
||||||
|
|
||||||
|
MockDefaultTrackNameFactory(Context context, boolean useTimestamp) {
|
||||||
|
super(context);
|
||||||
|
this.useTimestamp = useTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean useTimestampTrackName() {
|
||||||
|
return useTimestamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final long TIMESTAMP = 1288213406000L;
|
||||||
|
|
||||||
|
public void testTimestampTrackName() {
|
||||||
|
DefaultTrackNameFactory factory =
|
||||||
|
new MockDefaultTrackNameFactory(getContext(), true);
|
||||||
|
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||||
|
assertEquals(formatter.format(new Date(TIMESTAMP)),
|
||||||
|
factory.newTrackName(1, TIMESTAMP));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIncrementingTrackName() {
|
||||||
|
DefaultTrackNameFactory factory =
|
||||||
|
new MockDefaultTrackNameFactory(getContext(), false);
|
||||||
|
|
||||||
|
assertEquals("Track 1", factory.newTrackName(1, TIMESTAMP));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user