From d40765ea69996dac3af4158b1267f5e753973fe3 Mon Sep 17 00:00:00 2001 From: Stephen McDonald Date: Wed, 8 Jun 2016 16:15:07 +1000 Subject: [PATCH 1/8] Add support for click listeners on GeoJSON layers. --- .../utils/demo/GeoJsonDemoActivity.java | 7 ++ .../com/google/maps/android/BiMultiMap.java | 58 ++++++++++++++++ .../maps/android/geojson/GeoJsonLayer.java | 66 +++++++++++++++++++ .../maps/android/geojson/GeoJsonRenderer.java | 23 +++++-- .../google/maps/android/BiMultiMapTest.java | 44 +++++++++++++ 5 files changed, 191 insertions(+), 7 deletions(-) create mode 100644 library/src/com/google/maps/android/BiMultiMap.java create mode 100644 library/tests/src/com/google/maps/android/BiMultiMapTest.java diff --git a/demo/src/com/google/maps/android/utils/demo/GeoJsonDemoActivity.java b/demo/src/com/google/maps/android/utils/demo/GeoJsonDemoActivity.java index c98d40c37..c6a8a786f 100644 --- a/demo/src/com/google/maps/android/utils/demo/GeoJsonDemoActivity.java +++ b/demo/src/com/google/maps/android/utils/demo/GeoJsonDemoActivity.java @@ -122,6 +122,13 @@ protected void onPostExecute(JSONObject jsonObject) { // Add the layer onto the map addColorsToMarkers(); mLayer.addLayerToMap(); + + mLayer.setOnFeatureClickListener(new GeoJsonLayer.GeoJsonOnFeatureClickListener() { + @Override + public void onFeatureClick(GeoJsonFeature feature) { + Log.i(mLogTag, "Feature clicked: " + feature.getProperty("title")); + } + }); } } diff --git a/library/src/com/google/maps/android/BiMultiMap.java b/library/src/com/google/maps/android/BiMultiMap.java new file mode 100644 index 000000000..e2431ecbb --- /dev/null +++ b/library/src/com/google/maps/android/BiMultiMap.java @@ -0,0 +1,58 @@ +package com.google.maps.android; + +import java.util.Collection; +import java.util.HashMap; + +/** + * Extension of HashMap that provides two main features. Firstly it allows reverse lookup + * for a key given a value, by storing a second HashMap internally which maps values to keys. + * Secondly, it supports Collection values, in which case, each item in the collection is + * used as a key in the internal reverse HashMap. It's therefore up to the caller to ensure + * the overall set of values, and collection values, are unique. + * + * Used by GeoJsonRenderer to store GeoJsonFeature instances mapped to corresponding Marker, + * Polyline, and Polygon map objects. We want to look these up in reverse to provide access + * to GeoJsonFeature instances when map objects are clicked. + */ +public class BiMultiMap extends HashMap { + + private final HashMap mValuesToKeys = new HashMap<>(); + + public void putAll(HashMap map) { + // put() manages the reverse map, so call it on each entry. + for (Entry entry : map.entrySet()) { + put(entry.getKey(), entry.getValue()); + } + } + + @Override + public Object put(K key, Object value) { + // Store value/key in the reverse map, and store each item in the value + // if the value is a collection. + if (value instanceof Collection) { + for (Object valueItem: (Collection) value) { + mValuesToKeys.put(valueItem, key); + } + } else { + mValuesToKeys.put(value, key); + } + return super.put(key, value); + } + + public Object remove(Object key) { + // Also remove the value/key from the reverse map. + mValuesToKeys.remove(get(key)); + return super.remove(key); + } + + /** + * Reverse lookup of key by value. + * + * @param value Object value to lookup + * @return K the key for the given value + */ + public K getKey(Object value) { + return mValuesToKeys.get(value); + } + +} diff --git a/library/src/com/google/maps/android/geojson/GeoJsonLayer.java b/library/src/com/google/maps/android/geojson/GeoJsonLayer.java index e1997b0d1..051ad2655 100644 --- a/library/src/com/google/maps/android/geojson/GeoJsonLayer.java +++ b/library/src/com/google/maps/android/geojson/GeoJsonLayer.java @@ -2,6 +2,9 @@ import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.model.LatLngBounds; +import com.google.android.gms.maps.model.Marker; +import com.google.android.gms.maps.model.Polygon; +import com.google.android.gms.maps.model.Polyline; import org.json.JSONException; import org.json.JSONObject; @@ -70,6 +73,69 @@ public GeoJsonLayer(GoogleMap map, int resourceId, Context context) this(map, createJsonFileObject(context.getResources().openRawResource(resourceId))); } + /** + * Sets a single click listener for the entire GoogleMap object, that will be called + * with the corresponding GeoJsonFeature object when an object on the map (Polygon, + * Marker, Polyline) is clicked. + * + * Note that if multiple GeoJsonLayer objects are bound to a GoogleMap object, calling + * setOnFeatureClickListener on one will override the listener defined on the other. In + * that case, you must define each of the GoogleMap click listeners manually + * (OnPolygonClickListener, OnMarkerClickListener, OnPolylineClickListener), and then + * use the GeoJsonLayer.getFeature(mapObject) method on each GeoJsonLayer instance to + * determine if the given mapObject belongs to the layer. + * + * @param listener GeoJsonOnFeatureClickListener object providing the onFeatureClick + * method to call. + */ + public void setOnFeatureClickListener(final GeoJsonOnFeatureClickListener listener) { + + GoogleMap map = getMap(); + + map.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() { + @Override + public void onPolygonClick(Polygon polygon) { + listener.onFeatureClick(getFeature(polygon)); + } + }); + + map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { + @Override + public boolean onMarkerClick(Marker marker) { + listener.onFeatureClick(getFeature(marker)); + return false; + } + }); + + map.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() { + @Override + public void onPolylineClick(Polyline polyline) { + listener.onFeatureClick(getFeature(polyline)); + } + }); + + } + + /** + * Callback interface for when a GeoJsonLayer's map object is clicked. + */ + public interface GeoJsonOnFeatureClickListener { + void onFeatureClick(GeoJsonFeature feature); + } + + /** + * Retrieves a corresponding GeoJsonFeature instance for the given map object + * (Polygon, Marker, Polyline). Made available so that maps with multiple layers + * can implement their own click listeners and determine which layer the + * corresponding feature belongs to. + * + * @param mapObject Object map object, presumably clicked on + * @return GeoJsonFeature for the given map object clicked on + */ + public GeoJsonFeature getFeature(Object mapObject) { + return mRenderer.getFeature(mapObject); + } + /** * Takes a character input stream and converts it into a JSONObject * diff --git a/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java b/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java index d1a82393b..83b25d0e3 100644 --- a/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java +++ b/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java @@ -7,6 +7,7 @@ import com.google.android.gms.maps.model.PolygonOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; +import com.google.maps.android.BiMultiMap; import java.util.ArrayList; import java.util.HashMap; @@ -27,11 +28,7 @@ private final static Object FEATURE_NOT_ON_MAP = null; - /** - * Value is a Marker, Polyline, Polygon or an array of these that have been created from the - * corresponding key - */ - private final HashMap mFeatures; + private final BiMultiMap mFeatures = new BiMultiMap<>(); private final GeoJsonPointStyle mDefaultPointStyle; @@ -50,7 +47,7 @@ */ /* package */ GeoJsonRenderer(GoogleMap map, HashMap features) { mMap = map; - mFeatures = features; + mFeatures.putAll(features); mLayerOnMap = false; mDefaultPointStyle = new GeoJsonPointStyle(); mDefaultLineStringStyle = new GeoJsonLineStringStyle(); @@ -128,6 +125,16 @@ private static void removeFromMap(Object mapObject) { return mFeatures.keySet(); } + /** + * Gets a GeoJsonFeature for the given mapObject, which is a Marker, Polyline or Polygon. + * + * @param mapObject Object a Marker, Polyline or Polygon + * @return GeoJsonFeature for the given mapObject + */ + public GeoJsonFeature getFeature(Object mapObject) { + return mFeatures.getKey(mapObject); + } + /** * Checks for each style in the feature and adds a default style if none is applied * @@ -333,7 +340,9 @@ private Polygon addPolygonToMap(GeoJsonPolygonStyle polygonStyle, GeoJsonPolygon i++) { polygonOptions.addHole(polygon.getCoordinates().get(i)); } - return mMap.addPolygon(polygonOptions); + Polygon addedPolygon = mMap.addPolygon(polygonOptions); + addedPolygon.setClickable(true); + return addedPolygon; } /** diff --git a/library/tests/src/com/google/maps/android/BiMultiMapTest.java b/library/tests/src/com/google/maps/android/BiMultiMapTest.java new file mode 100644 index 000000000..9a1b4e96d --- /dev/null +++ b/library/tests/src/com/google/maps/android/BiMultiMapTest.java @@ -0,0 +1,44 @@ +package com.google.maps.android; + +import junit.framework.TestCase; + +import java.util.Arrays; +import java.util.List; + +public class BiMultiMapTest extends TestCase { + + private BiMultiMap mMap = new BiMultiMap<>(); + + public void testSingle() { + String key = "foo"; + String value = "bar"; + mMap.clear(); + mMap.put(key, value); + assertEquals(mMap.size(), 1); + assertEquals(mMap.get(key), value); + assertEquals(mMap.getKey(value), key); + mMap.remove(key); + assertEquals(mMap.size(), 0); + assertNull(mMap.get(key)); + assertNull(mMap.getKey(value)); + } + + public void testMulti() { + String key = "foo"; + List values = Arrays.asList("bar", "baz"); + mMap.clear(); + mMap.put(key, values); + assertEquals(mMap.size(), 1); + assertEquals(mMap.get(key), values); + for (String value : values) { + assertEquals(mMap.getKey(value), key); + } + mMap.remove(key); + assertEquals(mMap.size(), 0); + assertNull(mMap.get(key)); + for (String value : values) { + assertEquals(mMap.getKey(value), key); + } + } + +} From 504e1a4029e06f14174b4a8e28ae8c1d06df296a Mon Sep 17 00:00:00 2001 From: Stephen McDonald Date: Thu, 9 Jun 2016 15:32:33 +1000 Subject: [PATCH 2/8] Use toast in GeoJSON clickable layer demo. --- .../maps/android/utils/demo/GeoJsonDemoActivity.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/demo/src/com/google/maps/android/utils/demo/GeoJsonDemoActivity.java b/demo/src/com/google/maps/android/utils/demo/GeoJsonDemoActivity.java index c6a8a786f..544a0f690 100644 --- a/demo/src/com/google/maps/android/utils/demo/GeoJsonDemoActivity.java +++ b/demo/src/com/google/maps/android/utils/demo/GeoJsonDemoActivity.java @@ -11,6 +11,7 @@ import android.os.AsyncTask; import android.util.Log; +import android.widget.Toast; import java.io.BufferedReader; import java.io.IOException; @@ -83,6 +84,10 @@ private void addColorsToMarkers() { } } + private void showToast(String message) { + Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); + } + private class DownloadGeoJsonFile extends AsyncTask { @Override @@ -126,7 +131,7 @@ protected void onPostExecute(JSONObject jsonObject) { mLayer.setOnFeatureClickListener(new GeoJsonLayer.GeoJsonOnFeatureClickListener() { @Override public void onFeatureClick(GeoJsonFeature feature) { - Log.i(mLogTag, "Feature clicked: " + feature.getProperty("title")); + showToast("Feature clicked: " + feature.getProperty("title")); } }); } From 2d6a81025f7c443048c1ab7f9d2998190cc6bbff Mon Sep 17 00:00:00 2001 From: Stephen McDonald Date: Thu, 9 Jun 2016 15:36:20 +1000 Subject: [PATCH 3/8] Make GeoJsonLayer.getFeature() type-safe. --- .../maps/android/geojson/GeoJsonLayer.java | 39 +++++++++++++++---- .../maps/android/geojson/GeoJsonRenderer.java | 2 +- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/library/src/com/google/maps/android/geojson/GeoJsonLayer.java b/library/src/com/google/maps/android/geojson/GeoJsonLayer.java index 051ad2655..7fcf451b8 100644 --- a/library/src/com/google/maps/android/geojson/GeoJsonLayer.java +++ b/library/src/com/google/maps/android/geojson/GeoJsonLayer.java @@ -124,16 +124,39 @@ public interface GeoJsonOnFeatureClickListener { } /** - * Retrieves a corresponding GeoJsonFeature instance for the given map object - * (Polygon, Marker, Polyline). Made available so that maps with multiple layers - * can implement their own click listeners and determine which layer the - * corresponding feature belongs to. + * Retrieves a corresponding GeoJsonFeature instance for the given Polygon + * Allows maps with multiple layers to determine which layer the Polygon + * belongs to. * - * @param mapObject Object map object, presumably clicked on - * @return GeoJsonFeature for the given map object clicked on + * @param polygon Polygon map object + * @return GeoJsonFeature for the given polygon */ - public GeoJsonFeature getFeature(Object mapObject) { - return mRenderer.getFeature(mapObject); + public GeoJsonFeature getFeature(Polygon polygon) { + return mRenderer.getFeature(polygon); + } + + /** + * Retrieves a corresponding GeoJsonFeature instance for the given Polyline + * Allows maps with multiple layers to determine which layer the Polyline + * belongs to. + * + * @param polyline Polyline map object + * @return GeoJsonFeature for the given polyline + */ + public GeoJsonFeature getFeature(Polyline polyline) { + return mRenderer.getFeature(polyline); + } + + /** + * Retrieves a corresponding GeoJsonFeature instance for the given Marker + * Allows maps with multiple layers to determine which layer the Marker + * belongs to. + * + * @param marker Marker map object + * @return GeoJsonFeature for the given marker + */ + public GeoJsonFeature getFeature(Marker marker) { + return mRenderer.getFeature(marker); } /** diff --git a/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java b/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java index 83b25d0e3..7a11356ee 100644 --- a/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java +++ b/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java @@ -131,7 +131,7 @@ private static void removeFromMap(Object mapObject) { * @param mapObject Object a Marker, Polyline or Polygon * @return GeoJsonFeature for the given mapObject */ - public GeoJsonFeature getFeature(Object mapObject) { + /* package */ GeoJsonFeature getFeature(Object mapObject) { return mFeatures.getKey(mapObject); } From 61ab2f045c4fdb1f48776dd60926746782ee862b Mon Sep 17 00:00:00 2001 From: Stephen McDonald Date: Thu, 9 Jun 2016 16:11:51 +1000 Subject: [PATCH 4/8] Fix BiMultiMap.remove() and implement missing methods (clear, clone). --- .../com/google/maps/android/BiMultiMap.java | 55 ++++++++++++++----- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/library/src/com/google/maps/android/BiMultiMap.java b/library/src/com/google/maps/android/BiMultiMap.java index e2431ecbb..b9cc7090b 100644 --- a/library/src/com/google/maps/android/BiMultiMap.java +++ b/library/src/com/google/maps/android/BiMultiMap.java @@ -2,6 +2,7 @@ import java.util.Collection; import java.util.HashMap; +import java.util.Map; /** * Extension of HashMap that provides two main features. Firstly it allows reverse lookup @@ -16,40 +17,64 @@ */ public class BiMultiMap extends HashMap { - private final HashMap mValuesToKeys = new HashMap<>(); + private final Map mValuesToKeys = new HashMap<>(); - public void putAll(HashMap map) { + @Override + public void putAll(Map map) { // put() manages the reverse map, so call it on each entry. - for (Entry entry : map.entrySet()) { + for (Entry entry : map.entrySet()) { put(entry.getKey(), entry.getValue()); } } @Override public Object put(K key, Object value) { - // Store value/key in the reverse map, and store each item in the value - // if the value is a collection. + // Store value/key in the reverse map. + mValuesToKeys.put(value, key); + return super.put(key, value); + } + + public Object put(K key, Collection values) { + // Store values/key in the reverse map. + for (Object value : values) { + mValuesToKeys.put(value, key); + } + return super.put(key, values); + } + + @Override + public Object remove(Object key) { + Object value = super.remove(key); + // Also remove the value(s) and key from the reverse map. if (value instanceof Collection) { - for (Object valueItem: (Collection) value) { - mValuesToKeys.put(valueItem, key); + for (Object valueItem : (Collection) value) { + mValuesToKeys.remove(valueItem); } } else { - mValuesToKeys.put(value, key); + mValuesToKeys.remove(value); } - return super.put(key, value); + return value; } - public Object remove(Object key) { - // Also remove the value/key from the reverse map. - mValuesToKeys.remove(get(key)); - return super.remove(key); + @Override + public void clear() { + super.clear(); + mValuesToKeys.clear(); + } + + @SuppressWarnings("unchecked") + @Override + public BiMultiMap clone() { + BiMultiMap cloned = new BiMultiMap<>(); + cloned.putAll((Map) super.clone()); + return cloned; } /** * Reverse lookup of key by value. * - * @param value Object value to lookup - * @return K the key for the given value + * @param value Value to lookup + * @return Key for the given value */ public K getKey(Object value) { return mValuesToKeys.get(value); From 54a71f5d18ffacca3d543a83721b29a0abec5086 Mon Sep 17 00:00:00 2001 From: Stephen McDonald Date: Fri, 10 Jun 2016 10:12:11 +1000 Subject: [PATCH 5/8] Better isolation and correct assertion orders in BiMultiMapTest --- .../google/maps/android/BiMultiMapTest.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/library/tests/src/com/google/maps/android/BiMultiMapTest.java b/library/tests/src/com/google/maps/android/BiMultiMapTest.java index 9a1b4e96d..ce1cadbb7 100644 --- a/library/tests/src/com/google/maps/android/BiMultiMapTest.java +++ b/library/tests/src/com/google/maps/android/BiMultiMapTest.java @@ -7,37 +7,37 @@ public class BiMultiMapTest extends TestCase { - private BiMultiMap mMap = new BiMultiMap<>(); - public void testSingle() { + BiMultiMap mMap = new BiMultiMap<>(); String key = "foo"; String value = "bar"; mMap.clear(); mMap.put(key, value); - assertEquals(mMap.size(), 1); - assertEquals(mMap.get(key), value); - assertEquals(mMap.getKey(value), key); + assertEquals(1, mMap.size()); + assertEquals(value, mMap.get(key)); + assertEquals(key, mMap.getKey(value)); mMap.remove(key); - assertEquals(mMap.size(), 0); + assertEquals(0, mMap.size()); assertNull(mMap.get(key)); assertNull(mMap.getKey(value)); } public void testMulti() { + BiMultiMap mMap = new BiMultiMap<>(); String key = "foo"; List values = Arrays.asList("bar", "baz"); mMap.clear(); mMap.put(key, values); - assertEquals(mMap.size(), 1); - assertEquals(mMap.get(key), values); + assertEquals(1, mMap.size()); + assertEquals(values, mMap.get(key)); for (String value : values) { - assertEquals(mMap.getKey(value), key); + assertEquals(key, mMap.getKey(value)); } mMap.remove(key); - assertEquals(mMap.size(), 0); + assertEquals(0, mMap.size()); assertNull(mMap.get(key)); for (String value : values) { - assertEquals(mMap.getKey(value), key); + assertEquals(null, mMap.getKey(value)); } } From 5ac809c0b0fb124f69942414546e3dc6aefe70ea Mon Sep 17 00:00:00 2001 From: Stephen McDonald Date: Fri, 10 Jun 2016 10:20:35 +1000 Subject: [PATCH 6/8] Javadoc fixes --- .../com/google/maps/android/geojson/GeoJsonLayer.java | 9 ++++----- .../com/google/maps/android/geojson/GeoJsonRenderer.java | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/library/src/com/google/maps/android/geojson/GeoJsonLayer.java b/library/src/com/google/maps/android/geojson/GeoJsonLayer.java index 7fcf451b8..ae8a316de 100644 --- a/library/src/com/google/maps/android/geojson/GeoJsonLayer.java +++ b/library/src/com/google/maps/android/geojson/GeoJsonLayer.java @@ -85,8 +85,7 @@ public GeoJsonLayer(GoogleMap map, int resourceId, Context context) * use the GeoJsonLayer.getFeature(mapObject) method on each GeoJsonLayer instance to * determine if the given mapObject belongs to the layer. * - * @param listener GeoJsonOnFeatureClickListener object providing the onFeatureClick - * method to call. + * @param listener Listener providing the onFeatureClick method to call. */ public void setOnFeatureClickListener(final GeoJsonOnFeatureClickListener listener) { @@ -128,7 +127,7 @@ public interface GeoJsonOnFeatureClickListener { * Allows maps with multiple layers to determine which layer the Polygon * belongs to. * - * @param polygon Polygon map object + * @param polygon Polygon * @return GeoJsonFeature for the given polygon */ public GeoJsonFeature getFeature(Polygon polygon) { @@ -140,7 +139,7 @@ public GeoJsonFeature getFeature(Polygon polygon) { * Allows maps with multiple layers to determine which layer the Polyline * belongs to. * - * @param polyline Polyline map object + * @param polyline Polyline * @return GeoJsonFeature for the given polyline */ public GeoJsonFeature getFeature(Polyline polyline) { @@ -152,7 +151,7 @@ public GeoJsonFeature getFeature(Polyline polyline) { * Allows maps with multiple layers to determine which layer the Marker * belongs to. * - * @param marker Marker map object + * @param marker Marker * @return GeoJsonFeature for the given marker */ public GeoJsonFeature getFeature(Marker marker) { diff --git a/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java b/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java index 7a11356ee..0e630a150 100644 --- a/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java +++ b/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java @@ -126,10 +126,10 @@ private static void removeFromMap(Object mapObject) { } /** - * Gets a GeoJsonFeature for the given mapObject, which is a Marker, Polyline or Polygon. + * Gets a GeoJsonFeature for the given map object, which is a Marker, Polyline or Polygon. * - * @param mapObject Object a Marker, Polyline or Polygon - * @return GeoJsonFeature for the given mapObject + * @param mapObject Marker, Polyline or Polygon + * @return GeoJsonFeature for the given map object */ /* package */ GeoJsonFeature getFeature(Object mapObject) { return mFeatures.getKey(mapObject); From 251159e307d4555a20f80e55d7215f2a97f184de Mon Sep 17 00:00:00 2001 From: Stephen McDonald Date: Fri, 10 Jun 2016 10:27:13 +1000 Subject: [PATCH 7/8] Make GeoJSON Polylines clickable. --- .../src/com/google/maps/android/geojson/GeoJsonRenderer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java b/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java index 0e630a150..a37862629 100644 --- a/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java +++ b/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java @@ -304,7 +304,9 @@ private Polyline addLineStringToMap(GeoJsonLineStringStyle lineStringStyle, PolylineOptions polylineOptions = lineStringStyle.toPolylineOptions(); // Add coordinates polylineOptions.addAll(lineString.getCoordinates()); - return mMap.addPolyline(polylineOptions); + Polyline addedPolyline = mMap.addPolyline(polylineOptions); + addedPolyline.setClickable(true); + return addedPolyline; } /** From dcf33d688079ef8c15a4ad0c89824e16611e14db Mon Sep 17 00:00:00 2001 From: Stephen McDonald Date: Fri, 10 Jun 2016 11:59:01 +1000 Subject: [PATCH 8/8] Make BiMultiMap package private. --- .../android/{ => geojson}/BiMultiMap.java | 4 +- .../maps/android/geojson/GeoJsonRenderer.java | 1 - .../google/maps/android/BiMultiMapTest.java | 44 ------------------- .../maps/android/geojson/BiMultiMapTest.java | 42 ++++++++++++++++++ 4 files changed, 44 insertions(+), 47 deletions(-) rename library/src/com/google/maps/android/{ => geojson}/BiMultiMap.java (95%) delete mode 100644 library/tests/src/com/google/maps/android/BiMultiMapTest.java create mode 100644 library/tests/src/com/google/maps/android/geojson/BiMultiMapTest.java diff --git a/library/src/com/google/maps/android/BiMultiMap.java b/library/src/com/google/maps/android/geojson/BiMultiMap.java similarity index 95% rename from library/src/com/google/maps/android/BiMultiMap.java rename to library/src/com/google/maps/android/geojson/BiMultiMap.java index b9cc7090b..6f5a3ed2d 100644 --- a/library/src/com/google/maps/android/BiMultiMap.java +++ b/library/src/com/google/maps/android/geojson/BiMultiMap.java @@ -1,4 +1,4 @@ -package com.google.maps.android; +package com.google.maps.android.geojson; import java.util.Collection; import java.util.HashMap; @@ -15,7 +15,7 @@ * Polyline, and Polygon map objects. We want to look these up in reverse to provide access * to GeoJsonFeature instances when map objects are clicked. */ -public class BiMultiMap extends HashMap { +/* package */ class BiMultiMap extends HashMap { private final Map mValuesToKeys = new HashMap<>(); diff --git a/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java b/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java index a37862629..f5564bb63 100644 --- a/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java +++ b/library/src/com/google/maps/android/geojson/GeoJsonRenderer.java @@ -7,7 +7,6 @@ import com.google.android.gms.maps.model.PolygonOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; -import com.google.maps.android.BiMultiMap; import java.util.ArrayList; import java.util.HashMap; diff --git a/library/tests/src/com/google/maps/android/BiMultiMapTest.java b/library/tests/src/com/google/maps/android/BiMultiMapTest.java deleted file mode 100644 index ce1cadbb7..000000000 --- a/library/tests/src/com/google/maps/android/BiMultiMapTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.google.maps.android; - -import junit.framework.TestCase; - -import java.util.Arrays; -import java.util.List; - -public class BiMultiMapTest extends TestCase { - - public void testSingle() { - BiMultiMap mMap = new BiMultiMap<>(); - String key = "foo"; - String value = "bar"; - mMap.clear(); - mMap.put(key, value); - assertEquals(1, mMap.size()); - assertEquals(value, mMap.get(key)); - assertEquals(key, mMap.getKey(value)); - mMap.remove(key); - assertEquals(0, mMap.size()); - assertNull(mMap.get(key)); - assertNull(mMap.getKey(value)); - } - - public void testMulti() { - BiMultiMap mMap = new BiMultiMap<>(); - String key = "foo"; - List values = Arrays.asList("bar", "baz"); - mMap.clear(); - mMap.put(key, values); - assertEquals(1, mMap.size()); - assertEquals(values, mMap.get(key)); - for (String value : values) { - assertEquals(key, mMap.getKey(value)); - } - mMap.remove(key); - assertEquals(0, mMap.size()); - assertNull(mMap.get(key)); - for (String value : values) { - assertEquals(null, mMap.getKey(value)); - } - } - -} diff --git a/library/tests/src/com/google/maps/android/geojson/BiMultiMapTest.java b/library/tests/src/com/google/maps/android/geojson/BiMultiMapTest.java new file mode 100644 index 000000000..5d62889b5 --- /dev/null +++ b/library/tests/src/com/google/maps/android/geojson/BiMultiMapTest.java @@ -0,0 +1,42 @@ +package com.google.maps.android.geojson; + +import junit.framework.TestCase; + +import java.util.Arrays; +import java.util.List; + +public class BiMultiMapTest extends TestCase { + + public void testSingle() { + BiMultiMap map = new BiMultiMap<>(); + String key = "foo"; + String value = "bar"; + map.put(key, value); + assertEquals(1, map.size()); + assertEquals(value, map.get(key)); + assertEquals(key, map.getKey(value)); + map.remove(key); + assertEquals(0, map.size()); + assertNull(map.get(key)); + assertNull(map.getKey(value)); + } + + public void testMulti() { + BiMultiMap map = new BiMultiMap<>(); + String key = "foo"; + List values = Arrays.asList("bar", "baz"); + map.put(key, values); + assertEquals(1, map.size()); + assertEquals(values, map.get(key)); + for (String value : values) { + assertEquals(key, map.getKey(value)); + } + map.remove(key); + assertEquals(0, map.size()); + assertNull(map.get(key)); + for (String value : values) { + assertEquals(null, map.getKey(value)); + } + } + +}