6039 focal point uses MyLocationView padding (#6108)

* [android] - don't auto tint drawables + formatting

* [android] - formatting

* [android] #6039 - fixes focal point when padding mylocationview

* [android] #5977 - MyLocationView.setPadding example + formatting Manifest

* [android] - Reset to default configuration, cleanup class
This commit is contained in:
Tobrun
2016-08-23 12:53:36 +02:00
committed by GitHub
parent e1a6795a73
commit 50da6e5e71
8 changed files with 287 additions and 67 deletions

View File

@@ -124,7 +124,7 @@ public class MyLocationView extends View {
}
private void init(Context context) {
if(isInEditMode()){
if (isInEditMode()) {
return;
}
@@ -168,7 +168,6 @@ public class MyLocationView extends View {
foregroundDrawable = defaultDrawable;
foregroundBearingDrawable = bearingDrawable;
setForegroundDrawableTint(foregroundTintColor);
invalidateBounds();
}
@@ -199,7 +198,6 @@ public class MyLocationView extends View {
backgroundOffsetTop = top;
backgroundOffsetRight = right;
backgroundOffsetBottom = bottom;
setShadowDrawableTint(backgroundTintColor);
invalidateBounds();
}
@@ -389,8 +387,8 @@ public class MyLocationView extends View {
}
@Override
public void onRestoreInstanceState(Parcelable state){
if (state instanceof Bundle){
public void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
Bundle bundle = (Bundle) state;
tilt = bundle.getFloat("tilt");
state = bundle.getParcelable("superState");
@@ -496,11 +494,11 @@ public class MyLocationView extends View {
}
public float getCenterX() {
return getX() + getMeasuredWidth() / 2;
return (getX() + contentPadding[0] - contentPadding[2] + getMeasuredWidth()) / 2;
}
public float getCenterY() {
return getY() + getMeasuredHeight() / 2;
return (getY() + contentPadding[1] - contentPadding[3] + getMeasuredHeight()) / 2;
}
public void setContentPadding(int[] padding) {
@@ -564,19 +562,19 @@ public class MyLocationView extends View {
return;
}
if( event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR ){
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
// calculate the rotation matrix
SensorManager.getRotationMatrixFromVector(matrix, event.values );
SensorManager.getOrientation(matrix, orientation );
SensorManager.getRotationMatrixFromVector(matrix, event.values);
SensorManager.getOrientation(matrix, orientation);
float magneticHeading = (float) Math.toDegrees(SensorManager.getOrientation(matrix, orientation )[0]);
float magneticHeading = (float) Math.toDegrees(SensorManager.getOrientation(matrix, orientation)[0]);
currentDegree = (int) (magneticHeading);
// Change the user location view orientation to reflect the device orientation
setCompass(currentDegree);
if(myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW){
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
rotateCamera();
}
@@ -584,14 +582,15 @@ public class MyLocationView extends View {
}
}
private void rotateCamera(){
private void rotateCamera() {
CameraPosition.Builder builder = new CameraPosition.Builder();
builder.bearing(currentDegree);
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), COMPASS_UPDATE_RATE_MS, false /*linear interpolator*/);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}