summaryrefslogtreecommitdiff
path: root/android/MapboxGLAndroidSDKTestApp
diff options
context:
space:
mode:
authorLeith Bade <leith@mapbox.com>2015-10-30 15:44:17 +1100
committerLeith Bade <leith@mapbox.com>2015-10-31 09:49:37 +1100
commit009930ab8edbc5bf06a1da296ea5e6e09ad697db (patch)
tree21eaf20b6336c93af6e06c916bd0310393abac6f /android/MapboxGLAndroidSDKTestApp
parente0fd0fc071f309c70ffa16410c54a1931eb274c5 (diff)
downloadqtlocation-mapboxgl-009930ab8edbc5bf06a1da296ea5e6e09ad697db.tar.gz
[android] Save added markers in test app
Fixes #2877
Diffstat (limited to 'android/MapboxGLAndroidSDKTestApp')
-rw-r--r--android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java26
-rw-r--r--android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java33
2 files changed, 43 insertions, 16 deletions
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 29d6de7f4f..32cff91ced 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
@@ -55,10 +55,14 @@ public class MainActivity extends AppCompatActivity {
// Used for saving instance state
private static final String STATE_IS_ANNOTATIONS_ON = "isAnnotationsOn";
private static final String STATE_SELECTED_STYLE = "selectedStyle";
+ private static final String STATE_MARKER_LIST = "markerList";
// Used for permissions requests
private static final int PERMISSIONS_LOCATION = 0;
+ // Used for info window
+ private static final DecimalFormat LAT_LON_FORMATTER = new DecimalFormat("#.#####");
+
//
// Instance members
//
@@ -76,8 +80,7 @@ public class MainActivity extends AppCompatActivity {
// Used for Annotations
private boolean mIsAnnotationsOn = false;
-
- private static final DecimalFormat latLngFormatter = new DecimalFormat("#.#####");
+ private ArrayList<MarkerOptions> mMarkerList = new ArrayList<>();
//
// Lifecycle events
@@ -119,20 +122,23 @@ public class MainActivity extends AppCompatActivity {
mMapView.setOnMapLongClickListener(new MapView.OnMapLongClickListener() {
@Override
public void onMapLongClick(@NonNull LatLng point) {
- mMapView.addMarker(new MarkerOptions()
+ MarkerOptions marker = new MarkerOptions()
.position(point)
.title("Dropped Pin")
- .snippet(latLngFormatter.format(point.getLatitude()) + ", " +
- latLngFormatter.format(point.getLongitude()))
- .icon(null));
+ .snippet(LAT_LON_FORMATTER.format(point.getLatitude()) + ", " +
+ LAT_LON_FORMATTER.format(point.getLongitude()))
+ .icon(null);
+
+ mMarkerList.add(marker);
+ mMapView.addMarker(marker);
}
});
mMapView.setOnMapClickListener(new MapView.OnMapClickListener() {
@Override
public void onMapClick(@NonNull LatLng point) {
- String location = latLngFormatter.format(point.getLatitude()) + ", " +
- latLngFormatter.format(point.getLongitude());
+ String location = LAT_LON_FORMATTER.format(point.getLatitude()) + ", " +
+ LAT_LON_FORMATTER.format(point.getLongitude());
Snackbar.make(mCoordinatorLayout, "Map Click Listener " + location, Snackbar.LENGTH_SHORT).show();
}
});
@@ -190,6 +196,8 @@ public class MainActivity extends AppCompatActivity {
if (savedInstanceState != null) {
mIsAnnotationsOn = savedInstanceState.getBoolean(STATE_IS_ANNOTATIONS_ON);
mSelectedStyle = savedInstanceState.getInt(STATE_SELECTED_STYLE);
+ mMarkerList = savedInstanceState.getParcelableArrayList(STATE_MARKER_LIST);
+ mMapView.addMarkers(mMarkerList);
}
// Set default UI state
@@ -249,6 +257,7 @@ public class MainActivity extends AppCompatActivity {
mMapView.onSaveInstanceState(outState);
outState.putBoolean(STATE_IS_ANNOTATIONS_ON, mIsAnnotationsOn);
outState.putInt(STATE_SELECTED_STYLE, mSelectedStyle);
+ outState.putParcelableArrayList(STATE_MARKER_LIST, mMarkerList);
}
// Called when the system is running low on memory
@@ -515,6 +524,7 @@ public class MainActivity extends AppCompatActivity {
}
private void removeAnnotations() {
+ mMarkerList.clear();
mMapView.removeAllAnnotations();
}
diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java
index b24ef84cad..1a4257c517 100644
--- a/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java
+++ b/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java
@@ -6,25 +6,26 @@ import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
-import android.view.GestureDetector;
import android.view.MenuItem;
-import android.view.MotionEvent;
-import android.view.View;
import android.view.ViewGroup;
-import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
+
import java.text.DecimalFormat;
+import java.util.ArrayList;
public class PressForMarkerActivity extends AppCompatActivity implements MapView.OnMapLongClickListener {
private MapView mMapView;
+ private ArrayList<MarkerOptions> mMarkerList = new ArrayList<>();
+
+ private static final DecimalFormat LAT_LON_FORMATTER = new DecimalFormat("#.#####");
- private static final DecimalFormat latLonFormatter = new DecimalFormat("#.#####");
+ private static String STATE_MARKER_LIST = "markerList";
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -47,19 +48,35 @@ public class PressForMarkerActivity extends AppCompatActivity implements MapView
mMapView.setZoomLevel(11);
mMapView.setOnMapLongClickListener(this);
((ViewGroup) findViewById(R.id.activity_container)).addView(mMapView);
+
+ if (savedInstanceState != null) {
+ mMarkerList = savedInstanceState.getParcelableArrayList(STATE_MARKER_LIST);
+ mMapView.addMarkers(mMarkerList);
+ }
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+
+ mMapView.onSaveInstanceState(outState);
+ outState.putParcelableArrayList(STATE_MARKER_LIST, mMarkerList);
}
@Override
public void onMapLongClick(@NonNull LatLng point) {
final PointF pixel = mMapView.toScreenLocation(point);
- String title = latLonFormatter.format(point.getLatitude()) + ", " + latLonFormatter.format(point.getLongitude());
+ String title = LAT_LON_FORMATTER.format(point.getLatitude()) + ", " + LAT_LON_FORMATTER.format(point.getLongitude());
String snippet = "X = " + (int) pixel.x + ", Y = " + (int) pixel.y;
- mMapView.addMarker(new MarkerOptions()
+ MarkerOptions marker = new MarkerOptions()
.position(point)
.title(title)
- .snippet(snippet));
+ .snippet(snippet);
+
+ mMarkerList.add(marker);
+ mMapView.addMarker(marker);
}
/**