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 colorForString(String color) {
    if (color == null) {
        return (Color.BLACK);
    }//w  w w .j  a va 2 s . co m
    String c = color.toLowerCase();
    if (c.equals("red")) {
        return (Color.argb(150, 255, 0, 0));
    } else if (c.equals("yellow")) {
        //         return(Color.YELLOW);
        return (Color.argb(200, 255, 180, 0));
    } else if (c.equals("green")) {
        return (Color.GREEN);
    } else if (c.equals("blue")) {
        return (Color.BLUE);
    } else if (c.equals("purple")) {
        return (Color.argb(255, 255, 0, 255));
    } else if (c.equals("clear")) {
        return (Color.WHITE);
    } else {
        return (Color.BLACK);
    }
}

From source file:Main.java

/**
 * Returns a darker version of the specified color. Returns a translucent gray for transparent colors.
 *///  w  ww  .j  a v a2 s . c  om
private static int darkenColor(int color) {
    if (color == TRANSPARENT) {
        return Color.argb(127, 127, 127, 127);
    }
    return Color.rgb(Color.red(color) * 192 / 256, Color.green(color) * 192 / 256,
            Color.blue(color) * 192 / 256);
}

From source file:Main.java

public static int lighterColor(int color, float factor) {
    int red = (int) ((Color.red(color) * (1 - factor) / 255 + factor) * 255);
    int green = (int) ((Color.green(color) * (1 - factor) / 255 + factor) * 255);
    int blue = (int) ((Color.blue(color) * (1 - factor) / 255 + factor) * 255);
    return Color.argb(Color.alpha(color), red, green, blue);
}

From source file:Main.java

public static int getRandomColor() {
    Random random = new Random();
    int alpha = random.nextInt(50) + 206;
    int red = random.nextInt(200);
    int green = random.nextInt(200);
    int blue = random.nextInt(200);
    return Color.argb(alpha, red, green, blue);
}

From source file:Main.java

public static int adjustAlpha(int color, @SuppressWarnings("SameParameterValue") float factor) {
    int alpha = Math.round(Color.alpha(color) * factor);
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    return Color.argb(alpha, red, green, blue);
}

From source file:Main.java

/**
 * Gets the color.// www.jav a  2s  .  c  o m
 *
 * @param position the position
 * @param transparent the transparent
 * @return the color
 */
public static int getColor(int position, boolean transparent) {
    position = position % 5;
    switch (position) {
    case 0:
        return Color.argb(transparent ? 100 : 255, 240, 91, 0);
    case 1:
        return Color.argb(transparent ? 100 : 255, 246, 117, 184);
    case 2:
        return Color.argb(transparent ? 100 : 255, 187, 187, 1);
    case 3:
        return Color.argb(transparent ? 100 : 255, 0, 156, 239);
    case 4:
        return Color.argb(transparent ? 100 : 255, 0, 177, 4);
    }
    return 0;
}

From source file:Main.java

public static int darker(int color, float amount) {
    float diff = 255 * amount;
    int r = (int) Math.max(0, (Color.red(color) - diff));
    int b = (int) Math.max(0, (Color.blue(color) - diff));
    int g = (int) Math.max(0, (Color.green(color) - diff));
    return Color.argb(Color.alpha(color), r, g, b);
}

From source file:Main.java

public static int makePressColor(int color, int alpha) {
    int r = (color >> 16) & 0xFF;
    int g = (color >> 8) & 0xFF;
    int b = (color >> 0) & 0xFF;
    r = (r - 30 < 0) ? 0 : r - 30;//from  w  w w .j a va2s. c o  m
    g = (g - 30 < 0) ? 0 : g - 30;
    b = (b - 30 < 0) ? 0 : b - 30;
    return Color.argb(alpha, r, g, b);
}

From source file:Main.java

public static int getColor(String color) {
    int[] icolors = getArgbValue(color);
    int icolor = Color.rgb(0, 0, 0);
    if (icolors.length == 3) {
        icolor = Color.rgb(icolors[0], icolors[1], icolors[2]);
    } else if (icolors.length == 4) {
        icolor = Color.argb(icolors[0], icolors[1], icolors[2], icolors[3]);
    } else {//from w  w  w .  j a va  2s . com
        icolor = Color.parseColor(color);
    }
    return icolor;

}

From source file:Main.java

public static int getRandomArgb(int alpha, int begin, int last) {
    if (last > 255) {
        last = 255;//ww w  .  j av a 2 s.  c  o  m
    }
    int red = begin + new Random().nextInt(last - begin);
    int green = begin + new Random().nextInt(last - begin);
    int blue = begin + new Random().nextInt(last - begin);
    return Color.argb(alpha, red, green, blue);
}