Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
6039 focal point uses MyLocationView padding (#6108)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
tobrun authored Aug 23, 2016
1 parent e1a6795 commit 50da6e5
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public MyLocationView(Context context, AttributeSet attrs, int defStyleAttr) {
}

private void init(Context context) {
if(isInEditMode()){
if (isInEditMode()) {
return;
}

Expand Down Expand Up @@ -168,7 +168,6 @@ public final void setForegroundDrawables(Drawable defaultDrawable, Drawable bear

foregroundDrawable = defaultDrawable;
foregroundBearingDrawable = bearingDrawable;
setForegroundDrawableTint(foregroundTintColor);

invalidateBounds();
}
Expand Down Expand Up @@ -199,7 +198,6 @@ public final void setShadowDrawable(Drawable drawable, int left, int top, int ri
backgroundOffsetTop = top;
backgroundOffsetRight = right;
backgroundOffsetBottom = bottom;
setShadowDrawableTint(backgroundTintColor);

invalidateBounds();
}
Expand Down Expand Up @@ -389,8 +387,8 @@ protected Parcelable onSaveInstanceState() {
}

@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");
Expand Down Expand Up @@ -496,11 +494,11 @@ private void setCompass(float bearing) {
}

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) {
Expand Down Expand Up @@ -564,34 +562,35 @@ public void onSensorChanged(SensorEvent event) {
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();
}

compassUpdateNextTimestamp = currentTime + COMPASS_UPDATE_RATE_MS;
}
}

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) {
}

}

Expand Down
Loading

0 comments on commit 50da6e5

Please sign in to comment.