Bug 1354440 - Make the fade at the end of the tab strip work with RTL. r=maliu
authorTom Klein <twointofive@gmail.com>
Thu, 20 Apr 2017 01:26:10 -0500
changeset 402883 6003fe950ea3e85a7892cc614005dc7410851b51
parent 402882 b6428d328b6bd02cc88a18b60880a9beabc45d7b
child 402884 fa0c99211baaaa10f530cdfed37234f2851b0c54
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaliu
bugs1354440
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1354440 - Make the fade at the end of the tab strip work with RTL. r=maliu MozReview-Commit-ID: AVjtekO4eli
mobile/android/base/java/org/mozilla/gecko/tabs/TabStripView.java
--- a/mobile/android/base/java/org/mozilla/gecko/tabs/TabStripView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabStripView.java
@@ -16,16 +16,17 @@ import android.animation.ObjectAnimator;
 import android.content.Context;
 import android.content.res.Resources;
 import android.graphics.Canvas;
 import android.graphics.LinearGradient;
 import android.graphics.Paint;
 import android.graphics.Shader;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.ViewUtils;
 import android.support.v7.widget.helper.ItemTouchHelper;
 import android.util.AttributeSet;
 import android.view.View;
 import android.view.ViewTreeObserver;
 import android.view.animation.DecelerateInterpolator;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -216,49 +217,72 @@ public class TabStripView extends Recycl
     @Override
     protected void onSizeChanged(int w, int h, int oldw, int oldh) {
         super.onSizeChanged(w, h, oldw, oldh);
 
         if (w == oldw) {
             return;
         }
 
-        fadingEdgePaint.setShader(new LinearGradient(w - fadingEdgeSize, 0, w, 0,
-                new int[] { 0x0, 0x11292C29, 0xDD292C29 },
-                new float[] { 0, 0.4f, 1.0f }, Shader.TileMode.CLAMP));
+        // Gradient argb color stops.
+        final int transparent = 0x0;
+        final int inBetween = 0x11292C29;
+        final int darkest = 0xDD292C29;
+        if (ViewUtils.isLayoutRtl(this)) {
+            fadingEdgePaint.setShader(new LinearGradient(0, 0, fadingEdgeSize, 0,
+                    new int[] { darkest, inBetween, transparent },
+                    new float[] { 0, 0.6f, 1.0f }, Shader.TileMode.CLAMP));
+        } else {
+            fadingEdgePaint.setShader(new LinearGradient(w - fadingEdgeSize, 0, w, 0,
+                    new int[] { transparent, inBetween, darkest },
+                    new float[] { 0, 0.4f, 1.0f }, Shader.TileMode.CLAMP));
+        }
     }
 
-    private float getFadingEdgeStrength() {
+    private float getFadingEdgeStrength(boolean layoutIsLTR) {
         final int childCount = getChildCount();
         if (childCount == 0) {
             return 0.0f;
         } else {
             final LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager();
             if (layoutManager.findLastVisibleItemPosition() < adapter.getItemCount() - 1) {
                 return 1.0f;
             }
 
-            final int right = getChildAt(getChildCount() - 1).getRight();
-            final int paddingRight = getPaddingRight();
-            final int width = getWidth();
+            final float strength;
+            if (layoutIsLTR) {
+                final int right = getChildAt(getChildCount() - 1).getRight();
+                final int paddingRight = getPaddingRight();
+                final int width = getWidth();
 
-            final float strength = (right > width - paddingRight ?
-                    (float) (right - width + paddingRight) / fadingEdgeSize : 0.0f);
+                strength = (right > width - paddingRight ?
+                        (float) (right - width + paddingRight) / fadingEdgeSize : 0.0f);
+            } else {
+                final int left = getChildAt(getChildCount() - 1).getLeft();
+                final int paddingLeft = getPaddingLeft();
+
+                strength = left < paddingLeft ? (float) (paddingLeft - left) / fadingEdgeSize : 0.0f;
+            }
 
             return Math.max(0.0f, Math.min(strength, 1.0f));
         }
     }
 
     @Override
     public void draw(Canvas canvas) {
         super.draw(canvas);
-        final float strength = getFadingEdgeStrength();
+        final boolean isLTR = !ViewUtils.isLayoutRtl(this);
+        final float strength = getFadingEdgeStrength(isLTR);
         if (strength > 0.0f) {
-            final int r = getRight();
-            canvas.drawRect(r - fadingEdgeSize, getTop(), r, getBottom(), fadingEdgePaint);
+            if (isLTR) {
+                final int r = getRight();
+                canvas.drawRect(r - fadingEdgeSize, getTop(), r, getBottom(), fadingEdgePaint);
+            } else {
+                canvas.drawRect(0, getTop(), fadingEdgeSize, getBottom(), fadingEdgePaint);
+            }
             fadingEdgePaint.setAlpha((int) (strength * 255));
         }
     }
 
     private void animateRestoredTabs() {
         getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
             @Override
             public boolean onPreDraw() {