Java Code Examples for android.graphics.Color.HSVToColor

The following are Jave code examples for showing how to use HSVToColor 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: microMathematics   File: OpacityBar.java   Source Code and License Vote up 6 votes
/**
 * Calculate the color selected by the pointer on the bar.
 * 
 * @param coord
 *            Coordinate of the pointer.
 */
private void calculateColor(int coord) {
	coord = coord - mBarPointerHaloRadius;
	if (coord < 0) {
		coord = 0;
	} else if (coord > mBarLength) {
		coord = mBarLength;
	}

	mColor = Color.HSVToColor(Math.round(mPosToOpacFactor * coord),
			mHSVColor);
	if (Color.alpha(mColor) > 250) {
		mColor = Color.HSVToColor(mHSVColor);
	} else if (Color.alpha(mColor) < 5) {
		mColor = Color.TRANSPARENT;
	}
}
 
Example 2
Project: hsv-alpha-color-picker   File: ValueView.java   Source Code and License Vote up 6 votes
protected Bitmap makeBitmap(int w, int h) {
	final boolean isWide = w > h;
	final int n = Math.max(w, h);
	int[] colors = new int[n];

	float[] hsv = new float[]{0, 0, 0};
	observableColor.getHsv(hsv);

	for (int i = 0; i < n; ++i) {
		hsv[2] = isWide ? (float)i / n : 1 - (float)i / n;
		colors[i] = Color.HSVToColor(hsv);
	}
	final int bmpWidth = isWide ? w : 1;
	final int bmpHeight = isWide ? 1 : h;
	return Bitmap.createBitmap(colors, bmpWidth, bmpHeight, Bitmap.Config.ARGB_8888);
}
 
Example 3
Project: buildAPKsApps   File: MultiColorPicker.java   Source Code and License Vote up 6 votes
private Bitmap createColorWheelBitmap(int width, int height) {

        Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[] { 0f, 1f, 1f };
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
 
Example 4
Project: simple-share-android   File: Utils.java   Source Code and License Vote up 6 votes
public static int getComplementaryColor(int colorToInvert) {
    float[] hsv = new float[3];
    Color.RGBToHSV(Color.red(colorToInvert), Color.green(colorToInvert),
            Color.blue(colorToInvert), hsv);
    hsv[0] = (hsv[0] + 180) % 360;
    return Color.HSVToColor(hsv);
}
 
Example 5
Project: planetcon   File: ColorPicker.java   Source Code and License Vote up 6 votes
private Bitmap createColorDiscBitmap(int radius) {
    int centerColor, edgeColor;
    Bitmap bitmap = Bitmap.createBitmap(2 * radius, 2 * radius, Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    mHSV[0] = 0; mHSV[1] = 1; mHSV[2] = 1;   //red
    SweepGradient sweepGradient = new SweepGradient(radius, radius, getColors(mHSV), null);
    mColorPaint.setShader(sweepGradient);
    canvas.drawCircle(radius, radius, radius, mColorPaint);

    mHSV[0] = 0; mHSV[1] = 0; mHSV[2] = 1;   //white
    centerColor = Color.HSVToColor(255, mHSV);
    edgeColor = Color.HSVToColor(0, mHSV);
    RadialGradient radialGradient = new RadialGradient(radius, radius, radius, centerColor, edgeColor, TileMode.CLAMP);
    mColorPaint.setShader(radialGradient);
    canvas.drawCircle(radius, radius, radius, mColorPaint);

    return bitmap;
}
 
Example 6
Project: microMathematics   File: OpacityBar.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 == 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.HSVToColor(0x00, mHSVColor), color }, null,
			Shader.TileMode.CLAMP);
	mBarPaint.setShader(shader);
	calculateColor(mBarPointerPosition);
	mBarPointerPaint.setColor(mColor);
	if (mPicker != null) {
		mPicker.setNewCenterColor(mColor);
	}
	invalidate();
}
 
Example 7
Project: TextView_CustomEdit_CustomColor   File: ColorPickerView.java   Source Code and License Vote up 5 votes
private int[] buildHueColorArray(){

		int[] hue = new int[361];

		int count = 0;
		for(int i = hue.length -1; i >= 0; i--, count++){
			hue[count] = Color.HSVToColor(new float[]{i, 1f, 1f});
		}

		return hue;
	}
 
Example 8
Project: aos-Video   File: VideoInfoCommonClass.java   Source Code and License Vote up 5 votes
public static int getClearerColor(int color) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= 1.4f; // value component
    color = Color.HSVToColor(hsv);
    return color;
}
 
Example 9
Project: PasscodeView   File: Utils.java   Source Code and License Vote up 5 votes
/**
 * Get the darker version of the given color.
 *
 * @param color Normal color.
 * @return Darker shade of the color.
 * @see 'http://stackoverflow.com/a/4928826'
 */
@ColorInt
public static int makeColorDark(@ColorInt int color) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] = 1f - 0.8f * hsv[2]; // value component
    return Color.HSVToColor(hsv);
}
 
Example 10
Project: GitHub   File: DynamicSettersActivity.java   Source Code and License Vote up 5 votes
@OnClick(R.id.button_set_colors)
void onColorsClicked() {
    int color = Color.HSVToColor(new float[]{
            random.nextFloat() * 360,
            1f,
            0.75f
    });
    widget.setArrowColor(color);
    widget.setSelectionColor(color);
}
 
