当前位置: 首页>>代码示例>>Java>>正文


Java ColorUtils.HSLToColor方法代码示例

本文整理汇总了Java中android.support.v4.graphics.ColorUtils.HSLToColor方法的典型用法代码示例。如果您正苦于以下问题:Java ColorUtils.HSLToColor方法的具体用法?Java ColorUtils.HSLToColor怎么用?Java ColorUtils.HSLToColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.graphics.ColorUtils的用法示例。


在下文中一共展示了ColorUtils.HSLToColor方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shiftBrightness

import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
/**
 * Darkens or lightens the color by the specified amount.
 *
 * @param color  Which color to change
 * @param amount Negative to darken, positive to lighten. Must be in range [-255, 255]
 * @return The brightness-shifted color
 */
@ColorInt
public static int shiftBrightness(@ColorInt final int color, @IntRange(from = -255, to = 255) final int amount) {
    if (amount == 0f) {
        return color;
    }

    // convert from RGB to HSL (hue/saturation/lightness)
    final float[] hsl = new float[] { 0f, 0f, 0f };
    ColorUtils.colorToHSL(color, hsl);

    // clamp the lightness to [0..1] range (0% - 100%)
    float lightness = hsl[2] + amount / 255f;
    if (lightness < 0f) {
        lightness = 0f;
    } else if (lightness > 1f) {
        lightness = 1f;
    }
    hsl[2] = lightness;

    final int a = Color.alpha(color);
    final int result = ColorUtils.HSLToColor(hsl);
    return ColorUtils.setAlphaComponent(result, a);
}
 
开发者ID:milosmns,项目名称:silly-android,代码行数:31,代码来源:Coloring.java

示例2: randomColor

import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
private int randomColor() {
    float[] TEMP_HSL = new float[]{0, 0, 0};
    float[] hsl = TEMP_HSL;
    hsl[0] = (float) (Math.random() * 360);
    hsl[1] = (float) (40 + (Math.random() * 60));
    hsl[2] = (float) (40 + (Math.random() * 60));
    return ColorUtils.HSLToColor(hsl);
}
 
开发者ID:Devlight,项目名称:NavigationTabBar,代码行数:9,代码来源:SamplesNtbActivity.java

示例3: darken

import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
/**
 * Darken the argb color by a percentage.
 *
 * @param color   the argb color to lighten.
 * @param percent percentage to darken by, between 0.0 and 1.0.
 */
public static @ColorInt int darken(@ColorInt final int color, @FloatRange(from=0.0, to=1.0) final float percent) {
  final float[] hsl = new float[3];
  ColorUtils.colorToHSL(color, hsl);
  hsl[2] -= hsl[2] * percent;
  // HSLToColor sets alpha to fully opaque, so pluck the alpha from the original color.
  return (color & 0xFF000000) | (ColorUtils.HSLToColor(hsl) & 0x00FFFFFF);
}
 
开发者ID:kickstarter,项目名称:android-oss,代码行数:14,代码来源:KSColorUtils.java

示例4: lighten

import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
/**
 * Lighten the argb color by a percentage.
 *
 * @param color   the argb color to lighten.
 * @param percent percentage to lighten by, between 0.0 and 1.0.
 */
public static @ColorInt int lighten(@ColorInt final int color, @FloatRange(from=0.0, to=1.0) final float percent) {
  final float[] hsl = new float[3];
  ColorUtils.colorToHSL(color, hsl);
  hsl[2] += (1.0f - hsl[2]) * percent;
  // HSLToColor sets alpha to fully opaque, so pluck the alpha from the original color.
  return (color & 0xFF000000) | (ColorUtils.HSLToColor(hsl) & 0x00FFFFFF);
}
 
开发者ID:kickstarter,项目名称:android-oss,代码行数:14,代码来源:KSColorUtils.java

示例5: adjustColorForStatusBar

import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
/**
 * Calculate a darker variant of the given color to make it suitable for setting as the status
 * bar background.
 *
 * @param color the color to adjust.
 * @return the adjusted color.
 */
public static
@ColorInt
int adjustColorForStatusBar(@ColorInt int color) {
    float[] hsl = new float[3];
    ColorUtils.colorToHSL(color, hsl);

    // darken the color by 7.5%
    float lightness = hsl[2] * 0.925f;
    // constrain lightness to be within [0–1]
    lightness = Math.max(0f, Math.min(1f, lightness));
    hsl[2] = lightness;
    return ColorUtils.HSLToColor(hsl);
}
 
开发者ID:google,项目名称:iosched,代码行数:21,代码来源:UIUtils.java

示例6: changeLightness

import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
private int changeLightness(int backgroundColor, float lightnessChange) {
    ColorUtils.colorToHSL(backgroundColor, hsl);
    hsl[2] *= lightnessChange;
    return ColorUtils.HSLToColor(hsl);
}
 
开发者ID:schaal,项目名称:ocreader,代码行数:6,代码来源:ItemPagerActivity.java

示例7: createTintOrShade

import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
private @ColorInt int createTintOrShade(@ColorInt int color, float factor) {
    float[] hsl = new float[3];
    ColorUtils.colorToHSL(color, hsl);
    hsl[2] *= factor;
    return ColorUtils.HSLToColor(hsl);
}
 
开发者ID:debun8,项目名称:texo,代码行数:7,代码来源:ColorTool.java


注:本文中的android.support.v4.graphics.ColorUtils.HSLToColor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。