diff --git a/MyTracks/AndroidManifest.xml b/MyTracks/AndroidManifest.xml index 884e9e089..2b14aad27 100755 --- a/MyTracks/AndroidManifest.xml +++ b/MyTracks/AndroidManifest.xml @@ -77,7 +77,7 @@ - + diff --git a/MyTracks/res/values/keys.xml b/MyTracks/res/values/keys.xml index 3a02249ea..6288aa969 100644 --- a/MyTracks/res/values/keys.xml +++ b/MyTracks/res/values/keys.xml @@ -17,6 +17,7 @@ limitations under the License. announcementFrequency + autoResumeTrackTimeout bluetoothDevice bluetoothPairing bluetoothSensor @@ -37,7 +38,6 @@ limitations under the License. shareUrlOnly signalSamplingFrequency splitFrequency - autoResumeTrackTimeout recordingTrack diff --git a/MyTracks/src/com/google/android/apps/mymaps/VersionChecker.java b/MyTracks/src/com/google/android/apps/mymaps/VersionChecker.java deleted file mode 100644 index cfc1f8a3d..000000000 --- a/MyTracks/src/com/google/android/apps/mymaps/VersionChecker.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright 2009 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.mymaps; - -import com.google.android.apps.mymaps.MyMapsGDataWrapper.QueryFunction; -import com.google.android.apps.mytracks.MyTracksConstants; -import com.google.android.maps.mytracks.R; -import com.google.wireless.gdata.GDataException; -import com.google.wireless.gdata.client.HttpException; -import com.google.wireless.gdata.data.Entry; -import com.google.wireless.gdata.maps.MapsClient; -import com.google.wireless.gdata.parser.GDataParser; - -import android.app.AlertDialog; -import android.app.Dialog; -import android.app.TabActivity; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.content.pm.PackageManager.NameNotFoundException; -import android.content.Intent; -import android.net.Uri; -import android.util.Log; - -import java.io.IOException; - -public class VersionChecker { - /** The User id for the account storing MyTracks versions. */ - private static final String VERSION_USER_ID = "116927647071651051525"; - private static final String VERSION_CLIENT = "AndroidMyTracks"; - - private static final String VERSION_STATUS_LATEST = "latest"; - private static final String VERSION_STATUS_OKAY = "okay"; - private static final String VERSION_STATUS_OLD = "old"; - private static final String VERSION_STATUS_BAD = "bad"; - - private final TabActivity parentActivity; - private Dialog dialog; - private boolean canceledAvailable; - private boolean canceledRecommended; - - public VersionChecker(TabActivity parent) { - parentActivity = parent; - canceledAvailable = false; - canceledRecommended = false; - - startMapsQueryThread(); - } - - private void startMapsQueryThread() { - new Thread() { - @Override - public void run() { - MyMapsGDataWrapper mapsGDataWrapper = - new MyMapsGDataWrapper(parentActivity); - mapsGDataWrapper.runQuery(new QueryFunction() { - @Override - public void query(MapsClient client) throws IOException, Exception { - doMapsQuery(client); - } - }); - mapsGDataWrapper.cleanUp(); - } - }.start(); - } - - private void doMapsQuery(MapsClient client) - throws GDataException, IOException, HttpException { - final boolean newVersion; // Returned new version available - final boolean newVersionRecommended; // Returned new version recommended - final boolean newVersionRequired; // Returned new version required - String currentVersion = ""; - try { - PackageInfo pi = - parentActivity.getPackageManager().getPackageInfo( - "com.google.android.maps.mytracks", - PackageManager.GET_META_DATA); - currentVersion = pi.versionName; - } catch (NameNotFoundException e) { - Log.w(MyTracksConstants.TAG, "Failed to get version info.", e); - return; - } - - GDataParser parser = client.getParserForFeed( - Entry.class, - MapsClient.getVersionFeed( - VERSION_USER_ID, - VERSION_CLIENT, - currentVersion), - ""); - Entry en = parser.parseStandaloneEntry(); - if (currentVersion.equals(en.getTitle())) { - if (VERSION_STATUS_LATEST.equals(en.getContent())) { - newVersion = false; - newVersionRecommended = false; - newVersionRequired = false; - } else if (VERSION_STATUS_OKAY.equals(en.getContent())) { - newVersion = true; - newVersionRecommended = false; - newVersionRequired = false; - } else if (VERSION_STATUS_OLD.equals(en.getContent())) { - newVersion = true; - newVersionRecommended = true; - newVersionRequired = false; - } else if (VERSION_STATUS_BAD.equals(en.getContent())) { - newVersion = true; - newVersionRecommended = true; - newVersionRequired = true; - } else { - Log.e(MyTracksConstants.TAG, - "Got unknown version status: " + en.getContent()); - return; - } - } else { - Log.e(MyTracksConstants.TAG, - "Current version '" + currentVersion + "' doesn't match entry: " - + en.getTitle()); - return; - } - - if (!newVersion) { - Log.d(MyTracksConstants.TAG, "No new version available."); - return; - } - - final AlertDialog.Builder dialogBuilder = - new AlertDialog.Builder(parentActivity); - dialogBuilder.setTitle(R.string.version_check_title); - dialogBuilder.setPositiveButton(R.string.version_check_upgrade_button, - new OnClickListener() { - public void onClick(DialogInterface di, int number) { - Intent upgradeIntent = new Intent(); - upgradeIntent.setAction(Intent.ACTION_VIEW); - upgradeIntent.setData(Uri.parse(String.format("market://search?q=%s", - parentActivity.getResources().getString( - R.string.app_name).toString()))); - parentActivity.startActivity(upgradeIntent); - parentActivity.finish(); - } - }); - - if (newVersionRequired) { - dialogBuilder.setCancelable(false); - } else { - final boolean recommended = newVersionRecommended; - dialogBuilder.setNegativeButton(R.string.version_check_continue_button, - new OnClickListener() { - public void onClick(DialogInterface di, int number) { - dialog.dismiss(); - canceledAvailable = true; - if (recommended) { - canceledRecommended = true; - } - } - }); - } - - int messageResource; - if (newVersionRequired) { - messageResource = R.string.upgrade_required; - } else if (newVersionRecommended) { - messageResource = R.string.upgrade_recommended; - if (canceledRecommended) { - return; - } - } else { - messageResource = R.string.upgrade_available; - if (canceledAvailable) { - return; - } - } - - String message = parentActivity.getResources().getString(messageResource); - dialogBuilder.setMessage(String.format(message, - parentActivity.getResources().getString(R.string.app_name))); - parentActivity.getTabHost().post(new Runnable() { - public void run() { - dialog = dialogBuilder.create(); - dialog.show(); - } - }); - } -} diff --git a/MyTracks/src/com/google/android/apps/mytracks/MyTracksSettings.java b/MyTracks/src/com/google/android/apps/mytracks/MyTracksSettings.java index 1769df483..49161ef0e 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MyTracksSettings.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MyTracksSettings.java @@ -45,13 +45,13 @@ public class MyTracksSettings extends PreferenceActivity { /* * Default values - keep in sync with those in preferences.xml. */ + public static final int DEFAULT_AUTO_RESUME_TRACK_TIMEOUT = 10; // In min. public static final int DEFAULT_ANNOUNCEMENT_FREQUENCY = -1; 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 int DEFAULT_AUTO_RESUME_TRACK_TIMEOUT = 10; // In min. private static boolean mTTSAvailable; private BackupPreferencesListener backupListener; @@ -191,9 +191,6 @@ public class MyTracksSettings extends PreferenceActivity { final ListPreference splitFrequency = (ListPreference) findPreference( getString(R.string.split_frequency_key)); - final ListPreference autoResumeTrackTimeout = - (ListPreference) findPreference( - getString(R.string.auto_resume_track_timeout_key)); minRecordingDistance.setEntries(isMetric ? R.array.min_recording_distance_options @@ -207,7 +204,5 @@ public class MyTracksSettings extends PreferenceActivity { splitFrequency.setEntries(isMetric ? R.array.split_frequency_options : R.array.split_frequency_options_ft); - autoResumeTrackTimeout.setEntries( - R.array.auto_resume_track_timeout_options); } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/content/Track.java b/MyTracks/src/com/google/android/apps/mytracks/content/Track.java index 2b6b71abb..f881c966b 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/content/Track.java +++ b/MyTracks/src/com/google/android/apps/mytracks/content/Track.java @@ -196,13 +196,4 @@ public class Track implements Parcelable { public void setStatistics(TripStatistics stats) { this.stats = stats; } - - /** - * Returns the last time this track was modified, or -1 if not available. - * @return the last modified time, in milliseconds, since the epoch. - */ - public long getLastModified() { - // Don't use locations, just rely on stats. - return stats != null ? stats.getStopTime() : -1; - } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/PreferenceManager.java b/MyTracks/src/com/google/android/apps/mytracks/services/PreferenceManager.java index c212f2ef8..d7e300bd9 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/PreferenceManager.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/PreferenceManager.java @@ -30,6 +30,7 @@ import android.util.Log; public class PreferenceManager { private TrackRecordingService service; private final String announcementFrequencyKey; + private final String autoResumeTrackTimeoutKey; private final String maxRecordingDistanceKey; private final String metricUnitsKey; private final String minRecordingDistanceKey; @@ -38,13 +39,14 @@ public class PreferenceManager { private final String recordingTrackKey; private final String signalSamplingFrequencyKey; private final String splitFrequencyKey; - private final String autoResumeTrackTimeoutKey; public PreferenceManager(TrackRecordingService service) { this.service = service; announcementFrequencyKey = service.getString(R.string.announcement_frequency_key); + autoResumeTrackTimeoutKey = + service.getString(R.string.auto_resume_track_timeout_key); maxRecordingDistanceKey = service.getString(R.string.max_recording_distance_key); metricUnitsKey = @@ -61,8 +63,6 @@ public class PreferenceManager { service.getString(R.string.signal_sampling_frequency_key); recordingTrackKey = service.getString(R.string.recording_track_key); - autoResumeTrackTimeoutKey = - service.getString(R.string.auto_resume_track_timeout_key); } /** @@ -131,6 +131,10 @@ public class PreferenceManager { service.setAnnouncementFrequency( sharedPreferences.getInt(announcementFrequencyKey, -1)); } + if (key == null || key.equals(autoResumeTrackTimeoutKey)) { + service.setAutoResumeTrackTimeout( + sharedPreferences.getInt(autoResumeTrackTimeoutKey, -1)); + } if (key == null || key.equals(recordingTrackKey)) { service.setRecordingTrackId( sharedPreferences.getLong(recordingTrackKey, -1)); @@ -147,9 +151,5 @@ public class PreferenceManager { service.getSplitManager().setMetricUnits( sharedPreferences.getBoolean(metricUnitsKey, true)); } - if (key == null || key.equals(autoResumeTrackTimeoutKey)) { - service.setAutoResumeTrackTimeout( - sharedPreferences.getInt(autoResumeTrackTimeoutKey, -1)); - } } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java index d5abd7722..c3264cb82 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java @@ -630,6 +630,7 @@ public class TrackRecordingService extends Service implements LocationListener { @Override public void onCreate() { + super.onCreate(); Log.d(MyTracksConstants.TAG, "TrackRecordingService.onCreate"); providerUtils = MyTracksProviderUtils.Factory.get(this); notificationManager = @@ -692,6 +693,7 @@ public class TrackRecordingService extends Service implements LocationListener { executer.shutdown(); } splitManager.shutdown(); + super.onDestroy(); } @Override @@ -767,10 +769,11 @@ public class TrackRecordingService extends Service implements LocationListener { } // Check if the last modified time is within the acceptable range. - long lastModified = track.getLastModified(); + long lastModified = + track.getStatistics() != null ? track.getStatistics().getStopTime() : 0; Log.d(MyTracksConstants.TAG, "maybeResumeTrack: lastModified = " + lastModified); - return lastModified != -1 && System.currentTimeMillis() - lastModified <= + return lastModified > 0 && System.currentTimeMillis() - lastModified <= autoResumeTrackTimeout * 60 * 1000; } diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java index 135ea7993..8a768f637 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java @@ -15,17 +15,9 @@ */ package com.google.android.apps.mytracks.services; -import static com.google.android.apps.mytracks.MyTracksConstants.RESUME_TRACK_EXTRA_NAME; - -import com.google.android.apps.mytracks.content.MyTracksProviderUtils; -import com.google.android.apps.mytracks.content.Track; - import android.content.Intent; import android.os.IBinder; import android.test.ServiceTestCase; -import android.test.mock.MockContentProvider; -import android.test.mock.MockContentResolver; -import android.test.mock.MockContext; import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.SmallTest; @@ -36,11 +28,9 @@ import android.test.suitebuilder.annotation.SmallTest; */ public class TrackRecordingServiceTest extends ServiceTestCase { - private MyTracksProviderUtils providerUtils; public TrackRecordingServiceTest() { super(TrackRecordingService.class); - providerUtils = MyTracksProviderUtils.Factory.get(getContext()); } @SmallTest @@ -58,21 +48,4 @@ public class TrackRecordingServiceTest IBinder service = bindService(startIntent); assertNotNull(service); } - - @MediumTest - public void testResumeAfterReboot() throws Exception { - // TODO: Figure out how to mock getContentResolver() before submit. - /* - Track dummyTrack = new Track(); - dummyTrack.setName("Dummy Track"); - providerUtils.insertTrack(dummyTrack); - - Intent startIntent = new Intent(); - startIntent.setClass(getContext(), TrackRecordingService.class); - startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true); - startService(startIntent); - assertNotNull(getService()); - assertFalse(getService().isRecording()); - */ - } }