Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.graphics.Color;

public class Main {
    private static int getGradientColor(int startColor, int endColor, float radio) {
        if (radio <= 0.000001)
            return startColor;
        if (radio >= 1.0)
            return endColor;

        int a1 = Color.alpha(startColor);
        int r1 = Color.red(startColor);
        int g1 = Color.green(startColor);
        int b1 = Color.blue(startColor);

        int a2 = Color.alpha(endColor);
        int r2 = Color.red(endColor);
        int g2 = Color.green(endColor);
        int b2 = Color.blue(endColor);

        int a3 = (int) (a1 + (a2 - a1) * radio);
        int r3 = (int) (r1 + (r2 - r1) * radio);
        int g3 = (int) (g1 + (g2 - g1) * radio);
        int b3 = (int) (b1 + (b2 - b1) * radio);

        return Color.argb(a3, r3, g3, b3);
    }
}