Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.graphics.Color;

public class Main {
    public static final int GREEN = Color.rgb(0, 180, 0);
    public static final int ORANGE = Color.rgb(253, 129, 38);
    public static final int RED = Color.RED;
    public static final int GRAY = Color.rgb(192, 192, 192);

    public static int color(int color) {
        float r = Color.red(color) + 1;
        float g = Color.green(color) + 1;
        float b = Color.blue(color) + 1;
        if (2 * g >= 3 * r && g / b >= 2)
            return GREEN;
        if (r / g > 4 && r / b > 4)
            return RED;
        if (r / b >= 3 && g / b >= 2 && r > g * 1.2)
            return ORANGE;
        // at Sytadin, yellow stands for 'works', lets consider green
        if (r > 150 && g > 150 && b < 50)
            return GREEN;
        if (r / b > 0.8 && r / b < 1.3 && g / b > 0.8 && g / b < 1.3)
            return GRAY;
        //      Log.e(tag, "Warn : nok color extraction for: " + color + ". r : " + r +", g : " +g +", b : " + b);
        return Color.BLACK;
    }
}