Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * Alni Common - Common utilities to be used with Android development
 * Copyright (C) 2011-2013  Alexander Nilsen
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @author Alexander Nilsen
 *
 */

import static android.graphics.Color.*;

public class Main {
    public static int getColor(int c0, int c1, float p) {
        int a = ave(alpha(c0), alpha(c1), p);
        int r = ave(red(c0), red(c1), p);
        int g = ave(green(c0), green(c1), p);
        int b = ave(blue(c0), blue(c1), p);
        return argb(a, r, g, b);
    }

    public static float ave(float src, float dst, float p) {
        return src + (p * (dst - src));
    }

    private static int ave(int src, int dst, float p) {
        return src + Math.round(p * (dst - src));
    }
}