本文整理汇总了Java中android.support.v4.graphics.ColorUtils.setAlphaComponent方法的典型用法代码示例。如果您正苦于以下问题:Java ColorUtils.setAlphaComponent方法的具体用法?Java ColorUtils.setAlphaComponent怎么用?Java ColorUtils.setAlphaComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.graphics.ColorUtils
的用法示例。
在下文中一共展示了ColorUtils.setAlphaComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateColor
import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
/**
* The line's color will be:
* - mostly opaque white if the hotseat is white (ignoring alpha)
* - mostly opaque black if the hotseat is black (ignoring alpha)
*/
public void updateColor(ExtractedColors extractedColors) {
int originalLineAlpha = mLinePaint.getAlpha();
int color = extractedColors.getColor(ExtractedColors.HOTSEAT_INDEX, Color.TRANSPARENT);
if (color != Color.TRANSPARENT) {
color = ColorUtils.setAlphaComponent(color, 255);
if (color == Color.BLACK) {
mActiveAlpha = BLACK_ALPHA;
} else if (color == Color.WHITE) {
mActiveAlpha = WHITE_ALPHA;
} else {
Log.e(TAG, "Setting workspace page indicators to an unsupported color: #"
+ Integer.toHexString(color));
}
mLinePaint.setColor(color);
mLinePaint.setAlpha(originalLineAlpha);
}
}
示例2: updateHotseatPalette
import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
/**
* The hotseat's color is defined as follows:
* - 12% black for super light wallpaper
* - 18% white for super dark
* - 25% white otherwise
*/
void updateHotseatPalette(Palette hotseatPalette) {
int hotseatColor;
int vibrantColor;
if (hotseatPalette != null) {
int extractedVibrantColor = hotseatPalette.getVibrantColor(ExtractedColors.DEFAULT_COLOR);
if (ExtractionUtils.isSuperLight(hotseatPalette)) {
hotseatColor = ColorUtils.setAlphaComponent(Color.BLACK, (int) (0.12f * 255));
vibrantColor = ColorUtils.setAlphaComponent(extractedVibrantColor, (int) (0.12f * 255));
} else if (ExtractionUtils.isSuperDark(hotseatPalette)) {
hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.18f * 255));
vibrantColor = ColorUtils.setAlphaComponent(extractedVibrantColor, (int) (0.18f * 255));
} else {
hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.25f * 255));
vibrantColor = ColorUtils.setAlphaComponent(extractedVibrantColor, (int) (0.25f * 255));
}
setColorAtIndex(HOTSEAT_INDEX, hotseatColor);
setColorAtIndex(VIBRANT_INDEX, vibrantColor);
}
}
示例3: setBackgroundActiveColor
import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
public static void setBackgroundActiveColor(View editText, int accentColor) {
if (editText.getBackground() == null)
return;
int normalColor = StyledAttributesHelper.getColor(editText.getContext(),
R.attr.colorControlNormal, 0);
int disabledColor = ColorUtils.setAlphaComponent(normalColor, (int) (255.f *
StyledAttributesHelper.getFloat(editText.getContext(), android.R.attr.disabledAlpha, 1.f)));
int[][] states = new int[][]{
new int[]{-android.R.attr.state_enabled},
new int[]{-android.R.attr.state_pressed, -android.R.attr.state_focused},
new int[]{}
};
int[] colors = new int[]{
disabledColor,
normalColor,
accentColor
};
ColorStateList list = new ColorStateList(states, colors);
editText.setBackground(new ColorFilterWorkaroundDrawable(editText.getBackground()));
ViewCompat.setBackgroundTintList(editText, list);
}
示例4: 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);
}
示例5: updateTaskDescription
import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
private void updateTaskDescription() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
String title = getTitle().toString();
Drawable iconDrawable = getApplicationInfo().loadIcon(getPackageManager());
Bitmap icon = iconDrawable instanceof BitmapDrawable ? ((BitmapDrawable) iconDrawable).getBitmap() : null;
int colorPrimary;
if (position < getCount()) {
try {
colorPrimary = ContextCompat.getColor(IntroActivity.this, getBackgroundDark(position));
} catch (Resources.NotFoundException e) {
colorPrimary = ContextCompat.getColor(IntroActivity.this, getBackground(position));
}
} else {
TypedValue typedValue = new TypedValue();
TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary});
colorPrimary = a.getColor(0, 0);
a.recycle();
}
colorPrimary = ColorUtils.setAlphaComponent(colorPrimary, 0xFF);
setTaskDescription(new ActivityManager.TaskDescription(title, icon, colorPrimary));
}
}
示例6: createButtonShadowBitmap
import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
Bitmap createButtonShadowBitmap() {
int shadowRadius = (int) buttonElevation * 2;
int bitmapRadius = buttonRadius + (shadowRadius / 2);
int bitmapSize = bitmapRadius * 2;
Bitmap shadowBitmap = Bitmap.createBitmap(bitmapSize, bitmapSize, Bitmap.Config.ARGB_8888);
shadowBitmap.eraseColor(0x0);
int colors[] = {
ColorUtils.setAlphaComponent(SHADOW_COLOR, SHADOW_ALPHA),
ColorUtils.setAlphaComponent(SHADOW_COLOR, 0)
};
float stops[] = {
(float) (buttonRadius - (shadowRadius / 2)) / (float) bitmapRadius,
1f
};
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new RadialGradient(bitmapRadius, bitmapRadius, bitmapRadius, colors, stops, Shader.TileMode.CLAMP));
Canvas canvas = new Canvas(shadowBitmap);
canvas.drawRect(0, 0, bitmapSize, bitmapSize, paint);
return shadowBitmap;
}
示例7: updateTaskDescription
import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
private void updateTaskDescription() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
String title = getTitle().toString();
Drawable iconDrawable = getApplicationInfo().loadIcon(getPackageManager());
Bitmap icon = iconDrawable instanceof BitmapDrawable ? ((BitmapDrawable) iconDrawable).getBitmap() : null;
int colorPrimary;
if (position < getCount()) {
try {
colorPrimary = ContextCompat.getColor(IntroActivity.this, getBackgroundDark(position));
} catch (Resources.NotFoundException e) {
colorPrimary = ContextCompat.getColor(IntroActivity.this, getBackground(position));
}
}
else {
TypedValue typedValue = new TypedValue();
TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary});
colorPrimary = a.getColor(0, 0);
a.recycle();
}
colorPrimary = ColorUtils.setAlphaComponent(colorPrimary, 0xFF);
setTaskDescription(new ActivityManager.TaskDescription(title, icon, colorPrimary));
}
}
示例8: init
import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
public void init() {
accentColor = getContext().getResources().getColor(R.color.colorAccent);
bgPaint.setStyle(Paint.Style.STROKE);
bgPaint.setStrokeWidth(Tool.convertDpToPixel(2, getContext()));
bgPaint.setColor(Color.GRAY);
iconPaint.setFilterBitmap(true);
iconPaint.setColor(Color.WHITE);
iconPaint.setStyle(Paint.Style.FILL_AND_STROKE);
overlay = new PorterDuffColorFilter(ColorUtils.setAlphaComponent(Color.DKGRAY, 100), PorterDuff.Mode.SRC_OVER);
strokeWidth = Tool.convertDpToPixel(strokeWidth, getContext());
invisibleBitmap = Tool.drawableToBitmap(getResources().getDrawable(R.drawable.ic_visibility_off_24dp));
setWillNotDraw(false);
}
示例9: init
import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
private void init() {
final TypedValue typedValue = new TypedValue();
initUsingColorAccent(typedValue);
mImageBackgroundColor = getColor(R.color.alter_unchecked_image_background);
mImageCheckColor = getColor(R.color.alter_image_check_color);
mCheckedImageOverlayColor = getColor(R.color.alter_checked_photo_overlay);
mAlbumBackgroundColor = getColor(R.color.alter_album_background);
mAlbumNameTextColor = getColor(R.color.alter_album_name_text_color);
mAlbumImagesCountTextColor = getColor(R.color.alter_album_images_count_text_color);
mFabBackgroundColorWhenPressed = ColorUtils.setAlphaComponent(mFabBackgroundColor, (int) (android.graphics.Color.alpha(mFabBackgroundColor) * 0.8f));
mPickMode = PickMode.MULTIPLE_IMAGES;
mPopupThemeResId = Util.getDefaultPopupTheme(mContext);
mCaptureItemIconTintColor = mDoneFabIconTintColor = Util.getDefaultIconTintColor(mContext);
mShouldShowCaptureMenuItem = true;
mCheckIconTintColor = Color.WHITE;
mVideosEnabled = false;
mVideoLengthLimit = 0; // No limit
mVideoThumbnailOverlayColor = getColor(R.color.alter_video_thumbnail_overlay);
mVideoIconTintColor = Color.WHITE;
}
示例10: generateStateBackground
import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
private Drawable generateStateBackground(Theme lockTheme) {
int normalColor = lockTheme.getPrimaryColor(getContext());
int pressedColor = lockTheme.getDarkPrimaryColor(getContext());
//164 -> 64% alpha
int focusedColor = ColorUtils.setAlphaComponent(normalColor, 164);
int disabledColor = ContextCompat.getColor(getContext(), R.color.com_auth0_lock_submit_disabled);
final StateListDrawable buttonDrawable = new StateListDrawable();
buttonDrawable.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed}, new ColorDrawable(pressedColor));
buttonDrawable.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_focused}, new ColorDrawable(focusedColor));
buttonDrawable.addState(new int[]{android.R.attr.state_enabled}, new ColorDrawable(normalColor));
buttonDrawable.addState(new int[]{}, new ColorDrawable(disabledColor));
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
return new RippleDrawable(ColorStateList.valueOf(pressedColor), buttonDrawable, null);
}
return buttonDrawable;
}
示例11: onBindHeaderColumnViewHolder
import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
@Override
public void onBindHeaderColumnViewHolder(@NonNull ViewHolderImpl viewHolder, int column) {
TestHeaderColumnViewHolder vh = (TestHeaderColumnViewHolder) viewHolder;
vh.tvText.setText(mTableDataSource.getColumnHeaderData(column)); // skip left top header
int color = COLORS[column % COLORS.length];
GradientDrawable gd = new GradientDrawable(
mIsRtl ? GradientDrawable.Orientation.RIGHT_LEFT : GradientDrawable.Orientation.LEFT_RIGHT,
new int[]{ColorUtils.setAlphaComponent(color, 50), 0x00000000});
gd.setCornerRadius(0f);
vh.vGradient.setBackground(gd);
vh.vLine.setBackgroundColor(color);
}
示例12: updateColor
import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
/**
* The line's color will be:
* - mostly opaque white if the hotseat is white (ignoring alpha)
* - mostly opaque black if the hotseat is black (ignoring alpha)
*/
public void updateColor(ExtractedColors extractedColors) {
int originalLineAlpha = mLinePaint.getAlpha();
int color = extractedColors.getColor(ExtractedColors.HOTSEAT_INDEX, Color.TRANSPARENT);
if (color != Color.TRANSPARENT) {
color = ColorUtils.setAlphaComponent(color, 255);
if (color == Color.BLACK) {
mActiveAlpha = BLACK_ALPHA;
} else if (color == Color.WHITE) {
mActiveAlpha = WHITE_ALPHA;
}
mLinePaint.setColor(color);
mLinePaint.setAlpha(originalLineAlpha);
}
}
示例13: getLighterOrDarkerVersionOfColor
import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
public static int getLighterOrDarkerVersionOfColor(int color, float contrastRatio) {
int whiteMinAlpha = ColorUtils.calculateMinimumAlpha(Color.WHITE, color, contrastRatio);
int blackMinAlpha = ColorUtils.calculateMinimumAlpha(Color.BLACK, color, contrastRatio);
int translucentWhiteOrBlack;
if (whiteMinAlpha >= 0) {
translucentWhiteOrBlack = ColorUtils.setAlphaComponent(Color.WHITE, whiteMinAlpha);
} else if (blackMinAlpha >= 0) {
translucentWhiteOrBlack = ColorUtils.setAlphaComponent(Color.BLACK, blackMinAlpha);
} else {
translucentWhiteOrBlack = Color.WHITE;
}
return ColorUtils.compositeColors(translucentWhiteOrBlack, color);
}
示例14: Hotseat
import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
public Hotseat(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mLauncher = Launcher.getLauncher(context);
mHasVerticalHotseat = mLauncher.getDeviceProfile().isVerticalBarLayout();
mBackgroundColor = ColorUtils.setAlphaComponent(
ThemeUtils.getAttrColor(context, android.R.attr.colorPrimary), 0);
mBackground = new ColorDrawable(mBackgroundColor);
setBackground(mBackground);
}
示例15: updateHotseatPalette
import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
/**
* The hotseat's color is defined as follows:
* - 12% black for super light wallpaper
* - 18% white for super dark
* - 25% white otherwise
*/
public void updateHotseatPalette(Palette hotseatPalette) {
int hotseatColor;
if (hotseatPalette != null && ExtractionUtils.isSuperLight(hotseatPalette)) {
hotseatColor = ColorUtils.setAlphaComponent(Color.BLACK, (int) (0.12f * 255));
} else if (hotseatPalette != null && ExtractionUtils.isSuperDark(hotseatPalette)) {
hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.18f * 255));
} else {
hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.25f * 255));
}
setColorAtIndex(HOTSEAT_INDEX, hotseatColor);
}