Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.ColorMatrixColorFilter;

public class Main {
    /**
     * Generate a color filter with a given color.
     * @param color The color the filter represents.
     * @return A color filter that can be used to set background colors of image views.
     */
    public static ColorFilter getColorFilter(String color) {
        int iColor = Color.parseColor(color);
        return getColorFilter(iColor);
    }

    /**
     * Generate a color filter with a given color.
     * @param color The color the filter represents.
     * @return A color filter that can be used to set background colors of image views.
     */
    public static ColorFilter getColorFilter(int color) {
        int red = (color & 0xFF0000) / 0xFFFF;
        int green = (color & 0xFF00) / 0xFF;
        int blue = color & 0xFF;

        float[] matrix = { 0, 0, 0, 0, red, 0, 0, 0, 0, green, 0, 0, 0, 0, blue, 0, 0, 0, 1, 0 };

        return new ColorMatrixColorFilter(matrix);
    }
}