Example usage for android.support.v4.graphics ColorUtils RGBToHSL

List of usage examples for android.support.v4.graphics ColorUtils RGBToHSL

Introduction

In this page you can find the example usage for android.support.v4.graphics ColorUtils RGBToHSL.

Prototype

public static void RGBToHSL(@IntRange(from = 0x0, to = 0xFF) int r, @IntRange(from = 0x0, to = 0xFF) int g,
        @IntRange(from = 0x0, to = 0xFF) int b, @NonNull float[] outHsl) 

Source Link

Document

Convert RGB components to HSL (hue-saturation-lightness).

Usage

From source file:com.owncloud.android.utils.ThemeUtils.java

private static float[] colorToHSL(int color) {
    float[] hsl = new float[3];
    ColorUtils.RGBToHSL(Color.red(color), Color.green(color), Color.blue(color), hsl);

    return hsl;/*from   w ww .  j a v  a2 s  .  c om*/
}

From source file:com.microsoft.mimickeralarm.mimics.MimicColorCaptureFragment.java

@Override
public GameResult verify(Bitmap bitmap) {
    GameResult gameResult = new GameResult();
    gameResult.question = ((TextView) getView().findViewById(R.id.instruction_text)).getText().toString();

    try {/*from   www  .j a v  a  2  s  .c  o  m*/
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, output);
        ByteArrayInputStream inputStream = new ByteArrayInputStream(output.toByteArray());
        String[] features = { "Color" };
        Loggable.AppAction appAction = new Loggable.AppAction(Loggable.Key.APP_API_VISION);
        Logger.trackDurationStart(appAction);
        AnalyzeResult result = mVisionServiceRestClient.analyzeImage(inputStream, features);
        Logger.track(appAction);

        float[] accentHsl = new float[3];
        int[] accentRgb = hexStringToRgb(result.color.accentColor);
        ColorUtils.RGBToHSL(accentRgb[0], accentRgb[1], accentRgb[2], accentHsl);
        boolean colorInRange = isColorInRange(mQuestionColorRangeLower, mQuestionColorRangeUpper, accentHsl);
        Loggable.UserAction userAction = new Loggable.UserAction(Loggable.Key.ACTION_GAME_COLOR_SUCCESS);
        userAction.putProp(Loggable.Key.PROP_QUESTION, mQuestionColorName);
        userAction.putVision(result);

        //TODO: this will not work for languages other than English.
        if (colorInRange || result.color.dominantColorForeground.toLowerCase().equals(mQuestionColorName)
                || result.color.dominantColorBackground.toLowerCase().equals(mQuestionColorName)) {
            gameResult.success = true;
        }

        for (String color : result.color.dominantColors) {
            if (color.toLowerCase().equals(mQuestionColorName)) {
                gameResult.success = true;
                break;
            }
        }

        if (!gameResult.success) {
            userAction.Name = Loggable.Key.ACTION_GAME_COLOR_FAIL;
        }

        Logger.track(userAction);
    } catch (Exception ex) {
        Logger.trackException(ex);
    }

    return gameResult;
}