Example 11
Project: SmartChart   File: ChartUtils.java   Source Code and License Vote up 5 votes
public static int darkenColor(int color) {
    float[] hsv = new float[3];
    int alpha = Color.alpha(color);
    Color.colorToHSV(color, hsv);
    hsv[1] = Math.min(hsv[1] * DARKEN_SATURATION, 1.0f);
    hsv[2] = hsv[2] * DARKEN_INTENSITY;
    int tempColor = Color.HSVToColor(hsv);
    return Color.argb(alpha, Color.red(tempColor), Color.green(tempColor), Color.blue(tempColor));
}
 
Example 12
Project: boohee_v5.6   File: ChartUtils.java   Source Code and License Vote up 5 votes
public static int darkenColor(int color) {
    hsv = new float[3];
    int alpha = Color.alpha(color);
    Color.colorToHSV(color, hsv);
    hsv[1] = Math.min(hsv[1] * DARKEN_SATURATION, 1.0f);
    hsv[2] = hsv[2] * DARKEN_INTENSITY;
    int tempColor = Color.HSVToColor(hsv);
    return Color.argb(alpha, Color.red(tempColor), Color.green(tempColor), Color.blue(tempColor));
}
 
Example 13
Project: Hitalk   File: FloatingActionButton.java   Source Code and License Vote up 4 votes
private static int lightenColor(int color) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= 1.1f;
    return Color.HSVToColor(hsv);
}
 
Example 14
Project: Hotspot-master-devp   File: SectorMenuButton.java   Source Code and License Vote up 4 votes
private int getLighterColor(int color) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= 1.1f;
    return Color.HSVToColor(hsv);
}
 
Example 15
Project: Hello-Music-droid   File: ATEUtils.java   Source Code and License Vote up 4 votes
public static int getStatusBarColor(int primaryColor) {
    float[] arrayOfFloat = new float[3];
    Color.colorToHSV(primaryColor, arrayOfFloat);
    arrayOfFloat[2] *= 0.9F;
    return Color.HSVToColor(arrayOfFloat);
}
 
Example 16
Project: MovieApp   File: Utils.java   Source Code and License Vote up 4 votes
public static int getDarkColor(int color) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= 0.8f; // value component
    return Color.HSVToColor(hsv);
}
 
Example 17
Project: MDWechat   File: ColorPickerView.java   Source Code and License Vote up 4 votes
private void drawHuePanel(Canvas canvas) {
  final Rect rect = hueRect;

  if (BORDER_WIDTH_PX > 0) {
    borderPaint.setColor(borderColor);

    canvas.drawRect(rect.left - BORDER_WIDTH_PX,
        rect.top - BORDER_WIDTH_PX,
        rect.right + BORDER_WIDTH_PX,
        rect.bottom + BORDER_WIDTH_PX,
        borderPaint);
  }

  if (hueBackgroundCache == null) {
    hueBackgroundCache = new BitmapCache();
    hueBackgroundCache.bitmap = Bitmap.createBitmap(rect.width(), rect.height(), Config.ARGB_8888);
    hueBackgroundCache.canvas = new Canvas(hueBackgroundCache.bitmap);

    int[] hueColors = new int[(int) (rect.height() + 0.5f)];

    // Generate array of all colors, will be drawn as individual lines.
    float h = 360f;
    for (int i = 0; i < hueColors.length; i++) {
      hueColors[i] = Color.HSVToColor(new float[]{h, 1f, 1f});
      h -= 360f / hueColors.length;
    }

    // Time to draw the hue color gradient,
    // its drawn as individual lines which
    // will be quite many when the resolution is high
    // and/or the panel is large.
    Paint linePaint = new Paint();
    linePaint.setStrokeWidth(0);
    for (int i = 0; i < hueColors.length; i++) {
      linePaint.setColor(hueColors[i]);
      hueBackgroundCache.canvas.drawLine(0, i, hueBackgroundCache.bitmap.getWidth(), i, linePaint);
    }
  }

  canvas.drawBitmap(hueBackgroundCache.bitmap, null, rect, null);

  Point p = hueToPoint(hue);

  RectF r = new RectF();
  r.left = rect.left - sliderTrackerOffsetPx;
  r.right = rect.right + sliderTrackerOffsetPx;
  r.top = p.y - (sliderTrackerSizePx / 2);
  r.bottom = p.y + (sliderTrackerSizePx / 2);

  canvas.drawRoundRect(r, 2, 2, hueAlphaTrackerPaint);
}
 
Example 18
Project: Alligator   File: TestActivity.java   Source Code and License Vote up 4 votes
private static int getRandomColor() {
	Random random = new Random();
	return Color.HSVToColor(new float[]{random.nextInt(360), 0.1f, 1.0f});
}
 
Example 19
Project: Android-AudioRecorder-App   File: ColorPalette.java   Source Code and License Vote up 4 votes
public static int getDarkerColor(int color) {
  float[] hsv = new float[3];
  Color.colorToHSV(color, hsv);
  hsv[2] *= 0.72f; // value component
  return Color.HSVToColor(hsv);
}
 
Example 20
Project: MyCalendar   File: ColorPickerView.java   Source Code and License Vote up 2 votes
/**
 * Get the current color this view is showing.
 *
 * @return the current color.
 */
public int getColor() {
    return Color.HSVToColor(alpha, new float[]{hue, sat, val});
}