[android] #4076 - MapboxMapOptions initial version
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
|
||||
/**
|
||||
* {@code ApiAccess} provides a method to load the Mapbox access token.
|
||||
*/
|
||||
public final class ApiAccess {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Returns the Mapbox access token set in the app resources.
|
||||
* </p>
|
||||
* It will first search the application manifest for a {@link MapboxConstants#KEY_META_DATA_MANIFEST}
|
||||
* meta-data value. If not found it will then attempt to load the access token from the
|
||||
* {@code res/raw/token.txt} development file.
|
||||
*
|
||||
* @param context The {@link Context} of the {@link android.app.Activity} or {@link android.app.Fragment}.
|
||||
* @return The Mapbox access token or null if not found.
|
||||
* @see MapboxConstants#KEY_META_DATA_MANIFEST
|
||||
*/
|
||||
public static String getToken(@NonNull Context context) {
|
||||
try {
|
||||
// read out AndroidManifest
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
ApplicationInfo appInfo = packageManager.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
|
||||
String token = appInfo.metaData.getString(MapboxConstants.KEY_META_DATA_MANIFEST);
|
||||
if (token == null || token.isEmpty()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return token;
|
||||
} catch (Exception e) {
|
||||
// use fallback on string resource, used for development
|
||||
int tokenResId = context.getResources().getIdentifier("mapbox_access_token", "string", context.getPackageName());
|
||||
return tokenResId != 0 ? context.getString(tokenResId) : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user