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

The following are Jave code examples for showing how to use colorToHSV() 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.
Example 1
Project: Selector-Switch-UI-Component   File: SelectorUtil.java   Source Code and License Vote up 7 votes
/**
 * Generates a list of colors that blend from a starting color to an ending color. The
 * size of the list is same as dialModeCount.
 *
 * @param dialModeCount <tt>int</tt> : Size of the list.
 * @param startingColor <tt>int</tt> : Color to start blending from.
 * @param endingColor   <tt>int</tt> : Color to finally blend into.
 * @return colorList    List of Integers representing the blended colors.
 * @see Color#HSVToColor(float[])
 */
static List<Integer> generateBlendingColors(int dialModeCount, int startingColor, int endingColor) {

    List<Integer> colorList = new ArrayList<>(dialModeCount);
    float[] startingColorHSV = new float[3];
    float[] endingColorHSV = new float[3];

    Color.colorToHSV(startingColor, startingColorHSV);
    Color.colorToHSV(endingColor, endingColorHSV);

    float hInc = endingColorHSV[0] - startingColorHSV[0];
    float sInc = endingColorHSV[1] - startingColorHSV[1];
    float vInc = endingColorHSV[2] - startingColorHSV[2];
    float[] temp;

    // Generate the blending colors.
    for (int i = 0; i < dialModeCount; i++) {
        temp = new float[]{startingColorHSV[0] + i * hInc,
                startingColorHSV[1] + i * sInc,
                startingColorHSV[2] + i * vInc};
        colorList.add(Color.HSVToColor(temp));
    }

    return colorList;
}
 
Example 2
Project: xlight_android_native   File: SVBar.java   Source Code and License Vote up 6 votes
/**
 * Set the bar color. <br>
 * <br>
 * Its discouraged to use this method.
 * 
 * @param color
 */
public void setColor(int color) {
	int x1, y1;
	if(mOrientation) {
		x1 = (mBarLength + mBarPointerHaloRadius);
		y1 = mBarThickness;
	}        else {
		x1 = mBarThickness;
		y1 = (mBarLength + mBarPointerHaloRadius);
	}
	
	Color.colorToHSV(color, mHSVColor);
	shader = new LinearGradient(mBarPointerHaloRadius, 0,
			x1, y1, new int[] {Color.WHITE, color, Color.BLACK}, null,
			Shader.TileMode.CLAMP);
	mBarPaint.setShader(shader);
    calculateColor(mBarPointerPosition);
	mBarPointerPaint.setColor(mColor);
	if (mPicker != null) {
		mPicker.setNewCenterColor(mColor);
		if(mPicker.hasOpacityBar())
			mPicker.changeOpacityBarColor(mColor);
	}
	invalidate();
}
 
Example 3
Project: PlusGram   File: ColorPicker.java   Source Code and License Vote up 6 votes
public void setLocation(float value) {
    int color = colorForLocation(location = value);
    swatchPaint.setColor(color);

    float hsv[] = new float[3];
    Color.colorToHSV(color, hsv);

    if (hsv[0] < 0.001 && hsv[1] < 0.001 && hsv[2] > 0.92f) {
        int c = (int) ((1.0f - (hsv[2] - 0.92f) / 0.08f * 0.22f) * 255);
        swatchStrokePaint.setColor(Color.rgb(c, c, c));
    } else {
        swatchStrokePaint.setColor(color);
    }


    invalidate();
}
 
Example 4
Project: xlight_android_native   File: SaturationBar.java   Source Code and License Vote up 5 votes
/**
 * Set the bar color. <br>
 * <br>
 * Its discouraged to use this method.
 * 
 * @param color
 */
public void setColor(int color) {
	int x1, y1;
	if(mOrientation == ORIENTATION_HORIZONTAL) {
		x1 = (mBarLength + mBarPointerHaloRadius);
		y1 = mBarThickness;
	}
	else {
		x1 = mBarThickness;
		y1 = (mBarLength + mBarPointerHaloRadius);
	}
	
	Color.colorToHSV(color, mHSVColor);
	shader = new LinearGradient(mBarPointerHaloRadius, 0,
			x1, y1, new int[] {
					Color.WHITE, color }, null,
			Shader.TileMode.CLAMP);
	mBarPaint.setShader(shader);
	calculateColor(mBarPointerPosition);
	mBarPointerPaint.setColor(mColor);
	if (mPicker != null) {
		mPicker.setNewCenterColor(mColor);
		if(mPicker.hasValueBar())
			mPicker.changeValueBarColor(mColor);
		else if(mPicker.hasOpacityBar())
			mPicker.changeOpacityBarColor(mColor);
	}
	invalidate();
}
 
Example 5
Project: RetroMusicPlayer   File: ShadowImageView.java   Source Code and License Vote up 5 votes
public int getDarkerColor(int color) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[1] = hsv[1] + 0.1f;
    hsv[2] = hsv[2] - 0.1f;
    int darkerColor = Color.HSVToColor(hsv);
    return darkerColor;
}
 
Example 6
Project: revolution-irc   File: ThemeHelper.java   Source Code and License Vote up 5 votes
public static int getPrimaryDarkColor(Context ctx) {
    if (!hasCustomPrimaryColor(ctx))
        return StyledAttributesHelper.getColor(ctx, R.attr.colorPrimaryDark, 0);
    int color = getPrimaryColor(ctx);
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= 0.8f;
    return Color.HSVToColor(hsv);
}
 
