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:
Matthew Simmons
2010-11-01 13:48:33 -04:00
parent 261fb62e24
commit b7385cd4cc
6 changed files with 147 additions and 12 deletions
@@ -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);
recordingTrackId = Long.parseLong(trackUri.getLastPathSegment());
track.setId(recordingTrackId);
track.setName(getNewTrackName(this, recordingTrackId, startTime));
track.setName(new DefaultTrackNameFactory(this).newTrackName(
recordingTrackId, startTime));
providerUtils.updateTrack(track);
currentWaypointId = insertStatisticsMarker(null);
@@ -982,14 +983,6 @@ public class TrackRecordingService extends Service implements LocationListener {
setAutoResumeTrackRetries(sharedPreferences, 0);
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() {
return statsBuilder.getStatistics();