diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java index 7a41a5d17b2..1b3ad5ba6bd 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java @@ -119,6 +119,9 @@ public class MapView extends FrameLayout implements LocationListener { private ImageView mGpsMarker; private Location mGpsLocation; + // Used to manage Event Listeners + private ArrayList mOnMapChangedListener; + // // Properties // @@ -250,16 +253,10 @@ private void initialize(Context context, AttributeSet attrs) { .setInterval(1000) .setSmallestDisplacement(1) .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); - } - // Called when map state changes - private class MyOnMapChangedListener implements MapView.OnMapChangedListener { - - @Override - public void onMapChanged() { - Log.i(TAG, "onMapChanged()!! - Now a full class!"); - updateMap(); - } + // Setup Support For Listener Tracking + // MapView's internal listener is setup in onCreate() + mOnMapChangedListener = new ArrayList(); } // @@ -563,7 +560,12 @@ public void onCreate(Bundle savedInstanceState) { mNativeMapView.initializeDisplay(); mNativeMapView.initializeContext(); - addOnMapChangedListener(new MyOnMapChangedListener()); + addOnMapChangedListener(new OnMapChangedListener() { + @Override + public void onMapChanged() { + updateMap(); + } + }); } // Called when we need to save instance state @@ -1335,19 +1337,27 @@ public void run() { } + /** + * Defines callback for events OnMapChange + */ public interface OnMapChangedListener { void onMapChanged(); } - private ArrayList mOnMapChangedListener = new ArrayList(); - - // Adds a listener for onMapChanged + /** + * Add an OnMapChangedListner + * @param listener Listener to add + */ public void addOnMapChangedListener(@NonNull OnMapChangedListener listener) { if (listener != null) { mOnMapChangedListener.add(listener); } } + /** + * Remove an OnMapChangedListener + * @param listener Listener to remove + */ public void removeOnMapChangedListener(@NonNull OnMapChangedListener listener) { if (listener != null) { mOnMapChangedListener.remove(listener); @@ -1468,7 +1478,6 @@ private void updateLocation(Location location) { // Updates the UI to match the current map's position private void updateMap() { - Log.i(TAG, "updateMap()"); // rotateImageView(mCompassView, (float) mapView.getDirection()); if (isMyLocationEnabled() && mGpsLocation != null) { diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/MainActivity.java b/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/MainActivity.java index f3f061e34b9..0f6ed63c1a2 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/MainActivity.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/MainActivity.java @@ -624,7 +624,6 @@ private class MyOnMapChangedListener implements MapView.OnMapChangedListener { @Override public void onMapChanged() { - Log.i(TAG, "onMapChanged()"); updateMap(); } }