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


Java Color.alpha方法代码示例

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


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

示例1: getGradientColor

import android.graphics.Color; //导入方法依赖的package包/类
private static int getGradientColor(int startColor, int endColor, float percent)
{
    int startA = Color.alpha(startColor);
    int startR = Color.red(startColor);
    int startG = Color.green(startColor);
    int startB = Color.blue(startColor);

    int endA = Color.alpha(endColor);
    int endR = Color.red(endColor);
    int endG = Color.green(endColor);
    int endB = Color.blue(endColor);

    int currentA = (int) (startA * (1 - percent) + endA * percent);
    int currentR = (int) (startR * (1 - percent) + endR * percent);
    int currentG = (int) (startG * (1 - percent) + endG * percent);
    int currentB = (int) (startB * (1 - percent) + endB * percent);
    return Color.argb(currentA, currentR, currentG, currentB);
}
 
开发者ID:codeccc,项目名称:baselibrary-master,代码行数:19,代码来源:SmoothCheckBox.java

示例2: calculateContrast

import android.graphics.Color; //导入方法依赖的package包/类
/**
 * Returns the contrast ratio between {@code foreground} and {@code background}.
 * {@code background} must be opaque.
 * <p>
 * Formula defined
 * <a href="http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef">here</a>.
 */
