FileDocCategorySizeDatePackage
ColorFilterCache.javaAPI DocAndroid 5.1 API2831Thu Mar 12 22:22:56 GMT 2015android.support.v17.leanback.graphics

ColorFilterCache

public final class ColorFilterCache extends Object
Cache of {@link ColorFilter}s for a given color at different alpha levels.

Fields Summary
private static final android.util.SparseArray
sColorToFiltersMap
private final android.graphics.PorterDuffColorFilter[]
mFilters
Constructors Summary
private ColorFilterCache(int r, int g, int b)

        // Pre cache all 256 filter levels
        for (int i = 0x00; i <= 0xFF; i++) {
            int color = Color.argb(i, r, g, b);
            mFilters[i] = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP);
        }
    
Methods Summary
public static android.support.v17.leanback.graphics.ColorFilterCachegetColorFilterCache(int color)
Get a ColorDimmer for a given color. Only the RGB values are used; the alpha channel is ignored in color. Subsequent calls to this method with the same color value will return the same cache.

param
color The color to use for the color filters.
return
A cache of ColorFilters at different alpha levels for the color.


                                                                    
         
        final int r = Color.red(color);
        final int g = Color.green(color);
        final int b = Color.blue(color);
        color = Color.rgb(r, g, b);
        ColorFilterCache filters = sColorToFiltersMap.get(color);
        if (filters == null) {
            filters = new ColorFilterCache(r, g, b);
            sColorToFiltersMap.put(color, filters);
        }
        return filters;
    
public android.graphics.ColorFiltergetFilterForLevel(float level)
Returns a ColorFilter for a given alpha level between 0 and 1.0.

param
level The alpha level the filter should apply.
return
A ColorFilter at the alpha level for the color represented by the cache.

        if (level >= 0 && level <= 1.0) {
            int filterIndex = (int) (0xFF * level);
            return mFilters[filterIndex];
        } else {
            return null;
        }