Bug 1098096 - Add a hack to make overscroll effect work on Android 5.0 r=lucasr

This commit is contained in:
James Willcox 2014-11-20 10:40:50 -06:00
parent 3b41d1c98b
commit 1cad36e6fb

View File

@ -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) {
}
}
}