Backed out changeset a53711ef58c9 (bug 1707959) for linting failures. CLOSED TREE

This commit is contained in:
Butkovits Atila 2021-05-20 19:46:32 +03:00
Родитель 3e525ec94e
Коммит 1e689de392
1 изменённых файлов: 27 добавлений и 64 удалений

Просмотреть файл

@ -8,7 +8,6 @@ package org.mozilla.geckoview;
import org.mozilla.gecko.util.ThreadUtils;
import android.content.Context;
import android.graphics.BlendMode;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
@ -18,13 +17,9 @@ import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.core.os.BuildCompat;
import android.widget.EdgeEffect;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@UiThread
public final class OverscrollEdgeEffect {
@ -49,61 +44,6 @@ public final class OverscrollEdgeEffect {
mSession = session;
}
private static Field sPaintField;
private static Method sSetType;
// By default on SDK_INT 31 and above the edge effect default changed to "TYPE_STRETCH"
// which is an effect that we can't support due to using SurfaceTexture.
// This restores the edge effect type to TYPE_GLOW which is the default (and only option) on
// lower versions.
private void setType(final EdgeEffect edgeEffect) {
if (Build.VERSION.SDK_INT < 31 && !Build.VERSION.CODENAME.equals("S")) {
// setType is only available on 31 (early builds advertise themselves as 30,
// with codename S)
return;
}
// TODO: remove reflection once 31 is stable
if (sSetType == null) {
try {
sSetType = EdgeEffect.class.getDeclaredMethod("setType", int.class);
} catch (NoSuchMethodException e) {
// Nothing we can do here
return;
}
}
try {
sSetType.invoke(edgeEffect, /* TYPE_GLOW */ 0);
} catch (Exception ex) {
}
}
private void setBlendMode(EdgeEffect edgeEffect) {
if (Build.VERSION.SDK_INT >= 29) {
edgeEffect.setBlendMode(BlendMode.SRC);
return;
}
if (sPaintField == null) {
try {
sPaintField = EdgeEffect.class.getDeclaredField("mPaint");
sPaintField.setAccessible(true);
} catch (final NoSuchFieldException e) {
// Cannot get the field, nothing we can do here
return;
}
}
try {
final Paint paint = (Paint) sPaintField.get(edgeEffect);
final PorterDuffXfermode mode = new PorterDuffXfermode(PorterDuff.Mode.SRC);
paint.setXfermode(mode);
} catch (final IllegalAccessException ex) {
// Nothing we can do
}
}
/**
* Set the theme to use for overscroll from a given Context.
*
@ -112,11 +52,34 @@ public final class OverscrollEdgeEffect {
public void setTheme(final @NonNull Context context) {
ThreadUtils.assertOnUiThread();
final PorterDuffXfermode mode = new PorterDuffXfermode(PorterDuff.Mode.SRC);
Field paintField = null;
if (Build.VERSION.SDK_INT >= 21) {
try {
paintField = EdgeEffect.class.getDeclaredField("mPaint");
paintField.setAccessible(true);
} catch (final NoSuchFieldException e) {
}
}
for (int i = 0; i < mEdges.length; i++) {
final EdgeEffect edgeEffect = new EdgeEffect(context);
setBlendMode(edgeEffect);
setType(edgeEffect);
mEdges[i] = edgeEffect;
mEdges[i] = new EdgeEffect(context);
if (paintField == null) {
continue;
}
try {
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(mode);
} catch (final IllegalAccessException e) {
}
}
}