Save map orientation state
@@ -14,17 +14,14 @@ import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewCompat;
-import android.support.v4.view.ViewPropertyAnimatorListenerAdapter;
import android.support.v4.view.ViewPropertyAnimatorUpdateListener;
import android.support.v7.app.AlertDialog;
import android.support.v7.content.res.AppCompatResources;
import android.text.method.LinkMovementMethod;
-import android.view.DragEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
-import android.view.animation.OvershootInterpolator;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
@@ -59,6 +56,7 @@ public class MapFragment extends Fragment {
// constants
private final static String KEY_MAP_ZOOMLEVEL = "map_zoomlevel";
private final static String KEY_MAP_POSITION = "map_position";
+ private final static String KEY_MAP_ORIENTATION = "map_orientation";
private final static String KEY_INITIAL_LOCATION_SET = "initial_location_set";
//dependencies
@@ -114,6 +112,7 @@ public class MapFragment extends Fragment {
//OnClickListeners for rotate north FAB
private final View.OnClickListener rotationNorthOnClickListener = new View.OnClickListener() {
+ @Override
public void onClick(View v) {
float currentRotation = mapView.getMapOrientation() % 360;
if (currentRotation < 0.0f) {
@@ -223,28 +222,31 @@ public class MapFragment extends Fragment {
}
});
+ RotationGestureOverlay mRotationGestureOverlay = new RotationGestureOverlay(mapView) {
+ @Override
+ public boolean onTouchEvent(MotionEvent event, MapView mapView) {
+ setRotationNorth.setRotation(mapView.getMapOrientation());
+ return super.onTouchEvent(event, mapView);
+ }
+ };
+ mRotationGestureOverlay.setEnabled(true);
+ mapView.setMultiTouchControls(true);
+ mapView.getOverlays().add(mRotationGestureOverlay);
+
if (savedState != null) {
Integer zoomLevel = (Integer) savedState.get(KEY_MAP_ZOOMLEVEL);
GeoPoint position = savedState.getParcelable(KEY_MAP_POSITION);
+ Float orientation = (Float) savedState.get(KEY_MAP_ORIENTATION);
- if (zoomLevel != null && position != null) {
+ if (zoomLevel != null && position != null && orientation != null) {
mapView.getController().setZoom(zoomLevel);
+ mapView.setMapOrientation(orientation);
setToLocation(position);
}
isInitialLocationSet = savedState.getBoolean(KEY_INITIAL_LOCATION_SET, false);
}
-
- RotationGestureOverlay mRotationGestureOverlay = new RotationGestureOverlay(mapView) {
- @Override
- public boolean onTouchEvent(MotionEvent event, MapView mapView) {
setRotationNorth.setRotation(mapView.getMapOrientation());
- return super.onTouchEvent(event, mapView);
- }
- };
- mRotationGestureOverlay.setEnabled(true);
- mapView.setMultiTouchControls(true);
- mapView.getOverlays().add(mRotationGestureOverlay);
}
private void refreshView() {
@@ -300,6 +302,7 @@ public class MapFragment extends Fragment {
outState.putInt(KEY_MAP_ZOOMLEVEL, mapView.getZoomLevel());
outState.putParcelable(KEY_MAP_POSITION, (GeoPoint) mapView.getMapCenter());
+ outState.putFloat(KEY_MAP_ORIENTATION, mapView.getMapOrientation());
outState.putBoolean(KEY_INITIAL_LOCATION_SET, isInitialLocationSet);
}
