persist map type from apoorvnaik

This commit is contained in:
Jimmy Shih
2013-02-27 12:20:03 -08:00
parent e8e99dc3d0
commit 6bf211a5c6
3 changed files with 25 additions and 20 deletions
+1
View File
@@ -37,6 +37,7 @@ limitations under the License.
<string name="default_table_public_key">defaultTablePublic</string> <string name="default_table_public_key">defaultTablePublic</string>
<string name="drive_sync_key">driveSync</string> <string name="drive_sync_key">driveSync</string>
<string name="google_account_key">googleAccount</string> <string name="google_account_key">googleAccount</string>
<string name="map_type_key">mapType</string>
<string name="max_recording_distance_key">maxRecordingDistance</string> <string name="max_recording_distance_key">maxRecordingDistance</string>
<string name="metric_units_key">metricUnits</string> <string name="metric_units_key">metricUnits</string>
<string name="min_recording_distance_key">minRecordingDistance</string> <string name="min_recording_distance_key">minRecordingDistance</string>
@@ -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.GoogleLocationUtils;
import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.LocationUtils; 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.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap;
@@ -80,7 +81,6 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
private static final String private static final String
KEEP_CURRENT_LOCATION_VISIBLE_KEY = "keep_current_location_visible_key"; 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 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; private static final float DEFAULT_ZOOM_LEVEL = 18f;
@@ -125,7 +125,6 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
public void onCreate(Bundle bundle) { public void onCreate(Bundle bundle) {
super.onCreate(bundle); super.onCreate(bundle);
setHasOptionsMenu(true); setHasOptionsMenu(true);
ApiAdapterFactory.getApiAdapter().invalidMenu(getActivity());
mapOverlay = new MapOverlay(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); zoomToCurrentLocation = savedInstanceState.getBoolean(ZOOM_TO_CURRENT_LOCATION_KEY, false);
currentLocation = (Location) savedInstanceState.getParcelable(CURRENT_LOCATION_KEY); currentLocation = (Location) savedInstanceState.getParcelable(CURRENT_LOCATION_KEY);
updateCurrentLocation(); updateCurrentLocation();
if (googleMap != null) {
googleMap.setMapType(savedInstanceState.getInt(MAP_TYPE, GoogleMap.MAP_TYPE_NORMAL));
}
} }
} }
@Override @Override
public void onResume() { public void onResume() {
super.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(); resumeTrackDataHub();
} }
@@ -244,9 +246,6 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
} }
outState.putBoolean(KEEP_CURRENT_LOCATION_VISIBLE_KEY, keepCurrentLocationVisible); outState.putBoolean(KEEP_CURRENT_LOCATION_VISIBLE_KEY, keepCurrentLocationVisible);
outState.putBoolean(ZOOM_TO_CURRENT_LOCATION_KEY, zoomToCurrentLocation); outState.putBoolean(ZOOM_TO_CURRENT_LOCATION_KEY, zoomToCurrentLocation);
if (googleMap != null) {
outState.putInt(MAP_TYPE, googleMap.getMapType());
}
} }
@Override @Override
@@ -333,6 +332,7 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
if (googleMap != null) { if (googleMap != null) {
googleMap.setMapType(type); googleMap.setMapType(type);
menuItem.setChecked(true); menuItem.setChecked(true);
PreferencesUtils.setInt(getActivity(), R.string.map_type_key, type);
} }
return true; return true;
} }
@@ -639,10 +639,11 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
.include(southWest).include(northEast).build(); .include(southWest).include(northEast).build();
/** /**
* Note cannot call CameraUpdate.newLatLngBounds(LatLngBounds bounds, int padding) * Note cannot call CameraUpdate.newLatLngBounds(LatLngBounds bounds,
* if the map view has not undergone layout. Thus calling * int padding) if the map view has not undergone layout. Thus calling
* CameraUpdate.newLatLngBounds(LatLngBounds bounds, int width, int height, int padding) * CameraUpdate.newLatLngBounds(LatLngBounds bounds, int width, int
* after making sure that mapView is valid in the above code. * height, int padding) after making sure that mapView is valid in the
* above code.
*/ */
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds( CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(
bounds, mapView.getWidth(), mapView.getHeight(), MAP_VIEW_PADDING); bounds, mapView.getWidth(), mapView.getHeight(), MAP_VIEW_PADDING);
@@ -65,6 +65,9 @@ public class PreferencesUtils {
public static final int FREQUENCY_OFF = 0; public static final int FREQUENCY_OFF = 0;
public static final String GOOGLE_ACCOUNT_DEFAULT = ""; 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 int MAX_RECORDING_DISTANCE_DEFAULT = 200;
public static final boolean METRIC_UNITS_DEFAULT = true; public static final boolean METRIC_UNITS_DEFAULT = true;
public static final int MIN_RECORDING_DISTANCE_DEFAULT = 5; public static final int MIN_RECORDING_DISTANCE_DEFAULT = 5;