[android] #4396 - UserLocationView refactor

This commit is contained in:
Tobrun
2016-04-13 15:17:31 +02:00
parent b3e340ca11
commit 00381a2ae0
7 changed files with 657 additions and 643 deletions

View File

@@ -469,11 +469,11 @@ public class MapView extends FrameLayout {
outState.putBoolean(MapboxConstants.STATE_ZOOM_ENABLED, uiSettings.isZoomGesturesEnabled());
outState.putBoolean(MapboxConstants.STATE_ZOOM_ENABLED_CHANGE, uiSettings.isZoomGestureChangeAllowed());
outState.putBoolean(MapboxConstants.STATE_SCROLL_ENABLED, uiSettings.isScrollGesturesEnabled());
outState.putBoolean(MapboxConstants.STATE_SCROLL_ENABLED_CHANGE,uiSettings.isScrollGestureChangeAllowed());
outState.putBoolean(MapboxConstants.STATE_SCROLL_ENABLED_CHANGE, uiSettings.isScrollGestureChangeAllowed());
outState.putBoolean(MapboxConstants.STATE_ROTATE_ENABLED, uiSettings.isRotateGesturesEnabled());
outState.putBoolean(MapboxConstants.STATE_ROTATE_ENABLED_CHANGE,uiSettings.isRotateGestureChangeAllowed());
outState.putBoolean(MapboxConstants.STATE_ROTATE_ENABLED_CHANGE, uiSettings.isRotateGestureChangeAllowed());
outState.putBoolean(MapboxConstants.STATE_TILT_ENABLED, uiSettings.isTiltGesturesEnabled());
outState.putBoolean(MapboxConstants.STATE_TILT_ENABLED_CHANGE,uiSettings.isTiltGestureChangeAllowed());
outState.putBoolean(MapboxConstants.STATE_TILT_ENABLED_CHANGE, uiSettings.isTiltGestureChangeAllowed());
outState.putBoolean(MapboxConstants.STATE_ZOOM_CONTROLS_ENABLED, uiSettings.isZoomControlsEnabled());
// UiSettings - Compass
@@ -588,6 +588,7 @@ public class MapView extends FrameLayout {
if (duration != null) {
actualDuration = duration;
}
mUserLocationView.setTilt(pitch);
mNativeMapView.setPitch(pitch, actualDuration);
}
@@ -889,58 +890,59 @@ public class MapView extends FrameLayout {
* Set the user location view default drawable .
*/
void setUserLocationDrawable(Drawable drawable) {
mUserLocationView.setUserLocationDrawable(drawable);
mUserLocationView.setForegroundDrawable(drawable);
}
/**
* Set the user location view default drawable and its shadow.
*/
void setUserLocationDrawable(Drawable drawable, Drawable shadowDrawable) {
mUserLocationView.setUserLocationDrawable(drawable, shadowDrawable);
mUserLocationView.setForegroundDrawable(drawable);
mUserLocationView.setShadowDrawable(shadowDrawable);
}
//
// /**
// * Set the user location view bearing drawable.
// */
// void setUserLocationBearingDrawable(Drawable drawable) {
// mUserLocationView.setUserLocationBearingDrawable(drawable);
// }
//
// /**
// * Set the user location view bearing drawable and its shadow.
// */
// void setUserLocationBearingDrawable(Drawable drawable, Drawable shadowDrawable) {
// mUserLocationView.setUserLocationBearingDrawable(drawable, shadowDrawable);
// }
//
// /**
// * Set the stale user location view drawable.
// */
// void setUserLocationStaleDrawable(Drawable drawable) {
// mUserLocationView.setUserLocationStaleDrawable(drawable);
// }
//
// /**
// * Set the stale user location view drawable and its shadow.
// */
// void setUserLocationStaleDrawable(Drawable drawable, Drawable shadowDrawable) {
// mUserLocationView.setUserLocationStaleDrawable(drawable, shadowDrawable);
// }
/**
* Set the user location view bearing drawable.
*/
void setUserLocationBearingDrawable(Drawable drawable) {
mUserLocationView.setUserLocationBearingDrawable(drawable);
}
/**
* Set the user location view bearing drawable and its shadow.
*/
void setUserLocationBearingDrawable(Drawable drawable, Drawable shadowDrawable) {
mUserLocationView.setUserLocationBearingDrawable(drawable, shadowDrawable);
}
/**
* Set the stale user location view drawable.
*/
void setUserLocationStaleDrawable(Drawable drawable) {
mUserLocationView.setUserLocationStaleDrawable(drawable);
}
/**
* Set the stale user location view drawable and its shadow.
*/
void setUserLocationStaleDrawable(Drawable drawable, Drawable shadowDrawable) {
mUserLocationView.setUserLocationStaleDrawable(drawable, shadowDrawable);
}
/**
* Set the offset of the user location view shadow
*/
void setUserLocationShadowOffset(int x, int y) {
mUserLocationView.setUserLocationShadowOffset(x, y);
}
/**
* Change the accuracy color
* @param color int real color (not a @ColorRes)
*/
void setUserLocationAccuracyColor(int color) {
mUserLocationView.setUserLocationAccuracyColor(color);
}
// /**
// * Set the offset of the user location view shadow
// */
// void setUserLocationShadowOffset(int x, int y) {
// mUserLocationView.setUserLocationShadowOffset(x, y);
// }
//
// /**
// * Change the accuracy color
// * @param color int real color (not a @ColorRes)
// */
// void setUserLocationAccuracyColor(int color) {
// mUserLocationView.setUserLocationAccuracyColor(color);
// }
//
// Projection
@@ -955,7 +957,7 @@ public class MapView extends FrameLayout {
}
PointF toScreenLocation(@NonNull LatLng location) {
if (mDestroyed) {
if (mDestroyed || location == null) {
return new PointF();
}
PointF pointF = mNativeMapView.pixelForLatLng(location);
@@ -1125,7 +1127,7 @@ public class MapView extends FrameLayout {
}
private List<Marker> getMarkersInBounds(@NonNull LatLngBounds bbox) {
if (mDestroyed || bbox==null) {
if (mDestroyed || bbox == null) {
return new ArrayList<>();
}
@@ -1838,8 +1840,9 @@ public class MapView extends FrameLayout {
mNativeMapView.scaleBy(detector.getScaleFactor(), (getWidth() / 2) / mScreenDensity, (getHeight() / 2) / mScreenDensity);
} else {
// around user location view
PointF centerPoint = mUserLocationView.getMarkerScreenPoint();
mNativeMapView.scaleBy(detector.getScaleFactor(), centerPoint.x / mScreenDensity, centerPoint.y / mScreenDensity);
float x = mUserLocationView.getX() + mUserLocationView.getWidth() / 2;
float y = mUserLocationView.getY() + mUserLocationView.getHeight() / 2;
mNativeMapView.scaleBy(detector.getScaleFactor(), x / mScreenDensity, y / mScreenDensity);
}
}
return true;
@@ -1918,8 +1921,9 @@ public class MapView extends FrameLayout {
detector.getFocusY() / mScreenDensity);
} else {
// around center userlocation
PointF centerPoint = mUserLocationView.getMarkerScreenPoint();
mNativeMapView.setBearing(bearing, centerPoint.x / mScreenDensity, centerPoint.y / mScreenDensity);
float x = mUserLocationView.getX() + mUserLocationView.getWidth() / 2;
float y = mUserLocationView.getY() + mUserLocationView.getHeight() / 2;
mNativeMapView.setBearing(bearing, x / mScreenDensity, y / mScreenDensity);
}
return true;
}

View File

@@ -592,52 +592,52 @@ public class MapboxMap {
}
/**
* Set the user location view bearing drawable.
*/
public void setUserLocationBearingDrawable(Drawable drawable) {
mMapView.setUserLocationBearingDrawable(drawable);
}
/**
* Set the user location view bearing drawable and its shadow.
*/
public void setUserLocationBearingDrawable(Drawable drawable, Drawable shadowDrawable) {
mMapView.setUserLocationBearingDrawable(drawable, shadowDrawable);
}
/**
* Set the stale user location view drawable.
*/
public void setUserLocationStaleDrawable(Drawable drawable) {
mMapView.setUserLocationStaleDrawable(drawable);
}
/**
* Set the stale user location view drawable and its shadow.
*/
public void setUserLocationStaleDrawable(Drawable drawable, Drawable shadowDrawable) {
mMapView.setUserLocationStaleDrawable(drawable, shadowDrawable);
}
/**
* Set the offset of the user location view shadow.
*
* @param x int x offset in pixels
* @param y int y offset in pixels
*/
public void setUserLocationShadowOffset(int x, int y) {
mMapView.setUserLocationShadowOffset(x, y);
}
/**
* Change the accuracy circle (fill and stroke) color of the user location view
*
* @param color int real color (not a @ColorRes)
*/
public void setUserLocationAccuracyColor(int color) {
mMapView.setUserLocationAccuracyColor(color);
}
// * Set the user location view bearing drawable.
// */
// public void setUserLocationBearingDrawable(Drawable drawable) {
// mMapView.setUserLocationBearingDrawable(drawable);
// }
//
// /**
// * Set the user location view bearing drawable and its shadow.
// */
// public void setUserLocationBearingDrawable(Drawable drawable, Drawable shadowDrawable) {
// mMapView.setUserLocationBearingDrawable(drawable, shadowDrawable);
// }
//
// /**
// * Set the stale user location view drawable.
// */
// public void setUserLocationStaleDrawable(Drawable drawable) {
// mMapView.setUserLocationStaleDrawable(drawable);
// }
//
// /**
// * Set the stale user location view drawable and its shadow.
// */
// public void setUserLocationStaleDrawable(Drawable drawable, Drawable shadowDrawable) {
// mMapView.setUserLocationStaleDrawable(drawable, shadowDrawable);
// }
//
//
// /**
// * Set the offset of the user location view shadow.
// *
// * @param x int x offset in pixels
// * @param y int y offset in pixels
// */
// public void setUserLocationShadowOffset(int x, int y) {
// mMapView.setUserLocationShadowOffset(x, y);
// }
//
// /**
// * Change the accuracy circle (fill and stroke) color of the user location view
// *
// * @param color int real color (not a @ColorRes)
// */
// public void setUserLocationAccuracyColor(int color) {
// mMapView.setUserLocationAccuracyColor(color);
// }
/**

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="@color/white"/>
<size
android:width="@dimen/userlocationview_outer_circle"
android:height="@dimen/userlocationview_outer_circle"/>
</shape>

View File

@@ -9,4 +9,6 @@
<dimen name="ten_dp">10dp</dimen>
<dimen name="sixteen_dp">16dp</dimen>
<dimen name="seventy_six_dp">76dp</dimen>
<dimen name="userlocationview_inner_circle">19dp</dimen>
<dimen name="userlocationview_outer_circle">20dp</dimen>
</resources>