Bug 1098096 - Add a hack to make overscroll effect work on Android 5.0. r=lucasr, a=lsblakk
☠☠ backed out by a2e2a71b2228 ☠ ☠
authorJames Willcox <snorp@snorp.net>
Thu, 20 Nov 2014 10:40:50 -0600
changeset 235353 e40a4d279e30d773683c63e5300b348245c26c83
parent 235352 b355554a418f66d154d714124b63f15d8a7ffc15
child 235354 4af988d1770fc743911bd26782eac367c1ddf095
push id611
push userraliiev@mozilla.com
push dateMon, 05 Jan 2015 23:23:16 +0000
treeherdermozilla-release@345cd3b9c445 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr, lsblakk
bugs1098096
milestone35.0a2
Bug 1098096 - Add a hack to make overscroll effect work on Android 5.0. r=lucasr, a=lsblakk
mobile/android/base/gfx/OverscrollEdgeEffect.java
--- a/mobile/android/base/gfx/OverscrollEdgeEffect.java
+++ b/mobile/android/base/gfx/OverscrollEdgeEffect.java
@@ -4,38 +4,63 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.gfx;
 
 import org.mozilla.gecko.AppConstants.Versions;
 
 import android.content.Context;
 import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffXfermode;
 import android.view.View;
 import android.widget.EdgeEffect;
 
+import java.lang.reflect.Field;
 
 public class OverscrollEdgeEffect implements Overscroll {
     // Used to index particular edges in the edges array
     private static final int TOP = 0;
     private static final int BOTTOM = 1;
     private static final int LEFT = 2;
     private static final int RIGHT = 3;
 
     // All four edges of the screen
     private final EdgeEffect[] mEdges = new EdgeEffect[4];
 
     // The view we're showing this overscroll on.
     private final View mView;
 
     public OverscrollEdgeEffect(final View v) {
+        Field paintField = null;
+        if (Versions.feature21Plus) {
+            try {
+                paintField = EdgeEffect.class.getDeclaredField("mPaint");
+                paintField.setAccessible(true);
+            } catch (NoSuchFieldException e) {
+            }
+        }
+
         mView = v;
         Context context = v.getContext();
         for (int i = 0; i < 4; i++) {
             mEdges[i] = new EdgeEffect(context);
+
+            try {
+                if (paintField != null) {
+                    final Paint p = (Paint) paintField.get(mEdges[i]);
+
+                    // The Android EdgeEffect class uses a mode of SRC_ATOP here, which means it will only
+                    // draw the effect where there are non-transparent pixels in the destination. Since the LayerView
+                    // itself is fully transparent, it doesn't display at all. We need to use SRC instead.
+                    p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
+                }
+            } catch (IllegalAccessException e) {
+            }
         }
     }
 
     @Override
     public void setSize(final int width, final int height) {
         mEdges[LEFT].setSize(height, width);
         mEdges[RIGHT].setSize(height, width);
         mEdges[TOP].setSize(width, height);