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 lightenColor(int color, float factor) {
    float r = Color.red(color) * factor;
    float g = Color.green(color) * factor;
    float b = Color.blue(color) * factor;
    int ir = Math.min(255, (int) r);
    int ig = Math.min(255, (int) g);
    int ib = Math.min(255, (int) b);
    int ia = Color.alpha(color);
    return (Color.argb(ia, ir, ig, ib));
}

From source file:Main.java

public static int colorToColor(int i, int j, float f) {
    int k = Color.alpha(i);
    int l = Color.red(i);
    int i1 = Color.green(i);
    int j1 = Color.blue(i);
    int k1 = Color.alpha(j);
    int l1 = Color.red(j);
    int i2 = Color.green(j);
    int j2 = Color.blue(j);
    return Color.argb((int) (f * (float) k1 + (float) k * (1.0F - f)),
            (int) (f * (float) l1 + (float) l * (1.0F - f)), (int) (f * (float) i2 + (float) i1 * (1.0F - f)),
            (int) (f * (float) j2 + (float) j1 * (1.0F - f)));
}

From source file:Main.java

public static int adjustAlpha(int color, 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

/**
 * Get the value of color with specified alpha.
 *
 * @param color/*from   w w w  .j a v a  2 s.  c o m*/
 * @param alpha between 0 to 255.
 * @return Return the color with specified alpha.
 */
public static int getColorAtAlpha(int color, int alpha) {
    if (alpha < 0 || alpha > 255) {
        throw new IllegalArgumentException("The alpha should be 0 - 255.");
    }
    return Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color));
}

From source file:Main.java

public static int randomColor() {
    Random random = new Random();
    int r = random.nextInt(256);
    int g = random.nextInt(256);
    int b = random.nextInt(256);
    double color_perception = 1 - (0.299 * r + 0.587 * g + 0.114 * b) / 255;
    if (color_perception > 0.4) {
        return Color.argb(255, r, g, b);
    } else {/*from   www. j ava2 s  .c o m*/
        return randomColor();
    }
}

From source file:Main.java

public static int setRGBAToARGB(@NonNull final String color) {
    final int red = Integer.parseInt(color.substring(0, 2), 16);
    final int green = Integer.parseInt(color.substring(2, 4), 16);
    final int blue = Integer.parseInt(color.substring(4, 6), 16);
    final int alpha = Integer.parseInt(color.substring(6, 8), 16);
    return Color.argb(alpha, red, green, blue);
}

From source file:Main.java

/**
 * Set a transparent background to a WebView
 *
 * @param webView the WebView with a default background
 *///w  w w  .  ja v a 2 s.co  m
public static void setWebViewTransparentBackground(WebView webView) {

    if (android.os.Build.VERSION.SDK_INT < 16) {
        webView.setBackgroundColor(0x00000000);
    } else {
        webView.setBackgroundColor(Color.argb(1, 0, 0, 0));
    }
}

From source file:Main.java

public static int lighter(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 darken(int color, double fraction) {
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    red = darkenColor(red, fraction);/*from   www  . j  av  a  2  s .c  o  m*/
    green = darkenColor(green, fraction);
    blue = darkenColor(blue, fraction);
    int alpha = Color.alpha(color);

    return Color.argb(alpha, red, green, blue);
}

From source file:Main.java

public static int lighten(int color, double fraction) {
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    red = lightenColor(red, fraction);/*from  w  w  w . j  av  a 2  s  .c om*/
    green = lightenColor(green, fraction);
    blue = lightenColor(blue, fraction);
    int alpha = Color.alpha(color);
    return Color.argb(alpha, red, green, blue);
}