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 getContrastColor(String colorString) {
        int color = Color.parseColor(colorString);
        double y = (299 * Color.red(color) + 587 * Color.green(color) + 114 * Color.blue(color)) / 1000;
        if (y >= 128) {
            return Color.BLACK;
        } else {
            return Color.WHITE;
        }
    }
}