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

Commit

Permalink
[android] - RTL support
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Jan 5, 2018
1 parent aa158bb commit 5f8b613
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class MapboxMapOptions implements Parcelable {
@ColorInt
private int attributionTintColor = UNDEFINED_COLOR;
private boolean attributionEnabled = true;
private int attributionGravity = Gravity.BOTTOM;
private int attributionGravity = Gravity.BOTTOM | Gravity.START;
private int[] attributionMargins;

private double minZoom = MapboxConstants.MINIMUM_ZOOM;
Expand Down Expand Up @@ -234,7 +234,7 @@ public static MapboxMapOptions createFromAttributes(@NonNull Context context, @N
mapboxMapOptions.attributionEnabled(typedArray.getBoolean(
R.styleable.mapbox_MapView_mapbox_uiAttribution, true));
mapboxMapOptions.attributionGravity(typedArray.getInt(
R.styleable.mapbox_MapView_mapbox_uiAttributionGravity, Gravity.BOTTOM));
R.styleable.mapbox_MapView_mapbox_uiAttributionGravity, Gravity.BOTTOM | Gravity.START));
mapboxMapOptions.attributionMargins(new int[] {
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginLeft,
NINETY_TWO_DP * pxlRatio)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.graphics.Color;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -925,14 +926,21 @@ private void setWidgetMargins(@NonNull final View view, int[] initMargins, int l
initMargins[2] = right;
initMargins[3] = bottom;

// convert inital margins with padding
// convert initial margins with padding
int[] contentPadding = projection.getContentPadding();
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
left += contentPadding[0];
top += contentPadding[1];
right += contentPadding[2];
bottom += contentPadding[3];
layoutParams.setMargins(left, top, right, bottom);

// support RTL
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
layoutParams.setMarginStart(left);
layoutParams.setMarginEnd(right);
}

view.setLayoutParams(layoutParams);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testAttributionEnabled() {

@Test
public void testAttributionGravity() {
assertEquals(Gravity.BOTTOM, new MapboxMapOptions().getAttributionGravity());
assertEquals(Gravity.BOTTOM | Gravity.START, new MapboxMapOptions().getAttributionGravity());
assertEquals(Gravity.BOTTOM, new MapboxMapOptions().attributionGravity(Gravity.BOTTOM).getAttributionGravity());
assertNotEquals(Gravity.START, new MapboxMapOptions().attributionGravity(Gravity.BOTTOM).getAttributionGravity());
}
Expand Down

0 comments on commit 5f8b613

Please sign in to comment.