Java Code Examples for android.graphics.Color.rgb()

The following are Jave code examples for showing how to use rgb() of the android.graphics.Color class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: AndroidDigIn   File: SweepGradientRadarView.java   View Source Code Vote up 6 votes
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    mCx = w / 2;
    mCy = h / 2;
    mSweepGradient = new SweepGradient(mCx, mCy,
            new int[]{Color.argb(25, 0, 255, 0),
                    Color.argb(80, 0, 255, 0),
                    Color.argb(200, 0, 255, 0)},
            new float[]{0, 0.95f, 1.0f});
    mPaint = new Paint();
    mPaint.setShader(mSweepGradient);
    mDividerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCircleDividerColor = Color.BLACK;
    mCrossDividerColor = Color.WHITE;
    mRadarBgColor = Color.rgb(154, 154, 154);
    mDividerPaint.setColor(mCircleDividerColor);
    mDividerPaint.setStrokeWidth(3);
    mDividerPaint.setStyle(Paint.Style.STROKE);
}
 
Example 2
Project: Zero   File: Utils.java   View Source Code Vote up 6 votes
public static int calculateAverageColor(android.graphics.Bitmap bitmap, int pixelSpacing) {
    int R = 0;
    int G = 0;
    int B = 0;
    int height = bitmap.getHeight();
    int width = bitmap.getWidth();
    int n = 0;
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    for (int i = 0; i < pixels.length; i += pixelSpacing) {
        int color = pixels[i];
        R += Color.red(color);
        G += Color.green(color);
        B += Color.blue(color);
        n++;
    }
    return Color.rgb(R / n, G / n, B / n);
}
 
Example 3
Project: ProminentColor   File: ProminentColor.java   View Source Code Vote up 6 votes
private int readColor() {
    long red = 0;
    long green = 0;
    long blue = 0;
    long count = 0;

    for (int y = 0; y < bitmap.getHeight(); y++) {
        for (int x = 0; x < bitmap.getWidth(); x++) {
            int c = bitmap.getPixel(x, y);

            count++;
            red += Color.red(c);
            green += Color.green(c);
            blue += Color.blue(c);
        }
    }
    return Color.rgb((int) (red / count), (int) (green / count), (int) (blue / count));
}
 
