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

The following are Jave code examples for showing how to use green() 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: Swift-Braille-Soft-keyboard   File: ColorPickerView.java   View Source Code Vote up 6 votes
/**
 * Set the color this view should show.
 * @param color The color that should be selected. #argb
 * @param callback If you want to get a callback to
 * your OnColorChangedListener.
 */
public void setColor(int color, boolean callback){

	int alpha = Color.alpha(color);
	int red = Color.red(color);
	int blue = Color.blue(color);
	int green = Color.green(color);
	
	float[] hsv = new float[3];
	
	Color.RGBToHSV(red, green, blue, hsv);
	
	mAlpha = alpha;
	mHue = hsv[0];
	mSat = hsv[1];
	mVal = hsv[2];
	
	if(callback && mListener != null){			
		mListener.onColorChanged(Color.HSVToColor(mAlpha, new float[]{mHue, mSat, mVal}));				
	}
	
	invalidate();
}
 
Example 2
Project: SimpleDialogFragments   File: MainActivity.java   View Source Code Vote up 6 votes
private void newColor(int color){
    this.color = color;

    // Sets action bar colors
    if (getSupportActionBar() == null) return;

    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0xFF000000 | color));

    boolean dark = Color.red(color) * 0.299 + Color.green(color) * 0.587 + Color.blue(color) * 0.114 < 180;
    SpannableString s = new SpannableString(getSupportActionBar().getTitle());
    s.setSpan(new ForegroundColorSpan(dark ? Color.WHITE : Color.BLACK), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    getSupportActionBar().setTitle(s);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        float[] hsv = new float[3];
        Color.colorToHSV(color, hsv);
        hsv[2] *= 0.75;
        getWindow().setStatusBarColor(Color.HSVToColor(hsv));
    }
}
 
Example 3
Project: GitHub   File: AnimatedGifEncoder.java   View Source Code Vote up 6 votes
/**
 * Returns index of palette color closest to c
 *
 */
private int findClosest(int color) {
    if (colorTab == null)
        return -1;
    int r = Color.red(color);
    int g = Color.green(color);
    int b = Color.blue(color);
    int minpos = 0;
    int dmin = 256 * 256 * 256;
    int len = colorTab.length;
    for (int i = 0; i < len;) {
        int dr = r - (colorTab[i++] & 0xff);
        int dg = g - (colorTab[i++] & 0xff);
        int db = b - (colorTab[i] & 0xff);
        int d = dr * dr + dg * dg + db * db;
        int index = i / 3;
        if (usedEntry[index] && (d < dmin)) {
            dmin = d;
            minpos = index;
        }
        i++;
    }
    return minpos;
}
 
Example 4
Project: qmui   File: QMUIColorHelper.java   View Source Code Vote up 6 votes
/**
 * 根据比例,在两个color值之间计算出一个color值
 * <b>注意该方法是ARGB通道分开计算比例的</b>
 *
 * @param fromColor 开始的color值
 * @param toColor   最终的color值
 * @param fraction  比例,取值为[0,1],为0时返回 fromColor, 为1时返回 toColor
 * @return 计算出的color值
 */
public static int computeColor(@ColorInt int fromColor, @ColorInt int toColor, float fraction) {
    fraction = Math.max(Math.min(fraction, 1), 0);

    int minColorA = Color.alpha(fromColor);
    int maxColorA = Color.alpha(toColor);
    int resultA = (int) ((maxColorA - minColorA) * fraction) + minColorA;

    int minColorR = Color.red(fromColor);
    int maxColorR = Color.red(toColor);
    int resultR = (int) ((maxColorR - minColorR) * fraction) + minColorR;

    int minColorG = Color.green(fromColor);
    int maxColorG = Color.green(toColor);
    int resultG = (int) ((maxColorG - minColorG) * fraction) + minColorG;

    int minColorB = Color.blue(fromColor);
    int maxColorB = Color.blue(toColor);
    int resultB = (int) ((maxColorB - minColorB) * fraction) + minColorB;

    return Color.argb(resultA, resultR, resultG, resultB);
}
 
