/** * Make a dark color to ripple effect * @return */ protected int makePressColor(){ int r = (this.backgroundColor >> 16) & 0xFF; int g = (this.backgroundColor >> 8) & 0xFF; int b = (this.backgroundColor >> 0) & 0xFF; return Color.argb(128,r, g, b); }
/** * Make a dark color to ripple effect * @return */ protected int makePressColor(){ int r = (this.backgroundColor >> 16) & 0xFF; int g = (this.backgroundColor >> 8) & 0xFF; int b = (this.backgroundColor >> 0) & 0xFF; // r = (r+90 > 245) ? 245 : r+90; // g = (g+90 > 245) ? 245 : g+90; // b = (b+90 > 245) ? 245 : b+90; return Color.argb(128,r, g, b); }
/** * Make a dark color to press effect * * @return */ protected int makePressColor() { int r = (this.backgroundColor >> 16) & 0xFF; int g = (this.backgroundColor >> 8) & 0xFF; int b = (this.backgroundColor >> 0) & 0xFF; r = (r - 30 < 0) ? 0 : r - 30; g = (g - 30 < 0) ? 0 : g - 30; b = (b - 30 < 0) ? 0 : b - 30; return Color.argb(70, r, g, b); }
/** * Make a dark color to press effect * * @return */ protected int makePressColor() { int r = (this.backgroundColor >> 16) & 0xFF; int g = (this.backgroundColor >> 8) & 0xFF; int b = (this.backgroundColor >> 0) & 0xFF; r = (r - 30 < 0) ? 0 : r - 30; g = (g - 30 < 0) ? 0 : g - 30; b = (b - 30 < 0) ? 0 : b - 30; return Color.argb(70, r, g, b); }
/** * Make a dark color to press effect * * @return */ protected int makePressColor() { int r = (this.backgroundColor >> 16) & 0xFF; int g = (this.backgroundColor >> 8) & 0xFF; int b = (this.backgroundColor >> 0) & 0xFF; r = (r - 30 < 0) ? 0 : r - 30; g = (g - 30 < 0) ? 0 : g - 30; b = (b - 30 < 0) ? 0 : b - 30; return Color.argb(70, r, g, b); }
public int getColor() { byte alpha; if (this.a == null) { alpha = (byte)255; } else { long aLong = Math.round(this.a * 255.0); alpha = (aLong < 0) ? (byte)0 : (aLong >= 255) ? (byte)255 : (byte)aLong; } return Color.argb(alpha, this.r, this.g, this.b); } }
/** * Sets a color with a specific alpha value. * * @param color * @param alpha from 0-255 */ public void setColor(int color, int alpha) { setColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color))); }
/** * Set the alpha value of the {@code color} to be the given {@code alpha} value. */ private static int setColorAlpha(int color, byte alpha) { return Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color)); }
static int colorWithAlpha(int color, float percent) { int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); int alpha = Math.round(percent * 255); return Color.argb(alpha, r, g, b); }
/** * Set the alpha value of the {@code color} to be the given {@code alpha} value. */ private static int setColorAlpha(int color, byte alpha) { return Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color)); }
@ColorInt public static int increaseOpacityFromInt(Context context, @ColorInt int c, int alpha) { return Color.argb(alpha, Color.red(c), Color.green(c), Color.blue(c)); }
/** * Blend {@code color1} and {@code color2} using the given ratio. * * @param ratio of which to blend. 0.0 will return {@code color1}, 0.5 will give an even blend, * 1.0 will return {@code color2}. */ private static int blendColors(int color1, int color2, float ratio) { final float inverseRatio = 1f - ratio; float a = (Color.alpha(color1) * inverseRatio) + (Color.alpha(color2) * ratio); float r = (Color.red(color1) * inverseRatio) + (Color.red(color2) * ratio); float g = (Color.green(color1) * inverseRatio) + (Color.green(color2) * ratio); float b = (Color.blue(color1) * inverseRatio) + (Color.blue(color2) * ratio); return Color.argb((int) a, (int) r, (int) g, (int) b); } }
/** * Sets colors with a specific alpha value. * * @param colors * @param alpha */ public void setColors(int[] colors, int alpha) { resetColors(); for (int color : colors) { addColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color))); } }
/** * Sets the color of the selector to be draw over the * CircularImageView. Be sure to provide some opacity. * * @param selectorColor The color (including alpha) to set for the selector overlay. */ public void setSelectorColor(int selectorColor) { this.mSelectorColor = selectorColor; this.mSelectorFilter = new PorterDuffColorFilter(Color.argb(mSelectorAlpha, Color.red(mSelectorColor), Color.green(mSelectorColor), Color.blue(mSelectorColor)), PorterDuff.Mode.SRC_ATOP); this.invalidate(); }
@Implementation protected static int HSVToColor(int alpha, float hsv[]) { int rgb = java.awt.Color.HSBtoRGB(hsv[0] / 360, hsv[1], hsv[2]); return Color.argb(alpha, Color.red(rgb), Color.green(rgb), Color.blue(rgb)); } }
/** * Set the alpha value of the {@code color} to be the given {@code alpha} value. */ private static int setColorAlpha(int color, byte alpha) { return Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color)); }
@Test public void testArgb() { int color = Color.argb(100, 160, 160, 160); assertThat(color).isEqualTo(1688248480); }
@Test public void testRgbaColorParsing() { assertThat(parseTtmlColor("rgba(255,255,255,255)")).isEqualTo(WHITE); assertThat(parseTtmlColor("rgba(255,255,255,255)")) .isEqualTo(argb(255, 255, 255, 255)); assertThat(parseTtmlColor("rgba(0, 0, 0, 255)")).isEqualTo(BLACK); assertThat(parseTtmlColor("rgba(0, 0, 255, 0)")) .isEqualTo(argb(0, 0, 0, 255)); assertThat(parseTtmlColor("rgba(255, 0, 0, 255)")).isEqualTo(RED); assertThat(parseTtmlColor("rgba(255, 0, 255, 0)")) .isEqualTo(argb(0, 255, 0, 255)); assertThat(parseTtmlColor("rgba(255, 0, 0, 205)")) .isEqualTo(argb(205, 255, 0, 0)); }
/** * [r,g,b] */ @ColorInt static int jsonToColor(JsonReader reader) throws IOException { reader.beginArray(); int r = (int) (reader.nextDouble() * 255); int g = (int) (reader.nextDouble() * 255); int b = (int) (reader.nextDouble() * 255); while (reader.hasNext()) { reader.skipValue(); } reader.endArray(); return Color.argb(255, r, g, b); }
@Override public Integer parse(JsonReader reader, float scale) throws IOException { boolean isArray = reader.peek() == JsonToken.BEGIN_ARRAY; if (isArray) { reader.beginArray(); } double r = reader.nextDouble(); double g = reader.nextDouble(); double b = reader.nextDouble(); double a = reader.nextDouble(); if (isArray) { reader.endArray(); } if (r <= 1 && g <= 1 && b <= 1 && a <= 1) { r *= 255; g *= 255; b *= 255; a *= 255; } return Color.argb((int) a, (int) r, (int) g, (int) b); } }