[android] - introduce mapview weak reference in global layout listener
This commit is contained in:
@@ -22,7 +22,6 @@ import android.view.ViewTreeObserver;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ZoomButtonsController;
|
||||
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.annotations.Annotation;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
|
||||
@@ -37,19 +36,18 @@ import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
|
||||
import com.mapbox.mapboxsdk.net.ConnectivityReceiver;
|
||||
import com.mapbox.mapboxsdk.storage.FileSource;
|
||||
import com.mapbox.services.android.telemetry.MapboxTelemetry;
|
||||
import timber.log.Timber;
|
||||
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_MAP_NORTH_ANIMATION;
|
||||
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_WAIT_IDLE;
|
||||
|
||||
@@ -133,17 +131,7 @@ public class MapView extends FrameLayout {
|
||||
setContentDescription(context.getString(R.string.mapbox_mapActionDescription));
|
||||
setWillNotDraw(false);
|
||||
|
||||
getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
} else {
|
||||
getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
||||
}
|
||||
initialiseDrawingSurface(options);
|
||||
}
|
||||
});
|
||||
getViewTreeObserver().addOnGlobalLayoutListener(new MapViewLayoutListener(this, options));
|
||||
}
|
||||
|
||||
private void initialiseMap() {
|
||||
@@ -879,6 +867,30 @@ public class MapView extends FrameLayout {
|
||||
void onMapChanged(@MapChange int change);
|
||||
}
|
||||
|
||||
private static class MapViewLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener {
|
||||
|
||||
private WeakReference<MapView> mapViewWeakReference;
|
||||
private MapboxMapOptions options;
|
||||
|
||||
MapViewLayoutListener(MapView mapView, MapboxMapOptions options) {
|
||||
this.mapViewWeakReference = new WeakReference<>(mapView);
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
MapView mapView = mapViewWeakReference.get();
|
||||
if (mapView != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
mapView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
} else {
|
||||
mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
||||
}
|
||||
mapView.initialiseDrawingSurface(options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class FocalPointInvalidator implements FocalPointChangeListener {
|
||||
|
||||
private final List<FocalPointChangeListener> focalPointChangeListeners = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user