Example usage for android.graphics Color HSVToColor

List of usage examples for android.graphics Color HSVToColor

Introduction

In this page you can find the example usage for android.graphics Color HSVToColor.

Prototype

@ColorInt
public static int HSVToColor(@IntRange(from = 0, to = 255) int alpha, @Size(3) float hsv[]) 

Source Link

Document

Convert HSV components to an ARGB color.

Usage

From source file:Main.java

public static int fromHSV(int alpha0to255, float hue0to359, float saturation0to1, float value0to1) {
    return Color.HSVToColor(alpha0to255, new float[] { hue0to359, saturation0to1, value0to1 });
}

From source file:Main.java

public static int getSecurityLevelColor(final float security) {
    if (security > 0.5) {
        return Color.HSVToColor(255, new float[] { 180f * security, 100f, 100f });
    }/* ww  w .  j  ava2 s  . c  om*/
    if (security > 0.1) {
        return Color.HSVToColor(255, new float[] { Math.max(180f * security - 30f, 0f), 100f, 100f });
    }
    if (security > 0) {
        return Color.HSVToColor(255, new float[] { Math.max(180f * security - 60f, 0f), 100f, 100f });
    }
    return Color.HSVToColor(255, new float[] { 0f, 100f, 100f });
}

From source file:Main.java

public static int saturate(int color, float saturation) {
    float[] hsv = new float[3];
    Color.RGBToHSV(Color.red(color), Color.green(color), Color.blue(color), hsv);
    hsv[1] = saturation;/*from w  ww .  j  a  va 2s. com*/
    return Color.HSVToColor(Color.alpha(color), hsv);
}

From source file:Main.java

public static int brighten(int color, float brightness) {
    float[] hsv = new float[3];
    Color.RGBToHSV(Color.red(color), Color.green(color), Color.blue(color), hsv);
    hsv[2] = brightness;/* ww w  .j  a v a  2 s  . c o  m*/
    return Color.HSVToColor(Color.alpha(color), hsv);
}

From source file:Main.java

public static int saturateRelative(int color, float saturationOffset) {
    float[] hsv = new float[3];
    Color.RGBToHSV(Color.red(color), Color.green(color), Color.blue(color), hsv);
    hsv[1] += saturationOffset;/*from  w ww.  j  av a  2 s. co m*/
    if (hsv[1] > 1.0f) {
        hsv[1] = 1.0f;
    } else if (hsv[1] < 0.0f) {
        hsv[1] = 0.0f;
    }
    return Color.HSVToColor(Color.alpha(color), hsv);
}

From source file:Main.java

private static int adjustColorBrightness(int argb, float factor) {
    final float[] hsv = new float[3];
    Color.colorToHSV(argb, hsv);/* www . j a  v a 2 s.  c  o  m*/

    hsv[2] = Math.min(hsv[2] * factor, 1f);

    return Color.HSVToColor(Color.alpha(argb), hsv);
}

From source file:Main.java

/** Map background color preference to paper overlay color. */
public static int mapPaperColorPrefernce(int paperColorPreference) {
    final float hsv[] = new float[3];
    Color.colorToHSV(paperColorPreference, hsv);
    // Map saturation to alpha. The paper bitmap below the template will provide
    // the white background.
    final int alpha = (int) (hsv[1] * 255);
    // Saturation and value are set to max.
    hsv[1] = 1.f;//from   w w  w  . j  a  v  a  2 s .co  m
    hsv[2] = 1.f;
    return Color.HSVToColor(alpha, hsv);
}

From source file:Main.java

/**
 * Convert HSL to color.//from  w  w w .  j a v  a  2 s.  c  o  m
 * 
 * @param alpha
 * @param hue
 * @param saturation
 * @param lightness
 * @return
 */
public static int hslToColor(int alpha, float hue, float saturation, float lightness) {
    float hh = hue;
    float ss = saturation;
    float ll = lightness;

    float h, s, v;

    h = hh;
    ll *= 2;
    ss *= (ll <= 1) ? ll : 2 - ll;
    v = (ll + ss) / 2;
    s = ((ll + ss) != 0) ? (2 * ss) / (ll + ss) : 0;
    return Color.HSVToColor(alpha, new float[] { h, s, v });
}

From source file:Main.java

public static int getHighlightColor(int sampleColor) {
    // Set a constant value level in HSV, in case the averaged color is too light or too dark.
    float[] hsvBackground = new float[3];
    Color.colorToHSV(sampleColor, hsvBackground);
    hsvBackground[2] = 0.3f; // value parameter

    return Color.HSVToColor(0xf2, hsvBackground);
}

From source file:de.quist.app.maps.example.PolygonDemoActivity.java

@Override
public void onMapReady(Map map) {
    // Override the default content description on the view, for accessibility mode.
    // Ideally this string would be localised.
    map.setContentDescription("Google Map with polygons.");

    // Create a rectangle with two rectangular holes.
    map.addPolygon(BuildConfig.MAP_BINDING.newPolygonOptions()
            .addAll(createRectangle(BuildConfig.MAP_BINDING.newLatLng(-20, 130), 5, 5))
            .addHole(createRectangle(BuildConfig.MAP_BINDING.newLatLng(-22, 128), 1, 1))
            .addHole(createRectangle(BuildConfig.MAP_BINDING.newLatLng(-18, 133), 0.5, 1.5))
            .fillColor(Color.CYAN).strokeColor(Color.BLUE).strokeWidth(5));

    // Create a rectangle centered at Sydney.
    PolygonOptions options = BuildConfig.MAP_BINDING.newPolygonOptions().addAll(createRectangle(SYDNEY, 5, 8));

    int fillColor = Color.HSVToColor(mAlphaBar.getProgress(), new float[] { mColorBar.getProgress(), 1, 1 });
    mMutablePolygon = map.addPolygon(// www  . jav a 2  s. com
            options.strokeWidth(mWidthBar.getProgress()).strokeColor(Color.BLACK).fillColor(fillColor));

    mColorBar.setOnSeekBarChangeListener(this);
    mAlphaBar.setOnSeekBarChangeListener(this);
    mWidthBar.setOnSeekBarChangeListener(this);

    // Move the map so that it is centered on the mutable polygon.
    map.moveCamera(BuildConfig.MAP_BINDING.cameraUpdateFactory().newLatLng(SYDNEY));
}