[android] #4094 - bring back view package

This commit is contained in:
Tobrun
2016-02-24 12:21:31 +01:00
parent 46557874ec
commit 6679e7835d
8 changed files with 87 additions and 39 deletions

View File

@@ -3,7 +3,7 @@ package com.mapbox.mapboxsdk.constants;
import android.support.annotation.IntDef;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.UserLocationView;
import com.mapbox.mapboxsdk.maps.widgets.UserLocationView;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

View File

@@ -3,7 +3,7 @@ package com.mapbox.mapboxsdk.constants;
import android.support.annotation.IntDef;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.UserLocationView;
import com.mapbox.mapboxsdk.maps.widgets.UserLocationView;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

View File

@@ -79,6 +79,8 @@ import com.mapbox.mapboxsdk.exceptions.TelemetryServiceNotConfiguredException;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.layers.CustomLayer;
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;
@@ -212,9 +214,9 @@ public class MapView extends FrameLayout {
onConnectivityChanged(isConnected());
mUserLocationView = (UserLocationView) view.findViewById(R.id.userLocationView);
mUserLocationView.setMapView(this);
mUserLocationView.setMapboxMap(mMapboxMap);
mCompassView = (CompassView) view.findViewById(R.id.compassView);
mCompassView.setOnClickListener(new CompassView.CompassClickListener(this));
mCompassView.setOnClickListener(new CompassView.CompassClickListener(mMapboxMap));
mLogoView = (ImageView) view.findViewById(R.id.logoView);
// Setup Attributions control

View File

@@ -318,6 +318,17 @@ public class MapboxMap {
}
}
//
// Reset North
//
/**
*
*/
public void resetNorth() {
mMapView.resetNorth();
}
//
// Manual zoom controls
//
@@ -1039,6 +1050,17 @@ public class MapboxMap {
moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder(mCameraPosition).build()));
}
/**
*
* @return
*/
public int[] getPadding() {
return new int[]{mMapView.getContentPaddingLeft(),
mMapView.getContentPaddingTop(),
mMapView.getContentPaddingRight(),
mMapView.getContentPaddingBottom()};
}
//
// Map events
//
@@ -1314,6 +1336,14 @@ public class MapboxMap {
return mMapView;
}
//
// Invalidate
//
public void invalidate(){
mMapView.update();
}
//
// Interfaces
//

View File

