From c66a69e650aa126e849fd955c962445b0f2db95d Mon Sep 17 00:00:00 2001 From: Antonio Zugaldia Date: Mon, 30 Nov 2015 15:43:58 -0500 Subject: [PATCH] Added sample `InfoWindowConcurrentActivity` to illustrate the behavior of multiple InfoWindows visible at a time (#3115). --- .../src/main/AndroidManifest.xml | 19 +--- .../testapp/InfoWindowConcurrentActivity.java | 107 ++++++++++++++++++ .../mapboxsdk/testapp/MainActivity.java | 4 + .../layout/activity_infowindow_concurrent.xml | 24 ++++ .../src/main/res/menu/menu_drawer.xml | 6 + .../src/main/res/values/strings.xml | 2 + 6 files changed, 149 insertions(+), 13 deletions(-) create mode 100644 android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowConcurrentActivity.java create mode 100644 android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_concurrent.xml diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index f01181fecaf..e600ef3b5c9 100644 --- a/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -13,7 +13,6 @@ android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> - @@ -23,39 +22,34 @@ - - - - + - - - - - + - @@ -63,7 +57,6 @@ - diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowConcurrentActivity.java b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowConcurrentActivity.java new file mode 100644 index 00000000000..ca2f1f353e2 --- /dev/null +++ b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/InfoWindowConcurrentActivity.java @@ -0,0 +1,107 @@ +package com.mapbox.mapboxsdk.testapp; + +import android.os.Bundle; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.MenuItem; + +import com.mapbox.mapboxsdk.annotations.MarkerOptions; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.utils.ApiAccess; +import com.mapbox.mapboxsdk.views.MapView; + +public class InfoWindowConcurrentActivity extends AppCompatActivity { + + private MapView mMapView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_infowindow_concurrent); + + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setDisplayShowHomeEnabled(true); + } + + mMapView = (MapView) findViewById(R.id.mapView); + mMapView.setAccessToken(ApiAccess.getToken(this)); + mMapView.onCreate(savedInstanceState); + + // Enable to let concurrent multiple infowindows to be shown. + mMapView.setAllowConcurrentMultipleOpenInfoWindows(true); + + mMapView.addMarker(new MarkerOptions() + .title("Intersection") + .snippet("H St NW with 15th St NW") + .position(new LatLng(38.9002073, -77.03364419))); + + mMapView.addMarker(new MarkerOptions() + .title("White House") + .snippet("The official residence and principal workplace of the President of the United States, located at 1600 Pennsylvania Avenue NW in Washington, D.C. It has been the residence of every U.S. president since John Adams in 1800.") + .position(new LatLng(38.897705003219784, -77.03655168667463))); + + mMapView.addMarker(new MarkerOptions().title("Intersection") + .snippet("E St NW with 17th St NW") + .position(new LatLng(38.8954236, -77.0394623))); + } + + @Override + protected void onStart() { + super.onStart(); + mMapView.onStart(); + } + + @Override + public void onResume() { + super.onResume(); + mMapView.onResume(); + } + + @Override + public void onPause() { + super.onPause(); + mMapView.onPause(); + } + + @Override + protected void onStop() { + super.onStop(); + mMapView.onStop(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mMapView.onSaveInstanceState(outState); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mMapView.onDestroy(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mMapView.onLowMemory(); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + onBackPressed(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + +} diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java index 1c9d611145f..570c85342e6 100644 --- a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java +++ b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java @@ -361,6 +361,10 @@ public boolean onNavigationItemSelected(MenuItem menuItem) { startActivity(new Intent(getApplicationContext(), InfoWindowActivity.class)); return true; + case R.id.action_info_window_concurrent: + startActivity(new Intent(getApplicationContext(), InfoWindowConcurrentActivity.class)); + return true; + case R.id.action_visible_bounds: startActivity(new Intent(getApplicationContext(), VisibleCoordinateBoundsActivity.class)); return true; diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_concurrent.xml b/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_concurrent.xml new file mode 100644 index 00000000000..c2c3210589d --- /dev/null +++ b/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_concurrent.xml @@ -0,0 +1,24 @@ + + + + + + + + diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml b/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml index 8c48894ac9b..69c3f7e5931 100644 --- a/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml +++ b/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_drawer.xml @@ -78,6 +78,12 @@ android:icon="@drawable/ic_flip_to_front_24dp" android:title="@string/action_info_window" /> + + Add Bulk Markers Activity Manual Zoom Activity InfoWindow Activity + InfoWindow Activity (Concurrent) Visible Coordinate Bounds User tracking mode Polyline Activity @@ -27,6 +28,7 @@ Press For Marker Manual Zoom InfoWindow + InfoWindow (Concurrent) Add Markers in bulk Set Visible Bounds Center map around 2 markers