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 Bitmap nostalgic(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap newBitmap = Bitmap.createBitmap(width, height, Config.RGB_565);
    int pixColor = 0;
    int pixR = 0;
    int pixG = 0;
    int pixB = 0;
    int newR = 0;
    int newG = 0;
    int newB = 0;
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    for (int i = 0; i < height; i++) {
        for (int k = 0; k < width; k++) {
            pixColor = pixels[width * i + k];
            pixR = Color.red(pixColor);
            pixG = Color.green(pixColor);
            pixB = Color.blue(pixColor);
            newR = (int) (0.393 * pixR + 0.769 * pixG + 0.189 * pixB);
            newG = (int) (0.349 * pixR + 0.686 * pixG + 0.168 * pixB);
            newB = (int) (0.272 * pixR + 0.534 * pixG + 0.131 * pixB);
            int newColor = Color.argb(255, newR > 255 ? 255 : newR, newG > 255 ? 255 : newG,
                    newB > 255 ? 255 : newB);
            pixels[width * i + k] = newColor;
        }//  w  w w.j  a  va  2 s.  c o m
    }
    newBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return newBitmap;
}

From source file:com.theartball.theartball.AboutActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_about);
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(Color.argb(255, 11, 120, 228)));

    WebView aboutWebView = (WebView) findViewById(R.id.aboutText);
    String aboutText = "<span style='color:#ffffff;font-size:10pt;'><img width='100%%' src='http://theartball.com/images/logo-vodoravno.png' /> "
            + "The Artball is application by freestylers for freestylers! <br> <br>It will help you stay in touch with the latest news and videos from the Freestyle Football world."
            + "<br> You will also be able to read great articles about trainings, equipment, freestyle thoughts and freestyle life in general. "
            + "All articles are written by freestylers themselves. <br><br> Application is developed by: <br><br> Uros Zivaljevic from Serbia <br> Mario Plantosar from Croatia <br><br>"
            + " If you are interested in helping The Artball by writing news, or you have article that you want to be published in application, please contact us on: "
            + "<br><br> contact@theartball.com <br><br> Follow us on other social networks: <div style='width:65%%; margin:0 auto'><br><br><a href='https://instagram.com/theartball'>"
            + "<img width='30%%' src='http://theartball.com/images/instagram-icon.png'></a><a href='https://www.facebook.com/theartball'>"
            + "<img width='30%%' src='http://theartball.com/images/facebook-icon.png'/></a><a href='https://twitter.com/TheArtball'>"
            + "<img width='30%%' src='http://theartball.com/images/twitter-icon.png'></a></div> <br><br><br>Open Source Libraries: <br><br><u>Picasso</u><br><br><div style='background-color:#6DAEEF;'><br>"
            + "Copyright 2013 Square, Inc.<br><br>\n" + "\n"
            + "Licensed under the Apache License, Version 2.0 (the \"License\");\n"
            + "you may not use this file except in compliance with the License.\n"
            + "You may obtain a copy of the License at<br><br>\n" + "\n"
            + "   http://www.apache.org/licenses/LICENSE-2.0 <br><br>\n" + "\n"
            + "Unless required by applicable law or agreed to in writing, software\n"
            + "distributed under the License is distributed on an \"AS IS\" BASIS,\n"
            + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
            + "See the License for the specific language governing permissions and\n"
            + "limitations under the License.<br><br></div><br><br><br><u>PhotoView</u><br><br><div style='background-color:#6DAEEF;'><br>Copyright 2011, 2012 Chris Banes<br><br>\n"
            + "\n" + "Licensed under the Apache License, Version 2.0 (the \"License\");\n"
            + "you may not use this file except in compliance with the License.\n"
            + "You may obtain a copy of the License at<br><br>\n" + "\n"
            + "   http://www.apache.org/licenses/LICENSE-2.0 <br><br>" + "\n"
            + "Unless required by applicable law or agreed to in writing, software\n"
            + "distributed under the License is distributed on an \"AS IS\" BASIS,\n"
            + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
            + "See the License for the specific language governing permissions and\n"
            + "limitations under the License.<br><br></div><br><br><br><u>AsymmetricGridView</u><br><br><div style='background-color:#6DAEEF;'><br>Copyright (c) 2011-2014 Felipe Lima<br><br>\n"
            + "\n" + "Permission is hereby granted, free of charge, to any person obtaining a copy\n"
            + "of this software and associated documentation files (the \"Software\"), to deal\n"
            + "in the Software without restriction, including without limitation the rights\n"
            + "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n"
            + "copies of the Software, and to permit persons to whom the Software is\n"
            + "furnished to do so, subject to the following conditions:<br><br>\n" + "\n"
            + "The above copyright notice and this permission notice shall be included in\n"
            + "all copies or substantial portions of the Software.<br><br>\n" + "\n"
            + "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n"
            + "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n"
            + "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n"
            + "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n"
            + "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n"
            + "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n"
            + "THE SOFTWARE.<br><br></div></span>";

    aboutWebView.loadDataWithBaseURL("", aboutText, "text/html", "UTF-8", "");
    aboutWebView.setBackgroundColor(ContextCompat.getColor(this, R.color.mainBlue));
}

