Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Differentiate between initial start and configuration change restore #567

Merged
merged 1 commit into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ public class BigClusteringDemoActivity extends BaseDemoActivity {
private ClusterManager<MyItem> 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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ public class ClusteringDemoActivity extends BaseDemoActivity {
private ClusterManager<MyItem> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Person>(this, getMap());
mClusterManager.setRenderer(new PersonRenderer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -151,7 +152,5 @@ public void onFeatureClick(Feature feature) {
}

});

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -218,5 +220,4 @@ public String getUrl() {
return mUrl;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@
*/
public class HeatmapsPlacesDemoActivity extends BaseDemoActivity {

private GoogleMap mMap = null;

private final LatLng SYDNEY = new LatLng(-33.873651, 151.2058896);

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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));
}

/**
Expand All @@ -182,15 +174,15 @@ 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();
} else if (mOverlaysRendered == MAX_CHECKBOXES) {
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("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<LatLng> 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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<LatLng> 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<LatLng> simplifiedLine;

Expand All @@ -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));

Expand All @@ -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)
Expand All @@ -102,15 +104,15 @@ 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)
.strokeWidth(5));

// Oval polygon - the polygon should be closed
List<LatLng> oval = PolyUtil.decode(OVAL_POLYGON);
mMap.addPolygon(new PolygonOptions()
map.addPolygon(new PolygonOptions()
.addAll(oval)
.fillColor(Color.BLUE - ALPHA_ADJUSTMENT)
.strokeColor(Color.BLUE)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ public class VisibleClusteringDemoActivity extends BaseDemoActivity {
private ClusterManager<MyItem> 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<MyItem>(
Expand Down