use of android.widget.EdgeEffect in project Shuttle by timusus.
the class EdgeGlowUtil method setEffectColor.
// Utilities
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void setEffectColor(Object edgeEffect, @ColorInt int color) {
invalidateEdgeEffectFields();
if (edgeEffect instanceof EdgeEffectCompat) {
// EdgeEffectCompat
try {
EDGE_EFFECT_COMPAT_FIELD_EDGE_EFFECT.setAccessible(true);
edgeEffect = EDGE_EFFECT_COMPAT_FIELD_EDGE_EFFECT.get(edgeEffect);
} catch (IllegalAccessException e) {
e.printStackTrace();
return;
}
}
if (edgeEffect == null) {
return;
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
// EdgeGlow
try {
EDGE_GLOW_FIELD_EDGE.setAccessible(true);
final Drawable mEdge = (Drawable) EDGE_GLOW_FIELD_EDGE.get(edgeEffect);
EDGE_GLOW_FIELD_GLOW.setAccessible(true);
final Drawable mGlow = (Drawable) EDGE_GLOW_FIELD_GLOW.get(edgeEffect);
mEdge.setColorFilter(color, PorterDuff.Mode.SRC_IN);
mGlow.setColorFilter(color, PorterDuff.Mode.SRC_IN);
// free up any references
mEdge.setCallback(null);
// free up any references
mGlow.setCallback(null);
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
// EdgeEffect
((EdgeEffect) edgeEffect).setColor(color);
}
}
Aggregations