From source file:com.shopgun.android.utils.ColorUtils.java

/**
 * Returns the complimentary color. (Alpha channel remains intact)
 *
 * @param color An ARGB color to return the compliment of
 * @return An ARGB of compliment color/*  ww w . j a  va2  s . c  o  m*/
 */
@ColorInt
public static int getCompliment(@ColorInt int color) {
    // get existing colors
    int alpha = Color.alpha(color);
    int red = Color.red(color);
    int blue = Color.blue(color);
    int green = Color.green(color);

    // find compliments
    red = (~red) & 0xff;
    blue = (~blue) & 0xff;
    green = (~green) & 0xff;

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

From source file:Main.java

/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details./*from   www.ja  v  a 2s  .c  om*/
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int red = Color.red(baseColor);
    int green = Color.green(baseColor);
    int blue = Color.blue(baseColor);
    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = constrain(0, 1, (float) Math.pow(x, 3));
        stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.START:
        x0 = 1;
        x1 = 0;
        break;
    case Gravity.END:
        x0 = 0;
        x1 = 1;
        break;
    default:
        x0 = 0;
        x1 = 0;
        break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.TOP:
        y0 = 1;
        y1 = 0;
        break;
    case Gravity.BOTTOM:
        y0 = 0;
        y1 = 1;
        break;
    default:
        y0 = 0;
        y1 = 0;
        break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(width * x0, height * y0, width * x1, height * y1, stopColors, null,
                    Shader.TileMode.CLAMP);
        }
    });

    return paintDrawable;
}

From source file:Main.java

/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.//from   w  ww  . ja  va 2s  . co m
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {

    // Generate a cache key by hashing together the inputs, based on the method described in the Effective Java book
    int cacheKeyHash = baseColor;
    cacheKeyHash = 31 * cacheKeyHash + numStops;
    cacheKeyHash = 31 * cacheKeyHash + gravity;

    Drawable cachedGradient = cubicGradientScrimCache.get(cacheKeyHash);
    if (cachedGradient != null) {
        return cachedGradient;
    }

    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int red = Color.red(baseColor);
    int green = Color.green(baseColor);
    int blue = Color.blue(baseColor);
    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = Math.max(0, Math.min(1, (float) Math.pow(x, 3)));
        stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.START:
        x0 = 1;
        x1 = 0;
        break;
    case Gravity.END:
        x0 = 0;
        x1 = 1;
        break;
    default:
        x0 = 0;
        x1 = 0;
        break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.TOP:
        y0 = 1;
        y1 = 0;
        break;
    case Gravity.BOTTOM:
        y0 = 0;
        y1 = 1;
        break;
    default:
        y0 = 0;
        y1 = 0;
        break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(width * x0, height * y0, width * x1, height * y1, stopColors, null,
                    Shader.TileMode.CLAMP);
        }
    });

    cubicGradientScrimCache.put(cacheKeyHash, paintDrawable);
    return paintDrawable;
}

From source file:Main.java

public static Bitmap emboss(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap newBitmap = Bitmap.createBitmap(width, height, Config.RGB_565);

    int pixR = 0;
    int pixG = 0;
    int pixB = 0;

    int pixColor = 0;

    int newR = 0;
    int newG = 0;
    int newB = 0;

    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    int pos = 0;/*from ww w .j a  v a2s  .c  om*/
    for (int i = 1, length = height - 1; i < length; i++) {
        for (int k = 1, len = width - 1; k < len; k++) {
            pos = i * width + k;
            pixColor = pixels[pos];

            pixR = Color.red(pixColor);
            pixG = Color.green(pixColor);
            pixB = Color.blue(pixColor);

            pixColor = pixels[pos + 1];
            newR = Color.red(pixColor) - pixR + 127;
            newG = Color.green(pixColor) - pixG + 127;
            newB = Color.blue(pixColor) - pixB + 127;

            newR = Math.min(255, Math.max(0, newR));
            newG = Math.min(255, Math.max(0, newG));
            newB = Math.min(255, Math.max(0, newB));

            pixels[pos] = Color.argb(255, newR, newG, newB);
        }
    }

    newBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return newBitmap;
}

