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 {
    public static int ContrastColor(int color) {
        int d = 0;

        // Counting the perceptive luminance - human eye favors green color...
        double a = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;

        if (a < 0.5)
            return Color.BLACK; // bright colors - black font

        return Color.WHITE;// dark colors - white font

    }
}