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 {
    private static final int RPM_LOW = 1400;
    private static final int RPM_ECO = 1800;
    private static final int RPM_HIGH = 3000;
    private static final float GOOD = 120;
    private static final float BAD = 0;
    private static final float VALUE = 0.7f;
    private static final float SATURATION = 0.5f;

    public static int GetRPMColor(Double rpm) {
        float hue;
        if (rpm >= RPM_HIGH || rpm <= RPM_LOW) {
            hue = BAD;
        } else if (rpm == RPM_ECO) {
            hue = GOOD;
        } else if (rpm < RPM_ECO) {
            hue = (rpm.floatValue() - RPM_LOW) / (RPM_ECO - RPM_LOW) * (GOOD - BAD) + BAD;
        } else {
            hue = GOOD - (rpm.floatValue() - RPM_ECO) / (RPM_HIGH - RPM_ECO) * (GOOD - BAD) + BAD;
        }
        return Color.HSVToColor(new float[] { hue, SATURATION, VALUE });
    }
}