Skip to content

Commit f90d91d

Browse files
committed
Improve switch default behavior
When setting the position of the compass and attribution button, we need to assume the platform default gravity for those elements if no explicit value has been provided. An incorrect default was assumed for the attribution button (copied from the compass), so that is corrected here. The methods for setting gravity do not require a default since they are only called if an explicit gravity value has been provided. Those default cases are removed here. #731 (comment)
1 parent e7cc162 commit f90d91d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

android/src/main/java/com/mapbox/mapboxgl/MapboxMapBuilder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void setMyLocationTrackingMode(int myLocationTrackingMode) {
118118
public void setMyLocationRenderMode(int myLocationRenderMode) {
119119
this.myLocationRenderMode = myLocationRenderMode;
120120
}
121-
121+
122122
public void setLogoViewMargins(int x, int y) {
123123
options.logoMargins(new int[] {
124124
(int) x, //left
@@ -134,7 +134,6 @@ public void setCompassGravity(int gravity) {
134134
case 0:
135135
options.compassGravity(Gravity.TOP | Gravity.START);
136136
break;
137-
default:
138137
case 1:
139138
options.compassGravity(Gravity.TOP | Gravity.END);
140139
break;
@@ -154,6 +153,8 @@ public void setCompassViewMargins(int x, int y) {
154153
case Gravity.TOP | Gravity.START:
155154
options.compassMargins(new int[] {(int) x, (int) y, 0, 0});
156155
break;
156+
// If the application code has not specified gravity, assume the platform
157+
// default for the compass which is top-right
157158
default:
158159
case Gravity.TOP | Gravity.END:
159160
options.compassMargins(new int[] {0, (int) y, (int) x, 0});
@@ -173,7 +174,6 @@ public void setAttributionButtonGravity(int gravity) {
173174
case 0:
174175
options.attributionGravity(Gravity.TOP | Gravity.START);
175176
break;
176-
default:
177177
case 1:
178178
options.attributionGravity(Gravity.TOP | Gravity.END);
179179
break;
@@ -193,10 +193,12 @@ public void setAttributionButtonMargins(int x, int y) {
193193
case Gravity.TOP | Gravity.START:
194194
options.attributionMargins(new int[] {(int) x, (int) y, 0, 0});
195195
break;
196-
default:
197196
case Gravity.TOP | Gravity.END:
198197
options.attributionMargins(new int[] {0, (int) y, (int) x, 0});
199198
break;
199+
// If the application code has not specified gravity, assume the platform
200+
// default for the attribution button which is bottom left
201+
default:
200202
case Gravity.BOTTOM | Gravity.START:
201203
options.attributionMargins(new int[] {(int) x, 0, 0, (int) y});
202204
break;

0 commit comments

Comments
 (0)