Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright 2012-present Pixate, Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

import android.graphics.Color;

public class Main {
    /**
     * Lighten a color by percent.
     * 
     * @param color
     * @param percent 0.0 - 1.0
     * @return A new, lighter color.
     */
    public static int lightterByPercent(int color, float percent) {
        // TODO We may try an HSV approach...
        // float[] hsv = new float[3];
        // Color.colorToHSV(color, hsv);
        // hsv[2] *= (1 + percent);
        // return Color.HSVToColor(hsv);
        float r = Color.red(color) * (1 + percent);
        float g = Color.green(color) * (1 + percent);
        float b = Color.blue(color) * (1 + percent);
        int ir = Math.min(255, (int) r);
        int ig = Math.min(255, (int) g);
        int ib = Math.min(255, (int) b);
        int ia = Color.alpha(color);
        return (Color.argb(ia, ir, ig, ib));
    }
}