Apply review feedback.

This commit is contained in:
Bartlomiej Niechwiej
2010-09-30 23:46:47 -07:00
parent c282562867
commit beee6af79d
8 changed files with 15 additions and 250 deletions
+1 -1
View File
@@ -77,7 +77,7 @@
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</application>
<!-- Permissions to initialize service -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+1 -1
View File
@@ -17,6 +17,7 @@ limitations under the License.
<resources>
<!-- Keys for application preferences - DO NOT TRANSLATE -->
<string name="announcement_frequency_key">announcementFrequency</string>
<string name="auto_resume_track_timeout_key">autoResumeTrackTimeout</string>
<string name="bluetooth_device_key">bluetoothDevice</string>
<string name="bluetooth_pairing_key">bluetoothPairing</string>
<string name="bluetooth_sensor_key">bluetoothSensor</string>
@@ -37,7 +38,6 @@ limitations under the License.
<string name="share_url_only_key">shareUrlOnly</string>
<string name="signal_sampling_frequency_key">signalSamplingFrequency</string>
<string name="split_frequency_key">splitFrequency</string>
<string name="auto_resume_track_timeout_key">autoResumeTrackTimeout</string>
<!-- Preference keys which keep transient state (not user preferences) - DO NOT TRANSLATE -->
<string name="recording_track_key">recordingTrack</string>
@@ -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();
}
});
}
}
@@ -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);
}
}
@@ -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;
}
}
@@ -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));
}
}
}
@@ -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;
}
@@ -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<TrackRecordingService> {
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());
*/
}
}