public static double calculateContrast(@ColorInt int foreground, @ColorInt int background) {
    if (Color.alpha(background) != 255) {
        throw new IllegalArgumentException("background can not be translucent: #"
                + Integer.toHexString(background));
    }
    if (Color.alpha(foreground) < 255) {
        // If the foreground is translucent, composite the foreground over the background
        foreground = compositeColors(foreground, background);
    }

    final double luminance1 = calculateLuminance(foreground) + 0.05;
    final double luminance2 = calculateLuminance(background) + 0.05;

    // Now return the lighter luminance divided by the darker luminance
    return Math.max(luminance1, luminance2) / Math.min(luminance1, luminance2);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:ColorUtils.java

示例3: createCircleDrawable

import android.graphics.Color; //导入方法依赖的package包/类
private Drawable createCircleDrawable(int color, float strokeWidth) {
  int alpha = Color.alpha(color);
  int opaqueColor = opaque(color);

  ShapeDrawable fillDrawable = new ShapeDrawable(new OvalShape());

  final Paint paint = fillDrawable.getPaint();
  paint.setAntiAlias(true);
  paint.setColor(opaqueColor);

  Drawable[] layers = {
      fillDrawable,
      createInnerStrokesDrawable(opaqueColor, strokeWidth)
  };

  LayerDrawable drawable = alpha == 255 || !mStrokeVisible
      ? new LayerDrawable(layers)
      : new TranslucentLayerDrawable(alpha, layers);

  int halfStrokeWidth = (int) (strokeWidth / 2f);
  drawable.setLayerInset(1, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth);

  return drawable;
}
 
开发者ID:nhocga1995s,项目名称:MyCalendar,代码行数:25,代码来源:FloatingActionButtonLibrary.java

示例4: getLightenColor

import android.graphics.Color; //导入方法依赖的package包/类
private int getLightenColor(int color){
    double fraction = 0.2;
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    red = (int)Math.min(red + (red * fraction), 255);
    green = (int)Math.min(green + (green * fraction), 255);
    blue = (int)Math.min(blue + (blue * fraction), 255);
    int alpha = Color.alpha(color);
    return Color.argb(alpha, red, green, blue);
}
 
开发者ID:mjn1369,项目名称:PrettyDialog,代码行数:12,代码来源:PrettyDialogButton.java

示例5: manipulateColor

import android.graphics.Color; //导入方法依赖的package包/类
private int manipulateColor(int color, @FloatRange(from = 0, to = 2) float factor) {
    int a = Color.alpha(color);
    int r = Math.round(Color.red(color) * factor);
    int g = Math.round(Color.green(color) * factor);
    int b = Math.round(Color.blue(color) * factor);
    return Color.argb(a, Math.min(r, 255), Math.min(g, 255), Math.min(b, 255));
}
 
开发者ID:JMaroz,项目名称:RoundButton,代码行数:8,代码来源:RoundButton.java

示例6: onApplyThemeResource

import android.graphics.Color; //导入方法依赖的package包/类
@Override
protected void onApplyThemeResource(Resources.Theme theme, @StyleRes int resid,
                                    boolean first) {
    if (mParent == null) {
        super.onApplyThemeResource(theme, resid, first);
    } else {
        try {
            theme.setTo(mParent.getTheme());
        } catch (Exception e) {
            // Empty
        }
        theme.applyStyle(resid, false);
    }

    // Get the primary color and update the TaskDescription for this activity
    TypedArray a = theme.obtainStyledAttributes(
            com.android.internal.R.styleable.ActivityTaskDescription);
    if (mTaskDescription.getPrimaryColor() == 0) {
        int colorPrimary = a.getColor(
                com.android.internal.R.styleable.ActivityTaskDescription_colorPrimary, 0);
        if (colorPrimary != 0 && Color.alpha(colorPrimary) == 0xFF) {
            mTaskDescription.setPrimaryColor(colorPrimary);
        }
    }
    // For dev-preview only.
    if (mTaskDescription.getBackgroundColor() == 0) {
        int colorBackground = a.getColor(
                com.android.internal.R.styleable.ActivityTaskDescription_colorBackground, 0);
        if (colorBackground != 0 && Color.alpha(colorBackground) == 0xFF) {
            mTaskDescription.setBackgroundColor(colorBackground);
        }
    }
    a.recycle();
    setTaskDescription(mTaskDescription);
}
 
开发者ID:JessYanCoding,项目名称:ProgressManager,代码行数:36,代码来源:a.java

示例7: getDarkColor

import android.graphics.Color; //导入方法依赖的package包/类
/**
 * Get the dark color.
 *
 * @param color Original color.
 * @return Dark color.
 */
@ColorInt
private static int getDarkColor(final int color) {
    final float factor = 0.6f;

    final int a = Color.alpha(color);
    final int r = Math.round(Color.red(color) * factor);
    final int g = Math.round(Color.green(color) * factor);
    final int b = Math.round(Color.blue(color) * factor);
    return Color.argb(a,
            Math.min(r, 255),
            Math.min(g, 255),
            Math.min(b, 255));
}
 
开发者ID:kevalpatel2106,项目名称:EmoticonGIFKeyboard,代码行数:20,代码来源:EmoticonGifImageView.java

示例8: compositeColors

import android.graphics.Color; //导入方法依赖的package包/类
/**
 * Composite two potentially translucent colors over each other and returns the result.
 */
public static int compositeColors(@ColorInt int foreground, @ColorInt int background) {
    int bgAlpha = Color.alpha(background);
    int fgAlpha = Color.alpha(foreground);
    int a = compositeAlpha(fgAlpha, bgAlpha);

    int r = compositeComponent(Color.red(foreground), fgAlpha,
            Color.red(background), bgAlpha, a);
    int g = compositeComponent(Color.green(foreground), fgAlpha,
            Color.green(background), bgAlpha, a);
    int b = compositeComponent(Color.blue(foreground), fgAlpha,
            Color.blue(background), bgAlpha, a);

    return Color.argb(a, r, g, b);
}
 
开发者ID:scwang90,项目名称:SmartRefreshLayout,代码行数:18,代码来源:ColorUtils.java

示例9: findMinimumAlpha

import android.graphics.Color; //导入方法依赖的package包/类
/**
 * Finds the minimum alpha value which can be applied to {@code foreground} so that is has a
 * contrast value of at least {@code minContrastRatio} when compared to background.
 *
 * @return the alpha value in the range 0-255.
 */
private static int findMinimumAlpha(int foreground, int background, double minContrastRatio) {
    if (Color.alpha(background) != 255) {
        throw new IllegalArgumentException("background can not be translucent");
    }

    // First lets check that a fully opaque foreground has sufficient contrast
    int testForeground = modifyAlpha(foreground, 255);
    double testRatio = calculateContrast(testForeground, background);
    if (testRatio < minContrastRatio) {
        // Fully opaque foreground does not have sufficient contrast, return error
        return -1;
    }

    // Binary search to find a value with the minimum value which provides sufficient contrast
    int numIterations = 0;
    int minAlpha = 0;
    int maxAlpha = 255;

    while (numIterations <= MIN_ALPHA_SEARCH_MAX_ITERATIONS &&
            (maxAlpha - minAlpha) > MIN_ALPHA_SEARCH_PRECISION) {
        final int testAlpha = (minAlpha + maxAlpha) / 2;

        testForeground = modifyAlpha(foreground, testAlpha);
        testRatio = calculateContrast(testForeground, background);

        if (testRatio < minContrastRatio) {
            minAlpha = testAlpha;
        } else {
            maxAlpha = testAlpha;
        }

        numIterations++;
    }

    // Conservatively return the max of the range of possible alphas, which is known to pass.
    return maxAlpha;
}
 
开发者ID:gigabytedevelopers,项目名称:FireFiles,代码行数:44,代码来源:ColorUtils.java

示例10: FocusIndicatorHelper

import android.graphics.Color; //导入方法依赖的package包/类
public FocusIndicatorHelper(View container) {
    mContainer = container;

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    int color = container.getResources().getColor(R.color.focused_background);
    mMaxAlpha = Color.alpha(color);
    mPaint.setColor(0xFF000000 | color);

    setAlpha(0);
    mShift = 0;
}
 
开发者ID:TeamBrainStorm,项目名称:SimpleUILauncher,代码行数:12,代码来源:FocusIndicatorHelper.java

示例11: shiftColor

import android.graphics.Color; //导入方法依赖的package包/类
@ColorInt
public static int shiftColor(@ColorInt int color, @FloatRange(from = 0.0f, to = 2.0f) float by) {
    if (by == 1f) return color;
    int alpha = Color.alpha(color);
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= by; // value component
    return (alpha << 24) + (0x00ffffff & Color.HSVToColor(hsv));
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:10,代码来源:ColorUtil.java

示例12: darkenColor

import android.graphics.Color; //导入方法依赖的package包/类
public static int darkenColor(int color) {
    hsv = new float[3];
    int alpha = Color.alpha(color);
    Color.colorToHSV(color, hsv);
    hsv[1] = Math.min(hsv[1] * DARKEN_SATURATION, 1.0f);
    hsv[2] = hsv[2] * DARKEN_INTENSITY;
    int tempColor = Color.HSVToColor(hsv);
    return Color.argb(alpha, Color.red(tempColor), Color.green(tempColor), Color.blue(tempColor));
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:10,代码来源:ChartUtils.java

示例13: ObservableColor

import android.graphics.Color; //导入方法依赖的package包/类
ObservableColor(int color) {
	Color.colorToHSV(color, hsv);
	alpha = Color.alpha(color);
}
 
开发者ID:salim3dd,项目名称:hsv-alpha-color-picker,代码行数:5,代码来源:ObservableColor.java

示例14: makeCubicGradientScrimDrawable

import android.graphics.Color; //导入方法依赖的package包/类
/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {

    // Generate a cache key by hashing together the inputs, based on the method described in the Effective Java book
    int cacheKeyHash = baseColor;
    cacheKeyHash = 31 * cacheKeyHash + numStops;
    cacheKeyHash = 31 * cacheKeyHash + gravity;

    Drawable cachedGradient = cubicGradientScrimCache.get(cacheKeyHash);
    if (cachedGradient != null) {
        return cachedGradient;
    }

    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int red = Color.red(baseColor);
    int green = Color.green(baseColor);
    int blue = Color.blue(baseColor);
    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = MathUtil.constrain(0, 1, (float) Math.pow(x, 3));
        stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:  x0 = 1; x1 = 0; break;
        case Gravity.RIGHT: x0 = 0; x1 = 1; break;
        default:            x0 = 0; x1 = 0; break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:    y0 = 1; y1 = 0; break;
        case Gravity.BOTTOM: y0 = 0; y1 = 1; break;
        default:             y0 = 0; y1 = 0; break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
        }
    });

    cubicGradientScrimCache.put(cacheKeyHash, paintDrawable);
    return paintDrawable;
}
 
开发者ID:htqqdd,项目名称:music_player,代码行数:64,代码来源:ScrimUtil.java

示例15: setShadowColor

import android.graphics.Color; //导入方法依赖的package包/类
public void setShadowColor(final int shadowColor) {
    mShadowColor = shadowColor;
    mShadowAlpha = Color.alpha(shadowColor);

    resetShadow();
}
 
开发者ID:gsrathoreniks,项目名称:ShadowLibrary-Android,代码行数:7,代码来源:ShadowLayout.java


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