From 1cad36e6fbbcd8de817097f6005b630e4ccac071 Mon Sep 17 00:00:00 2001 From: James Willcox Date: Thu, 20 Nov 2014 10:40:50 -0600 Subject: [PATCH] Bug 1098096 - Add a hack to make overscroll effect work on Android 5.0 r=lucasr --- .../base/gfx/OverscrollEdgeEffect.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/mobile/android/base/gfx/OverscrollEdgeEffect.java b/mobile/android/base/gfx/OverscrollEdgeEffect.java index 26a77bde988..f2a73e07fcd 100644 --- a/mobile/android/base/gfx/OverscrollEdgeEffect.java +++ b/mobile/android/base/gfx/OverscrollEdgeEffect.java @@ -9,9 +9,13 @@ 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 @@ -27,10 +31,31 @@ public class OverscrollEdgeEffect implements Overscroll { 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) { + } } }