Example usage for android.graphics Color argb

List of usage examples for android.graphics Color argb

Introduction

In this page you can find the example usage for android.graphics Color argb.

Prototype

@ColorInt
public static int argb(float alpha, float red, float green, float blue) 

Source Link

Document

Return a color-int from alpha, red, green, blue float components in the range \([0..1]\).

Usage

From source file:Main.java

public static int generateRandomColor() {
    Random rnd = new Random();
    int r = rnd.nextInt(256);
    int g = rnd.nextInt(256);
    int b = rnd.nextInt(256);

    if ((r == 0 && g == 0 && b == 0) || (r == 255 && g == 255 && b == 255)) {
        return generateRandomColor();
    }/*from ww w  .  j  a  v  a  2s  .co  m*/

    int color = Color.argb(30, r, g, b);

    return color;
}

From source file:Main.java

public static int darker(final int color) {
    final int a = Color.alpha(color);
    int r = Color.red(color);
    int g = Color.green(color);
    int b = Color.blue(color);

    r -= 32;/*from   w  w  w.  j  a  v a 2  s  . c om*/
    if (r < 0) {
        r = 0;
    }
    g -= 32;
    if (g < 0) {
        g = 0;
    }
    b -= 32;
    if (b < 0) {
        b = 0;
    }
    return Color.argb(a, r, g, b);
}

From source file:Main.java

public static int darker2times(final int color) {
    final int a = Color.alpha(color);
    int r = Color.red(color);
    int g = Color.green(color);
    int b = Color.blue(color);

    r -= 64;/*from  w ww.j  a va 2 s .com*/
    if (r < 0) {
        r = 0;
    }
    g -= 64;
    if (g < 0) {
        g = 0;
    }
    b -= 64;
    if (b < 0) {
        b = 0;
    }
    return Color.argb(a, r, g, b);
}

From source file:Main.java

public static int darker2times(final int color) {
    final int a = Color.alpha(color);
    int r = Color.red(color);
    int g = Color.green(color);
    int b = Color.blue(color);

    r -= 64;// w w  w .j a  va 2 s .c  o m
    if (r < 0) {
        r = 0;
    }
    g -= 64;
    if (g > 0) {
        g = 0;
    }
    b -= 64;
    if (b < 0) {
        b = 0;
    }
    return Color.argb(a, r, g, b);
}

From source file:Main.java

public static int darkenColor(int color) {
    float[] hsv = new float[3];
    int alpha = Color.alpha(color);
    Color.colorToHSV(color, hsv);
    hsv[1] = Math.min(hsv[1] * DARKEN_SATURATION, 1.0f);
    hsv[2] = hsv[2] * DARKEN_INTENSITY;//from ww w. j av  a  2s .  c o m
    int tempColor = Color.HSVToColor(hsv);
    return Color.argb(alpha, Color.red(tempColor), Color.green(tempColor), Color.blue(tempColor));
}

From source file:Main.java

public static int darkenColor(int color) {
    float[] hsv = new float[3];
    int alpha = Color.alpha(color);
    Color.colorToHSV(color, hsv);
    hsv[1] = Math.min(hsv[1] * SATURATION_DARKEN, 1.0f);
    hsv[2] = hsv[2] * INTENSITY_DARKEN;//w  w w .j  a va 2s .c  o  m
    int tempColor = Color.HSVToColor(hsv);
    return Color.argb(alpha, Color.red(tempColor), Color.green(tempColor), Color.blue(tempColor));
}

From source file:Main.java

/**
 * Get a darker version of a color/*from w  w w  .j  av a 2s.  c o m*/
 * @param color the color to be darkened
 * @param factor the factor by which to darken the color
 * @return an integer representation of the darkened color
 */
private static int darker(int color, double factor) {
    int a = Color.alpha(color);
    int r = Color.red(color);
    int g = Color.green(color);
    int b = Color.blue(color);

    return Color.argb(a, Math.max((int) (r * factor), 0), Math.max((int) (g * factor), 0),
            Math.max((int) (b * factor), 0));
}

From source file:Main.java

public static int brighter2times(final int color) {
    final int a = Color.alpha(color);
    int r = Color.red(color);
    int g = Color.green(color);
    int b = Color.blue(color);

    r += 64;/*  ww w .  ja  v  a 2s . c  om*/
    if (r > 255) {
        r = 255;
    }
    g += 64;
    if (g > 255) {
        g = 255;
    }
    b += 64;
    if (b > 255) {
        b = 255;
    }

    return Color.argb(a, r, g, b);
}

From source file:Main.java

private static int parserColor(String value) {
    String regularExpression = ",";
    if (value.contains(regularExpression)) {
        String[] temp = value.split(regularExpression);

        int color = Color.parseColor(temp[0]);
        int alpha = Integer.valueOf(temp[1]);
        int red = (color & 0xff0000) >> 16;
        int green = (color & 0x00ff00) >> 8;
        int blue = (color & 0x0000ff);

        return Color.argb(alpha, red, green, blue);
    }/*from  ww  w .j  av  a2s. com*/
    return Color.parseColor(value);
}

From source file:Main.java

/**
 * Method returning given color modified to lighter color (positive translation) or darker
 * (negative translation).//  w  w w.  j  a  va 2 s  .  com
 *
 * @param primaryColor basic color
 * @param translation  positive or negative value of color translation
 * @return lighter/darker color
 */
public static int getColorWithTranslateBrightness(int primaryColor, int translation) {
    if (translation >= 0) {
        return Color.argb(Color.alpha(primaryColor), Math.min(Color.red(primaryColor) + translation, 255),
                Math.min(Color.green(primaryColor) + translation, 255),
                Math.min(Color.blue(primaryColor) + translation, 255));
    } else {
        return Color.argb(Color.alpha(primaryColor), Math.max(Color.red(primaryColor) + translation, 0),
                Math.max(Color.green(primaryColor) + translation, 0),
                Math.max(Color.blue(primaryColor) + translation, 0));
    }
}