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

Commit

Permalink
[android] - Correct logo placement for creating a Mapview programatic…
Browse files Browse the repository at this point in the history
…ally, fixup non default placements
  • Loading branch information
tobrun committed May 23, 2017
1 parent a19fd81 commit f098980
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class MapboxMapOptions implements Parcelable {

private static final float FOUR_DP = 4f;
private static final float EIGHTY_NINE_DP = 92f;
private static final float NIGHTY_TWO_DP = 92f;

private CameraPosition cameraPosition;

Expand Down Expand Up @@ -241,7 +241,7 @@ public static MapboxMapOptions createFromAttributes(@NonNull Context context, @N
R.styleable.mapbox_MapView_mapbox_uiAttributionGravity, Gravity.BOTTOM));
mapboxMapOptions.attributionMargins(new int[] {
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginLeft,
EIGHTY_NINE_DP * pxlRatio)),
NIGHTY_TWO_DP * pxlRatio)),
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginTop,
FOUR_DP * pxlRatio)),
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginRight,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.maps.widgets.CompassView;
import com.mapbox.mapboxsdk.storage.Resource;
import com.mapbox.mapboxsdk.utils.ColorUtils;

import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -193,12 +194,16 @@ private Drawable decode(byte[] bitmap) {
private void initialiseLogo(MapboxMapOptions options, Resources resources) {
setLogoEnabled(options.getLogoEnabled());
setLogoGravity(options.getLogoGravity());
int[] logoMargins = options.getLogoMargins();
setLogoMargins(resources, options.getLogoMargins());
}

private void setLogoMargins(Resources resources, int[]logoMargins) {
if (logoMargins != null) {
setLogoMargins(logoMargins[0], logoMargins[1], logoMargins[2], logoMargins[3]);
} else {
int twoDp = (int) resources.getDimension(R.dimen.mapbox_two_dp);
setLogoMargins(twoDp, twoDp, twoDp, twoDp);
// user did not specify margins when programmatically creating a map
int fourDp = (int) resources.getDimension(R.dimen.mapbox_four_dp);
setLogoMargins(fourDp, fourDp, fourDp, fourDp);
}
}

Expand All @@ -223,15 +228,23 @@ private void restoreLogo(Bundle savedInstanceState) {
private void initialiseAttribution(Context context, MapboxMapOptions options) {
setAttributionEnabled(options.getAttributionEnabled());
setAttributionGravity(options.getAttributionGravity());
int[] attributionMargins = options.getAttributionMargins();
setAttributionMargins(context, options.getAttributionMargins());
int attributionTintColor = options.getAttributionTintColor();
setAttributionTintColor(attributionTintColor != -1
? attributionTintColor : ColorUtils.getPrimaryColor(context));
}

private void setAttributionMargins(Context context, int[] attributionMargins) {
if (attributionMargins != null) {
setAttributionMargins(attributionMargins[0], attributionMargins[1],
attributionMargins[2], attributionMargins[3]);
} else {
// user did not specify margins when programmatically creating a map
Resources resources = context.getResources();
int margin = (int) resources.getDimension(R.dimen.mapbox_four_dp);
int leftMargin = (int) resources.getDimension(R.dimen.mapbox_ninety_two_dp);
setAttributionMargins(leftMargin, margin, margin, margin);
}

int attributionTintColor = options.getAttributionTintColor();
setAttributionTintColor(attributionTintColor != -1
? attributionTintColor : ColorUtils.getPrimaryColor(context));
}

private void saveAttribution(Bundle outState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
<dimen name="mapbox_eight_dp">8dp</dimen>
<dimen name="mapbox_ten_dp">10dp</dimen>
<dimen name="mapbox_sixteen_dp">16dp</dimen>
<dimen name="mapbox_ninety_five_dp">95dp</dimen>
<dimen name="mapbox_ninety_two_dp">92dp</dimen>
<dimen name="mapbox_my_locationview_outer_circle">18dp</dimen>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"
app:mapbox_uiAttributionGravity="top|end"
app:mapbox_uiLogoGravity="top|end"
app:mapbox_uiLogoMarginRight="10dp"/>
app:mapbox_uiLogoMarginRight="28dp"/>

</RelativeLayout>

0 comments on commit f098980

Please sign in to comment.