diff --git a/MyTracks/res/values/keys.xml b/MyTracks/res/values/keys.xml
index a0e41006b..5f80fc37e 100644
--- a/MyTracks/res/values/keys.xml
+++ b/MyTracks/res/values/keys.xml
@@ -37,6 +37,7 @@ limitations under the License.
defaultTablePublic
driveSync
googleAccount
+ mapType
maxRecordingDistance
metricUnits
minRecordingDistance
diff --git a/MyTracks/src/com/google/android/apps/mytracks/content/MyTracksProvider.java b/MyTracks/src/com/google/android/apps/mytracks/content/MyTracksProvider.java
index 7ba2db8f9..d4d95bf6b 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/content/MyTracksProvider.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/content/MyTracksProvider.java
@@ -225,7 +225,8 @@ public class MyTracksProvider extends ContentProvider {
} finally {
db.endTransaction();
}
-
+ getContext().getContentResolver().notifyChange(url, null, false);
+
if (driveSync && table.equals(TracksColumns.TABLE_NAME)) {
String driveDeletedList = PreferencesUtils.getString(getContext(),
R.string.drive_deleted_list_key, PreferencesUtils.DRIVE_DELETED_LIST_DEFAULT);
@@ -235,9 +236,7 @@ public class MyTracksProvider extends ContentProvider {
driveDeletedList += ";" + driveIds;
}
PreferencesUtils.setString(getContext(), R.string.drive_deleted_list_key, driveDeletedList);
- }
-
- getContext().getContentResolver().notifyChange(url, null, true);
+ }
if (shouldVacuum) {
// If a potentially large amount of data was deleted, reclaim its space.
@@ -286,6 +285,7 @@ public class MyTracksProvider extends ContentProvider {
} finally {
db.endTransaction();
}
+ getContext().getContentResolver().notifyChange(url, null, false);
return result;
}
@@ -311,6 +311,7 @@ public class MyTracksProvider extends ContentProvider {
} finally {
db.endTransaction();
}
+ getContext().getContentResolver().notifyChange(url, null, false);
return numInserted;
}
@@ -408,7 +409,7 @@ public class MyTracksProvider extends ContentProvider {
} finally {
db.endTransaction();
}
- getContext().getContentResolver().notifyChange(url, null, true);
+ getContext().getContentResolver().notifyChange(url, null, false);
return count;
}
@@ -468,9 +469,7 @@ public class MyTracksProvider extends ContentProvider {
}
long rowId = db.insert(TrackPointsColumns.TABLE_NAME, TrackPointsColumns._ID, values);
if (rowId >= 0) {
- Uri uri = ContentUris.appendId(TrackPointsColumns.CONTENT_URI.buildUpon(), rowId).build();
- getContext().getContentResolver().notifyChange(url, null, true);
- return uri;
+ return ContentUris.appendId(TrackPointsColumns.CONTENT_URI.buildUpon(), rowId).build();
}
throw new SQLiteException("Failed to insert a track point " + url);
}
@@ -489,9 +488,7 @@ public class MyTracksProvider extends ContentProvider {
}
long rowId = db.insert(TracksColumns.TABLE_NAME, TracksColumns._ID, contentValues);
if (rowId >= 0) {
- Uri uri = ContentUris.appendId(TracksColumns.CONTENT_URI.buildUpon(), rowId).build();
- getContext().getContentResolver().notifyChange(url, null, true);
- return uri;
+ return ContentUris.appendId(TracksColumns.CONTENT_URI.buildUpon(), rowId).build();
}
throw new SQLException("Failed to insert a track " + url);
}
@@ -505,9 +502,7 @@ public class MyTracksProvider extends ContentProvider {
private Uri insertWaypoint(Uri url, ContentValues contentValues) {
long rowId = db.insert(WaypointsColumns.TABLE_NAME, WaypointsColumns._ID, contentValues);
if (rowId >= 0) {
- Uri uri = ContentUris.appendId(WaypointsColumns.CONTENT_URI.buildUpon(), rowId).build();
- getContext().getContentResolver().notifyChange(url, null, true);
- return uri;
+ return ContentUris.appendId(WaypointsColumns.CONTENT_URI.buildUpon(), rowId).build();
}
throw new SQLException("Failed to insert a waypoint " + url);
}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/MyTracksMapFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/MyTracksMapFragment.java
index b549bd85e..87b4fd05f 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/fragments/MyTracksMapFragment.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/MyTracksMapFragment.java
@@ -31,6 +31,7 @@ import com.google.android.apps.mytracks.util.ApiAdapterFactory;
import com.google.android.apps.mytracks.util.GoogleLocationUtils;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.LocationUtils;
+import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
@@ -80,8 +81,7 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
private static final String
KEEP_CURRENT_LOCATION_VISIBLE_KEY = "keep_current_location_visible_key";
private static final String ZOOM_TO_CURRENT_LOCATION_KEY = "zoom_to_current_location_key";
- private static final String MAP_TYPE = "map_type";
-
+
private static final float DEFAULT_ZOOM_LEVEL = 18f;
// Google's latitude and longitude
@@ -125,7 +125,6 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setHasOptionsMenu(true);
- ApiAdapterFactory.getApiAdapter().invalidMenu(getActivity());
mapOverlay = new MapOverlay(getActivity());
}
@@ -224,15 +223,18 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
zoomToCurrentLocation = savedInstanceState.getBoolean(ZOOM_TO_CURRENT_LOCATION_KEY, false);
currentLocation = (Location) savedInstanceState.getParcelable(CURRENT_LOCATION_KEY);
updateCurrentLocation();
- if (googleMap != null) {
- googleMap.setMapType(savedInstanceState.getInt(MAP_TYPE, GoogleMap.MAP_TYPE_NORMAL));
- }
}
}
@Override
public void onResume() {
super.onResume();
+ if (googleMap != null) {
+ int mapType = PreferencesUtils.getInt(
+ getActivity(), R.string.map_type_key, PreferencesUtils.MAP_TYPE_DEFAUlT);
+ googleMap.setMapType(mapType);
+ ApiAdapterFactory.getApiAdapter().invalidMenu(getActivity());
+ }
resumeTrackDataHub();
}
@@ -244,9 +246,6 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
}
outState.putBoolean(KEEP_CURRENT_LOCATION_VISIBLE_KEY, keepCurrentLocationVisible);
outState.putBoolean(ZOOM_TO_CURRENT_LOCATION_KEY, zoomToCurrentLocation);
- if (googleMap != null) {
- outState.putInt(MAP_TYPE, googleMap.getMapType());
- }
}
@Override
@@ -333,6 +332,7 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
if (googleMap != null) {
googleMap.setMapType(type);
menuItem.setChecked(true);
+ PreferencesUtils.setInt(getActivity(), R.string.map_type_key, type);
}
return true;
}
@@ -637,12 +637,13 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
tripStatistics.getTopDegrees(), tripStatistics.getRightDegrees());
LatLngBounds bounds = LatLngBounds.builder()
.include(southWest).include(northEast).build();
-
+
/**
- * Note cannot call CameraUpdate.newLatLngBounds(LatLngBounds bounds, int padding)
- * if the map view has not undergone layout. Thus calling
- * CameraUpdate.newLatLngBounds(LatLngBounds bounds, int width, int height, int padding)
- * after making sure that mapView is valid in the above code.
+ * Note cannot call CameraUpdate.newLatLngBounds(LatLngBounds bounds,
+ * int padding) if the map view has not undergone layout. Thus calling
+ * CameraUpdate.newLatLngBounds(LatLngBounds bounds, int width, int
+ * height, int padding) after making sure that mapView is valid in the
+ * above code.
*/
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(
bounds, mapView.getWidth(), mapView.getHeight(), MAP_VIEW_PADDING);
diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/TrackWriter.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/TrackWriter.java
index 7246063b1..e937ef44e 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/io/file/TrackWriter.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/TrackWriter.java
@@ -240,7 +240,8 @@ public class TrackWriter {
wroteSegment = false;
}
if (wroteTrack) {
- trackFormatWriter.writeEndTrack(locationFactory.lastLocation);
+ Location lastValidTrackPoint = myTracksProviderUtils.getLastValidTrackPoint(track.getId());
+ trackFormatWriter.writeEndTrack(lastValidTrackPoint);
} else {
// Write an empty track
trackFormatWriter.writeBeginTrack(null);
diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/PreferencesUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/PreferencesUtils.java
index b7f233ad5..55ed3d358 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/util/PreferencesUtils.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/util/PreferencesUtils.java
@@ -59,12 +59,15 @@ public class PreferencesUtils {
public static final boolean DEFAULT_TABLE_PUBLIC_DEFAULT = false;
public static final String DRIVE_DELETED_LIST_DEFAULT = "";
public static final long DRIVE_LARGEST_CHANGE_ID_DEFAULT = -1L;
- public static final boolean DRIVE_SYNC_DEFAULT = false;
-
+ public static final boolean DRIVE_SYNC_DEFAULT = false;
+
// Value for split_frequency_key and voice_frequency_key
public static final int FREQUENCY_OFF = 0;
-
+
public static final String GOOGLE_ACCOUNT_DEFAULT = "";
+
+ public static final int MAP_TYPE_DEFAUlT = 1;
+
public static final int MAX_RECORDING_DISTANCE_DEFAULT = 200;
public static final boolean METRIC_UNITS_DEFAULT = true;
public static final int MIN_RECORDING_DISTANCE_DEFAULT = 5;
@@ -84,13 +87,13 @@ public class PreferencesUtils {
public static final boolean RECORDING_TRACK_PAUSED_DEFAULT = true;
public static final boolean REPORT_SPEED_DEFAULT = true;
public static final long SELECTED_TRACK_ID_DEFAULT = -1L;
-
+
public static final boolean SEND_TO_DRIVE_DEFAULT = false;
public static final boolean SEND_TO_FUSION_TABLES_DEFAULT = false;
public static final boolean SEND_TO_MAPS_DEFAULT = false;
public static final boolean SEND_TO_SPREADSHEETS_DEFAULT = false;
-
- public static final String SENSOR_TYPE_DEFAULT = "NONE";
+
+ public static final String SENSOR_TYPE_DEFAULT = "NONE";
public static final int SPLIT_FREQUENCY_DEFAULT = 0;
public static final boolean STATS_SHOW_COORDINATE_DEFAULT = false;
public static final boolean STATS_SHOW_ELEVATION_DEFAULT = false;