本文整理汇总了Java中android.support.v4.graphics.ColorUtils类的典型用法代码示例。如果您正苦于以下问题:Java ColorUtils类的具体用法?Java ColorUtils怎么用?Java ColorUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ColorUtils类属于android.support.v4.graphics包,在下文中一共展示了ColorUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import android.support.v4.graphics.ColorUtils; //导入依赖的package包/类
@Override
public void update(final ParticulateMatterSample sample) {
FragmentActivity activity = getActivity();
currentValue = sample;
if (activity == null || sample == null) {
return;
}
activity.runOnUiThread(() -> {
pm1.setText(String.format(Locale.getDefault(), "%d", sample.getPm1_0()));
pm25.setText(String.format(Locale.getDefault(), "%d", sample.getPm2_5()));
AQIColor pm25Color = AQIColor.fromPM25Level(sample.getPm2_5());
pm1Card.setCardBackgroundColor(
ColorUtils.setAlphaComponent(pm25Color.getColor(), 136));
pm25Card.setCardBackgroundColor(
ColorUtils.setAlphaComponent(pm25Color.getColor(), 136));
pm10.setText(String.format(Locale.getDefault(), "%d", sample.getPm10()));
pm10Card.setCardBackgroundColor(
ColorUtils.setAlphaComponent(AQIColor.fromPM10Level(sample.getPm10()).getColor(), 136));
time.setText(Settings.dateFormat.format(sample.getDate()));
});
}
示例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: drawBoxWithShadow
import android.support.v4.graphics.ColorUtils; //导入依赖的package包/类
private RectF drawBoxWithShadow(Canvas c, Paint p, int width, int height) {
Resources res = mContext.getResources();
float shadowBlur = res.getDimension(R.dimen.widget_preview_shadow_blur);
float keyShadowDistance = res.getDimension(R.dimen.widget_preview_key_shadow_distance);
float corner = res.getDimension(R.dimen.widget_preview_corner_radius);
RectF bounds = new RectF(shadowBlur, shadowBlur,
width - shadowBlur, height - shadowBlur - keyShadowDistance);
p.setColor(Color.WHITE);
// Key shadow
p.setShadowLayer(shadowBlur, 0, keyShadowDistance,
ShadowGenerator.KEY_SHADOW_ALPHA << 24);
c.drawRoundRect(bounds, corner, corner, p);
// Ambient shadow
p.setShadowLayer(shadowBlur, 0, 0,
ColorUtils.setAlphaComponent(Color.BLACK, ShadowGenerator.AMBIENT_SHADOW_ALPHA));
c.drawRoundRect(bounds, corner, corner, p);
p.clearShadowLayer();
return bounds;
}
示例4: setup
import android.support.v4.graphics.ColorUtils; //导入依赖的package包/类
void setup(int position) {
int color = colors[position];
int alpha = Color.alpha(color);
colorPanelView.setColor(color);
imageView.setImageResource(selectedPosition == position ? R.drawable.cpv_preset_checked : 0);
if (alpha != 255) {
if (alpha <= ColorPickerDialog.ALPHA_THRESHOLD) {
colorPanelView.setBorderColor(color | 0xFF000000);
imageView.setColorFilter(/*color | 0xFF000000*/Color.BLACK, PorterDuff.Mode.SRC_IN);
} else {
colorPanelView.setBorderColor(originalBorderColor);
if (ColorUtils.calculateLuminance(colors[position]) >= 0.65) {
imageView.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_IN);
} else {
imageView.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
}
}
} else {
setColorFilter(position);
}
setOnClickListener(position);
}
示例5: 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);
}
示例6: setPrimaryColors
import android.support.v4.graphics.ColorUtils; //导入依赖的package包/类
@Override
public void setPrimaryColors(int... colors) {
super.setPrimaryColors(colors);
if (colors.length > 0) {
mBoundaryColor = mBackColor = colors[0];
if (mBackColor == 0 || mBackColor == 0xffffffff) {
mBoundaryColor = 0xff606060;
}
if (colors.length > 1) {
mModelColor = colors[1];
lModelColor = ColorUtils.setAlphaComponent(colors[1], 225);
rModelColor = ColorUtils.setAlphaComponent(colors[1], 200);
textPaint.setColor(ColorUtils.setAlphaComponent(colors[1], 150));
}
}
}
示例7: setPrimaryColor
import android.support.v4.graphics.ColorUtils; //导入依赖的package包/类
public void setPrimaryColor(int color) {
// private int COLOR_BACKGROUND = Color.parseColor("#7ECEC9");
// private int COLOR_MOUNTAIN_1 = Color.parseColor("#86DAD7");
// private int COLOR_MOUNTAIN_2 = Color.parseColor("#3C929C");
// private int COLOR_MOUNTAIN_3 = Color.parseColor("#3E5F73");
// private int COLOR_TREE_1_BRANCH = Color.parseColor("#1F7177");
// private int COLOR_TREE_1_BTRUNK = Color.parseColor("#0C3E48");
// private int COLOR_TREE_2_BRANCH = Color.parseColor("#34888F");
// private int COLOR_TREE_2_BTRUNK = Color.parseColor("#1B6169");
// private int COLOR_TREE_3_BRANCH = Color.parseColor("#57B1AE");
// private int COLOR_TREE_3_BTRUNK = Color.parseColor("#62A4AD");
COLOR_BACKGROUND = color;
COLOR_MOUNTAIN_1 = ColorUtils.compositeColors(0x99ffffff,color);
COLOR_MOUNTAIN_2 = ColorUtils.compositeColors(0x993C929C,color);
COLOR_MOUNTAIN_3 = ColorUtils.compositeColors(0xCC3E5F73,color);
COLOR_TREE_1_BRANCH = ColorUtils.compositeColors(0x551F7177,color);
COLOR_TREE_1_BTRUNK = ColorUtils.compositeColors(0xCC0C3E48,color);
COLOR_TREE_2_BRANCH = ColorUtils.compositeColors(0x5534888F,color);
COLOR_TREE_2_BTRUNK = ColorUtils.compositeColors(0xCC1B6169,color);
COLOR_TREE_3_BRANCH = ColorUtils.compositeColors(0x5557B1AE,color);
COLOR_TREE_3_BTRUNK = ColorUtils.compositeColors(0xCC62A4AD,color);
}
示例8: drawColorBlock
import android.support.v4.graphics.ColorUtils; //导入依赖的package包/类
/**
* 绘制矩形色块
* @param canvas 默认画布
*/
private void drawColorBlock(Canvas canvas) {
float left, top;
int column, row;
for (int i = 0; i < blockHorizontalNum * BLOCK_VERTICAL_NUM; i++) {
row = i / blockHorizontalNum;
column = i % blockHorizontalNum;
boolean flag = false;
for (Point point : pointList) {
if (point.equals(column, row)) {
flag = true;
break;
}
}
if (flag) {
continue;
}
blockPaint.setColor(ColorUtils.setAlphaComponent(lModelColor, 255 / (column + 1)));
left = blockLeft + column * (blockWidth + DIVIDING_LINE_SIZE);
top = DIVIDING_LINE_SIZE + row * (blockHeight + DIVIDING_LINE_SIZE);
canvas.drawRect(left, top, left + blockWidth, top + blockHeight, blockPaint);
}
}
示例9: setupStatusBarView
import android.support.v4.graphics.ColorUtils; //导入依赖的package包/类
/**
* 设置一个可以自定义颜色的状态栏
*/
private void setupStatusBarView() {
if (mBarParams.statusBarView == null) {
mBarParams.statusBarView = new View(mActivity);
}
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, getStatusBarHeight(mActivity));
params.gravity = Gravity.TOP;
if (!isNavigationAtBottom(mActivity)) {
params.rightMargin = getNavigationBarWidth(mActivity);
}
mBarParams.statusBarView.setLayoutParams(params);
mBarParams.statusBarView.setBackgroundColor(ColorUtils.blendARGB(mBarParams.statusBarColor,
mBarParams.statusBarColorTransform, mBarParams.statusBarAlpha));
mBarParams.statusBarView.setVisibility(View.VISIBLE);
ViewGroup viewGroup = (ViewGroup) mBarParams.statusBarView.getParent();
if (viewGroup != null)
viewGroup.removeView(mBarParams.statusBarView);
mViewGroup.addView(mBarParams.statusBarView);
}
示例10: 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);
}
示例11: 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();
}
示例12: createButtonColorStateList
import android.support.v4.graphics.ColorUtils; //导入依赖的package包/类
private ColorStateList createButtonColorStateList(Context context, int baseColorAttr) {
states = new int[4][];
colors = new int[4];
int baseColor = ThemeUtils.getThemeAttrColor(context, baseColorAttr);
int colorControlHighlight = ThemeUtils.getThemeAttrColor(context, R.attr.colorControlHighlight);
states[0] = ThemeUtils.DISABLED_STATE_SET;
colors[0] = ThemeUtils.getDisabledThemeAttrColor(context, R.attr.colorButtonNormal);
int i = 0 + 1;
states[i] = ThemeUtils.PRESSED_STATE_SET;
colors[i] = ColorUtils.compositeColors(colorControlHighlight, baseColor);
i++;
states[i] = ThemeUtils.FOCUSED_STATE_SET;
colors[i] = ColorUtils.compositeColors(colorControlHighlight, baseColor);
i++;
states[i] = ThemeUtils.EMPTY_STATE_SET;
colors[i] = baseColor;
i++;
return new ColorStateList(states, colors);
}
示例13: updateTaskDescription
import android.support.v4.graphics.ColorUtils; //导入依赖的package包/类
private void updateTaskDescription(int position) {
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 < slidesAdapter.getCount()) {
colorPrimary = ContextCompat.getColor(this,
slidesAdapter.slides.get(position).backgroundColor);
} 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));
}
}
示例14: 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);
}
}
示例15: run
import android.support.v4.graphics.ColorUtils; //导入依赖的package包/类
@Override
public void run() {
// set to coloralpha
Log.e("happily", "Setting alpha to " + colorAlpha);
int newColor = ColorUtils.setAlphaComponent(backgroundColor, colorAlpha);
changeBackground(previousColor, newColor);
previousColor = newColor;
if (smileProbability > 0.8) {
progressBar.setProgress(progressBar.getProgress() + 8);
}
if (progressBar.getProgress() == 100) {
showQuote();
} else {
mHandler.postDelayed(mStatusChecker, mInterval);
}
}