[android] #4076 - MapboxMapOptions initial version

This commit is contained in:
Tobrun
2016-03-09 09:44:44 -05:00
parent 9c4192411a
commit 3679dc254f
34 changed files with 579 additions and 180 deletions

View File

@@ -95,7 +95,7 @@ public final class CameraPosition implements Parcelable {
}
CameraPosition cameraPosition = (CameraPosition) o;
if (!target.equals(cameraPosition.target)) {
if (target != null && !target.equals(cameraPosition.target)) {
return false;
} else if (zoom != cameraPosition.zoom) {
return false;

View File

@@ -35,12 +35,12 @@ public class MapboxConstants {
/**
* The currently supported minimum zoom level.
*/
public static final double MINIMUM_ZOOM = 0.0;
public static final float MINIMUM_ZOOM = 0.0f;
/**
* The currently supported maximum zoom level.
*/
public static final double MAXIMUM_ZOOM = 25.5;
public static final float MAXIMUM_ZOOM = 25.5f;
/**
* The currently supported maximum tilt value.

View File

@@ -2,15 +2,13 @@ package com.mapbox.mapboxsdk.maps;
import android.app.Fragment;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
/**
* Fragment wrapper around a map view.
@@ -26,27 +24,37 @@ import com.mapbox.mapboxsdk.utils.ApiAccess;
*
* @see #getMapAsync(OnMapReadyCallback)
*/
public class MapFragment extends Fragment {
public final class MapFragment extends Fragment {
private MapView mMap;
private OnMapReadyCallback mOnMapReadyCallback;
public static MapFragment newInstance() {
return new MapFragment();
public static MapFragment newInstance(@Nullable MapboxMapOptions mapboxMapOptions) {
MapFragment mapFragment = new MapFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(MapboxConstants.FRAG_ARG_MAPBOXMAPOPTIONS, mapboxMapOptions);
mapFragment.setArguments(bundle);
return mapFragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
mMap = (MapView) inflater.inflate(R.layout.fragment_mapview, container, false);
mMap.setAccessToken(ApiAccess.getToken(inflater.getContext()));
MapboxMapOptions options = getArguments().getParcelable(MapboxConstants.FRAG_ARG_MAPBOXMAPOPTIONS);
return mMap = new MapView(inflater.getContext(), options);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mMap.onCreate(savedInstanceState);
return mMap;
}
@Override
public void onStart() {
super.onStart();
mMap.onStart();
mMap.getMapAsync(mOnMapReadyCallback);
}
@Override
@@ -63,8 +71,8 @@ public class MapFragment extends Fragment {
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
mMap.onSaveInstanceState(outState);
super.onSaveInstanceState(outState);
mMap.onSaveInstanceState(outState);
}
@Override
@@ -75,8 +83,8 @@ public class MapFragment extends Fragment {
@Override
public void onLowMemory() {
mMap.onLowMemory();
super.onLowMemory();
mMap.onLowMemory();
}
@Override
@@ -86,13 +94,7 @@ public class MapFragment extends Fragment {
mMap = null;
}
@NonNull
public void getMapAsync(@NonNull final OnMapReadyCallback onMapReadyCallback) {
new Handler().post(new Runnable() {
@Override
public void run() {
mMap.getMapAsync(onMapReadyCallback);
}
});
mOnMapReadyCallback = onMapReadyCallback;
}
}

View File

@@ -83,7 +83,6 @@ import com.mapbox.mapboxsdk.maps.widgets.CompassView;
import com.mapbox.mapboxsdk.maps.widgets.UserLocationView;
import com.mapbox.mapboxsdk.telemetry.MapboxEvent;
import com.mapbox.mapboxsdk.telemetry.MapboxEventManager;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -114,10 +113,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
public class MapView extends FrameLayout {
private static final String TAG = "MapView";
private static final float DIMENSION_SEVEN_DP = 7f;
private static final float DIMENSION_TEN_DP = 10f;
private static final float DIMENSION_SIXTEEN_DP = 16f;
private static final float DIMENSION_SEVENTY_SIX_DP = 76f;
private MapboxMap mMapboxMap;
private List<Icon> mIcons;
@@ -162,16 +157,22 @@ public class MapView extends FrameLayout {
@UiThread
public MapView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initialize(context, attrs);
initialize(context, MapboxMapOptions.createFromAttributes(context, attrs));
}
@UiThread
public MapView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize(context, attrs);
initialize(context, MapboxMapOptions.createFromAttributes(context, attrs));
}
private void initialize(@NonNull Context context, @Nullable AttributeSet attrs) {
@UiThread
public MapView(@NonNull Context context, @Nullable MapboxMapOptions options) {
super(context);
initialize(context, options);
}
private void initialize(@NonNull Context context, @Nullable MapboxMapOptions options) {
mInitialLoad = true;
mOnMapChangedListener = new CopyOnWriteArrayList<>();
mMapboxMap = new MapboxMap(this);
@@ -234,69 +235,69 @@ public class MapView extends FrameLayout {
mScreenDensity = context.getResources().getDisplayMetrics().density;
// Load the attributes
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MapView, 0, 0);
try {
// Debug mode
mMapboxMap.setDebugActive(typedArray.getBoolean(R.styleable.MapView_debug_active, false));
// Move camera
CameraPosition cameraPosition = new CameraPosition.Builder(typedArray).build();
mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
// Access token
String accessToken = typedArray.getString(R.styleable.MapView_access_token);
if (accessToken != null) {
setAccessToken(typedArray.getString(R.styleable.MapView_access_token));
}
// Style url
String styleUrl = typedArray.getString(R.styleable.MapView_style_url);
if (styleUrl != null) {
mMapboxMap.setStyleUrl(styleUrl);
}
// Enable gestures
UiSettings uiSettings = mMapboxMap.getUiSettings();
uiSettings.setZoomGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_enabled, true));
uiSettings.setScrollGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_scroll_enabled, true));
uiSettings.setRotateGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_rotate_enabled, true));
uiSettings.setTiltGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_tilt_enabled, true));
uiSettings.setZoomControlsEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_controls_enabled, false));
// Zoom
uiSettings.setMaxZoom(typedArray.getFloat(R.styleable.MapView_zoom_max, (float) MapboxConstants.MAXIMUM_ZOOM));
uiSettings.setMinZoom(typedArray.getFloat(R.styleable.MapView_zoom_min, (float) MapboxConstants.MINIMUM_ZOOM));
// Compass
uiSettings.setCompassEnabled(typedArray.getBoolean(R.styleable.MapView_compass_enabled, true));
uiSettings.setCompassGravity(typedArray.getInt(R.styleable.MapView_compass_gravity, Gravity.TOP | Gravity.END));
uiSettings.setCompassMargins((int) (typedArray.getDimension(R.styleable.MapView_compass_margin_left, DIMENSION_TEN_DP) * mScreenDensity)
, ((int) typedArray.getDimension(R.styleable.MapView_compass_margin_top, DIMENSION_TEN_DP * mScreenDensity))
, ((int) typedArray.getDimension(R.styleable.MapView_compass_margin_right, DIMENSION_TEN_DP * mScreenDensity))
, ((int) typedArray.getDimension(R.styleable.MapView_compass_margin_bottom, DIMENSION_TEN_DP * mScreenDensity)));
// Logo
uiSettings.setLogoEnabled(typedArray.getBoolean(R.styleable.MapView_logo_visibility, true));
uiSettings.setLogoGravity(typedArray.getInt(R.styleable.MapView_logo_gravity, Gravity.BOTTOM | Gravity.START));
uiSettings.setLogoMargins((int) (typedArray.getDimension(R.styleable.MapView_logo_margin_left, DIMENSION_SIXTEEN_DP) * mScreenDensity)
, (int) (typedArray.getDimension(R.styleable.MapView_logo_margin_top, DIMENSION_SIXTEEN_DP) * mScreenDensity)
, (int) (typedArray.getDimension(R.styleable.MapView_logo_margin_right, DIMENSION_SIXTEEN_DP) * mScreenDensity)
, (int) (typedArray.getDimension(R.styleable.MapView_logo_margin_bottom, DIMENSION_SIXTEEN_DP) * mScreenDensity));
// Attribution
uiSettings.setAttributionEnabled(typedArray.getBoolean(R.styleable.MapView_attribution_visibility, true));
uiSettings.setAttributionGravity(typedArray.getInt(R.styleable.MapView_attribution_gravity, Gravity.BOTTOM));
uiSettings.setAttributionMargins((int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_left, DIMENSION_SEVENTY_SIX_DP) * mScreenDensity)
, (int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_top, DIMENSION_SEVEN_DP) * mScreenDensity)
, (int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_right, DIMENSION_SEVEN_DP) * mScreenDensity)
, (int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_bottom, DIMENSION_SEVEN_DP) * mScreenDensity));
// User location
mMapboxMap.setMyLocationEnabled(typedArray.getBoolean(R.styleable.MapView_my_location_enabled, false));
} finally {
typedArray.recycle();
}
// // Load the attributes
// TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MapView, 0, 0);
// try {
// // Debug mode
// mMapboxMap.setDebugActive(typedArray.getBoolean(R.styleable.MapView_debug_active, false));
//
// // Move camera
// CameraPosition cameraPosition = new CameraPosition.Builder(typedArray).build();
// mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
//
// // Access token
// String accessToken = typedArray.getString(R.styleable.MapView_access_token);
// if (accessToken != null) {
// setAccessToken(typedArray.getString(R.styleable.MapView_access_token));
// }
//
// // Style url
// String styleUrl = typedArray.getString(R.styleable.MapView_style_url);
// if (styleUrl != null) {
// mMapboxMap.setStyleUrl(styleUrl);
// }
//
// // Enable gestures
// UiSettings uiSettings = mMapboxMap.getUiSettings();
// uiSettings.setZoomGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_enabled, true));
// uiSettings.setScrollGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_scroll_enabled, true));
// uiSettings.setRotateGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_rotate_enabled, true));
// uiSettings.setTiltGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_tilt_enabled, true));
// uiSettings.setZoomControlsEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_controls_enabled, false));
//
// // Zoom
// uiSettings.setMaxZoom(typedArray.getFloat(R.styleable.MapView_zoom_max, (float) MapboxConstants.MAXIMUM_ZOOM));
// uiSettings.setMinZoom(typedArray.getFloat(R.styleable.MapView_zoom_min, (float) MapboxConstants.MINIMUM_ZOOM));
//
// // Compass
// uiSettings.setCompassEnabled(typedArray.getBoolean(R.styleable.MapView_compass_enabled, true));
// uiSettings.setCompassGravity(typedArray.getInt(R.styleable.MapView_compass_gravity, Gravity.TOP | Gravity.END));
// uiSettings.setCompassMargins((int) (typedArray.getDimension(R.styleable.MapView_compass_margin_left, DIMENSION_TEN_DP) * mScreenDensity)
// , ((int) typedArray.getDimension(R.styleable.MapView_compass_margin_top, DIMENSION_TEN_DP * mScreenDensity))
// , ((int) typedArray.getDimension(R.styleable.MapView_compass_margin_right, DIMENSION_TEN_DP * mScreenDensity))
// , ((int) typedArray.getDimension(R.styleable.MapView_compass_margin_bottom, DIMENSION_TEN_DP * mScreenDensity)));
//
// // Logo
// uiSettings.setLogoEnabled(typedArray.getBoolean(R.styleable.MapView_logo_visibility, true));
// uiSettings.setLogoGravity(typedArray.getInt(R.styleable.MapView_logo_gravity, Gravity.BOTTOM | Gravity.START));
// uiSettings.setLogoMargins((int) (typedArray.getDimension(R.styleable.MapView_logo_margin_left, DIMENSION_SIXTEEN_DP) * mScreenDensity)
// , (int) (typedArray.getDimension(R.styleable.MapView_logo_margin_top, DIMENSION_SIXTEEN_DP) * mScreenDensity)
// , (int) (typedArray.getDimension(R.styleable.MapView_logo_margin_right, DIMENSION_SIXTEEN_DP) * mScreenDensity)
// , (int) (typedArray.getDimension(R.styleable.MapView_logo_margin_bottom, DIMENSION_SIXTEEN_DP) * mScreenDensity));
//
// // Attribution
// uiSettings.setAttributionEnabled(typedArray.getBoolean(R.styleable.MapView_attribution_visibility, true));
// uiSettings.setAttributionGravity(typedArray.getInt(R.styleable.MapView_attribution_gravity, Gravity.BOTTOM));
// uiSettings.setAttributionMargins((int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_left, DIMENSION_SEVENTY_SIX_DP) * mScreenDensity)
// , (int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_top, DIMENSION_SEVEN_DP) * mScreenDensity)
// , (int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_right, DIMENSION_SEVEN_DP) * mScreenDensity)
// , (int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_bottom, DIMENSION_SEVEN_DP) * mScreenDensity));
//
// // User location
// mMapboxMap.setMyLocationEnabled(typedArray.getBoolean(R.styleable.MapView_my_location_enabled, false));
// } finally {
// typedArray.recycle();
// }
}
//
@@ -1497,6 +1498,7 @@ public class MapView extends FrameLayout {
break;
case MotionEvent.ACTION_UP:
if (mQuickZoom) {
// insert here?
mQuickZoom = false;
break;
}

View File

@@ -1,8 +1,6 @@
package com.mapbox.mapboxsdk.maps;
import android.content.Context;
import android.location.Location;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -31,7 +29,6 @@ import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.layers.CustomLayer;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import java.util.ArrayList;
import java.util.List;
@@ -54,7 +51,6 @@ public class MapboxMap {
private Projection mProjection;
private CameraPosition mCameraPosition;
private boolean mInvalidCameraPosition;
private String mStyleUrl;
private LongSparseArray<Annotation> mAnnotations;
private List<Marker> mSelectedMarkers;
private List<InfoWindow> mInfoWindows;
@@ -459,16 +455,9 @@ public class MapboxMap {
* <p>
* Sets the current Mapbox access token used to load map styles and tiles.
* </p>
* <p>
* You must set a valid access token before you call {@link MapView#onCreate(Bundle)}
* or an exception will be thrown.
* </p>
* You can use {@link ApiAccess#getToken(Context)} to load an access token from your
* application's manifest.
*
* @param accessToken Your public Mapbox access token.
* @see MapView#onCreate(Bundle)
* @see ApiAccess#getToken(Context)
* @see MapView#setAccessToken(String)
*/
@UiThread
public void setAccessToken(@NonNull String accessToken) {
@@ -1058,7 +1047,6 @@ public class MapboxMap {
}
/**
*
* @return
*/
public int[] getPadding() {
@@ -1347,7 +1335,7 @@ public class MapboxMap {
// Invalidate
//
public void invalidate(){
public void invalidate() {
mMapView.update();
}
@@ -1466,7 +1454,7 @@ public class MapboxMap {
}
/**
* Interface definition for a callback to be invoked when the user long presses on a marker's info window.
* Interface definition for a callback to be invoked when the user long presses on a marker's info window.
*
* @see MapboxMap#setOnInfoWindowClickListener(OnInfoWindowClickListener)
*/

View File

@@ -0,0 +1,299 @@
package com.mapbox.mapboxsdk.maps;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.Gravity;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
public class MapboxMapOptions implements Parcelable {
private static final float DIMENSION_SEVEN_DP = 7f;
private static final float DIMENSION_TEN_DP = 10f;
private static final float DIMENSION_SIXTEEN_DP = 16f;
private static final float DIMENSION_SEVENTY_SIX_DP = 76f;
private CameraPosition cameraPosition;
private boolean debugActive;
private boolean compassEnabled = true;
private int compassGravity = Gravity.TOP | Gravity.END;
private int compassMargins[];
private boolean logoEnabled = true;
private int logoGravity;
private int logoMargins[];
private boolean attributionEnabled = true;
private int attributionGravity;
private int attributionMargins[];
private float minZoom = MapboxConstants.MINIMUM_ZOOM;
private float maxZoom = MapboxConstants.MAXIMUM_ZOOM;
private boolean rotateGesturesEnabled = true;
private boolean scrollGesturesEnabled = true;
private boolean tiltGesturesEnabled = true;
private boolean zoomControlsEnabled = true;
private boolean zoomGesturesEnabled = true;
private boolean locationEnabled;
private String style;
private String accessToken;
public MapboxMapOptions() {
}
private MapboxMapOptions(Parcel in) {
cameraPosition = in.readParcelable(CameraPosition.class.getClassLoader());
debugActive = in.readByte() != 0;
compassEnabled = in.readByte() != 0;
rotateGesturesEnabled = in.readByte() != 0;
scrollGesturesEnabled = in.readByte() != 0;
tiltGesturesEnabled = in.readByte() != 0;
zoomControlsEnabled = in.readByte() != 0;
zoomGesturesEnabled = in.readByte() != 0;
style = in.readString();
accessToken = in.readString();
}
public static MapboxMapOptions createFromAttributes(Context context, AttributeSet attrs) {
MapboxMapOptions mapboxMapOptions = new MapboxMapOptions();
float screenDensity = context.getResources().getDisplayMetrics().density;
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MapView, 0, 0);
try {
mapboxMapOptions.debugActive(typedArray.getBoolean(R.styleable.MapView_debug_active, false));
mapboxMapOptions.camera(new CameraPosition.Builder(typedArray).build());
mapboxMapOptions.accessToken(typedArray.getString(R.styleable.MapView_access_token));
mapboxMapOptions.styleUrl(typedArray.getString(R.styleable.MapView_style_url));
mapboxMapOptions.zoomGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_enabled, true));
mapboxMapOptions.scrollGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_scroll_enabled, true));
mapboxMapOptions.rotateGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_rotate_enabled, true));
mapboxMapOptions.tiltGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_tilt_enabled, true));
mapboxMapOptions.zoomControlsEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_controls_enabled, false));
mapboxMapOptions.maxZoom(typedArray.getFloat(R.styleable.MapView_zoom_max, MapboxConstants.MAXIMUM_ZOOM));
mapboxMapOptions.minZoom(typedArray.getFloat(R.styleable.MapView_zoom_min, MapboxConstants.MINIMUM_ZOOM));
mapboxMapOptions.compassEnabled(typedArray.getBoolean(R.styleable.MapView_compass_enabled, true));
mapboxMapOptions.compassGravity(typedArray.getInt(R.styleable.MapView_compass_gravity, Gravity.TOP | Gravity.END));
mapboxMapOptions.compassMargins(new int[]{(int) (typedArray.getDimension(R.styleable.MapView_compass_margin_left, DIMENSION_TEN_DP) * screenDensity)
, ((int) typedArray.getDimension(R.styleable.MapView_compass_margin_top, DIMENSION_TEN_DP * screenDensity))
, ((int) typedArray.getDimension(R.styleable.MapView_compass_margin_right, DIMENSION_TEN_DP * screenDensity))
, ((int) typedArray.getDimension(R.styleable.MapView_compass_margin_bottom, DIMENSION_TEN_DP * screenDensity))});
//
// // Logo
uiSettings.setLogoEnabled(typedArray.getBoolean(R.styleable.MapView_logo_visibility, true));
uiSettings.setLogoGravity(typedArray.getInt(R.styleable.MapView_logo_gravity, Gravity.BOTTOM | Gravity.START));
uiSettings.setLogoMargins((int) (typedArray.getDimension(R.styleable.MapView_logo_margin_left, DIMENSION_SIXTEEN_DP) * mScreenDensity)
, (int) (typedArray.getDimension(R.styleable.MapView_logo_margin_top, DIMENSION_SIXTEEN_DP) * mScreenDensity)
, (int) (typedArray.getDimension(R.styleable.MapView_logo_margin_right, DIMENSION_SIXTEEN_DP) * mScreenDensity)
, (int) (typedArray.getDimension(R.styleable.MapView_logo_margin_bottom, DIMENSION_SIXTEEN_DP) * mScreenDensity));
//
// // Attribution
// uiSettings.setAttributionEnabled(typedArray.getBoolean(R.styleable.MapView_attribution_visibility, true));
// uiSettings.setAttributionGravity(typedArray.getInt(R.styleable.MapView_attribution_gravity, Gravity.BOTTOM));
// uiSettings.setAttributionMargins((int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_left, DIMENSION_SEVENTY_SIX_DP) * mScreenDensity)
// , (int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_top, DIMENSION_SEVEN_DP) * mScreenDensity)
// , (int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_right, DIMENSION_SEVEN_DP) * mScreenDensity)
// , (int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_bottom, DIMENSION_SEVEN_DP) * mScreenDensity));
//
// // User location
// mMapboxMap.setMyLocationEnabled(typedArray.getBoolean(R.styleable.MapView_my_location_enabled, false));
} finally {
typedArray.recycle();
}
return mapboxMapOptions;
}
public MapboxMapOptions camera(CameraPosition cameraPosition) {
this.cameraPosition = cameraPosition;
return this;
}
public MapboxMapOptions accessToken(String accessToken) {
this.accessToken = accessToken;
return this;
}
public MapboxMapOptions styleUrl(String styleUrl) {
style = styleUrl;
return this;
}
public MapboxMapOptions debugActive(boolean enabled) {
debugActive = enabled;
return this;
}
public MapboxMapOptions minZoom(float minZoom) {
this.minZoom = minZoom;
return this;
}
public MapboxMapOptions maxZoom(float maxZoom) {
this.maxZoom = maxZoom;
return this;
}
public MapboxMapOptions compassEnabled(boolean enabled) {
compassEnabled = enabled;
return this;
}
public MapboxMapOptions compassGravity(int gravity) {
compassGravity = gravity;
return this;
}
public MapboxMapOptions compassMargins(int[] margins) {
compassMargins = margins;
return this;
}
public MapboxMapOptions logoEnabled(boolean enabled){
logoEnabled = enabled;
return this
}
public MapboxMapOptions logoGravity(int gravity){
logoGravity = gravity;
return this;
}
public MapboxMapOptions logoMargins(int[]margins){
logoMargins = margins;
return this;
}
public MapboxMapOptions rotateGesturesEnabled(boolean enabled) {
rotateGesturesEnabled = enabled;
return this;
}
public MapboxMapOptions scrollGesturesEnabled(boolean enabled) {
scrollGesturesEnabled = enabled;
return this;
}
public MapboxMapOptions tiltGesturesEnabled(boolean enabled) {
tiltGesturesEnabled = enabled;
return this;
}
public MapboxMapOptions zoomControlsEnabled(boolean enabled) {
zoomControlsEnabled = enabled;
return this;
}
public MapboxMapOptions zoomGesturesEnabled(boolean enabled) {
zoomGesturesEnabled = enabled;
return this;
}
public CameraPosition getCamera() {
return cameraPosition;
}
public float getMinZoom() {
return minZoom;
}
public float getMaxZoom() {
return maxZoom;
}
public boolean getCompassEnabled() {
return compassEnabled;
}
public int getCompassGravity() {
return compassGravity;
}
public int[] getCompassMargins() {
return compassMargins;
}
public boolean getLogoEnabled() {
return logoEnabled;
}
public int getLogoGravity() {
return logoGravity;
}
public int[] getLogoMargins() {
return logoMargins;
}
public String getAccessToken() {
return accessToken;
}
public String getStyle() {
return style;
}
public boolean getRotateGesturesEnabled() {
return rotateGesturesEnabled;
}
public boolean getScrollGesturesEnabled() {
return scrollGesturesEnabled;
}
public boolean getTitltGesturesEnabeld() {
return tiltGesturesEnabled;
}
public boolean getZoomControlsEnabled() {
return zoomControlsEnabled;
}
public boolean getZoomGesturesEnabled() {
return zoomGesturesEnabled;
}
public static final Parcelable.Creator<MapboxMapOptions> CREATOR
= new Parcelable.Creator<MapboxMapOptions>() {
public MapboxMapOptions createFromParcel(Parcel in) {
return new MapboxMapOptions(in);
}
public MapboxMapOptions[] newArray(int size) {
return new MapboxMapOptions[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(cameraPosition, flags);
dest.writeByte((byte) (debugActive ? 1 : 0));
dest.writeByte((byte) (compassEnabled ? 1 : 0));
dest.writeByte((byte) (rotateGesturesEnabled ? 1 : 0));
dest.writeByte((byte) (scrollGesturesEnabled ? 1 : 0));
dest.writeByte((byte) (tiltGesturesEnabled ? 1 : 0));
dest.writeByte((byte) (zoomControlsEnabled ? 1 : 0));
dest.writeByte((byte) (zoomGesturesEnabled ? 1 : 0));
dest.writeString(style);
dest.writeString(accessToken);
}
}

View File

@@ -1,16 +1,14 @@
package com.mapbox.mapboxsdk.maps;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
/**
* Support Fragment wrapper around a map view.
@@ -30,17 +28,25 @@ public class SupportMapFragment extends Fragment {
private MapView mMap;
public static SupportMapFragment newInstance() {
return new SupportMapFragment();
public static MapFragment newInstance(@Nullable MapboxMapOptions mapboxMapOptions) {
MapFragment mapFragment = new MapFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(MapboxConstants.FRAG_ARG_MAPBOXMAPOPTIONS, mapboxMapOptions);
mapFragment.setArguments(bundle);
return mapFragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
mMap = (MapView) inflater.inflate(R.layout.fragment_mapview, container, false);
mMap.setAccessToken(ApiAccess.getToken(inflater.getContext()));
MapboxMapOptions options = getArguments().getParcelable(MapboxConstants.FRAG_ARG_MAPBOXMAPOPTIONS);
return mMap = new MapView(inflater.getContext(), options);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mMap.onCreate(savedInstanceState);
return mMap;
}
@Override
@@ -63,8 +69,8 @@ public class SupportMapFragment extends Fragment {
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
mMap.onSaveInstanceState(outState);
super.onSaveInstanceState(outState);
mMap.onSaveInstanceState(outState);
}
@Override
@@ -75,8 +81,8 @@ public class SupportMapFragment extends Fragment {
@Override
public void onLowMemory() {
mMap.onLowMemory();
super.onLowMemory();
mMap.onLowMemory();
}
@Override
@@ -86,13 +92,7 @@ public class SupportMapFragment extends Fragment {
mMap = null;
}
@NonNull
public void getMapAsync(@NonNull final OnMapReadyCallback onMapReadyCallback) {
new Handler().post(new Runnable() {
@Override
public void run() {
mMap.getMapAsync(onMapReadyCallback);
}
});
mMap.getMapAsync(onMapReadyCallback);
}
}
}

View File

@@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<com.mapbox.mapboxsdk.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@@ -18,7 +18,7 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
public class AnimatedMarkerActivity extends AppCompatActivity {

View File

@@ -22,7 +22,7 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.utils.GeoParseUtil;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
import org.json.JSONException;

View File

@@ -14,10 +14,9 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
public class CameraActivity extends AppCompatActivity {

View File

@@ -11,12 +11,11 @@ import android.view.MenuItem;
import android.view.View;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
public class CoordinateChangeActivity extends AppCompatActivity {

View File

@@ -21,7 +21,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
import java.util.List;

View File

@@ -13,13 +13,12 @@ import android.view.View;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
public class DynamicMarkerChangeActivity extends AppCompatActivity {

View File

@@ -26,7 +26,7 @@ import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.Projection;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
import java.util.List;

View File

@@ -11,10 +11,9 @@ import android.widget.Toast;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
import java.text.DecimalFormat;

View File

@@ -21,7 +21,7 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.annotations.CityStateMarker;
import com.mapbox.mapboxsdk.testapp.annotations.CityStateMarkerOptions;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
public class InfoWindowAdapterActivity extends AppCompatActivity {

View File

@@ -9,10 +9,10 @@ import android.view.MenuItem;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
public class InfoWindowConcurrentActivity extends AppCompatActivity {
@@ -35,7 +35,6 @@ public class InfoWindowConcurrentActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.infoWindowConcurrentMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {

View File

@@ -17,7 +17,7 @@ import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
public class LatLngBoundsActivity extends AppCompatActivity {

View File

@@ -43,7 +43,7 @@ import com.mapbox.mapboxsdk.maps.TrackingSettings;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.testapp.layers.ExampleCustomLayer;
import com.mapbox.mapboxsdk.testapp.utils.GeoParseUtil;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
import java.text.DecimalFormat;
import java.util.ArrayList;

View File

@@ -15,7 +15,7 @@ import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
public class ManualZoomActivity extends AppCompatActivity {

View File

@@ -10,11 +10,13 @@ import android.view.MenuItem;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.maps.MapFragment;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapFragment;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
public class MapFragmentActivity extends AppCompatActivity {
@@ -35,7 +37,12 @@ public class MapFragmentActivity extends AppCompatActivity {
MapFragment mapFragment;
if (savedInstanceState == null) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(R.id.fragment_container, mapFragment = MapFragment.newInstance(), "com.mapbox.map");
MapboxMapOptions options = new MapboxMapOptions();
options.accessToken(ApiAccess.getToken(this));
options.styleUrl(Style.SATELLITE);
transaction.add(R.id.fragment_container, mapFragment = MapFragment.newInstance(options), "com.mapbox.map");
transaction.commit();
} else {
mapFragment = (MapFragment) getFragmentManager().findFragmentByTag("com.mapbox.map");
@@ -44,7 +51,6 @@ public class MapFragmentActivity extends AppCompatActivity {
mapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyleUrl(Style.SATELLITE_STREETS);
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(new LatLng(48.861431, 2.334166))

View File

@@ -11,14 +11,13 @@ import android.view.MenuItem;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.TrackingSettings;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
public class MapPaddingActivity extends AppCompatActivity {

View File

@@ -14,7 +14,7 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
public class MapboxMapActivity extends AppCompatActivity {

View File

@@ -16,7 +16,7 @@ import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
public class MaxMinZoomActivity extends AppCompatActivity {

View File

@@ -22,7 +22,7 @@ import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.TrackingSettings;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
public class MyLocationTrackingModeActivity extends AppCompatActivity implements MapboxMap.OnMyLocationChangeListener, AdapterView.OnItemSelectedListener {

View File

@@ -28,7 +28,7 @@ import com.mapbox.mapboxsdk.offline.OfflineRegionStatus;
import com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition;
import com.mapbox.mapboxsdk.testapp.offline.DownloadRegionDialog;
import com.mapbox.mapboxsdk.testapp.offline.ListRegionsDialog;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
import org.json.JSONObject;

View File

@@ -15,7 +15,7 @@ import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
import java.util.ArrayList;

View File

@@ -15,7 +15,7 @@ import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
import java.text.DecimalFormat;

View File

@@ -20,7 +20,7 @@ import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
public class ScrollByActivity extends AppCompatActivity {

View File

@@ -35,25 +35,25 @@ public class SupportMapFragmentActivity extends AppCompatActivity {
SupportMapFragment mapFragment;
if (savedInstanceState == null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.fragment_container, mapFragment = SupportMapFragment.newInstance(), "com.mapbox.map");
// transaction.add(R.id.fragment_container, mapFragment = SupportMapFragment.newInstance(), "com.mapbox.map");
transaction.commit();
} else {
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentByTag("com.mapbox.map");
}
mapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyleUrl(Style.SATELLITE_STREETS);
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(new LatLng(48.861431, 2.334166))
.zoom(10)
.bearing(0)
.tilt(0)
.build()));
}
});
// mapFragment.getMapAsync(new OnMapReadyCallback() {
// @Override
// public void onMapReady(@NonNull MapboxMap mapboxMap) {
// mapboxMap.setStyleUrl(Style.SATELLITE_STREETS);
// mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
// new CameraPosition.Builder()
// .target(new LatLng(48.861431, 2.334166))
// .zoom(10)
// .bearing(0)
// .tilt(0)
// .build()));
// }
// });
}
@Override

View File

@@ -9,11 +9,10 @@ import android.view.MenuItem;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
public class TiltActivity extends AppCompatActivity {

View File

@@ -1,4 +1,4 @@
package com.mapbox.mapboxsdk.utils;
package com.mapbox.mapboxsdk.testapp.utils;
import android.content.Context;
import android.content.pm.ApplicationInfo;

View File

@@ -0,0 +1,114 @@
package com.mapbox.mapboxsdk.maps;
import android.view.Gravity;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import org.junit.Test;
import java.util.Arrays;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class MapboxMapOptionsTest {
@Test
public void testSanity() {
assertNotNull("should not be null", new MapboxMapOptions());
}
@Test
public void testCompassEnabled() {
assertTrue(new MapboxMapOptions().compassEnabled(true).getCompassEnabled());
assertFalse(new MapboxMapOptions().compassEnabled(false).getCompassEnabled());
}
@Test
public void testCompassGravity() {
assertEquals(Gravity.TOP | Gravity.END, new MapboxMapOptions().getCompassGravity());
assertEquals(Gravity.BOTTOM, new MapboxMapOptions().compassGravity(Gravity.BOTTOM).getCompassGravity());
assertNotEquals(Gravity.START, new MapboxMapOptions().compassGravity(Gravity.BOTTOM).getCompassGravity());
}
@Test
public void testCompassMargins() {
assertTrue(Arrays.equals(new int[]{0, 1, 2, 3}, new MapboxMapOptions().compassMargins(new int[]{0, 1, 2, 3}).getCompassMargins()));
assertFalse(Arrays.equals(new int[]{0, 1, 2, 3}, new MapboxMapOptions().compassMargins(new int[]{0, 0, 0, 0}).getCompassMargins()));
}
@Test
public void testMinZoom() {
assertEquals(MapboxConstants.MINIMUM_ZOOM, new MapboxMapOptions().getMinZoom());
assertEquals(5.0f, new MapboxMapOptions().minZoom(5.0f).getMinZoom());
assertNotEquals(2.0f, new MapboxMapOptions().minZoom(5.0f).getMinZoom());
}
@Test
public void testMaxZoom() {
assertEquals(MapboxConstants.MAXIMUM_ZOOM, new MapboxMapOptions().getMaxZoom());
assertEquals(5.0f, new MapboxMapOptions().maxZoom(5.0f).getMaxZoom());
assertNotEquals(2.0f, new MapboxMapOptions().maxZoom(5.0f).getMaxZoom());
}
@Test
public void testTiltGesturesEnabled() {
assertTrue(new MapboxMapOptions().tiltGesturesEnabled(true).getTitltGesturesEnabeld());
assertFalse(new MapboxMapOptions().tiltGesturesEnabled(false).getTitltGesturesEnabeld());
}
@Test
public void testScrollGesturesEnabled() {
assertTrue(new MapboxMapOptions().scrollGesturesEnabled(true).getScrollGesturesEnabled());
assertFalse(new MapboxMapOptions().scrollGesturesEnabled(false).getScrollGesturesEnabled());
}
@Test
public void testZoomGesturesEnabled() {
assertTrue(new MapboxMapOptions().zoomGesturesEnabled(true).getZoomGesturesEnabled());
assertFalse(new MapboxMapOptions().zoomGesturesEnabled(false).getZoomGesturesEnabled());
}
@Test
public void testRotateGesturesEnabled() {
assertTrue(new MapboxMapOptions().rotateGesturesEnabled(true).getRotateGesturesEnabled());
assertFalse(new MapboxMapOptions().rotateGesturesEnabled(false).getRotateGesturesEnabled());
}
@Test
public void testZoomControlsEnabled() {
assertTrue(new MapboxMapOptions().zoomControlsEnabled(true).getZoomControlsEnabled());
assertFalse(new MapboxMapOptions().zoomControlsEnabled(false).getZoomControlsEnabled());
}
@Test
public void testStyleUrl() {
assertEquals(Style.DARK, new MapboxMapOptions().styleUrl(Style.DARK).getStyle());
assertNotEquals(Style.LIGHT, new MapboxMapOptions().styleUrl(Style.DARK).getStyle());
assertNull(new MapboxMapOptions().getStyle());
}
@Test
public void testCamera() {
CameraPosition position = new CameraPosition.Builder().build();
assertEquals(new CameraPosition.Builder(position).build(), new MapboxMapOptions().camera(position).getCamera());
assertNotEquals(new CameraPosition.Builder().target(new LatLng(1, 1)), new MapboxMapOptions().camera(position));
assertNull(new MapboxMapOptions().getCamera());
}
@Test
public void testAccessToken() {
assertNull(new MapboxMapOptions().getAccessToken());
assertEquals("test", new MapboxMapOptions().accessToken("test").getAccessToken());
assertNotEquals("nottest", new MapboxMapOptions().accessToken("test").getStyle());
}
}