Merge heads

This commit is contained in:
youtaol
2012-05-09 12:20:53 +08:00
parent b6fdf4e6e4
commit 7b14315cbe
97 changed files with 2987 additions and 2768 deletions
@@ -16,13 +16,13 @@
package com.google.android.apps.mytracks.content;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.SQLException;
@@ -190,13 +190,11 @@ public class MyTracksProvider extends ContentProvider {
if (Binder.getCallingPid() == Process.myPid()) {
return true;
} else {
Context context = getContext();
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getBoolean(context.getString(R.string.allow_access_key), false);
return PreferencesUtils.getBoolean(
getContext(), R.string.allow_access_key, PreferencesUtils.ALLOW_ACCESS_DEFAULT);
}
}
@Override
public boolean onCreate() {
if (!canAccess()) {
@@ -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();
}
@@ -294,11 +288,13 @@ public class TrackDataHub {
}
private void loadSharedPreferences() {
selectedTrackId = PreferencesUtils.getSelectedTrackId(context);
metricUnits = PreferencesUtils.isMetricUnits(context);
reportSpeed = PreferencesUtils.isReportSpeed(context);
minRequiredAccuracy = preferences.getInt(MIN_REQUIRED_ACCURACY_KEY,
DEFAULT_MIN_REQUIRED_ACCURACY);
selectedTrackId = PreferencesUtils.getLong(context, R.string.selected_track_id_key);
metricUnits = PreferencesUtils.getBoolean(
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
reportSpeed = PreferencesUtils.getBoolean(
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
minRequiredAccuracy = PreferencesUtils.getInt(context, R.string.min_required_accuracy_key,
PreferencesUtils.MIN_REQUIRED_ACCURACY_DEFAULT);
}
/** Updates known magnetic declination if needed. */
@@ -372,8 +368,9 @@ public class TrackDataHub {
if (!isStarted()) {
loadSharedPreferences();
}
long recordingTrackId = PreferencesUtils.getRecordingTrackId(context);
return recordingTrackId != -1L && recordingTrackId == selectedTrackId;
long recordingTrackId = PreferencesUtils.getLong(context, R.string.recording_track_id_key);
return recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT
&& recordingTrackId == selectedTrackId;
}
/**
@@ -391,7 +388,7 @@ public class TrackDataHub {
// Save the selection to memory and flush.
selectedTrackId = trackId;
PreferencesUtils.setSelectedTrackId(context, selectedTrackId);
PreferencesUtils.setLong(context, R.string.selected_track_id_key, selectedTrackId);
// Force it to reload data from the beginning.
Log.d(TAG, "Loading track");
@@ -605,21 +602,23 @@ 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);
} else if (PreferencesUtils.getMetricUnitsKey(context).equals(key)) {
metricUnits = PreferencesUtils.isMetricUnits(context);
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, PreferencesUtils.METRIC_UNITS_DEFAULT);
notifyUnitsChanged();
} else if (PreferencesUtils.getReportSpeedKey(context).equals(key)) {
reportSpeed = PreferencesUtils.isReportSpeed(context);
} else if (PreferencesUtils.getKey(context, R.string.report_speed_key).equals(key)) {
reportSpeed = PreferencesUtils.getBoolean(
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
notifySpeedReportingChanged();
} else if (PreferencesUtils.getSelectedTrackIdKey(context).equals(key)) {
loadTrack(PreferencesUtils.getSelectedTrackId(context));
} else if (PreferencesUtils.getKey(context, R.string.selected_track_id_key).equals(key)) {
loadTrack(PreferencesUtils.getLong(context, R.string.selected_track_id_key));
}
}