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

Commit 50da6e5

Browse files
authored
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
1 parent e1a6795 commit 50da6e5

File tree

8 files changed

+287
-67
lines changed

8 files changed

+287
-67
lines changed

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java

+13-14
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public MyLocationView(Context context, AttributeSet attrs, int defStyleAttr) {
124124
}
125125

126126
private void init(Context context) {
127-
if(isInEditMode()){
127+
if (isInEditMode()) {
128128
return;
129129
}
130130

@@ -168,7 +168,6 @@ public final void setForegroundDrawables(Drawable defaultDrawable, Drawable bear
168168

169169
foregroundDrawable = defaultDrawable;
170170
foregroundBearingDrawable = bearingDrawable;
171-
setForegroundDrawableTint(foregroundTintColor);
172171

173172
invalidateBounds();
174173
}
@@ -199,7 +198,6 @@ public final void setShadowDrawable(Drawable drawable, int left, int top, int ri
199198
backgroundOffsetTop = top;
200199
backgroundOffsetRight = right;
201200
backgroundOffsetBottom = bottom;
202-
setShadowDrawableTint(backgroundTintColor);
203201

204202
invalidateBounds();
205203
}
@@ -389,8 +387,8 @@ protected Parcelable onSaveInstanceState() {
389387
}
390388

391389
@Override
392-
public void onRestoreInstanceState(Parcelable state){
393-
if (state instanceof Bundle){
390+
public void onRestoreInstanceState(Parcelable state) {
391+
if (state instanceof Bundle) {
394392
Bundle bundle = (Bundle) state;
395393
tilt = bundle.getFloat("tilt");
396394
state = bundle.getParcelable("superState");
@@ -496,11 +494,11 @@ private void setCompass(float bearing) {
496494
}
497495

498496
public float getCenterX() {
499-
return getX() + getMeasuredWidth() / 2;
497+
return (getX() + contentPadding[0] - contentPadding[2] + getMeasuredWidth()) / 2;
500498
}
501499

502500
public float getCenterY() {
503-
return getY() + getMeasuredHeight() / 2;
501+
return (getY() + contentPadding[1] - contentPadding[3] + getMeasuredHeight()) / 2;
504502
}
505503

506504
public void setContentPadding(int[] padding) {
@@ -564,34 +562,35 @@ public void onSensorChanged(SensorEvent event) {
564562
return;
565563
}
566564

567-
if( event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR ){
565+
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
568566

569567
// calculate the rotation matrix
570-
SensorManager.getRotationMatrixFromVector(matrix, event.values );
571-
SensorManager.getOrientation(matrix, orientation );
568+
SensorManager.getRotationMatrixFromVector(matrix, event.values);
569+
SensorManager.getOrientation(matrix, orientation);
572570

573-
float magneticHeading = (float) Math.toDegrees(SensorManager.getOrientation(matrix, orientation )[0]);
571+
float magneticHeading = (float) Math.toDegrees(SensorManager.getOrientation(matrix, orientation)[0]);
574572
currentDegree = (int) (magneticHeading);
575573

576574
// Change the user location view orientation to reflect the device orientation
577575
setCompass(currentDegree);
578576

579-
if(myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW){
577+
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
580578
rotateCamera();
581579
}
582580

583581
compassUpdateNextTimestamp = currentTime + COMPASS_UPDATE_RATE_MS;
584582
}
585583
}
586584

587-
private void rotateCamera(){
585+
private void rotateCamera() {
588586
CameraPosition.Builder builder = new CameraPosition.Builder();
589587
builder.bearing(currentDegree);
590588
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), COMPASS_UPDATE_RATE_MS, false /*linear interpolator*/);
591589
}
592590

593591
@Override
594-
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
592+
public void onAccuracyChanged(Sensor sensor, int accuracy) {
593+
}
595594

596595
}
597596

0 commit comments

Comments
 (0)