Search in sources :

Example 11 with EdgeEffect

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);
    }
}
Also used : EdgeEffectCompat(android.support.v4.widget.EdgeEffectCompat) Drawable(android.graphics.drawable.Drawable) EdgeEffect(android.widget.EdgeEffect) TargetApi(android.annotation.TargetApi)

Aggregations

EdgeEffect (android.widget.EdgeEffect)11 Context (android.content.Context)2 TargetApi (android.annotation.TargetApi)1 Drawable (android.graphics.drawable.Drawable)1 EdgeEffectCompat (android.support.v4.widget.EdgeEffectCompat)1 ViewConfiguration (android.view.ViewConfiguration)1 LinearInterpolator (android.view.animation.LinearInterpolator)1 Scroller (android.widget.Scroller)1