Example 5
Project: firefox-tv   File: ColorUtils.java   View Source Code Vote up 5 votes
private static int grayscaleFromRGB(final int color) {
    final int red = Color.red(color);
    final int green = Color.green(color);
    final int blue = Color.blue(color);
    // Magic weighting taken from a stackoverflow post, supposedly related to how
    // humans perceive color.
    return (int) (0.299 * red + 0.587 * green + 0.114 * blue);
}
 
Example 6
Project: ht-viewpagerwithindicator   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 7
Project: javaide   File: ColorPickerPreference.java   View Source Code Vote up 5 votes
public static int darken(int color, float 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));
}
 
Example 8
Project: Musicoco   File: MarkerDrawable.java   View Source Code Vote up 5 votes
private static int blendColors(int color1, int color2, float factor) {
    final float inverseFactor = 1f - factor;
    float a = (Color.alpha(color1) * factor) + (Color.alpha(color2) * inverseFactor);
    float r = (Color.red(color1) * factor) + (Color.red(color2) * inverseFactor);
    float g = (Color.green(color1) * factor) + (Color.green(color2) * inverseFactor);
    float b = (Color.blue(color1) * factor) + (Color.blue(color2) * inverseFactor);
    return Color.argb((int) a, (int) r, (int) g, (int) b);
}
 
Example 9
Project: GitHub   File: PaletteActivity1.java   View Source Code Vote up 5 votes
private int generateTransparentColor(float percent, int rgb) {
    int red = Color.red(rgb);
    int green = Color.green(rgb);
    int blue = Color.blue(rgb);
    int alpha = Color.alpha(rgb);
    alpha = (int) (alpha * percent);
    return Color.argb(alpha, red, green, blue);
}
 
Example 10
Project: PrettyDialog   File: PrettyDialogButton.java   View Source Code Vote up 5 votes
private int getLightenColor(int color){
    double fraction = 0.2;
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    red = (int)Math.min(red + (red * fraction), 255);
    green = (int)Math.min(green + (green * fraction), 255);
    blue = (int)Math.min(blue + (blue * fraction), 255);
    int alpha = Color.alpha(color);
    return Color.argb(alpha, red, green, blue);
}
 
Example 11
Project: FireFiles   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 12
Project: cafebar   File: CafeBarUtil.java   View Source Code Vote up 5 votes
static int getSubTitleTextColor(@ColorInt int color) {
    int titleColor = getTitleTextColor(color);
    int alpha2 = Math.round(Color.alpha(titleColor) * 0.7f);
    int red = Color.red(titleColor);
    int green = Color.green(titleColor);
    int blue = Color.blue(titleColor);
    return Color.argb(alpha2, red, green, blue);
}
 
Example 13
Project: MetadataEditor   File: ColorUtil.java   View Source Code Vote up 5 votes
/**
 * Taken from CollapsingToolbarLayout's CollapsingTextHelper class.
 */
public static int blendColors(int color1, int color2, @FloatRange(from = 0.0, to = 1.0) float ratio) {
    final float inverseRatio = 1f - ratio;
    float a = (Color.alpha(color1) * inverseRatio) + (Color.alpha(color2) * ratio);
    float r = (Color.red(color1) * inverseRatio) + (Color.red(color2) * ratio);
    float g = (Color.green(color1) * inverseRatio) + (Color.green(color2) * ratio);
    float b = (Color.blue(color1) * inverseRatio) + (Color.blue(color2) * ratio);
    return Color.argb((int) a, (int) r, (int) g, (int) b);
}
 
Example 14
Project: music_player   File: ColorUtil.java   View Source Code Vote up 5 votes
public static double getColorDarkness(@ColorInt int color) {
    if (color == Color.BLACK)
        return 1.0;
    else if (color == Color.WHITE || color == Color.TRANSPARENT)
        return 0.0;
    else
        return (1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255);
}
 
Example 15
Project: SSTVEncoder2   File: YuvConverter.java   View Source Code Vote up 4 votes
static int convertToY(int color) {
    double R = Color.red(color);
    double G = Color.green(color);
    double B = Color.blue(color);
    return clamp(16.0 + (.003906 * ((65.738 * R) + (129.057 * G) + (25.064 * B))));
}
 
