Java tutorial
//package com.java2s; /* * Copyright (C) 2015 Twitter, 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 { private static final int RGB_TOTAL_COLORS = 256; /** * This method calculates a lighter color provided a factor of increase in lightness. * * @param color A color value * @param factor Factor of increase in lightness, range can be between 0 - 1.0 * @return The calculated darker color */ public static int calculateLighterColor(final int color, final float factor) { final int a = Color.alpha(color); final int r = Color.red(color); final int g = Color.green(color); final int b = Color.blue(color); final int lightnessLevel = Math.round(RGB_TOTAL_COLORS * factor); return Color.argb(a, Math.min(r + lightnessLevel, 255), Math.min(g + lightnessLevel, 255), Math.min(b + lightnessLevel, 255)); } }