Example 4
Project: sctalk   File: IMUIHelper.java   View Source Code Vote up 6 votes
public static void setTextHilighted(TextView textView, String text,SearchElement searchElement) {
    textView.setText(text);
    if (textView == null
            || TextUtils.isEmpty(text)
            || searchElement ==null) {
        return;
    }

    int startIndex = searchElement.startIndex;
    int endIndex = searchElement.endIndex;
    if (startIndex < 0 || endIndex > text.length()) {
        return;
    }
    // 开始高亮处理
    int color =  Color.rgb(69, 192, 26);
    textView.setText(text, BufferType.SPANNABLE);
    Spannable span = (Spannable) textView.getText();
    span.setSpan(new ForegroundColorSpan(color), startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
Example 5
Project: ClouldReader   File: CommonUtils.java   View Source Code Vote up 5 votes
/**
 * 随机颜色
 */
public static int randomColor() {
    Random random = new Random();
    int red = random.nextInt(150) + 50;//50-199
    int green = random.nextInt(150) + 50;//50-199
    int blue = random.nextInt(150) + 50;//50-199
    return Color.rgb(red, green, blue);
}
 
Example 6
Project: Coder   File: MDTintUtil.java   View Source Code Vote up 5 votes
public static void setTint(@NonNull SwitchCompat switchCompat, @ColorInt int color) {
    int[] colors = new int[]{color, Color.rgb(236, 236, 236), Color.rgb(236, 236, 236), Color.rgb(236, 236, 236), Color.rgb(236, 236, 236), Color.rgb(236, 236, 236)};
    int[][] states = new int[6][];
    states[0] = new int[]{android.R.attr.state_checked, android.R.attr.state_enabled};
    states[1] = new int[]{android.R.attr.state_enabled, android.R.attr.state_focused};
    states[2] = new int[]{android.R.attr.state_enabled};
    states[3] = new int[]{android.R.attr.state_focused};
    states[4] = new int[]{android.R.attr.state_window_focused};
    states[5] = new int[]{};
    switchCompat.setThumbTintList(new ColorStateList(states, colors));
}
 
Example 7
Project: iosched-reader   File: SlidingTabStrip.java   View Source Code Vote up 5 votes
/**
 * Blend {@code color1} and {@code color2} using the given ratio.
 *
 * @param ratio of which to blend. 1.0 will return {@code color1}, 0.5 will give an even blend,
 *              0.0 will return {@code color2}.
 */
private static int blendColors(int color1, int color2, float ratio) {
    final float inverseRation = 1f - ratio;
    float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
    float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
    float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
    return Color.rgb((int) r, (int) g, (int) b);
}
 
Example 8
Project: easyfilemanager   File: Utils.java   View Source Code Vote up 5 votes
public static int blendColors(int color1, int color2, float ratio) {
    final float inverseRation = 1f - ratio;
    float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
    float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
    float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
    return Color.rgb((int) r, (int) g, (int) b);
}
 
Example 9
Project: GitHub   File: CircularProgressBarSample.java   View Source Code Vote up 5 votes
/**
 * generates random colors for the ProgressBar
 */
protected void switchColor() {
    Random r = new Random();
    int randomColor = Color.rgb(r.nextInt(256), r.nextInt(256), r.nextInt(256));
    mHoloCircularProgressBar.setProgressColor(randomColor);

    randomColor = Color.rgb(r.nextInt(256), r.nextInt(256), r.nextInt(256));
    mHoloCircularProgressBar.setProgressBackgroundColor(randomColor);
}
 
Example 10
Project: MaterialAbout   File: RippleUtil.java   View Source Code Vote up 5 votes
public static int darker(int color) {
    int r = Color.red(color);
    int b = Color.blue(color);
    int g = Color.green(color);

    return Color.rgb((int) (r * .9), (int) (g * .9), (int) (b * .9));
}
 
Example 11
Project: music_player   File: ColorUtil.java   View Source Code Vote up 5 votes
@ColorInt
public static int getMixedColor(@ColorInt int color1, @ColorInt int color2) {
    return Color.rgb(
            (Color.red(color1) + Color.red(color2)) / 2,
            (Color.green(color1) + Color.green(color2)) / 2,
            (Color.blue(color1) + Color.blue(color2)) / 2
    );
}
 
Example 12
Project: Farmacias   File: ColorMap.java   View Source Code Vote up 4 votes
private int generateRandomColor() {
    int red = ((int) (Math.random() * 255));
    int green = ((int) (Math.random() * 255));
    int blue = ((int) (Math.random() * 255));
    return Color.rgb(red, green, blue);
}
 
Example 13
Project: PicKing   File: Aitaotu.java   View Source Code Vote up 4 votes
@Override
public int getBackgroundColor() {
    return Color.rgb(158, 195, 255);
}
 
Example 14
Project: lighthouse   File: BitmapColors.java   View Source Code Vote up 4 votes
public int getPrimaryColorByCube() {
    int rank = 0;
    int color = 0;

    int x = 0;
    int y = 0;
    int z = 0;
    for (AdjacentColorCube cube : cubes) {
        if (cube != null) {
            int cubeRank = 0;
            int cubeColor = 0;
            int totalRank = 0;
            int[] frequency = cube.getFrequency();
            int cubeX = 0;
            int cubeY = 0;
            int cubeZ = 0;
            for (int item : frequency) {
                if (item > cubeRank) {
                    cubeRank = item;
                    cubeColor = Color.rgb(x + cubeX, y + cubeY, z + cubeZ);
                }
                totalRank += item;
                cubeZ++;
                if (cubeZ >= AdjacentColorCube.DIMENSION) {
                    cubeZ = 0;
                    cubeY++;
                    if (cubeY >= AdjacentColorCube.DIMENSION) {
                        cubeY = 0;
                        cubeX++;
                    }
                }
            }
            if (totalRank > rank) {
                rank = totalRank;
                color = cubeColor;
            }
        }
        z += AdjacentColorCube.DIMENSION;
        if (z >= 256) {
            z = 0;
            y += AdjacentColorCube.DIMENSION;
            if (y >= 256) {
                y = 0;
                x += AdjacentColorCube.DIMENSION;
            }
        }
    }
    return color;
}
 
Example 15
Project: boohee_v5.6   File: ColorUtils.java   View Source Code Vote up 4 votes
@ColorInt
public static int HSLToColor(@NonNull float[] hsl) {
    float h = hsl[0];
    float s = hsl[1];
    float l = hsl[2];
    float c = (1.0f - Math.abs((2.0f * l) - 1.0f)) * s;
    float m = l - (0.5f * c);
    float x = c * (1.0f - Math.abs(((h / 60.0f) % 2.0f) - 1.0f));
    int r = 0;
    int g = 0;
    int b = 0;
    switch (((int) h) / 60) {
        case 0:
            r = Math.round(255.0f * (c + m));
            g = Math.round(255.0f * (x + m));
            b = Math.round(255.0f * m);
            break;
        case 1:
            r = Math.round(255.0f * (x + m));
            g = Math.round(255.0f * (c + m));
            b = Math.round(255.0f * m);
            break;
        case 2:
            r = Math.round(255.0f * m);
            g = Math.round(255.0f * (c + m));
            b = Math.round(255.0f * (x + m));
            break;
        case 3:
            r = Math.round(255.0f * m);
            g = Math.round(255.0f * (x + m));
            b = Math.round(255.0f * (c + m));
            break;
        case 4:
            r = Math.round(255.0f * (x + m));
            g = Math.round(255.0f * m);
            b = Math.round(255.0f * (c + m));
            break;
        case 5:
        case 6:
            r = Math.round(255.0f * (c + m));
            g = Math.round(255.0f * m);
            b = Math.round(255.0f * (x + m));
            break;
    }
    return Color.rgb(constrain(r, 0, 255), constrain(g, 0, 255), constrain(b, 0, 255));
}
 
Example 16
Project: starcor.xul   File: XulGIFDecoder.java   View Source Code Vote up 4 votes
private static int _readColor(InputStream is) throws IOException {
	int r = is.read();
	int g = is.read();
	int b = is.read();
	return Color.rgb(r, g, b);
}
 
Example 17
Project: FireFiles   File: ColorUtils.java   View Source Code Vote up 4 votes
static int HSLtoRGB (float[] hsl) {
    final float h = hsl[0];
    final float s = hsl[1];
    final float l = hsl[2];

    final float c = (1f - Math.abs(2 * l - 1f)) * s;
    final float m = l - 0.5f * c;
    final float x = c * (1f - Math.abs((h / 60f % 2f) - 1f));

    final int hueSegment = (int) h / 60;

    int r = 0, g = 0, b = 0;

    switch (hueSegment) {
        case 0:
            r = Math.round(255 * (c + m));
            g = Math.round(255 * (x + m));
            b = Math.round(255 * m);
            break;
        case 1:
            r = Math.round(255 * (x + m));
            g = Math.round(255 * (c + m));
            b = Math.round(255 * m);
            break;
        case 2:
            r = Math.round(255 * m);
            g = Math.round(255 * (c + m));
            b = Math.round(255 * (x + m));
            break;
        case 3:
            r = Math.round(255 * m);
            g = Math.round(255 * (x + m));
            b = Math.round(255 * (c + m));
            break;
        case 4:
            r = Math.round(255 * (x + m));
            g = Math.round(255 * m);
            b = Math.round(255 * (c + m));
            break;
        case 5:
        case 6:
            r = Math.round(255 * (c + m));
            g = Math.round(255 * m);
            b = Math.round(255 * (x + m));
            break;
    }

    r = Math.max(0, Math.min(255, r));
    g = Math.max(0, Math.min(255, g));
    b = Math.max(0, Math.min(255, b));

    return Color.rgb(r, g, b);
}
 
Example 18
Project: richeditor   File: DarkTheme.java   View Source Code Vote up 4 votes
@Override
public int getAccentColor() {
    return Color.rgb(255,161,118);
}
 
Example 19
Project: GitHub   File: ColorTemplate.java   View Source Code Vote up 2 votes
/**
 * Returns the Android ICS holo blue light color.
 *
 * @return
 */
public static int getHoloBlue() {
    return Color.rgb(51, 181, 229);
}
 
Example 20
Project: chromium-for-android-56-debug-video   File: ColorUtils.java   View Source Code Vote up 2 votes
/**
 * Returns an opaque version of the given color.
 * @param color Color for which an opaque version should be returned.
 * @return Opaque version of the given color.
 */
public static int getOpaqueColor(int color) {
    return Color.rgb(Color.red(color), Color.green(color), Color.blue(color));
}