diff --git a/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbarTablet.java b/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbarTablet.java index e35cd6f2e16a..e0f51ba76248 100644 --- a/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbarTablet.java +++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbarTablet.java @@ -8,6 +8,7 @@ package org.mozilla.gecko.toolbar; import org.mozilla.gecko.R; import org.mozilla.gecko.animation.PropertyAnimator; import org.mozilla.gecko.animation.ViewHelper; +import org.mozilla.gecko.util.ViewUtil; import android.content.Context; import android.graphics.drawable.Drawable; @@ -97,13 +98,12 @@ class BrowserToolbarTablet extends BrowserToolbarTabletBase { if (!willShowForward) { // Set the margin before the transition when hiding the forward button. We // have to do this so that the favicon isn't clipped during the transition - MarginLayoutParams layoutParams = - (MarginLayoutParams) urlDisplayLayout.getLayoutParams(); - MarginLayoutParamsCompat.setMarginStart(layoutParams, 0); + MarginLayoutParams layoutParams = (MarginLayoutParams) urlDisplayLayout.getLayoutParams(); + ViewUtil.setMarginStart(layoutParams, 0, isLayoutRtl()); // Do the same on the URL edit container layoutParams = (MarginLayoutParams) urlEditLayout.getLayoutParams(); - MarginLayoutParamsCompat.setMarginStart(layoutParams, 0); + ViewUtil.setMarginStart(layoutParams, 0, isLayoutRtl()); requestLayout(); // Note, we already translated the favicon, site security, and text field @@ -117,12 +117,11 @@ class BrowserToolbarTablet extends BrowserToolbarTabletBase { final ForwardButtonState newForwardButtonState; if (willShowForward) { // Increase the margins to ensure the text does not run outside the View. - MarginLayoutParams layoutParams = - (MarginLayoutParams) urlDisplayLayout.getLayoutParams(); - MarginLayoutParamsCompat.setMarginStart(layoutParams, forwardButtonTranslationWidth); + MarginLayoutParams layoutParams = (MarginLayoutParams) urlDisplayLayout.getLayoutParams(); + ViewUtil.setMarginStart(layoutParams, forwardButtonTranslationWidth, isLayoutRtl()); layoutParams = (MarginLayoutParams) urlEditLayout.getLayoutParams(); - MarginLayoutParamsCompat.setMarginStart(layoutParams, forwardButtonTranslationWidth); + ViewUtil.setMarginStart(layoutParams, forwardButtonTranslationWidth, isLayoutRtl()); newForwardButtonState = ForwardButtonState.DISPLAYED; } else { diff --git a/mobile/android/base/java/org/mozilla/gecko/util/ViewUtil.java b/mobile/android/base/java/org/mozilla/gecko/util/ViewUtil.java index 180e821e7c58..c81c926fdb3f 100644 --- a/mobile/android/base/java/org/mozilla/gecko/util/ViewUtil.java +++ b/mobile/android/base/java/org/mozilla/gecko/util/ViewUtil.java @@ -5,7 +5,10 @@ package org.mozilla.gecko.util; import android.content.res.TypedArray; +import android.os.Build; +import android.support.v4.view.MarginLayoutParamsCompat; import android.view.View; +import android.view.ViewGroup; import org.mozilla.gecko.AppConstants; import org.mozilla.gecko.R; @@ -30,4 +33,22 @@ public class ViewUtil { // until API 16. view.setBackgroundDrawable(backgroundDrawableArray.getDrawable(0)); } + + /** + * Android framework have a bug margin start/end for RTL between 19~22. We can only use MarginLayoutParamsCompat before 17 and after 23. + * @param layoutParams + * @param marginStart + * @param isLayoutRtl + */ + public static void setMarginStart(ViewGroup.MarginLayoutParams layoutParams, int marginStart, boolean isLayoutRtl) { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && Build.VERSION.SDK_INT < Build.VERSION_CODES.M){ + if(isLayoutRtl){ + layoutParams.rightMargin = marginStart; + } else { + layoutParams.leftMargin = marginStart; + } + } else { + MarginLayoutParamsCompat.setMarginStart(layoutParams, marginStart); + } + } }