Example 7
Project: LaunchEnr   File: PendingAppWidgetHostView.java   Source Code and License Vote up 5 votes
private void updateSettingColor() {
    int color = IconColorExtractor.get(getContext(), mIcon);
    // Make the dominant color bright.
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[1] = Math.min(hsv[1], MIN_SATUNATION);
    hsv[2] = 1;
    color = Color.HSVToColor(hsv);

    mSettingIconDrawable.setColorFilter(color,  PorterDuff.Mode.SRC_IN);
}
 
Example 8
Project: SimpleDialogFragments   File: ColorWheelView.java   Source Code and License Vote up 5 votes
C(int rgba){
    float[] hsv = new float[3];
    Color.colorToHSV(rgba, hsv);
    int alpha = Color.alpha(rgba);

    alpha(alpha);
    hue(hsv[0]);
    sat(hsv[1]);
    val(hsv[2]);
}
 
Example 9
Project: mobile-store   File: FeatureImage.java   Source Code and License Vote up 5 votes
private void init(Context context) {
    float[] hsv = new float[3];
    Color.colorToHSV(ContextCompat.getColor(context, R.color.fdroid_blue), hsv);
    hsv[1] *= 0.5f;
    hsv[2] *= 0.7f;
    baseColour = Color.HSVToColor(hsv);
}
 
Example 10
Project: Metronome-Android   File: ColorUtils.java   Source Code and License Vote up 5 votes
@ColorInt
public static int getDarkColor(@ColorInt int color) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= 0.8f;
    return Color.HSVToColor(hsv);
}
 
Example 11
Project: hsv-alpha-color-picker   File: ObservableColor.java   Source Code and License Vote up 4 votes
ObservableColor(int color) {
	Color.colorToHSV(color, hsv);
	alpha = Color.alpha(color);
}
 
Example 12
Project: hsv-alpha-color-picker   File: ObservableColor.java   Source Code and License Vote up 4 votes
public void updateColor(int color, ColorObserver sender) {
	Color.colorToHSV(color, hsv);
	alpha = Color.alpha(color);
	notifyOtherObservers(sender);
}
 
Example 13
Project: gofun-app   File: ChangelogDialog.java   Source Code and License Vote up 4 votes
private int shiftColor(int color, boolean up) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= (up ? 1.1f : 0.9f); // value component
    return Color.HSVToColor(hsv);
}
 
Example 14
Project: planetcon   File: ColorPicker.java   Source Code and License Vote up 4 votes
public void setColor(int color) {
    Color.colorToHSV(color, mColorHSV);
    invalidate();
}
 
Example 15
Project: buildAPKsApps   File: ColorPicker.java   Source Code and License Vote up 4 votes
public void setColor(int color) {
    Color.colorToHSV(color, colorHSV);
}
 
Example 16
Project: xlight_android_native   File: ColorPicker.java   Source Code and License Vote up 4 votes
/**
 * Set the color to be highlighted by the pointer. If the
 * instances {@code SVBar} and the {@code OpacityBar} aren't null the color
 * will also be set to them
 * 
 * @param color The RGB value of the color to highlight. If this is not a
 *            color displayed on the color wheel a very simple algorithm is
 *            used to map it to the color wheel. The resulting color often
 *            won't look close to the original color. This is especially
 *            true for shades of grey. You have been warned!
 */
public void setColor(int color) {
	mAngle = colorToAngle(color);
	mPointerColor.setColor(calculateColor(mAngle));

	// check of the instance isn't null
	if (mOpacityBar != null) {
		// set the value of the opacity
		mOpacityBar.setColor(mColor);
		mOpacityBar.setOpacity(Color.alpha(color));
	}

	// check if the instance isn't null
	if (mSVbar != null) {
		// the array mHSV will be filled with the HSV values of the color.
		Color.colorToHSV(color, mHSV);
		mSVbar.setColor(mColor);

		// because of the design of the Saturation/Value bar,
		// we can only use Saturation or Value every time.
		// Here will be checked which we shall use.
		if (mHSV[1] < mHSV[2]) {
			mSVbar.setSaturation(mHSV[1]);
		} else if(mHSV[1] > mHSV[2]){
			mSVbar.setValue(mHSV[2]);
		}
	}

	if (mSaturationBar != null) {
		Color.colorToHSV(color, mHSV);
		mSaturationBar.setColor(mColor);
		mSaturationBar.setSaturation(mHSV[1]);
	}

	if (mValueBar != null && mSaturationBar == null) {
		Color.colorToHSV(color, mHSV);
		mValueBar.setColor(mColor);
		mValueBar.setValue(mHSV[2]);
	} else if (mValueBar != null) {
		Color.colorToHSV(color, mHSV);
		mValueBar.setValue(mHSV[2]);
	}
       setNewCenterColor(color);
}
 
Example 17
Project: Bigbang   File: Utils.java   Source Code and License Vote up 4 votes
public static int colorAtLightness(int color, float lightness) {
	float[] hsv = new float[3];
	Color.colorToHSV(color, hsv);
	hsv[2] = lightness;
	return Color.HSVToColor(hsv);
}
 
Example 18
Project: RoadLab-Pro   File: UIUtils.java   Source Code and License Vote up 4 votes
public static int darkenColor(int color) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= 0.8f;
    return Color.HSVToColor(hsv);
}
 
Example 19
Project: AssistantBySDK   File: Utils.java   Source Code and License Vote up 4 votes
public static int darkenColor(int color) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] = hsv[2] * 0.8f; // value component
    return Color.HSVToColor(hsv);
}
 
Example 20
Project: SOS-The-Healthcare-Companion   File: ColorUtils.java   Source Code and License Vote up 4 votes
public static int getDarkVariant(int color) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= 0.8f;
    return Color.HSVToColor(hsv);
}