List of usage examples for android.support.v4.graphics ColorUtils setAlphaComponent
@ColorInt public static int setAlphaComponent(@ColorInt int color, @IntRange(from = 0x0, to = 0xFF) int alpha)
From source file:ooo.oxo.moments.util.ColorMixer.java
public static int mix(@ColorInt int background, @ColorInt int foreground, float ratio) { int alpha = Color.alpha(foreground); alpha = (int) Math.floor((float) alpha * Math.max(0f, Math.min(1f, ratio))); foreground = ColorUtils.setAlphaComponent(foreground, alpha); return ColorUtils.compositeColors(foreground, background); }
From source file:me.xingrz.gankmeizhi.util.ColorMixer.java
/** * ??/*from w w w . j ava2 s . c o m*/ * * @param background * @param foreground ? * @param ratio ?? * @return ?? */ public static int mix(@ColorInt int background, @ColorInt int foreground, float ratio) { int alpha = Color.alpha(foreground); alpha = (int) Math.floor((float) alpha * ratio); foreground = ColorUtils.setAlphaComponent(foreground, alpha); return ColorUtils.compositeColors(foreground, background); }
From source file:com.marlonjones.voidlauncher.Hotseat.java
public Hotseat(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mLauncher = Launcher.getLauncher(context); mHasVerticalHotseat = mLauncher.getDeviceProfile().isVerticalBarLayout(); mBackgroundColor = ColorUtils .setAlphaComponent(ContextCompat.getColor(context, R.color.all_apps_container_color), 0); mBackground = new ColorDrawable(mBackgroundColor); setBackground(mBackground);/*from w w w.ja v a2 s .co m*/ }
From source file:android.support.v7.internal.widget.ThemeUtils.java
static int getThemeAttrColor(Context context, int attr, float alpha) { final int color = getThemeAttrColor(context, attr); final int originalAlpha = Color.alpha(color); return ColorUtils.setAlphaComponent(color, Math.round(originalAlpha * alpha)); }
From source file:com.android.launcher3.Hotseat.java
public Hotseat(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mLauncher = Launcher.getLauncher(context); mHasVerticalHotseat = mLauncher.getDeviceProfile().isVerticalBarLayout(); mBackgroundColor = ColorUtils .setAlphaComponent(ContextCompat.getColor(context, R.color.all_apps_container_color), 0); mBackground = new ColorDrawable(mBackgroundColor); if (Utilities.getDockBackgroundPrefEnabled(getContext()) != -1) { setBackgroundColor(Utilities.getDockBackgroundPrefEnabled(getContext())); } else {//from ww w. java2s. co m setBackground(mBackground); } //setBackgroundColor(ContextCompat.getColor(context, R.color.colorPrimary)); }
From source file:org.mariotaku.twidere.text.OriginalStatusSpan.java
@Override public void draw(final Canvas canvas, final CharSequence text, final int start, final int end, final float x, final int top, final int y, final int bottom, final Paint paint) { if (!(paint instanceof TextPaint)) return;// w w w .j a v a 2 s. c om final TextPaint tp = (TextPaint) paint; mBounds.left = x; mBounds.right = x + paint.measureText(text, start, end) + mPadding * 2; mBounds.top = top; mBounds.bottom = bottom; final int innerTextColor = TwidereColorUtils.getContrastYIQ(tp.linkColor, ThemeUtils.ACCENT_COLOR_THRESHOLD, mDarkLightColors[0], mDarkLightColors[1]); mPaint.setStyle(Paint.Style.FILL); mPaint.setColor(tp.linkColor); mBounds.inset(mPaint.getStrokeWidth() / 2, mPaint.getStrokeWidth() / 2); canvas.drawRoundRect(mBounds, mCornerRadius, mCornerRadius, mPaint); mBounds.inset(-mPaint.getStrokeWidth() / 2, -mPaint.getStrokeWidth() / 2); mPaint.setStyle(Paint.Style.STROKE); mPaint.setColor( ColorUtils.compositeColors(ColorUtils.setAlphaComponent(innerTextColor, 0x80), tp.linkColor)); mBounds.inset(mPaint.getStrokeWidth() / 2, mPaint.getStrokeWidth() / 2); canvas.drawRoundRect(mBounds, mCornerRadius, mCornerRadius, mPaint); paint.setColor(innerTextColor); canvas.drawText(text, start, end, x + mPadding, top + (bottom - top) / 2 - (paint.descent() + paint.ascent()) / 2, paint); }
From source file:com.android.launcher3.dynamicui.ExtractionUtils.java
/** @return Whether the foreground color is legible on the background color. */ private static boolean isLegible(int foreground, int background) { background = ColorUtils.setAlphaComponent(background, 255); return ColorUtils.calculateContrast(foreground, background) >= MIN_CONTRAST_RATIO; }
From source file:com.savvasdalkitsis.betwixt.demo.InterpolatorView.java
private void init() { paint = new Paint(); paint.setColor(Color.BLACK);//from w w w .jav a 2 s . c om paint.setStrokeWidth(getResources().getDimensionPixelSize(R.dimen.interpolation_width)); paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setAntiAlias(true); paint.setStrokeCap(Paint.Cap.ROUND); linePaint.setColor(Color.WHITE); linePaint.setStrokeWidth(getResources().getDimensionPixelSize(R.dimen.interpolation_width)); float dashSize = getResources().getDimensionPixelSize(R.dimen.dash_size); linePaint.setPathEffect(new DashPathEffect(new float[] { dashSize, dashSize }, 0)); linePaint.setStyle(Paint.Style.STROKE); rectPaint = new Paint(); rectPaint.setARGB(255, 255, 200, 200); radius = getResources().getDimensionPixelSize(R.dimen.circle_radius); animationInset = getResources().getDimensionPixelSize(R.dimen.play_inset); circlePaint.setColor(Color.RED); circlePaint.setAntiAlias(true); textPaint.setColor(Color.BLACK); textPaint.setAntiAlias(true); textPaint.setTextSize(getResources().getDimensionPixelSize(R.dimen.interpolator_description_size)); textPaddingLeft = getResources().getDimensionPixelSize(R.dimen.text_padding_left); dim.setColor(ColorUtils.setAlphaComponent(Color.BLACK, 200)); setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { play(); } }); playAnimator.setStartDelay(500); playAnimator.setDuration(1000); playAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { progress = animation.getAnimatedFraction(); postInvalidate(); } }); playAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationCancel(Animator animation) { endAnimation(); } @Override public void onAnimationEnd(final Animator animation) { postDelayed(new Runnable() { @Override public void run() { endAnimation(); } }, 500); } }); }
From source file:com.bilibili.magicasakura.utils.ColorStateListUtils.java
static ColorStateList inflateColorStateList(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException { final int innerDepth = parser.getDepth() + 1; int depth;// w ww. j a va2 s .co m int type; LinkedList<int[]> stateList = new LinkedList<>(); LinkedList<Integer> colorList = new LinkedList<>(); while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) { if (type != XmlPullParser.START_TAG || depth > innerDepth || !parser.getName().equals("item")) { continue; } TypedArray a1 = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.color }); final int value = a1.getResourceId(0, Color.MAGENTA); final int baseColor = value == Color.MAGENTA ? Color.MAGENTA : ThemeUtils.replaceColorById(context, value); a1.recycle(); TypedArray a2 = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.alpha }); final float alphaMod = a2.getFloat(0, 1.0f); a2.recycle(); colorList.add(alphaMod != 1.0f ? ColorUtils.setAlphaComponent(baseColor, Math.round(Color.alpha(baseColor) * alphaMod)) : baseColor); stateList.add(extractStateSet(attrs)); } if (stateList.size() > 0 && stateList.size() == colorList.size()) { int[] colors = new int[colorList.size()]; for (int i = 0; i < colorList.size(); i++) { colors[i] = colorList.get(i); } return new ColorStateList(stateList.toArray(new int[stateList.size()][]), colors); } return null; }
From source file:p1.nd.khan.jubair.mohammadd.popularmovies.adapter.MovieAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { final ViewHolder viewHolder = (ViewHolder) view.getTag(); viewHolder.posterItemReleaseDate.setText( Utility.formatReleaseDate(cursor.getString(cursor.getColumnIndex(MovieEntry.C_RELEASE_DATE)))); viewHolder.gridItemRating.setText(//from ww w . jav a 2 s. c om Utility.formatRating(context, cursor.getString(cursor.getColumnIndex(MovieEntry.C_VOTE_AVERAGE)))); viewHolder.posterItemStar .setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_star_rate_black_18dp)); String posterPath = cursor.getString(cursor.getColumnIndex(MovieEntry.C_POSTER_PATH)); final int colorPrimaryLight = ContextCompat.getColor(context, (R.color.colorPrimaryTransparent)); Picasso.with(viewHolder.posterImage.getContext()) .load(context.getString(R.string.POSTER_IMAGE_URL) + "/" + posterPath) .placeholder(R.drawable.placeholder).into(viewHolder.posterImage, new Callback() { @Override public void onSuccess() { Bitmap posterBitmap = ((BitmapDrawable) viewHolder.posterImage.getDrawable()).getBitmap(); Palette.from(posterBitmap).generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { viewHolder.gridImageContainer.setBackgroundColor(ColorUtils .setAlphaComponent(palette.getMutedColor(colorPrimaryLight), 190)); } }); } @Override public void onError() { //do nothing } }); }