Added "Improve this map" functionality, current zoom level, center latitude and longitude will be parsed in to the url of improve this map.

This commit is contained in:
tobrun
2015-09-06 16:37:34 +02:00
committed by Justin R. Miller
parent 9a6924435b
commit e7398c16c1
2 changed files with 18 additions and 6 deletions

View File

@@ -120,6 +120,8 @@ public class MapView extends FrameLayout implements LocationListener {
private static final float DIMENSION_SIXTEEN_DP = 16f;
private static final float DIMENSION_TEN_DP = 10f;
private static final int IMPROVE_THIS_MAP_INDEX = 2;
/**
* Every annotation that has been added to the map.
*/
@@ -425,7 +427,7 @@ public class MapView extends FrameLayout implements LocationListener {
LayoutParams attrParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
mAttributionsView.setLayoutParams(attrParams);
addView(mAttributionsView);
mAttributionsView.setOnClickListener(new AttributionOnClickListener());
mAttributionsView.setOnClickListener(new AttributionOnClickListener(this));
// Setup Support For Listener Tracking
// MapView's internal listener is setup in onCreate()
@@ -2040,6 +2042,12 @@ public class MapView extends FrameLayout implements LocationListener {
private static class AttributionOnClickListener implements View.OnClickListener, DialogInterface.OnClickListener {
private MapView mMapView;
public AttributionOnClickListener(MapView mapView) {
mMapView = mapView;
}
// Called when someone presses the attribution icon
@Override
public void onClick(View v) {
@@ -2051,13 +2059,17 @@ public class MapView extends FrameLayout implements LocationListener {
builder.show();
}
// Called when someone selects an attribution
// Called when someone selects an attribution, 'Improve this map' adds location data to the url
@Override
public void onClick(DialogInterface dialog, int which) {
Context context = ((Dialog)dialog).getContext();
String[]links = context.getResources().getStringArray(R.array.attribution_links);
Context context = ((Dialog) dialog).getContext();
String url = context.getResources().getStringArray(R.array.attribution_links)[which];
if (which == IMPROVE_THIS_MAP_INDEX) {
LatLng latLng = mMapView.getCenterCoordinate();
url = String.format(url, latLng.getLongitude(), latLng.getLatitude(), (int) mMapView.getZoomLevel());
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(links[which]));
intent.setData(Uri.parse(url));
context.startActivity(intent);
}
}

View File

@@ -8,6 +8,6 @@
<array name="attribution_links" formatted="false" translatable="false">
<item>https://www.mapbox.com/about/maps/</item>
<item>http://www.openstreetmap.org/about/</item>
<item>https://www.mapbox.com/map-feedback</item>
<item>https://www.mapbox.com/map-feedback/#/%1$f/%2$f/%3$d</item>
</array>
</resources>