Lazy load view components in MapView. (#141)
* Lazy load view components in MapView. * Fix failing tests. * Fix style. * Lazy inflating view components. * Remove debug logging. * Fix android ui tests.
This commit is contained in:
@@ -5,20 +5,20 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.collection.LongSparseArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.TextureView;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.collection.LongSparseArray;
|
||||
|
||||
import com.mapbox.android.gestures.AndroidGesturesManager;
|
||||
import com.mapbox.mapboxsdk.MapStrictMode;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
@@ -73,14 +73,20 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
private View renderView;
|
||||
|
||||
private AttributionClickListener attributionClickListener;
|
||||
private MapboxMapOptions mapboxMapOptions;
|
||||
MapboxMapOptions mapboxMapOptions;
|
||||
private MapRenderer mapRenderer;
|
||||
private boolean destroyed;
|
||||
|
||||
@Nullable
|
||||
private CompassView compassView;
|
||||
private PointF focalPoint;
|
||||
private ImageView attrView;
|
||||
private ImageView logoView;
|
||||
|
||||
// callback for focal point invalidation
|
||||
private final FocalPointInvalidator focalInvalidator = new FocalPointInvalidator();
|
||||
// callback for registering touch listeners
|
||||
private final GesturesManagerInteractionListener registerTouchListener = new GesturesManagerInteractionListener();
|
||||
// callback for camera change events
|
||||
private final CameraChangeDispatcher cameraDispatcher = new CameraChangeDispatcher();
|
||||
|
||||
@Nullable
|
||||
private MapGestureDetector mapGestureDetector;
|
||||
@@ -131,14 +137,6 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
|
||||
mapboxMapOptions = options;
|
||||
|
||||
// inflate view
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.mapbox_mapview_internal, this);
|
||||
compassView = view.findViewById(R.id.compassView);
|
||||
attrView = view.findViewById(R.id.attributionView);
|
||||
attrView.setImageDrawable(BitmapUtils.getDrawableFromRes(getContext(), R.drawable.mapbox_info_bg_selector));
|
||||
logoView = view.findViewById(R.id.logoView);
|
||||
logoView.setImageDrawable(BitmapUtils.getDrawableFromRes(getContext(), R.drawable.mapbox_logo_icon));
|
||||
|
||||
// add accessibility support
|
||||
setContentDescription(context.getString(R.string.mapbox_mapActionDescription));
|
||||
setWillNotDraw(false);
|
||||
@@ -149,18 +147,11 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
Context context = getContext();
|
||||
|
||||
// callback for focal point invalidation
|
||||
final FocalPointInvalidator focalInvalidator = new FocalPointInvalidator();
|
||||
focalInvalidator.addListener(createFocalPointChangeListener());
|
||||
|
||||
// callback for registering touch listeners
|
||||
GesturesManagerInteractionListener registerTouchListener = new GesturesManagerInteractionListener();
|
||||
|
||||
// callback for camera change events
|
||||
final CameraChangeDispatcher cameraDispatcher = new CameraChangeDispatcher();
|
||||
|
||||
// setup components for MapboxMap creation
|
||||
Projection proj = new Projection(nativeMapView, this);
|
||||
UiSettings uiSettings = new UiSettings(proj, focalInvalidator, compassView, attrView, logoView, getPixelRatio());
|
||||
UiSettings uiSettings = new UiSettings(proj, focalInvalidator, getPixelRatio(), this);
|
||||
LongSparseArray<Annotation> annotationsArray = new LongSparseArray<>();
|
||||
IconManager iconManager = new IconManager(nativeMapView);
|
||||
Annotations annotations = new AnnotationContainer(nativeMapView, annotationsArray);
|
||||
@@ -169,30 +160,23 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
Polylines polylines = new PolylineContainer(nativeMapView, annotationsArray);
|
||||
ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(nativeMapView, annotationsArray);
|
||||
AnnotationManager annotationManager = new AnnotationManager(this, annotationsArray, iconManager,
|
||||
annotations, markers, polygons, polylines, shapeAnnotations);
|
||||
annotations, markers, polygons, polylines, shapeAnnotations);
|
||||
Transform transform = new Transform(this, nativeMapView, cameraDispatcher);
|
||||
|
||||
// MapboxMap
|
||||
List<MapboxMap.OnDeveloperAnimationListener> developerAnimationListeners = new ArrayList<>();
|
||||
mapboxMap = new MapboxMap(nativeMapView, transform, uiSettings, proj, registerTouchListener, cameraDispatcher,
|
||||
developerAnimationListeners);
|
||||
developerAnimationListeners);
|
||||
mapboxMap.injectAnnotationManager(annotationManager);
|
||||
|
||||
// user input
|
||||
mapGestureDetector = new MapGestureDetector(context, transform, proj, uiSettings,
|
||||
annotationManager, cameraDispatcher);
|
||||
annotationManager, cameraDispatcher);
|
||||
mapKeyListener = new MapKeyListener(transform, uiSettings, mapGestureDetector);
|
||||
|
||||
// compass
|
||||
compassView.injectCompassAnimationListener(createCompassAnimationListener(cameraDispatcher));
|
||||
compassView.setOnClickListener(createCompassClickListener(cameraDispatcher));
|
||||
|
||||
// LocationComponent
|
||||
mapboxMap.injectLocationComponent(new LocationComponent(mapboxMap, transform, developerAnimationListeners));
|
||||
|
||||
// inject widgets with MapboxMap
|
||||
attrView.setOnClickListener(attributionClickListener = new AttributionClickListener(context, mapboxMap));
|
||||
|
||||
// Ensure this view is interactable
|
||||
setClickable(true);
|
||||
setLongClickable(true);
|
||||
@@ -213,6 +197,44 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
mapCallback.initialised();
|
||||
}
|
||||
|
||||
protected CompassView initialiseCompassView() {
|
||||
compassView = new CompassView(this.getContext());
|
||||
addView(compassView);
|
||||
compassView.setTag("compassView");
|
||||
compassView.getLayoutParams().width = LayoutParams.WRAP_CONTENT;
|
||||
compassView.getLayoutParams().height = LayoutParams.WRAP_CONTENT;
|
||||
compassView.setContentDescription(getResources().getString(R.string.mapbox_compassContentDescription));
|
||||
compassView.injectCompassAnimationListener(createCompassAnimationListener(cameraDispatcher));
|
||||
compassView.setOnClickListener(createCompassClickListener(cameraDispatcher));
|
||||
return compassView;
|
||||
}
|
||||
|
||||
protected ImageView initialiseAttributionView() {
|
||||
ImageView attrView = new ImageView(this.getContext());
|
||||
addView(attrView);
|
||||
attrView.setTag("attrView");
|
||||
attrView.getLayoutParams().width = LayoutParams.WRAP_CONTENT;
|
||||
attrView.getLayoutParams().height = LayoutParams.WRAP_CONTENT;
|
||||
attrView.setAdjustViewBounds(true);
|
||||
attrView.setClickable(true);
|
||||
attrView.setFocusable(true);
|
||||
attrView.setContentDescription(getResources().getString(R.string.mapbox_attributionsIconContentDescription));
|
||||
attrView.setImageDrawable(BitmapUtils.getDrawableFromRes(getContext(), R.drawable.mapbox_info_bg_selector));
|
||||
// inject widgets with MapboxMap
|
||||
attrView.setOnClickListener(attributionClickListener = new AttributionClickListener(getContext(), mapboxMap));
|
||||
return attrView;
|
||||
}
|
||||
|
||||
protected ImageView initialiseLogoView() {
|
||||
ImageView logoView = new ImageView(this.getContext());
|
||||
addView(logoView);
|
||||
logoView.setTag("logoView");
|
||||
logoView.getLayoutParams().width = LayoutParams.WRAP_CONTENT;
|
||||
logoView.getLayoutParams().height = LayoutParams.WRAP_CONTENT;
|
||||
logoView.setImageDrawable(BitmapUtils.getDrawableFromRes(getContext(), R.drawable.mapbox_logo_icon));
|
||||
return logoView;
|
||||
}
|
||||
|
||||
private FocalPointChangeListener createFocalPointChangeListener() {
|
||||
return new FocalPointChangeListener() {
|
||||
@Override
|
||||
@@ -223,7 +245,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
}
|
||||
|
||||
private MapboxMap.OnCompassAnimationListener createCompassAnimationListener(@NonNull final CameraChangeDispatcher
|
||||
cameraChangeDispatcher) {
|
||||
cameraChangeDispatcher) {
|
||||
return new MapboxMap.OnCompassAnimationListener() {
|
||||
@Override
|
||||
public void onCompassAnimation() {
|
||||
@@ -232,7 +254,9 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
|
||||
@Override
|
||||
public void onCompassAnimationFinished() {
|
||||
compassView.isAnimating(false);
|
||||
if (compassView != null) {
|
||||
compassView.isAnimating(false);
|
||||
}
|
||||
cameraChangeDispatcher.onCameraIdle();
|
||||
}
|
||||
};
|
||||
@@ -289,7 +313,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
TextureView textureView = new TextureView(getContext());
|
||||
boolean translucentSurface = options.getTranslucentTextureSurface();
|
||||
mapRenderer = new TextureViewMapRenderer(getContext(),
|
||||
textureView, localFontFamily, translucentSurface) {
|
||||
textureView, localFontFamily, translucentSurface) {
|
||||
@Override
|
||||
protected void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||
MapView.this.onSurfaceCreated();
|
||||
@@ -316,7 +340,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
|
||||
boolean crossSourceCollisions = mapboxMapOptions.getCrossSourceCollisions();
|
||||
nativeMapView = new NativeMapView(
|
||||
getContext(), getPixelRatio(), crossSourceCollisions, this, mapChangeReceiver, mapRenderer
|
||||
getContext(), getPixelRatio(), crossSourceCollisions, this, mapChangeReceiver, mapRenderer
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1225,7 +1249,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
public void setGesturesManager(AndroidGesturesManager gesturesManager, boolean attachDefaultListeners,
|
||||
boolean setDefaultMutuallyExclusives) {
|
||||
mapGestureDetector.setGesturesManager(
|
||||
getContext(), gesturesManager, attachDefaultListeners, setDefaultMutuallyExclusives);
|
||||
getContext(), gesturesManager, attachDefaultListeners, setDefaultMutuallyExclusives);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1235,8 +1259,8 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
}
|
||||
|
||||
private class MapCallback implements OnDidFinishLoadingStyleListener,
|
||||
OnDidFinishRenderingFrameListener, OnDidFinishLoadingMapListener,
|
||||
OnCameraIsChangingListener, OnCameraDidChangeListener, OnDidFailLoadingMapListener {
|
||||
OnDidFinishRenderingFrameListener, OnDidFinishLoadingMapListener,
|
||||
OnCameraIsChangingListener, OnCameraDidChangeListener, OnDidFailLoadingMapListener {
|
||||
|
||||
private final List<OnMapReadyCallback> onMapReadyCallbackList = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -7,17 +7,19 @@ import android.graphics.PointF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.FloatRange;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.Px;
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
@@ -34,18 +36,23 @@ public final class UiSettings {
|
||||
@NonNull
|
||||
private final FocalPointChangeListener focalPointChangeListener;
|
||||
@NonNull
|
||||
private final Projection projection;
|
||||
private final MapView mapView;
|
||||
@NonNull
|
||||
private final CompassView compassView;
|
||||
private final Projection projection;
|
||||
@VisibleForTesting
|
||||
@Nullable
|
||||
CompassView compassView;
|
||||
private final int[] compassMargins = new int[4];
|
||||
|
||||
@NonNull
|
||||
private final ImageView attributionsView;
|
||||
@VisibleForTesting
|
||||
@Nullable
|
||||
ImageView attributionsView;
|
||||
private final int[] attributionsMargins = new int[4];
|
||||
private AttributionDialogManager attributionDialogManager;
|
||||
|
||||
@NonNull
|
||||
private final View logoView;
|
||||
@VisibleForTesting
|
||||
@Nullable
|
||||
ImageView logoView;
|
||||
private final int[] logoMargins = new int[4];
|
||||
|
||||
private final float pixelRatio;
|
||||
@@ -79,23 +86,34 @@ public final class UiSettings {
|
||||
@Nullable
|
||||
private PointF userProvidedFocalPoint;
|
||||
|
||||
@VisibleForTesting
|
||||
boolean isCompassInitialized = false;
|
||||
@VisibleForTesting
|
||||
boolean isAttributionInitialized = false;
|
||||
@VisibleForTesting
|
||||
boolean isLogoInitialized = false;
|
||||
private double clockwiseBearing;
|
||||
|
||||
UiSettings(@NonNull Projection projection, @NonNull FocalPointChangeListener listener,
|
||||
@NonNull CompassView compassView, @NonNull ImageView attributionsView, @NonNull View logoView,
|
||||
float pixelRatio) {
|
||||
float pixelRatio, MapView mapView) {
|
||||
this.projection = projection;
|
||||
this.focalPointChangeListener = listener;
|
||||
this.compassView = compassView;
|
||||
this.attributionsView = attributionsView;
|
||||
this.logoView = logoView;
|
||||
this.pixelRatio = pixelRatio;
|
||||
this.mapView = mapView;
|
||||
}
|
||||
|
||||
void initialise(@NonNull Context context, @NonNull MapboxMapOptions options) {
|
||||
Resources resources = context.getResources();
|
||||
initialiseGestures(options);
|
||||
initialiseCompass(options, resources);
|
||||
initialiseLogo(options, resources);
|
||||
initialiseAttribution(context, options);
|
||||
if (options.getCompassEnabled()) {
|
||||
initialiseCompass(options, resources);
|
||||
}
|
||||
if (options.getLogoEnabled()) {
|
||||
initialiseLogo(options, resources);
|
||||
}
|
||||
if (options.getAttributionEnabled()) {
|
||||
initialiseAttribution(context, options);
|
||||
}
|
||||
}
|
||||
|
||||
void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
@@ -163,6 +181,8 @@ public final class UiSettings {
|
||||
}
|
||||
|
||||
private void initialiseCompass(MapboxMapOptions options, @NonNull Resources resources) {
|
||||
isCompassInitialized = true;
|
||||
compassView = mapView.initialiseCompassView();
|
||||
setCompassEnabled(options.getCompassEnabled());
|
||||
setCompassGravity(options.getCompassGravity());
|
||||
int[] compassMargins = options.getCompassMargins();
|
||||
@@ -192,6 +212,11 @@ public final class UiSettings {
|
||||
}
|
||||
|
||||
private void restoreCompass(Bundle savedInstanceState) {
|
||||
boolean compassEnabled = savedInstanceState.getBoolean(MapboxConstants.STATE_COMPASS_ENABLED);
|
||||
if (compassEnabled && !isCompassInitialized) {
|
||||
compassView = mapView.initialiseCompassView();
|
||||
isCompassInitialized = true;
|
||||
}
|
||||
setCompassEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_COMPASS_ENABLED));
|
||||
setCompassGravity(savedInstanceState.getInt(MapboxConstants.STATE_COMPASS_GRAVITY));
|
||||
setCompassMargins(savedInstanceState.getInt(MapboxConstants.STATE_COMPASS_MARGIN_LEFT),
|
||||
@@ -200,10 +225,12 @@ public final class UiSettings {
|
||||
savedInstanceState.getInt(MapboxConstants.STATE_COMPASS_MARGIN_BOTTOM));
|
||||
setCompassFadeFacingNorth(savedInstanceState.getBoolean(MapboxConstants.STATE_COMPASS_FADE_WHEN_FACING_NORTH));
|
||||
setCompassImage(BitmapUtils.getDrawableFromByteArray(
|
||||
compassView.getContext(), savedInstanceState.getByteArray(MapboxConstants.STATE_COMPASS_IMAGE_BITMAP)));
|
||||
mapView.getContext(), savedInstanceState.getByteArray(MapboxConstants.STATE_COMPASS_IMAGE_BITMAP)));
|
||||
}
|
||||
|
||||
private void initialiseLogo(MapboxMapOptions options, @NonNull Resources resources) {
|
||||
isLogoInitialized = true;
|
||||
logoView = mapView.initialiseLogoView();
|
||||
setLogoEnabled(options.getLogoEnabled());
|
||||
setLogoGravity(options.getLogoGravity());
|
||||
setLogoMargins(resources, options.getLogoMargins());
|
||||
@@ -229,6 +256,11 @@ public final class UiSettings {
|
||||
}
|
||||
|
||||
private void restoreLogo(Bundle savedInstanceState) {
|
||||
boolean logoEnabled = savedInstanceState.getBoolean(MapboxConstants.STATE_LOGO_ENABLED);
|
||||
if (logoEnabled && !isLogoInitialized) {
|
||||
logoView = mapView.initialiseLogoView();
|
||||
isLogoInitialized = true;
|
||||
}
|
||||
setLogoEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_LOGO_ENABLED));
|
||||
setLogoGravity(savedInstanceState.getInt(MapboxConstants.STATE_LOGO_GRAVITY));
|
||||
setLogoMargins(savedInstanceState.getInt(MapboxConstants.STATE_LOGO_MARGIN_LEFT),
|
||||
@@ -238,6 +270,8 @@ public final class UiSettings {
|
||||
}
|
||||
|
||||
private void initialiseAttribution(@NonNull Context context, MapboxMapOptions options) {
|
||||
isAttributionInitialized = true;
|
||||
attributionsView = mapView.initialiseAttributionView();
|
||||
setAttributionEnabled(options.getAttributionEnabled());
|
||||
setAttributionGravity(options.getAttributionGravity());
|
||||
setAttributionMargins(context, options.getAttributionMargins());
|
||||
@@ -269,6 +303,11 @@ public final class UiSettings {
|
||||
}
|
||||
|
||||
private void restoreAttribution(Bundle savedInstanceState) {
|
||||
boolean attributionEnabled = savedInstanceState.getBoolean(MapboxConstants.STATE_ATTRIBUTION_ENABLED);
|
||||
if (attributionEnabled && !isAttributionInitialized) {
|
||||
attributionsView = mapView.initialiseAttributionView();
|
||||
isAttributionInitialized = true;
|
||||
}
|
||||
setAttributionEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_ATTRIBUTION_ENABLED));
|
||||
setAttributionGravity(savedInstanceState.getInt(MapboxConstants.STATE_ATTRIBUTION_GRAVITY));
|
||||
setAttributionMargins(savedInstanceState.getInt(MapboxConstants.STATE_ATTRIBUTION_MARGIN_LEFT),
|
||||
@@ -289,7 +328,13 @@ public final class UiSettings {
|
||||
* @param compassEnabled True to enable the compass; false to disable the compass.
|
||||
*/
|
||||
public void setCompassEnabled(boolean compassEnabled) {
|
||||
compassView.setEnabled(compassEnabled);
|
||||
if (compassEnabled && !isCompassInitialized) {
|
||||
initialiseCompass(mapView.mapboxMapOptions, mapView.getContext().getResources());
|
||||
}
|
||||
if (compassView != null) {
|
||||
compassView.setEnabled(compassEnabled);
|
||||
compassView.update(clockwiseBearing);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -298,7 +343,11 @@ public final class UiSettings {
|
||||
* @return True if the compass is enabled; false if the compass is disabled.
|
||||
*/
|
||||
public boolean isCompassEnabled() {
|
||||
return compassView.isEnabled();
|
||||
if (compassView != null) {
|
||||
return compassView.isEnabled();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,7 +361,9 @@ public final class UiSettings {
|
||||
*/
|
||||
@UiThread
|
||||
public void setCompassGravity(int gravity) {
|
||||
setWidgetGravity(compassView, gravity);
|
||||
if (compassView != null) {
|
||||
setWidgetGravity(compassView, gravity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -324,7 +375,9 @@ public final class UiSettings {
|
||||
* @param compassFadeFacingNorth True to enable the fading animation; false to disable it
|
||||
*/
|
||||
public void setCompassFadeFacingNorth(boolean compassFadeFacingNorth) {
|
||||
compassView.fadeCompassViewFacingNorth(compassFadeFacingNorth);
|
||||
if (compassView != null) {
|
||||
compassView.fadeCompassViewFacingNorth(compassFadeFacingNorth);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,7 +389,9 @@ public final class UiSettings {
|
||||
* @param compass the drawable to show as image compass
|
||||
*/
|
||||
public void setCompassImage(@NonNull Drawable compass) {
|
||||
compassView.setCompassImage(compass);
|
||||
if (compassView != null) {
|
||||
compassView.setCompassImage(compass);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -345,7 +400,11 @@ public final class UiSettings {
|
||||
* @return True if the compass will fade, false if it remains visible
|
||||
*/
|
||||
public boolean isCompassFadeWhenFacingNorth() {
|
||||
return compassView.isFadeCompassViewFacingNorth();
|
||||
if (compassView != null) {
|
||||
return compassView.isFadeCompassViewFacingNorth();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -354,7 +413,11 @@ public final class UiSettings {
|
||||
* @return The gravity
|
||||
*/
|
||||
public int getCompassGravity() {
|
||||
return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).gravity;
|
||||
if (compassView != null) {
|
||||
return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).gravity;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -368,7 +431,9 @@ public final class UiSettings {
|
||||
*/
|
||||
@UiThread
|
||||
public void setCompassMargins(@Px int left, @Px int top, @Px int right, @Px int bottom) {
|
||||
setWidgetMargins(compassView, compassMargins, left, top, right, bottom);
|
||||
if (compassView != null) {
|
||||
setWidgetMargins(compassView, compassMargins, left, top, right, bottom);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -416,14 +481,20 @@ public final class UiSettings {
|
||||
*
|
||||
* @return the drawable used as compass image
|
||||
*/
|
||||
@NonNull
|
||||
@Nullable
|
||||
public Drawable getCompassImage() {
|
||||
return compassView.getCompassImage();
|
||||
if (compassView != null) {
|
||||
return compassView.getCompassImage();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void update(@NonNull CameraPosition cameraPosition) {
|
||||
double clockwiseBearing = -cameraPosition.bearing;
|
||||
compassView.update(clockwiseBearing);
|
||||
clockwiseBearing = -cameraPosition.bearing;
|
||||
if (compassView != null) {
|
||||
compassView.update(clockwiseBearing);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -435,7 +506,12 @@ public final class UiSettings {
|
||||
* @param enabled True to enable the logo; false to disable the logo.
|
||||
*/
|
||||
public void setLogoEnabled(boolean enabled) {
|
||||
logoView.setVisibility(enabled ? View.VISIBLE : View.GONE);
|
||||
if (enabled && !isLogoInitialized) {
|
||||
initialiseLogo(mapView.mapboxMapOptions, mapView.getContext().getResources());
|
||||
}
|
||||
if (logoView != null) {
|
||||
logoView.setVisibility(enabled ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -444,7 +520,11 @@ public final class UiSettings {
|
||||
* @return True if the logo is enabled; false if the logo is disabled.
|
||||
*/
|
||||
public boolean isLogoEnabled() {
|
||||
return logoView.getVisibility() == View.VISIBLE;
|
||||
if (logoView != null) {
|
||||
return logoView.getVisibility() == View.VISIBLE;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -457,7 +537,9 @@ public final class UiSettings {
|
||||
* @param gravity Android SDK Gravity.
|
||||
*/
|
||||
public void setLogoGravity(int gravity) {
|
||||
setWidgetGravity(logoView, gravity);
|
||||
if (logoView != null) {
|
||||
setWidgetGravity(logoView, gravity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -466,7 +548,11 @@ public final class UiSettings {
|
||||
* @return The gravity
|
||||
*/
|
||||
public int getLogoGravity() {
|
||||
return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).gravity;
|
||||
if (logoView != null) {
|
||||
return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).gravity;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -479,7 +565,9 @@ public final class UiSettings {
|
||||
* @param bottom The bottom margin in pixels.
|
||||
*/
|
||||
public void setLogoMargins(@Px int left, @Px int top, @Px int right, @Px int bottom) {
|
||||
setWidgetMargins(logoView, logoMargins, left, top, right, bottom);
|
||||
if (logoView != null) {
|
||||
setWidgetMargins(logoView, logoMargins, left, top, right, bottom);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -531,7 +619,12 @@ public final class UiSettings {
|
||||
* @param enabled True to enable the attribution; false to disable the attribution.
|
||||
*/
|
||||
public void setAttributionEnabled(boolean enabled) {
|
||||
attributionsView.setVisibility(enabled ? View.VISIBLE : View.GONE);
|
||||
if (enabled && !isAttributionInitialized) {
|
||||
initialiseAttribution(mapView.getContext(), mapView.mapboxMapOptions);
|
||||
}
|
||||
if (attributionsView != null) {
|
||||
attributionsView.setVisibility(enabled ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -540,7 +633,11 @@ public final class UiSettings {
|
||||
* @return True if the attribution is enabled; false if the attribution is disabled.
|
||||
*/
|
||||
public boolean isAttributionEnabled() {
|
||||
return attributionsView.getVisibility() == View.VISIBLE;
|
||||
if (attributionsView != null) {
|
||||
return attributionsView.getVisibility() == View.VISIBLE;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -575,7 +672,9 @@ public final class UiSettings {
|
||||
* @param gravity Android SDK Gravity.
|
||||
*/
|
||||
public void setAttributionGravity(int gravity) {
|
||||
setWidgetGravity(attributionsView, gravity);
|
||||
if (attributionsView != null) {
|
||||
setWidgetGravity(attributionsView, gravity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -584,7 +683,11 @@ public final class UiSettings {
|
||||
* @return The gravity
|
||||
*/
|
||||
public int getAttributionGravity() {
|
||||
return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).gravity;
|
||||
if (attributionsView != null) {
|
||||
return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).gravity;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -596,7 +699,9 @@ public final class UiSettings {
|
||||
* @param bottom The bottom margin in pixels.
|
||||
*/
|
||||
public void setAttributionMargins(@Px int left, @Px int top, @Px int right, @Px int bottom) {
|
||||
setWidgetMargins(attributionsView, attributionsMargins, left, top, right, bottom);
|
||||
if (attributionsView != null) {
|
||||
setWidgetMargins(attributionsView, attributionsMargins, left, top, right, bottom);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -608,6 +713,9 @@ public final class UiSettings {
|
||||
*/
|
||||
public void setAttributionTintColor(@ColorInt int tintColor) {
|
||||
// Check that the tint color being passed in isn't transparent.
|
||||
if (attributionsView == null) {
|
||||
return;
|
||||
}
|
||||
if (Color.alpha(tintColor) == 0) {
|
||||
ColorUtils.setTintList(attributionsView,
|
||||
ContextCompat.getColor(attributionsView.getContext(), R.color.mapbox_blue));
|
||||
|
||||
Reference in New Issue
Block a user