@@ -1,13 +1,12 @@
package com.mapbox.mapboxsdk.maps;
import android.graphics.PointF;
import android.graphics.RectF;
import android.support.annotation.FloatRange;
import android.support.annotation.NonNull;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.geometry.VisibleRegion;
import com.mapbox.mapboxsdk.utils.MathUtils;
/**
* A projection is used to translate between on screen location and geographic coordinates on
@@ -22,6 +21,20 @@ public class Projection {
this.mMapView = mapView;
}
/**
* <p>
* Returns the distance spanned by one pixel at the specified latitude and current zoom level.
* </p>
* The distance between pixels decreases as the latitude approaches the poles.
* This relationship parallels the relationship between longitudinal coordinates at different latitudes.
*
* @param latitude The latitude for which to return the value.
* @return The distance measured in meters.
*/
public double getMetersPerPixelAtLatitude(@FloatRange(from = -180, to = 180) double latitude) {
return mMapView.getMetersPerPixelAtLatitude(latitude);
}
/**
* Returns the geographic location that corresponds to a screen location.
* The screen location is specified in screen pixels (not display pixels) relative to the

View File

@@ -1,4 +1,4 @@
package com.mapbox.mapboxsdk.maps;
package com.mapbox.mapboxsdk.maps.widgets;
import android.content.Context;
import android.support.v4.content.ContextCompat;
@@ -11,6 +11,8 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import java.lang.ref.WeakReference;
import java.util.Timer;
@@ -21,7 +23,7 @@ import java.util.TimerTask;
* when it isn't true north (0.0). Tapping the compass resets the bearing to true
* north and hides the compass.
*/
public class CompassView extends ImageView {
public final class CompassView extends ImageView {
private Timer mNorthTimer;
private double mDirection = 0.0f;
@@ -139,17 +141,17 @@ public class CompassView extends ImageView {
public static class CompassClickListener implements View.OnClickListener {
private WeakReference<MapView> mMapView;
private WeakReference<MapboxMap> mMapboxMap;
public CompassClickListener(final MapView mapView) {
mMapView = new WeakReference<>(mapView);
public CompassClickListener(final MapboxMap mapboxMap) {
mMapboxMap = new WeakReference<>(mapboxMap);
}
@Override
public void onClick(View v) {
final MapView mapView = mMapView.get();
if (mapView != null) {
mapView.resetNorth();
final MapboxMap mapboxMap = mMapboxMap.get();
if (mapboxMap != null) {
mapboxMap.resetNorth();
}
}
}

View File

@@ -1,4 +1,4 @@
package com.mapbox.mapboxsdk.maps;
package com.mapbox.mapboxsdk.maps.widgets;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
@@ -33,6 +33,8 @@ import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.location.LocationListener;
import com.mapbox.mapboxsdk.location.LocationService;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.Projection;
import java.lang.ref.WeakReference;
@@ -43,9 +45,8 @@ import java.lang.ref.WeakReference;
public final class UserLocationView extends View {
private MapView mMapView;
private float mDensity;
private MapboxMap mMapboxMap;
private Projection mProjection;
private boolean mShowMarker;
private boolean mShowDirection;
@@ -97,7 +98,6 @@ public final class UserLocationView extends View {
@MyBearingTracking.Mode
private int mMyBearingTrackingMode;
// Compass data
private MyBearingListener mBearingChangeListener;
@@ -132,9 +132,9 @@ public final class UserLocationView extends View {
// Setup the custom paint
Resources resources = context.getResources();
int accuracyColor = resources.getColor(R.color.my_location_ring);
int accuracyColor = ContextCompat.getColor(context,R.color.my_location_ring);
mDensity = resources.getDisplayMetrics().density;
float density = resources.getDisplayMetrics().density;
mMarkerCoordinate = new LatLng(0.0, 0.0);
mMarkerScreenPoint = new PointF();
mMarkerScreenMatrix = new Matrix();
@@ -148,7 +148,7 @@ public final class UserLocationView extends View {
mAccuracyPaintStroke = new Paint();
mAccuracyPaintStroke.setAntiAlias(true);
mAccuracyPaintStroke.setStyle(Paint.Style.STROKE);
mAccuracyPaintStroke.setStrokeWidth(0.5f * mDensity);
mAccuracyPaintStroke.setStrokeWidth(0.5f * density);
mAccuracyPaintStroke.setColor(accuracyColor);
mAccuracyPaintStroke.setAlpha((int) (255 * 0.5f));
@@ -195,8 +195,9 @@ public final class UserLocationView extends View {
mUserLocationStaleDrawable.setBounds(mUserLocationStaleDrawableBounds);
}
public void setMapView(MapView mapView) {
mMapView = mapView;
public void setMapboxMap(MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
mProjection = mapboxMap.getProjection();
}
public void onStart() {
@@ -247,7 +248,7 @@ public final class UserLocationView extends View {
if (myLocationTrackingMode != MyLocationTracking.TRACKING_NONE && mUserLocation != null) {
// center map directly if we have a location fix
mMarkerCoordinate = new LatLng(mUserLocation.getLatitude(), mUserLocation.getLongitude());
mMapView.getMapboxMap().moveCamera(CameraUpdateFactory.newLatLng(new LatLng(mUserLocation)));
mMapboxMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(mUserLocation)));
// center view directly
mMarkerScreenMatrix.reset();
@@ -283,11 +284,11 @@ public final class UserLocationView extends View {
if (mShowDirection) {
bearing = mMyBearingTrackingMode == MyBearingTracking.COMPASS ? mBearingChangeListener.getCompassBearing() : mUserLocation.getBearing();
} else {
bearing = (float) mMapView.getBearing();
bearing = mMapboxMap.getCameraPosition().bearing;
}
if (mCurrentMapViewCoordinate == null) {
mCurrentMapViewCoordinate = mMapView.getMapboxMap().getCameraPosition().target;
mCurrentMapViewCoordinate = mMapboxMap.getCameraPosition().target;
}
// only update if there is an actual change
@@ -296,7 +297,7 @@ public final class UserLocationView extends View {
.target(mMarkerCoordinate)
.bearing(bearing)
.build();
mMapView.getMapboxMap().animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 300, null);
mMapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 300, null);
mMarkerScreenMatrix.reset();
mMarkerScreenPoint = getMarkerScreenPoint();
mMarkerScreenMatrix.setTranslate(mMarkerScreenPoint.x, mMarkerScreenPoint.y);
@@ -310,10 +311,10 @@ public final class UserLocationView extends View {
// rotate so arrow in points to bearing
if (mShowDirection) {
if (mMyBearingTrackingMode == MyBearingTracking.COMPASS && mMyLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
mMarkerScreenMatrix.preRotate(mCompassMarkerDirection + (float) mMapView.getDirection());
mMarkerScreenMatrix.preRotate(mCompassMarkerDirection + mMapboxMap.getCameraPosition().bearing);
} else if (mMyBearingTrackingMode == MyBearingTracking.GPS) {
if (mMyLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
mMarkerScreenMatrix.preRotate(mGpsMarkerDirection + (float) mMapView.getDirection());
mMarkerScreenMatrix.preRotate(mGpsMarkerDirection + mMapboxMap.getCameraPosition().bearing);
} else {
mMarkerScreenMatrix.preRotate(mGpsMarkerDirection);
}
@@ -324,7 +325,7 @@ public final class UserLocationView extends View {
if (mShowAccuracy && !mStaleMarker) {
mAccuracyPath.reset();
mAccuracyPath.addCircle(0.0f, 0.0f,
(float) (mMarkerAccuracy / mMapView.getMetersPerPixelAtLatitude(
(float) (mMarkerAccuracy / mMapboxMap.getProjection().getMetersPerPixelAtLatitude(
mMarkerCoordinate.getLatitude())),
Path.Direction.CW);
@@ -471,9 +472,8 @@ public final class UserLocationView extends View {
SensorManager.getRotationMatrix(mR, null, mLastAccelerometer, mLastMagnetometer);
SensorManager.getOrientation(mR, mOrientation);
float azimuthInRadians = mOrientation[0];
float azimuthInDegress = (float) (Math.toDegrees(azimuthInRadians) + 360) % 360;
mCompassBearing = azimuthInDegress;
mCompassBearing = (float) (Math.toDegrees(azimuthInRadians) + 360) % 360;
if (mCompassBearing < 0) {
// only allow positive degrees
mCompassBearing += 360;
@@ -658,7 +658,7 @@ public final class UserLocationView extends View {
}
void updateOnNextFrame() {
mMapView.update();
mMapboxMap.invalidate();
}
/**
@@ -760,10 +760,11 @@ public final class UserLocationView extends View {
public PointF getMarkerScreenPoint() {
if (mMyLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
mMarkerScreenPoint = mMapView.toScreenLocation(mMarkerCoordinate);
mMarkerScreenPoint = mProjection.toScreenLocation(mMarkerCoordinate);
} else {
mMarkerScreenPoint = new PointF(((getMeasuredWidth() + mMapView.getContentPaddingLeft() - mMapView.getContentPaddingRight()) / 2)
, ((getMeasuredHeight() - mMapView.getContentPaddingBottom() + mMapView.getContentPaddingTop()) / 2));
int[] contentPadding = mMapboxMap.getPadding();
mMarkerScreenPoint = new PointF(((getMeasuredWidth() + contentPadding[0] - contentPadding[2]) / 2)
, ((getMeasuredHeight() - contentPadding[3] + contentPadding[1]) / 2));
}
return mMarkerScreenPoint;
}