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 darker color provided a factor of reduction in lightness. * * @param color The original color value * @param factor Factor of lightness reduction, range can be between 0 - 1.0 * @return The calculated darker color */ public static int calculateDarkerColor(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.max(r - lightnessLevel, 0), Math.max(g - lightnessLevel, 0), Math.max(b - lightnessLevel, 0)); } }