ColorFilterCachepublic 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.ColorFilterCache | getColorFilterCache(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.
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.ColorFilter | getFilterForLevel(float level)Returns a ColorFilter for a given alpha level between 0 and 1.0.
if (level >= 0 && level <= 1.0) {
int filterIndex = (int) (0xFF * level);
return mFilters[filterIndex];
} else {
return null;
}
|
|