Bug 1324280 - Revert MarginLayoutParamsCompat with setting margin left/right by current layout direction, r=sebastian
MozReview-Commit-ID: amwDqXRxE5
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbarTablet.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbarTablet.java
@@ -3,16 +3,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
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;
import android.support.v4.view.MarginLayoutParamsCompat;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
/**
@@ -92,42 +93,40 @@ class BrowserToolbarTablet extends Brows
new PropertyAnimator(isSwitchingTabs ? 10 : FORWARD_ANIMATION_DURATION);
forwardAnim.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
@Override
public void onPropertyAnimationStart() {
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
// in prepareForwardAnimation, so they should appear to have not moved at
// all at this point.
}
}
@Override
public void onPropertyAnimationEnd() {
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 {
newForwardButtonState = ForwardButtonState.HIDDEN;
}
urlDisplayLayout.finishForwardAnimation();
updateForwardButtonState(newForwardButtonState);
--- a/mobile/android/base/java/org/mozilla/gecko/util/ViewUtil.java
+++ b/mobile/android/base/java/org/mozilla/gecko/util/ViewUtil.java
@@ -1,16 +1,19 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
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;
public class ViewUtil {
/**
* Enable a circular touch ripple for a given view. This is intended for borderless views,
@@ -25,9 +28,27 @@ public class ViewUtil {
} else {
backgroundDrawableArray = view.getContext().obtainStyledAttributes(new int[] { R.attr.selectableItemBackground });
}
// This call is deprecated, but the replacement setBackground(Drawable) isn't available
// 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);
+ }
+ }
}