List of usage examples for android.graphics Color alpha
@IntRange(from = 0, to = 255) public static int alpha(int color)
From source file:tk.wasdennnoch.androidn_ify.utils.NotificationColorUtil.java
private int processColor(int color) { return Color.argb(Color.alpha(color), 255 - Color.red(color), 255 - Color.green(color), 255 - Color.blue(color)); }
From source file:com.example.android.drawabletinting.DrawableTintingFragment.java
/** * Update the tint of the image with the color set in the seekbars and selected blend mode. * The seekbars are set to a maximum of 255, with one for each of the four components of the * ARGB color. (Alpha, Red, Green, Blue.) Once a color has been computed using * {@link Color#argb(int, int, int, int)}, it is set togethe with the blend mode on the background * image using/*w ww . j a v a2s. c o m*/ * {@link android.widget.ImageView#setColorFilter(int, android.graphics.PorterDuff.Mode)}. */ public void updateTint(int color, PorterDuff.Mode mode) { // Set the color hint of the image: ARGB mHintColor = color; // Set the color tint mode based on the selection of the Spinner mMode = mode; // Log selection Log.d(TAG, String.format("Updating tint with color [ARGB: %d,%d,%d,%d] and mode [%s]", Color.alpha(color), Color.red(color), Color.green(color), Color.blue(color), mode.toString())); // Apply the color tint for the selected tint mode mImage.setColorFilter(mHintColor, mMode); // Update the text for each label with the value of each channel mAlphaText.setText(getString(R.string.value_alpha, Color.alpha(color))); mRedText.setText(getString(R.string.value_red, Color.red(color))); mGreenText.setText(getString(R.string.value_green, Color.green(color))); mBlueText.setText(getString(R.string.value_blue, Color.blue(color))); }
From source file:org.getlantern.firetweet.view.ShapedImageView.java
public void setBorderColor(int color) { setBorderColorsInternal(Color.alpha(color), color); }
From source file:dimchoi.com.my.widget.AnimatedSvgView.java
@SuppressLint("DrawAllocation") @Override/* www . ja v a 2 s . c o m*/ protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mState == STATE_NOT_STARTED || mGlyphData == null) { return; } long t = System.currentTimeMillis() - mStartTime; // Draw outlines (starts as traced) for (int i = 0; i < mGlyphData.length; i++) { float phase = constrain(0, 1, (t - (mTraceTime - mTraceTimePerGlyph) * i * 1f / mGlyphData.length) * 1f / mTraceTimePerGlyph); float distance = INTERPOLATOR.getInterpolation(phase) * mGlyphData[i].length; mGlyphData[i].paint.setColor(mTraceResidueColors[i]); mGlyphData[i].paint .setPathEffect(new DashPathEffect(new float[] { distance, mGlyphData[i].length }, 0)); canvas.drawPath(mGlyphData[i].path, mGlyphData[i].paint); mGlyphData[i].paint.setColor(mTraceColors[i]); mGlyphData[i].paint.setPathEffect(new DashPathEffect( new float[] { 0, distance, phase > 0 ? mMarkerLength : 0, mGlyphData[i].length }, 0)); canvas.drawPath(mGlyphData[i].path, mGlyphData[i].paint); } if (t > mFillStart) { if (mState < STATE_FILL_STARTED) { changeState(STATE_FILL_STARTED); } // If after fill start, draw fill float phase = constrain(0, 1, (t - mFillStart) * 1f / mFillTime); for (int i = 0; i < mGlyphData.length; i++) { GlyphData glyphData = mGlyphData[i]; int fillColor = mFillColors[i]; int a = (int) (phase * ((float) Color.alpha(fillColor) / (float) 255) * 255); int r = Color.red(fillColor); int g = Color.green(fillColor); int b = Color.blue(fillColor); mFillPaint.setARGB(a, r, g, b); canvas.drawPath(glyphData.path, mFillPaint); } } if (t < mFillStart + mFillTime) { // draw next frame if animation isn't finished ViewCompat.postInvalidateOnAnimation(this); } else { changeState(STATE_FINISHED); } }
From source file:com.ibm.mil.readyapps.physio.fragments.PainLocationFragment.java
/** * Pulls the bitmap image of the body part out of its RelativeLayout, colors it appropriatly, * and then tells the zoomLayout where it needs to zoom to. Also swaps the FRONT/BACK buttons * for the ADD/DELETE buttons.//from www . j a v a2s .c om * * @param image the body part the touch occured in. */ private void zoomOnImage(RelativeLayout image) { Bitmap bitm = ((BitmapDrawable) image.getBackground()).getBitmap(); Bitmap temp = bitm.copy(bitm.getConfig(), true); int[] pixels = new int[temp.getHeight() * temp.getWidth()]; temp.getPixels(pixels, 0, temp.getWidth(), 0, 0, temp.getWidth(), temp.getHeight()); for (int i = 0; i < temp.getHeight() * temp.getWidth(); i++) { if (pixels[i] != 0) { int r, g, b; if (!blue) { r = Color.red(pixels[i]) + 100; if (r > 255) { r = 255; } g = Color.green(pixels[i]) - 50; b = Color.blue(pixels[i]) - 50; } else { r = Color.red(pixels[i]) - 30; g = Color.green(pixels[i]) + 15; b = Color.blue(pixels[i]) + 100; if (b > 255) { b = 255; } } pixels[i] = Color.argb(Color.alpha(pixels[i]), r, g, b); } } temp.setPixels(pixels, 0, temp.getWidth(), 0, 0, temp.getWidth(), temp.getHeight()); image.setBackground(new BitmapDrawable(getResources(), temp)); Rect rect = new Rect(); image.getGlobalVisibleRect(rect); zoomLayout.zoomToRect(rect, 0, getYOffset()); current = image; zoomed = true; swapButtons(); placePointer(rect.centerX(), rect.centerY()); }
From source file:com.ridgelineapps.wallpaper.Utils.java
public static Paint createPaint(Paint p, int colorChange, int alphaChange) { int a = Color.alpha(p.getColor()) + alphaChange; int r = Color.red(p.getColor()) + colorChange; int g = Color.green(p.getColor()) + colorChange; int b = Color.blue(p.getColor()) + colorChange; if (a < 0) a = 0;/*from w ww . j a v a 2 s. co m*/ if (a > 255) a = 255; if (r < 0) r = 0; if (r > 255) r = 255; if (g < 0) g = 0; if (g > 255) g = 255; if (b < 0) b = 0; if (b > 255) b = 255; return createPaint(a, r, g, b); }
From source file:com.rks.musicx.misc.utils.Helper.java
/** * Return alpha color//from w w w . j av a2 s . c om * * @param color * @param ratio * @return */ public static int getColorWithAplha(int color, float ratio) { int transColor; int alpha = Math.round(Color.alpha(color) * ratio); int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); transColor = Color.argb(alpha, r, g, b); return transColor; }
From source file:com.jrummyapps.android.widget.AnimatedSvgView.java
@SuppressLint("DrawAllocation") @Override//from w w w.j a v a 2 s . c o m protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mState == STATE_NOT_STARTED || mGlyphData == null) { return; } long t = System.currentTimeMillis() - mStartTime; // Draw outlines (starts as traced) if (t < mFillStart + mFillTime) { for (int i = 0; i < mGlyphData.length; i++) { float phase = constrain(0, 1, (t - (mTraceTime - mTraceTimePerGlyph) * i * 1f / mGlyphData.length) * 1f / mTraceTimePerGlyph); float distance = INTERPOLATOR.getInterpolation(phase) * mGlyphData[i].length; mGlyphData[i].paint.setColor(mTraceResidueColors[i]); mGlyphData[i].paint .setPathEffect(new DashPathEffect(new float[] { distance, mGlyphData[i].length }, 0)); canvas.drawPath(mGlyphData[i].path, mGlyphData[i].paint); mGlyphData[i].paint.setColor(mTraceColors[i]); mGlyphData[i].paint.setPathEffect(new DashPathEffect( new float[] { 0, distance, phase > 0 ? mMarkerLength : 0, mGlyphData[i].length }, 0)); canvas.drawPath(mGlyphData[i].path, mGlyphData[i].paint); } } if (t > mFillStart && t < mFillStart + mFillTime) { if (mState < STATE_FILL_STARTED) { changeState(STATE_FILL_STARTED); } // If after fill start, draw fill float phase = constrain(0, 1, (t - mFillStart) * 1f / mFillTime); for (int i = 0; i < mGlyphData.length; i++) { GlyphData glyphData = mGlyphData[i]; int fillColor = mFillColors[i]; int a = (int) (phase * ((float) Color.alpha(fillColor) / (float) 255) * 255); int r = Color.red(fillColor); int g = Color.green(fillColor); int b = Color.blue(fillColor); mFillPaint.setARGB(a, r, g, b); canvas.drawPath(glyphData.path, mFillPaint); } } if (t > mFillStart + mFillTime) { float phase = (t - mDisappearTime - mFillStart) * 1f / mFillTime; if (phase < 0) phase = 0; else if (phase > 1) phase = 1; for (int i = 0; i < mGlyphData.length; i++) { GlyphData glyphData = mGlyphData[i]; int fillColor = mFillColors[i]; int a = 255 - (int) (phase * ((float) Color.alpha(fillColor) / (float) 255) * 255); int r = Color.red(fillColor); int g = Color.green(fillColor); int b = Color.blue(fillColor); mFillPaint.setARGB(a, r, g, b); canvas.drawPath(glyphData.path, mFillPaint); mGlyphData[i].paint.setAlpha(a); canvas.drawPath(mGlyphData[i].path, mGlyphData[i].paint); } } if (t < mFillStart + mDisappearTime + mFillTime) { // draw next frame if animation isn't finished ViewCompat.postInvalidateOnAnimation(this); } else { changeState(STATE_FINISHED); } }
From source file:com.jaredrummler.android.colorpicker.ColorPanelView.java
/** * Show a toast message with the hex color code below the view. *//*from ww w . ja va2s . c o m*/ public void showHint() { final int[] screenPos = new int[2]; final Rect displayFrame = new Rect(); getLocationOnScreen(screenPos); getWindowVisibleDisplayFrame(displayFrame); final Context context = getContext(); final int width = getWidth(); final int height = getHeight(); final int midy = screenPos[1] + height / 2; int referenceX = screenPos[0] + width / 2; if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) { final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; referenceX = screenWidth - referenceX; // mirror } StringBuilder hint = new StringBuilder("#"); if (Color.alpha(color) != 255) { hint.append(Integer.toHexString(color).toUpperCase(Locale.ENGLISH)); } else { hint.append(String.format("%06X", 0xFFFFFF & color).toUpperCase(Locale.ENGLISH)); } Toast cheatSheet = Toast.makeText(context, hint.toString(), Toast.LENGTH_SHORT); if (midy < displayFrame.height()) { // Show along the top; follow action buttons cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX, screenPos[1] + height - displayFrame.top); } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); }
From source file:com.andremion.music.MusicCoverView.java
public void setTrackColor(@ColorInt int trackColor) { if (trackColor != getTrackColor()) { int alpha = (mShape == SHAPE_CIRCLE) ? ALPHA_OPAQUE : ALPHA_TRANSPARENT; mTrackPaint.setColor(trackColor); mTrackAlpha = Color.alpha(trackColor); mTrackPaint.setAlpha(alpha * mTrackAlpha / ALPHA_OPAQUE); invalidate();//from w w w . jav a2 s . co m } }