當前位置: 首頁>>代碼示例>>Java>>正文


Java ColorUtils.colorToHSL方法代碼示例

本文整理匯總了Java中android.support.v4.graphics.ColorUtils.colorToHSL方法的典型用法代碼示例。如果您正苦於以下問題:Java ColorUtils.colorToHSL方法的具體用法?Java ColorUtils.colorToHSL怎麽用?Java ColorUtils.colorToHSL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v4.graphics.ColorUtils的用法示例。


在下文中一共展示了ColorUtils.colorToHSL方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: animateTint

import android.support.v4.graphics.ColorUtils; //導入方法依賴的package包/類
public static void animateTint(ImageView view, int from, int to, int duration) {
    final float[] fromHSL = new float[3];
    final float[] toHSL = new float[3];
    float[] currentHSL = new float[3];
    ColorUtils.colorToHSL(from, fromHSL);
    ColorUtils.colorToHSL(to, toHSL);
    int fromAlpha = Color.alpha(from);
    int toAlpha = Color.alpha(to);

    final ValueAnimator anim = ObjectAnimator.ofFloat(0f, 1f);
    anim.addUpdateListener((ValueAnimator animation) -> {
        float mul = (Float) animation.getAnimatedValue();
        ColorUtils.blendHSL(fromHSL, toHSL, mul, currentHSL);
        int color = ColorUtils.HSLToColor(currentHSL);
        color = ColorUtils.setAlphaComponent(color, fromAlpha +
                (int) ((toAlpha - fromAlpha) * mul));
        setTint(view, color);
    });
    anim.setDuration(duration);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.start();
}
 
開發者ID:MCMrARM,項目名稱:revolution-irc,代碼行數:23,代碼來源:ImageViewTintUtils.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: isTextColorReadable

import android.support.v4.graphics.ColorUtils; //導入方法依賴的package包/類
public static boolean isTextColorReadable(String color) {
    float delta = HiSettingsHelper.getInstance().isNightMode() ? 0.35f : 0.1f;
    float[] textHslColor = new float[3], refHslColor = new float[3];
    ColorUtils.colorToHSL(Color.parseColor(color), textHslColor);
    ColorUtils.colorToHSL(HiSettingsHelper.getInstance().isNightMode() ? NIGHT_REF_COLOR : DAY_REF_COLOR, refHslColor);
    return Math.abs(textHslColor[2] - refHslColor[2]) >= delta;
}
 
開發者ID:GreenSkinMonster,項目名稱:hipda,代碼行數:8,代碼來源:ColorHelper.java

示例6: 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

示例7: 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

示例8: 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.colorToHSL方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。