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

ColorFilterDimmer

public final class ColorFilterDimmer extends Object
Helper class for applying a dim level to a View. The ColorFilterDimmer uses a ColorFilter in a Paint object to dim the view according to the currently active level.

Fields Summary
private final ColorFilterCache
mColorDimmer
private final float
mActiveLevel
private final float
mDimmedLevel
private final android.graphics.Paint
mPaint
private android.graphics.ColorFilter
mFilter
Constructors Summary
private ColorFilterDimmer(ColorFilterCache dimmer, float activeLevel, float dimmedLevel)

        mColorDimmer = dimmer;
        if (activeLevel > 1.0f) activeLevel = 1.0f;
        if (activeLevel < 0.0f) activeLevel = 0.0f;
        if (dimmedLevel > 1.0f) dimmedLevel = 1.0f;
        if (dimmedLevel < 0.0f) dimmedLevel = 0.0f;
        mActiveLevel = activeLevel;
        mDimmedLevel = dimmedLevel;
        mPaint = new Paint();
    
Methods Summary
public voidapplyFilterToView(android.view.View view)
Apply current the ColorFilter to a View. This method will set the hardware layer of the view when applying a filter, and remove it when not applying a filter.

param
view The View to apply the ColorFilter to.

        if (mFilter != null) {
            view.setLayerType(View.LAYER_TYPE_HARDWARE, mPaint);
        } else {
            view.setLayerType(View.LAYER_TYPE_NONE, null);
        }
        // FIXME: Current framework has bug that not triggering invalidate when change layer
        // paint.  Will add conditional sdk version check once bug is fixed in released
        // framework.
        view.invalidate();
    
public static android.support.v17.leanback.graphics.ColorFilterDimmercreate(ColorFilterCache dimmer, float activeLevel, float dimmedLevel)
Creates a ColorFilterDimmer for the given color and levels..

param
dimmer The ColorFilterCache for dim color.
param
activeLevel The level of dimming when the View is in its active state. Must be a float value between 0.0 and 1.0.
param
dimmedLevel The level of dimming when the View is in its dimmed state. Must be a float value between 0.0 and 1.0.

        return new ColorFilterDimmer(dimmer, activeLevel, dimmedLevel);
    
public static android.support.v17.leanback.graphics.ColorFilterDimmercreateDefault(android.content.Context context)
Creates a default ColorFilterDimmer. Uses the default color and level for the dimmer.

param
context A Context used to retrieve Resources.
return
A ColorFilterDimmer with the default dim color and levels.

        TypedArray a = context.obtainStyledAttributes(R.styleable.LeanbackTheme);

        int dimColor = a.getColor(R.styleable.LeanbackTheme_overlayDimMaskColor,
                context.getResources().getColor(R.color.lb_view_dim_mask_color));
        float activeLevel = a.getFraction(R.styleable.LeanbackTheme_overlayDimActiveLevel, 1, 1,
                context.getResources().getFraction(R.fraction.lb_view_active_level, 1, 0));
        float dimmedLevel = a.getFraction(R.styleable.LeanbackTheme_overlayDimDimmedLevel, 1, 1,
                context.getResources().getFraction(R.fraction.lb_view_dimmed_level, 1, 1));
        a.recycle();
        return new ColorFilterDimmer(ColorFilterCache.getColorFilterCache(
                    dimColor), activeLevel, dimmedLevel);
    
public android.graphics.ColorFiltergetColorFilter()
Gets the ColorFilter set to the current dim level.

return
The current ColorFilter.

        return mFilter;
    
public android.graphics.PaintgetPaint()
Gets the Paint object set to the current dim level.

return
The current Paint object.

        return mPaint;
    
public voidsetActiveLevel(float level)
Sets the active level of the dimmer. Updates the ColorFilter based on the level.

param
level A float between 0 (fully dim) and 1 (fully active).

        if (level < 0.0f) level = 0.0f;
        if (level > 1.0f) level = 1.0f;
        mFilter = mColorDimmer.getFilterForLevel(
                mDimmedLevel + level * (mActiveLevel - mDimmedLevel));
        mPaint.setColorFilter(mFilter);