From source file:Main.java

/**
 * Concerts a String color (#ff882465) to an int color
 *
 * @throws NumberFormatException/* w  w w . ja  va2s  . co  m*/
 */
public static int convertToColorInt(String argb, boolean useAlpha) throws NumberFormatException {

    if (argb.startsWith("#")) {
        argb = argb.replace("#", "");
    }

    int alpha = -1, red = -1, green = -1, blue = -1;

    if (argb.length() == 8) {
        alpha = Integer.parseInt(argb.substring(0, 2), 16);
        red = Integer.parseInt(argb.substring(2, 4), 16);
        green = Integer.parseInt(argb.substring(4, 6), 16);
        blue = Integer.parseInt(argb.substring(6, 8), 16);
    } else if (argb.length() == 6) {
        alpha = 255;
        red = Integer.parseInt(argb.substring(0, 2), 16);
        green = Integer.parseInt(argb.substring(2, 4), 16);
        blue = Integer.parseInt(argb.substring(4, 6), 16);
    }

    return Color.argb(useAlpha ? alpha : -1, red, green, blue);
}

From source file:Main.java

/**
 * Create a bitmap that contains the transformation to make to create the final 
 * bitmap with a new tint color. You can then call processTintTransformationMap() 
 * to get a bitmap with the desired tint.
 * @param bitmap The original bitmap.//from w w w.j  av  a 2 s . c om
 * @param tintColor Tint color in the original bitmap.
 * @return A transformation map to be used with processTintTransformationMap(). The 
 * transformation values are stored in the red and green values. The alpha value is 
 * significant and the blue value can be ignored.
 */
public static Bitmap createTintTransformationMap(Bitmap bitmap, int tintColor) {
    // tint color
    int[] t = new int[] { Color.red(tintColor), Color.green(tintColor), Color.blue(tintColor) };

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);

    int maxIndex = getMaxIndex(t);
    int mintIndex = getMinIndex(t);

    for (int i = 0; i < pixels.length; i++) {
        int color = pixels[i];
        // pixel color
        int[] p = new int[] { Color.red(color), Color.green(color), Color.blue(color) };
        int alpha = Color.alpha(color);

        float[] transformation = calculateTransformation(t[maxIndex], t[mintIndex], p[maxIndex], p[mintIndex]);
        pixels[i] = Color.argb(alpha, (int) (transformation[0] * 255), (int) (transformation[1] * 255), 0);
    }
    return Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_8888);
}

From source file:Main.java

/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient.
 *//*from www.j  ava2  s.c  o  m*/
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {

    // Generate a cache key by hashing together the inputs, based on the method described in the Effective Java book
    int cacheKeyHash = baseColor;
    cacheKeyHash = 31 * cacheKeyHash + numStops;
    cacheKeyHash = 31 * cacheKeyHash + gravity;

    Drawable cachedGradient = cubicGradientScrimCache.get(cacheKeyHash);
    if (cachedGradient != null) {
        return cachedGradient;
    }

    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int red = Color.red(baseColor);
    int green = Color.green(baseColor);
    int blue = Color.blue(baseColor);
    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = constrain(0, 1, (float) Math.pow(x, 3));
        stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.LEFT:
        x0 = 1;
        x1 = 0;
        break;
    case Gravity.RIGHT:
        x0 = 0;
        x1 = 1;
        break;
    default:
        x0 = 0;
        x1 = 0;
        break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.TOP:
        y0 = 1;
        y1 = 0;
        break;
    case Gravity.BOTTOM:
        y0 = 0;
        y1 = 1;
        break;
    default:
        y0 = 0;
        y1 = 0;
        break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(width * x0, height * y0, width * x1, height * y1,
                    stopColors, null, Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    cubicGradientScrimCache.put(cacheKeyHash, paintDrawable);
    return paintDrawable;
}

From source file:Main.java

/**
 * Composite two potentially translucent colors over each other and returns the result.
 */// w  w w . j  a  v a  2s. c  o m
public static int compositeColors(int foreground, int background) {
    final float alpha1 = Color.alpha(foreground) / 255f;
    final float alpha2 = Color.alpha(background) / 255f;

    float a = (alpha1 + alpha2) * (1f - alpha1);
    float r = (Color.red(foreground) * alpha1) + (Color.red(background) * alpha2 * (1f - alpha1));
    float g = (Color.green(foreground) * alpha1) + (Color.green(background) * alpha2 * (1f - alpha1));
    float b = (Color.blue(foreground) * alpha1) + (Color.blue(background) * alpha2 * (1f - alpha1));

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