ColorOverlayDimmerpublic 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 int | applyToColor(int color)Change the RGB of the color according to current dim level. Maintains the
alpha value of the color.
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.ColorOverlayDimmer | createColorOverlayDimmer(int dimColor, float activeLevel, float dimmedLevel)Creates a ColorOverlayDimmer for the given color and levels.
return new ColorOverlayDimmer(dimColor, activeLevel, dimmedLevel);
| public static android.support.v17.leanback.graphics.ColorOverlayDimmer | createDefault(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 void | drawColorOverlay(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.
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 int | getAlpha()Returns the alpha value for the dimmer.
return mAlpha;
| public float | getAlphaFloat()Returns the float value between 0 and 1 corresponding to alpha between
0 and 255.
return mAlphaFloat;
| public android.graphics.Paint | getPaint()Returns the Paint object set to the current alpha value.
return mPaint;
| public boolean | needsDraw()Returns whether the dimmer needs to draw.
return mAlpha != 0;
| public void | setActiveLevel(float level)Sets the active level of the dimmer. Updates the alpha value based on the
level.
mAlphaFloat = (mDimmedLevel + level * (mActiveLevel - mDimmedLevel));
mAlpha = (int) (255 * mAlphaFloat);
mPaint.setAlpha(mAlpha);
|
|