Example 16
Project: cafebar   File: CafeBarUtil.java   View Source Code Vote up 4 votes
static int getTitleTextColor(@ColorInt int color) {
    double darkness = 1-(0.299*Color.red(color) + 0.587*Color.green(color) + 0.114*Color.blue(color))/255;
    return (darkness < 0.35) ? getDarkerColor(color) : Color.WHITE;
}
 
Example 17
Project: phonk   File: AndroidUtils.java   View Source Code Vote up 4 votes
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);
}
 
Example 18
Project: Mire   File: ColorHelpers.java   View Source Code Vote up 4 votes
public static int getBodyTextColor(Context context, @ColorInt int color) 
{
       double darkness = 1-(0.299*Color.red(color) + 0.587*Color.green(color) + 0.114*Color.blue(color))/255;

	return (darkness < 0.35) ? context.getResources().getColor(R.color.semi_black) : context.getResources().getColor(R.color.semi_white);
}
 
Example 19
Project: PlusGram   File: CheckBoxSquare.java   View Source Code Vote up 4 votes
@Override
protected void onDraw(Canvas canvas) {
    if (getVisibility() != VISIBLE) {
        return;
    }

    float checkProgress;
    float bounceProgress;
    if (progress <= 0.5f) {
        bounceProgress = checkProgress = progress / 0.5f;
        int rD = (int) ((Color.red(color) - 0x73) * checkProgress);
        int gD = (int) ((Color.green(color) - 0x73) * checkProgress);
        int bD = (int) ((Color.blue(color) - 0x73) * checkProgress);
        int c = Color.rgb(0x73 + rD, 0x73 + gD, 0x73 + bD);
        backgroundPaint.setColor(c);
    } else {
        bounceProgress = 2.0f - progress / 0.5f;
        checkProgress = 1.0f;
        backgroundPaint.setColor(color);
    }
    if (isDisabled) {
        backgroundPaint.setColor(0xffb0b0b0);
    }
    float bounce = AndroidUtilities.dp(1) * bounceProgress;
    rectF.set(bounce, bounce, AndroidUtilities.dp(18) - bounce, AndroidUtilities.dp(18) - bounce);

    drawBitmap.eraseColor(0);
    drawCanvas.drawRoundRect(rectF, AndroidUtilities.dp(2), AndroidUtilities.dp(2), backgroundPaint);

    if (checkProgress != 1) {
        float rad = Math.min(AndroidUtilities.dp(7), AndroidUtilities.dp(7) * checkProgress + bounce);
        rectF.set(AndroidUtilities.dp(2) + rad, AndroidUtilities.dp(2) + rad, AndroidUtilities.dp(16) - rad, AndroidUtilities.dp(16) - rad);
        drawCanvas.drawRect(rectF, eraser);
    }

    if (progress > 0.5f) {
        int endX = (int) (AndroidUtilities.dp(7.5f) - AndroidUtilities.dp(5) * (1.0f - bounceProgress));
        int endY = (int) (AndroidUtilities.dpf2(13.5f) - AndroidUtilities.dp(5) * (1.0f - bounceProgress));
        drawCanvas.drawLine(AndroidUtilities.dp(7.5f), (int) AndroidUtilities.dpf2(13.5f), endX, endY, checkPaint);
        endX = (int) (AndroidUtilities.dpf2(6.5f) + AndroidUtilities.dp(9) * (1.0f - bounceProgress));
        endY = (int) (AndroidUtilities.dpf2(13.5f) - AndroidUtilities.dp(9) * (1.0f - bounceProgress));
        drawCanvas.drawLine((int) AndroidUtilities.dpf2(6.5f), (int) AndroidUtilities.dpf2(13.5f), endX, endY, checkPaint);
    }
    canvas.drawBitmap(drawBitmap, 0, 0, null);
}
 
Example 20
Project: AndelaTrackChallenge   File: Easel.java   View Source Code Vote up 4 votes
public static boolean isColorDark(@ColorInt int color) {
    double darkness = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;
    return darkness >= 0.5;
}