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

Commit

Permalink
[android] - keep state of initial overlain views margins
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Jun 29, 2017
1 parent 1df45a5 commit 271e6d4
Showing 1 changed file with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ public final class UiSettings {
private final FocalPointChangeListener focalPointChangeListener;
private final Projection projection;
private final CompassView compassView;
private final int[] compassMargins = new int[4];

private final ImageView attributionsView;
private final int[] attributionsMargins = new int[4];

private final View logoView;
private final int[] logoMargins = new int[4];

private float pixelRatio;

private boolean rotateGesturesEnabled = true;
Expand Down Expand Up @@ -370,7 +376,7 @@ public int getCompassGravity() {
*/
@UiThread
public void setCompassMargins(int left, int top, int right, int bottom) {
setWidgetMargins(compassView, left, top, right, bottom);
setWidgetMargins(compassView, compassMargins, left, top, right, bottom);
}

/**
Expand All @@ -379,7 +385,7 @@ public void setCompassMargins(int left, int top, int right, int bottom) {
* @return The left margin in pixels
*/
public int getCompassMarginLeft() {
return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).leftMargin;
return compassMargins[0];
}

/**
Expand All @@ -388,7 +394,7 @@ public int getCompassMarginLeft() {
* @return The top margin in pixels
*/
public int getCompassMarginTop() {
return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).topMargin;
return compassMargins[1];
}

/**
Expand All @@ -397,7 +403,7 @@ public int getCompassMarginTop() {
* @return The right margin in pixels
*/
public int getCompassMarginRight() {
return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).rightMargin;
return compassMargins[2];
}

/**
Expand All @@ -406,7 +412,7 @@ public int getCompassMarginRight() {
* @return The bottom margin in pixels
*/
public int getCompassMarginBottom() {
return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).bottomMargin;
return compassMargins[3];
}

/**
Expand Down Expand Up @@ -480,7 +486,7 @@ public int getLogoGravity() {
* @param bottom The bottom margin in pixels.
*/
public void setLogoMargins(int left, int top, int right, int bottom) {
setWidgetMargins(logoView, left, top, right, bottom);
setWidgetMargins(logoView, logoMargins, left, top, right, bottom);
}

/**
Expand All @@ -489,7 +495,7 @@ public void setLogoMargins(int left, int top, int right, int bottom) {
* @return The left margin in pixels
*/
public int getLogoMarginLeft() {
return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).leftMargin;
return logoMargins[0];
}

/**
Expand All @@ -498,7 +504,7 @@ public int getLogoMarginLeft() {
* @return The top margin in pixels
*/
public int getLogoMarginTop() {
return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).topMargin;
return logoMargins[1];
}

/**
Expand All @@ -507,7 +513,7 @@ public int getLogoMarginTop() {
* @return The right margin in pixels
*/
public int getLogoMarginRight() {
return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).rightMargin;
return logoMargins[2];
}

/**
Expand All @@ -516,7 +522,7 @@ public int getLogoMarginRight() {
* @return The bottom margin in pixels
*/
public int getLogoMarginBottom() {
return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).bottomMargin;
return logoMargins[3];
}

/**
Expand Down Expand Up @@ -571,7 +577,7 @@ public int getAttributionGravity() {
* @param bottom The bottom margin in pixels.
*/
public void setAttributionMargins(int left, int top, int right, int bottom) {
setWidgetMargins(attributionsView, left, top, right, bottom);
setWidgetMargins(attributionsView, attributionsMargins, left, top, right, bottom);
}

/**
Expand All @@ -598,7 +604,7 @@ public void setAttributionTintColor(@ColorInt int tintColor) {
* @return The left margin in pixels
*/
public int getAttributionMarginLeft() {
return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).leftMargin;
return attributionsMargins[0];
}

/**
Expand All @@ -607,7 +613,7 @@ public int getAttributionMarginLeft() {
* @return The top margin in pixels
*/
public int getAttributionMarginTop() {
return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).topMargin;
return attributionsMargins[1];
}

/**
Expand All @@ -616,7 +622,7 @@ public int getAttributionMarginTop() {
* @return The right margin in pixels
*/
public int getAttributionMarginRight() {
return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).rightMargin;
return attributionsMargins[2];
}

/**
Expand All @@ -625,7 +631,7 @@ public int getAttributionMarginRight() {
* @return The bottom margin in pixels
*/
public int getAttributionMarginBottom() {
return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).bottomMargin;
return attributionsMargins[3];
}

/**
Expand Down Expand Up @@ -929,7 +935,14 @@ private void setWidgetGravity(@NonNull final View view, int gravity) {
view.setLayoutParams(layoutParams);
}

private void setWidgetMargins(@NonNull final View view, int left, int top, int right, int bottom) {
private void setWidgetMargins(@NonNull final View view, int[] initMargins, int left, int top, int right, int bottom) {
// keep state of initially set margins
initMargins[0] = left;
initMargins[1] = top;
initMargins[2] = right;
initMargins[3] = bottom;

// convert inital margins with padding
int[] contentPadding = projection.getContentPadding();
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
left += contentPadding[0];
Expand Down

0 comments on commit 271e6d4

Please sign in to comment.