diff --git a/demo/src/main/java/com/google/maps/android/utils/demo/BaseDemoActivity.java b/demo/src/main/java/com/google/maps/android/utils/demo/BaseDemoActivity.java index cff0c73cf..f6446c15e 100644 --- a/demo/src/main/java/com/google/maps/android/utils/demo/BaseDemoActivity.java +++ b/demo/src/main/java/com/google/maps/android/utils/demo/BaseDemoActivity.java @@ -26,6 +26,7 @@ public abstract class BaseDemoActivity extends FragmentActivity implements OnMapReadyCallback { private GoogleMap mMap; + private boolean mIsRestore; protected int getLayoutId() { return R.layout.map; @@ -34,23 +35,18 @@ protected int getLayoutId() { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mIsRestore = savedInstanceState != null; setContentView(getLayoutId()); setUpMap(); } - @Override - protected void onResume() { - super.onResume(); - setUpMap(); - } - @Override public void onMapReady(GoogleMap map) { if (mMap != null) { return; } mMap = map; - startDemo(); + startDemo(mIsRestore); } private void setUpMap() { @@ -60,7 +56,7 @@ private void setUpMap() { /** * Run the demo-specific code. */ - protected abstract void startDemo(); + protected abstract void startDemo(boolean isRestore); protected GoogleMap getMap() { return mMap; diff --git a/demo/src/main/java/com/google/maps/android/utils/demo/BigClusteringDemoActivity.java b/demo/src/main/java/com/google/maps/android/utils/demo/BigClusteringDemoActivity.java index a7688c22c..bf1ee93a6 100644 --- a/demo/src/main/java/com/google/maps/android/utils/demo/BigClusteringDemoActivity.java +++ b/demo/src/main/java/com/google/maps/android/utils/demo/BigClusteringDemoActivity.java @@ -32,8 +32,10 @@ public class BigClusteringDemoActivity extends BaseDemoActivity { private ClusterManager mClusterManager; @Override - protected void startDemo() { - getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.503186, -0.126446), 10)); + protected void startDemo(boolean isRestore) { + if (!isRestore) { + getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.503186, -0.126446), 10)); + } mClusterManager = new ClusterManager<>(this, getMap()); diff --git a/demo/src/main/java/com/google/maps/android/utils/demo/ClusteringDemoActivity.java b/demo/src/main/java/com/google/maps/android/utils/demo/ClusteringDemoActivity.java index c05432405..aed90c798 100644 --- a/demo/src/main/java/com/google/maps/android/utils/demo/ClusteringDemoActivity.java +++ b/demo/src/main/java/com/google/maps/android/utils/demo/ClusteringDemoActivity.java @@ -35,8 +35,10 @@ public class ClusteringDemoActivity extends BaseDemoActivity { private ClusterManager mClusterManager; @Override - protected void startDemo() { - getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.503186, -0.126446), 10)); + protected void startDemo(boolean isRestore) { + if (!isRestore) { + getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.503186, -0.126446), 10)); + } mClusterManager = new ClusterManager<>(this, getMap()); getMap().setOnCameraIdleListener(mClusterManager); diff --git a/demo/src/main/java/com/google/maps/android/utils/demo/CustomMarkerClusteringDemoActivity.java b/demo/src/main/java/com/google/maps/android/utils/demo/CustomMarkerClusteringDemoActivity.java index 1a27245f2..bbd8994bd 100644 --- a/demo/src/main/java/com/google/maps/android/utils/demo/CustomMarkerClusteringDemoActivity.java +++ b/demo/src/main/java/com/google/maps/android/utils/demo/CustomMarkerClusteringDemoActivity.java @@ -155,8 +155,10 @@ public void onClusterItemInfoWindowClick(Person item) { } @Override - protected void startDemo() { - getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.503186, -0.126446), 9.5f)); + protected void startDemo(boolean isRestore) { + if (!isRestore) { + getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.503186, -0.126446), 9.5f)); + } mClusterManager = new ClusterManager(this, getMap()); mClusterManager.setRenderer(new PersonRenderer()); diff --git a/demo/src/main/java/com/google/maps/android/utils/demo/DistanceDemoActivity.java b/demo/src/main/java/com/google/maps/android/utils/demo/DistanceDemoActivity.java index 250eb83f1..51622e7ad 100644 --- a/demo/src/main/java/com/google/maps/android/utils/demo/DistanceDemoActivity.java +++ b/demo/src/main/java/com/google/maps/android/utils/demo/DistanceDemoActivity.java @@ -42,10 +42,12 @@ protected int getLayoutId() { } @Override - protected void startDemo() { + protected void startDemo(boolean isRestore) { mTextView = findViewById(R.id.textView); - getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.8256, 151.2395), 10)); + if (!isRestore) { + getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.8256, 151.2395), 10)); + } getMap().setOnMarkerDragListener(this); mMarkerA = getMap().addMarker(new MarkerOptions().position(new LatLng(-33.9046, 151.155)).draggable(true)); diff --git a/demo/src/main/java/com/google/maps/android/utils/demo/GeoJsonDemoActivity.java b/demo/src/main/java/com/google/maps/android/utils/demo/GeoJsonDemoActivity.java index 20b85a2e9..68f31f95a 100644 --- a/demo/src/main/java/com/google/maps/android/utils/demo/GeoJsonDemoActivity.java +++ b/demo/src/main/java/com/google/maps/android/utils/demo/GeoJsonDemoActivity.java @@ -46,7 +46,10 @@ protected int getLayoutId() { } @Override - protected void startDemo() { + protected void startDemo(boolean isRestore) { + if (!isRestore) { + getMap().moveCamera(CameraUpdateFactory.newLatLng(new LatLng(31.4118,-103.5355))); + } // Download the GeoJSON file. retrieveFileFromUrl(); // Alternate approach of loading a local GeoJSON file. @@ -133,14 +136,12 @@ protected void onPostExecute(GeoJsonLayer layer) { addGeoJsonLayerToMap(layer); } } - } private void addGeoJsonLayerToMap(GeoJsonLayer layer) { addColorsToMarkers(layer); layer.addLayerToMap(); - getMap().moveCamera(CameraUpdateFactory.newLatLng(new LatLng(31.4118,-103.5355))); // Demonstrate receiving features via GeoJsonLayer clicks. layer.setOnFeatureClickListener(new GeoJsonLayer.GeoJsonOnFeatureClickListener() { @Override @@ -151,7 +152,5 @@ public void onFeatureClick(Feature feature) { } }); - } - } diff --git a/demo/src/main/java/com/google/maps/android/utils/demo/HeatmapsDemoActivity.java b/demo/src/main/java/com/google/maps/android/utils/demo/HeatmapsDemoActivity.java index acbb741fe..3ffb130c0 100644 --- a/demo/src/main/java/com/google/maps/android/utils/demo/HeatmapsDemoActivity.java +++ b/demo/src/main/java/com/google/maps/android/utils/demo/HeatmapsDemoActivity.java @@ -97,8 +97,10 @@ protected int getLayoutId() { } @Override - protected void startDemo() { - getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-25, 143), 4)); + protected void startDemo(boolean isRestore) { + if (!isRestore) { + getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-25, 143), 4)); + } // Set up the spinner/dropdown list Spinner spinner = findViewById(R.id.spinner); @@ -218,5 +220,4 @@ public String getUrl() { return mUrl; } } - } diff --git a/demo/src/main/java/com/google/maps/android/utils/demo/HeatmapsPlacesDemoActivity.java b/demo/src/main/java/com/google/maps/android/utils/demo/HeatmapsPlacesDemoActivity.java index 1f262929d..e45fc128d 100644 --- a/demo/src/main/java/com/google/maps/android/utils/demo/HeatmapsPlacesDemoActivity.java +++ b/demo/src/main/java/com/google/maps/android/utils/demo/HeatmapsPlacesDemoActivity.java @@ -61,8 +61,6 @@ */ public class HeatmapsPlacesDemoActivity extends BaseDemoActivity { - private GoogleMap mMap = null; - private final LatLng SYDNEY = new LatLng(-33.873651, 151.2058896); /** @@ -139,8 +137,8 @@ protected int getLayoutId() { } @Override - protected void startDemo() { - EditText editText = (EditText) findViewById(R.id.input_text); + protected void startDemo(boolean isRestore) { + EditText editText = findViewById(R.id.input_text); editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { @@ -153,23 +151,17 @@ public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent } }); - mCheckboxLayout = (LinearLayout) findViewById(R.id.checkboxes); - setUpMap(); - } - - private void setUpMap() { - if (mMap == null) { - mMap = getMap(); - if (mMap != null) { - mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 11)); - // Add a circle around Sydney to roughly encompass the results - mMap.addCircle(new CircleOptions() - .center(SYDNEY) - .radius(SEARCH_RADIUS * 1.2) - .strokeColor(Color.RED) - .strokeWidth(4)); - } + mCheckboxLayout = findViewById(R.id.checkboxes); + GoogleMap map = getMap(); + if (!isRestore) { + map.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 11)); } + // Add a circle around Sydney to roughly encompass the results + map.addCircle(new CircleOptions() + .center(SYDNEY) + .radius(SEARCH_RADIUS * 1.2) + .strokeColor(Color.RED) + .strokeWidth(4)); } /** @@ -182,7 +174,7 @@ public void submit(View view) { Toast.LENGTH_LONG).show(); return; } - EditText editText = (EditText) findViewById(R.id.input_text); + EditText editText = findViewById(R.id.input_text); String keyword = editText.getText().toString(); if (mOverlays.contains(keyword)) { Toast.makeText(this, "This keyword has already been inputted :(", Toast.LENGTH_SHORT).show(); @@ -190,7 +182,7 @@ public void submit(View view) { Toast.makeText(this, "You can only input " + MAX_CHECKBOXES + " keywords. :(", Toast.LENGTH_SHORT).show(); } else if (keyword.length() != 0) { mOverlaysInput++; - ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar); + ProgressBar progressBar = findViewById(R.id.progress_bar); progressBar.setVisibility(View.VISIBLE); new MakeOverlayTask().execute(keyword); editText.setText(""); diff --git a/demo/src/main/java/com/google/maps/android/utils/demo/IconGeneratorDemoActivity.java b/demo/src/main/java/com/google/maps/android/utils/demo/IconGeneratorDemoActivity.java index 29b487108..e4d11ed7f 100644 --- a/demo/src/main/java/com/google/maps/android/utils/demo/IconGeneratorDemoActivity.java +++ b/demo/src/main/java/com/google/maps/android/utils/demo/IconGeneratorDemoActivity.java @@ -33,8 +33,10 @@ public class IconGeneratorDemoActivity extends BaseDemoActivity { @Override - protected void startDemo() { - getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.8696, 151.2094), 10)); + protected void startDemo(boolean isRestore) { + if (!isRestore) { + getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.8696, 151.2094), 10)); + } IconGenerator iconFactory = new IconGenerator(this); addIcon(iconFactory, "Default", new LatLng(-33.8696, 151.2094)); diff --git a/demo/src/main/java/com/google/maps/android/utils/demo/KmlDemoActivity.java b/demo/src/main/java/com/google/maps/android/utils/demo/KmlDemoActivity.java index e770d169f..34569079d 100644 --- a/demo/src/main/java/com/google/maps/android/utils/demo/KmlDemoActivity.java +++ b/demo/src/main/java/com/google/maps/android/utils/demo/KmlDemoActivity.java @@ -25,12 +25,14 @@ public class KmlDemoActivity extends BaseDemoActivity { private GoogleMap mMap; + private boolean mIsRestore; protected int getLayoutId() { return R.layout.kml_demo; } - public void startDemo () { + public void startDemo (boolean isRestore) { + mIsRestore = isRestore; try { mMap = getMap(); //retrieveFileFromResource(); @@ -57,6 +59,7 @@ private void retrieveFileFromUrl() { } private void moveCameraToKml(KmlLayer kmlLayer) { + if (mIsRestore) return; //Retrieve the first container in the KML layer KmlContainer container = kmlLayer.getContainers().iterator().next(); //Retrieve a nested container within the first container diff --git a/demo/src/main/java/com/google/maps/android/utils/demo/PolyDecodeDemoActivity.java b/demo/src/main/java/com/google/maps/android/utils/demo/PolyDecodeDemoActivity.java index a076191d3..370b445c2 100644 --- a/demo/src/main/java/com/google/maps/android/utils/demo/PolyDecodeDemoActivity.java +++ b/demo/src/main/java/com/google/maps/android/utils/demo/PolyDecodeDemoActivity.java @@ -28,11 +28,13 @@ public class PolyDecodeDemoActivity extends BaseDemoActivity { private final static String LINE = "rvumEis{y[}DUaBGu@EqESyCMyAGGZGdEEhBAb@DZBXCPGP]Xg@LSBy@E{@SiBi@wAYa@AQGcAY]I]KeBm@_Bw@cBu@ICKB}KiGsEkCeEmBqJcFkFuCsFuCgB_AkAi@cA[qAWuAKeB?uALgB\\eDx@oBb@eAVeAd@cEdAaCp@s@PO@MBuEpA{@R{@NaAHwADuBAqAGE?qCS[@gAO{Fg@qIcAsCg@u@SeBk@aA_@uCsAkBcAsAy@AMGIw@e@_Bq@eA[eCi@QOAK@O@YF}CA_@Ga@c@cAg@eACW@YVgDD]Nq@j@}AR{@rBcHvBwHvAuFJk@B_@AgAGk@UkAkBcH{@qCuAiEa@gAa@w@c@o@mA{Ae@s@[m@_AaCy@uB_@kAq@_Be@}@c@m@{AwAkDuDyC_De@w@{@kB_A}BQo@UsBGy@AaA@cLBkCHsBNoD@c@E]q@eAiBcDwDoGYY_@QWEwE_@i@E}@@{BNaA@s@EyB_@c@?a@F}B\\iCv@uDjAa@Ds@Bs@EyAWo@Sm@a@YSu@c@g@Mi@GqBUi@MUMMMq@}@SWWM]C[DUJONg@hAW\\QHo@BYIOKcG{FqCsBgByAaAa@gA]c@I{@Gi@@cALcEv@_G|@gAJwAAUGUAk@C{Ga@gACu@A[Em@Sg@Y_AmA[u@Oo@qAmGeAeEs@sCgAqDg@{@[_@m@e@y@a@YIKCuAYuAQyAUuAWUaA_@wBiBgJaAoFyCwNy@cFIm@Bg@?a@t@yIVuDx@qKfA}N^aE@yE@qAIeDYaFBW\\eBFkANkANWd@gALc@PwAZiBb@qCFgCDcCGkCKoC`@gExBaVViDH}@kAOwAWe@Cg@BUDBU`@sERcCJ{BzFeB"; @Override - protected void startDemo() { + protected void startDemo(boolean isRestore) { List decodedPath = PolyUtil.decode(LINE); getMap().addPolyline(new PolylineOptions().addAll(decodedPath)); - getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.8256, 151.2395), 12)); + if (!isRestore) { + getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.8256, 151.2395), 12)); + } } } diff --git a/demo/src/main/java/com/google/maps/android/utils/demo/PolySimplifyDemoActivity.java b/demo/src/main/java/com/google/maps/android/utils/demo/PolySimplifyDemoActivity.java index 379f5249c..65cf52056 100644 --- a/demo/src/main/java/com/google/maps/android/utils/demo/PolySimplifyDemoActivity.java +++ b/demo/src/main/java/com/google/maps/android/utils/demo/PolySimplifyDemoActivity.java @@ -35,16 +35,18 @@ public class PolySimplifyDemoActivity extends BaseDemoActivity { private final static int ALPHA_ADJUSTMENT = 0x77000000; @Override - protected void startDemo() { - GoogleMap mMap = getMap(); + protected void startDemo(boolean isRestore) { + GoogleMap map = getMap(); // Original line List line = PolyUtil.decode(LINE); - mMap.addPolyline(new PolylineOptions() + map.addPolyline(new PolylineOptions() .addAll(line) .color(Color.BLACK)); - getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(28.05870, -82.4090), 15)); + if (!isRestore) { + map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(28.05870, -82.4090), 15)); + } List simplifiedLine; @@ -54,31 +56,31 @@ protected void startDemo() { */ double tolerance = 5; // meters simplifiedLine = PolyUtil.simplify(line, tolerance); - mMap.addPolyline(new PolylineOptions() + map.addPolyline(new PolylineOptions() .addAll(simplifiedLine) .color(Color.RED - ALPHA_ADJUSTMENT)); tolerance = 20; // meters simplifiedLine = PolyUtil.simplify(line, tolerance); - mMap.addPolyline(new PolylineOptions() + map.addPolyline(new PolylineOptions() .addAll(simplifiedLine) .color(Color.GREEN - ALPHA_ADJUSTMENT)); tolerance = 50; // meters simplifiedLine = PolyUtil.simplify(line, tolerance); - mMap.addPolyline(new PolylineOptions() + map.addPolyline(new PolylineOptions() .addAll(simplifiedLine) .color(Color.MAGENTA - ALPHA_ADJUSTMENT)); tolerance = 500; // meters simplifiedLine = PolyUtil.simplify(line, tolerance); - mMap.addPolyline(new PolylineOptions() + map.addPolyline(new PolylineOptions() .addAll(simplifiedLine) .color(Color.YELLOW - ALPHA_ADJUSTMENT)); tolerance = 1000; // meters simplifiedLine = PolyUtil.simplify(line, tolerance); - mMap.addPolyline(new PolylineOptions() + map.addPolyline(new PolylineOptions() .addAll(simplifiedLine) .color(Color.BLUE - ALPHA_ADJUSTMENT)); @@ -93,7 +95,7 @@ protected void startDemo() { triangle.add(new LatLng(28.06038, -82.40924)); triangle.add(new LatLng(28.06025,-82.41030)); // Should match first point - mMap.addPolygon(new PolygonOptions() + map.addPolygon(new PolygonOptions() .addAll(triangle) .fillColor(Color.BLUE - ALPHA_ADJUSTMENT) .strokeColor(Color.BLUE) @@ -102,7 +104,7 @@ protected void startDemo() { // Simplified triangle polygon tolerance = 88; // meters List simplifiedTriangle = PolyUtil.simplify(triangle, tolerance); - mMap.addPolygon(new PolygonOptions() + map.addPolygon(new PolygonOptions() .addAll(simplifiedTriangle) .fillColor(Color.YELLOW - ALPHA_ADJUSTMENT) .strokeColor(Color.YELLOW) @@ -110,7 +112,7 @@ protected void startDemo() { // Oval polygon - the polygon should be closed List oval = PolyUtil.decode(OVAL_POLYGON); - mMap.addPolygon(new PolygonOptions() + map.addPolygon(new PolygonOptions() .addAll(oval) .fillColor(Color.BLUE - ALPHA_ADJUSTMENT) .strokeColor(Color.BLUE) @@ -119,7 +121,7 @@ protected void startDemo() { // Simplified oval polygon tolerance = 10; // meters List simplifiedOval= PolyUtil.simplify(oval, tolerance); - mMap.addPolygon(new PolygonOptions() + map.addPolygon(new PolygonOptions() .addAll(simplifiedOval) .fillColor(Color.YELLOW - ALPHA_ADJUSTMENT) .strokeColor(Color.YELLOW) diff --git a/demo/src/main/java/com/google/maps/android/utils/demo/TileProviderAndProjectionDemo.java b/demo/src/main/java/com/google/maps/android/utils/demo/TileProviderAndProjectionDemo.java index 6bb5af209..e97b290a7 100644 --- a/demo/src/main/java/com/google/maps/android/utils/demo/TileProviderAndProjectionDemo.java +++ b/demo/src/main/java/com/google/maps/android/utils/demo/TileProviderAndProjectionDemo.java @@ -34,8 +34,9 @@ import java.util.List; public class TileProviderAndProjectionDemo extends BaseDemoActivity { + @Override - protected void startDemo() { + protected void startDemo(boolean isRestore) { PointTileOverlay pto = new PointTileOverlay(); pto.addPoint(new LatLng(0, 0)); pto.addPoint(new LatLng(21, -10)); diff --git a/demo/src/main/java/com/google/maps/android/utils/demo/VisibleClusteringDemoActivity.java b/demo/src/main/java/com/google/maps/android/utils/demo/VisibleClusteringDemoActivity.java index 061ca0019..3db559381 100644 --- a/demo/src/main/java/com/google/maps/android/utils/demo/VisibleClusteringDemoActivity.java +++ b/demo/src/main/java/com/google/maps/android/utils/demo/VisibleClusteringDemoActivity.java @@ -34,11 +34,13 @@ public class VisibleClusteringDemoActivity extends BaseDemoActivity { private ClusterManager mClusterManager; @Override - protected void startDemo() { + protected void startDemo(boolean isRestore) { DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); - getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.503186, -0.126446), 10)); + if (!isRestore) { + getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.503186, -0.126446), 10)); + } mClusterManager = new ClusterManager<>(this, getMap()); mClusterManager.setAlgorithm(new NonHierarchicalViewBasedAlgorithm(