Back to project page unknown-pleasures.
The source code is released under:
Creative Commons Attribution NonCommercial NoDerivs (CC-NC-ND) THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTE...
If you think the Android project unknown-pleasures listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * DimSupport.java//from w w w.j a v a2s.c om * Author: marek.brodziak@gmail.com * Created: May 22, 2014 * Copyright 2014 by miniti */ package pl.miniti.android.pleasures.palette; import android.graphics.Color; /** * Class offering dimming support for all subclassing palettes */ public abstract class DimSupport implements Palette { /** * Number of last/first lines which will be dimmed by this palette */ private static final int THRESHOLD = 10; /** * If true the dimming is enabled */ protected boolean dimmed = true; /* * (non-Javadoc) * * @see pl.miniti.android.pleasures.palette.Palette#of(int, int) */ @Override public int of(int line, int of) { int rgb = rgb(line, of); if (dimmed) { if (line < 10) { int alpha = 255 * line / THRESHOLD; return Color.argb(alpha, Color.red(rgb), Color.green(rgb), Color.blue(rgb)); } else if (line > of - THRESHOLD) { int alpha = 255 * (of - line) / THRESHOLD; return Color.argb(alpha, Color.red(rgb), Color.green(rgb), Color.blue(rgb)); } } return rgb; } /* * (non-Javadoc) * * @see pl.miniti.android.pleasures.palette.Palette#setDimmed(boolean) */ @Override public void setDimmed(boolean dim) { this.dimmed = dim; } /** * Line color to be provided by the subclasses * * @param line * line number * @param of * number of lines * @return line color */ protected abstract int rgb(int line, int of); }