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

ColorOverlayDimmer

public final class ColorOverlayDimmer extends Object
Helper class for assigning a dim color to Paint. It holds the alpha value for the current active level.

Fields Summary
private final float
mActiveLevel
private final float
mDimmedLevel
private final android.graphics.Paint
mPaint
private int
mAlpha
private float
mAlphaFloat
Constructors Summary
private ColorOverlayDimmer(int dimColor, float activeLevel, float dimmedLevel)

        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;
        mPaint = new Paint();
        dimColor = Color.rgb(Color.red(dimColor), Color.green(dimColor), Color.blue(dimColor));
        mPaint.setColor(dimColor);
        mActiveLevel = activeLevel;
        mDimmedLevel = dimmedLevel;
        setActiveLevel(1);
    
Methods Summary
public intapplyToColor(int color)
Change the RGB of the color according to current dim level. Maintains the alpha value of the color.

param
color The color to apply the dim level to.
return
A color with the RGB values adjusted by the alpha of the current dim level.

        float f = 1 - mAlphaFloat;
        return Color.argb(Color.alpha(color),
                (int)(Color.red(color) * f),
                (int)(Color.green(color) * f),
                (int)(Color.blue(color) * f));
    
public static android.support.v17.leanback.graphics.ColorOverlayDimmercreateColorOverlayDimmer(int dimColor, float activeLevel, float dimmedLevel)
Creates a ColorOverlayDimmer for the given color and levels.

param
dimColor The color for fully dimmed. Only the RGB values are used; the alpha channel is ignored.
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 ColorOverlayDimmer(dimColor, activeLevel, dimmedLevel);
    
public static android.support.v17.leanback.graphics.ColorOverlayDimmercreateDefault(android.content.Context context)
Creates a default ColorOverlayDimmer.

        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 ColorOverlayDimmer(dimColor, activeLevel, dimmedLevel);
    
public voiddrawColorOverlay(android.graphics.Canvas c, android.view.View v, boolean includePadding)
Draw a dim color overlay on top of a child View inside the canvas of the parent View.

param
c Canvas of the parent View.
param
v A child of the parent View.
param
includePadding Set to true to draw overlay on padding area of the View.

        c.save();
        float dx = v.getLeft() + v.getTranslationX();
        float dy = v.getTop() + v.getTranslationY();
        c.translate(dx, dy);
        c.concat(v.getMatrix());
        c.translate(-dx, -dy);
        if (includePadding) {
            c.drawRect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom(), mPaint);
        } else {
            c.drawRect(v.getLeft() + v.getPaddingLeft(),
                    v.getTop() + v.getPaddingTop(),
                    v.getRight() - v.getPaddingRight(),
                    v.getBottom() - v.getPaddingBottom(), mPaint);
        }
        c.restore();
    
public intgetAlpha()
Returns the alpha value for the dimmer.

        return mAlpha;
    
public floatgetAlphaFloat()
Returns the float value between 0 and 1 corresponding to alpha between 0 and 255.

        return mAlphaFloat;
    
public android.graphics.PaintgetPaint()
Returns the Paint object set to the current alpha value.

        return mPaint;
    
public booleanneedsDraw()
Returns whether the dimmer needs to draw.

        return mAlpha != 0;
    
public voidsetActiveLevel(float level)
Sets the active level of the dimmer. Updates the alpha value based on the level.

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

        mAlphaFloat = (mDimmedLevel + level * (mActiveLevel - mDimmedLevel));
        mAlpha = (int) (255 * mAlphaFloat);
        mPaint.setAlpha(mAlpha);