Skip to content

Commit

Permalink
mapbox#1940 - Cleaning up setup process for OnMapChangedListeners. Re…
Browse files Browse the repository at this point in the history
…moving debug log statements.
  • Loading branch information
bleege committed Aug 5, 2015
1 parent b16bba8 commit 54ae508
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public class MapView extends FrameLayout implements LocationListener {
private ImageView mGpsMarker;
private Location mGpsLocation;

// Used to manage Event Listeners
private ArrayList<OnMapChangedListener> mOnMapChangedListener;

//
// Properties
//
Expand Down Expand Up @@ -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<OnMapChangedListener>();
}

//
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1335,19 +1337,27 @@ public void run() {
}


/**
* Defines callback for events OnMapChange
*/
public interface OnMapChangedListener {
void onMapChanged();
}

private ArrayList<OnMapChangedListener> mOnMapChangedListener = new ArrayList<OnMapChangedListener>();

// 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);
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,6 @@ private class MyOnMapChangedListener implements MapView.OnMapChangedListener {

@Override
public void onMapChanged() {
Log.i(TAG, "onMapChanged()");
updateMap();
}
}
Expand Down

0 comments on commit 54ae508

Please sign in to comment.