List of usage examples for android.graphics Color alpha
@IntRange(from = 0, to = 255) public static int alpha(int color)
From source file:com.mixiaoxiao.support.widget.SmoothSwitch.java
private int getPressedColor(int color) { float dark = 0.6f; return Color.argb(Color.alpha(color), (int) (Color.red(color) * dark), (int) (Color.green(color) * dark), (int) (Color.blue(color) * dark)); }
From source file:com.astir_trotter.atcustom.ui.iconics.core.IconicsDrawable.java
/** * Set contour color for the.// w w w . jav a 2s . c o m * * @param contourColor * @return The current IconExtDrawable for chaining. */ public IconicsDrawable contourColor(@ColorInt int contourColor) { int red = Color.red(contourColor); int green = Color.green(contourColor); int blue = Color.blue(contourColor); mContourPaint.setColor(Color.rgb(red, green, blue)); mContourPaint.setAlpha(Color.alpha(contourColor)); mContourColor = contourColor; invalidateSelf(); return this; }
From source file:com.mixiaoxiao.support.widget.SmoothSwitch.java
private int getAlphaColor(int originalColor, float alpha) { final int originalAlpha = Color.alpha(originalColor); // Return the color, multiplying the original alpha by the disabled // value//from w w w .j ava 2 s. com return (originalColor & 0x00ffffff) | (Math.round(originalAlpha * alpha) << 24); }
From source file:io.jawg.osmcontributor.ui.utils.BitmapHandler.java
/** * Get the white icon corresponding to a poiType. * * @param poiType the PoiType or null for notes. * @return The white icon.//from w w w. j a v a 2 s . c o m */ public Drawable getIconWhite(PoiType poiType) { Bitmap myBitmap = BitmapFactory.decodeResource(context.getResources(), poiType == null ? R.drawable.open_book : getIconDrawableId(poiType)); myBitmap = myBitmap.copy(myBitmap.getConfig(), true); int[] allpixels = new int[myBitmap.getHeight() * myBitmap.getWidth()]; myBitmap.getPixels(allpixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight()); for (int i = 0; i < myBitmap.getHeight() * myBitmap.getWidth(); i++) { if (allpixels[i] != 0) { int A = Color.alpha(allpixels[i]); // inverting byte for each R/G/B channel int R = 255 - Color.red(allpixels[i]); int G = 255 - Color.green(allpixels[i]); int B = 255 - Color.blue(allpixels[i]); // set newly-inverted pixel to output image allpixels[i] = Color.argb(A, R, G, B); } } myBitmap.setPixels(allpixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight()); return new BitmapDrawable(context.getResources(), myBitmap); }
From source file:net.hadifar.dope.ui.widget.pagerIndicator.NumericPageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;/*from w ww .j a va2s. c om*/ } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } // mCurrentPage is -1 on first start and after orientation changed. If // so, retrieve the correct index from viewpager. if (mCurrentPage == -1 && mViewPager != null) { mCurrentPage = mViewPager.getCurrentItem(); } // Handle the first time we draw the view, when onMeasure has not been // called yet if (mTextFirstPart == null) { updateText(); } // Draw the main text (e.g. "Page 1 of 20"). The hardest part is drawing // the page // number itself, because of the animated effect in which the current // page fades // out and the next one fades in. In order to implement this effect we // are forced to // draw the text in four "chunks": the first part ("Page "), the current // page // number ("1"), the next page number ("2"), and the last part // (" of 20"). // To implement the fade in and fade out animations we simply change the // alpha // of the page number text, relative to the view pager scroll final float currentPageWeight = 1 - mPageOffset; final float nextPageWeight = mPageOffset; final float firstPartWidth = mPaintText.measureText(mTextFirstPart); final String currentPageNumber = Integer.toString(mCurrentPage + 1); final String nextPageNumber = Integer.toString(mCurrentPage + 2); final float currentPageNumberWidth = mPaintText.measureText(currentPageNumber); final float nextPageNumberWidth = mPaintText.measureText(nextPageNumber); final float pageNumberWidth = currentPageWeight * currentPageNumberWidth + nextPageWeight * nextPageNumberWidth; final float lastPartWidth = mPaintText.measureText(mTextLastPart); final float totalWidth = firstPartWidth + pageNumberWidth + lastPartWidth; float currentX = (getWidth() - totalWidth) / 2; canvas.drawText(mTextFirstPart, currentX, mTextBottom, mPaintText); currentX += firstPartWidth; final float pageNumberCenterX = currentX + pageNumberWidth / 2; final int startAlpha = Color.alpha(mColorPageNumberText); final int endAlpha = 0; final float currentPageNumberAlpha = currentPageWeight * startAlpha + nextPageWeight * endAlpha; mPaintPageNumberText.setAlpha((int) currentPageNumberAlpha); canvas.drawText(currentPageNumber, pageNumberCenterX - currentPageNumberWidth / 2, mTextBottom, mPaintPageNumberText); final float nextPageNumberAlpha = nextPageWeight * startAlpha + currentPageWeight * endAlpha; mPaintPageNumberText.setAlpha((int) nextPageNumberAlpha); canvas.drawText(nextPageNumber, pageNumberCenterX - nextPageNumberWidth / 2, mTextBottom, mPaintPageNumberText); currentX += pageNumberWidth; canvas.drawText(mTextLastPart, currentX, mTextBottom, mPaintText); // Draw the "start" and "end" buttons if (mShowStartEndButtons) { final int textStartAlpha = Color.alpha(mColorText); final int textEndAlpha = 0; if (mCurrentPage != 0 && mStartDown) { canvas.drawRect(mRectStart, mPaintButtonBackground); } if (mCurrentPage != count - 1 && mEndDown) { canvas.drawRect(mRectEnd, mPaintButtonBackground); } if (mCurrentPage == 0) { mPaintText.setAlpha((int) (nextPageWeight * textStartAlpha + currentPageWeight * textEndAlpha)); } // canvas.drawText(mTextStartButton, mRectStart.centerX() - mWidthStartText / 2, mRectStartText.bottom, mPaintText); mPaintText.setAlpha(Color.alpha(mColorText)); if (mCurrentPage < count - 1) { if (mCurrentPage == count - 2) { mPaintText.setAlpha((int) (currentPageWeight * textStartAlpha + nextPageWeight * textEndAlpha)); } // canvas.drawText(mTextEndButton, mRectEnd.centerX() - mWidthEndText / 2, mRectEndText.bottom, mPaintText); mPaintText.setAlpha(Color.alpha(mColorText)); } } // Draw the "next" and "previous" buttons if (mShowChangePageButtons) { final int textStartAlpha = Color.alpha(mColorText); final int textEndAlpha = 0; if (mCurrentPage != 0 && mPreviousDown) { canvas.drawRect(mRectPrevious, mPaintButtonBackground); } if (mCurrentPage != count - 1 && mNextDown) { canvas.drawRect(mRectNext, mPaintButtonBackground); } if (mCurrentPage == 0) { mPaintText.setAlpha((int) (nextPageWeight * textStartAlpha + currentPageWeight * textEndAlpha)); } canvas.drawText(mTextPreviousButton, mRectPrevious.centerX() - mWidthPreviousText / 2, mRectPreviousText.bottom, mPaintText); mPaintText.setAlpha(Color.alpha(mColorText)); if (mCurrentPage < count - 1) { if (mCurrentPage == count - 2) { mPaintText.setAlpha((int) (currentPageWeight * textStartAlpha + nextPageWeight * textEndAlpha)); } canvas.drawText(mTextNextButton, mRectNext.centerX() - mWidthNextText / 2, mRectNextText.bottom, mPaintText); mPaintText.setAlpha(Color.alpha(mColorText)); } } }
From source file:org.mariotaku.twidere.util.ThemeUtils.java
public static int getOptimalLinkColor(int linkColor, int color) { final int[] yiq = new int[3]; TwidereColorUtils.colorToYIQ(color, yiq); final int y = yiq[0]; TwidereColorUtils.colorToYIQ(linkColor, yiq); if (y < 32 && yiq[0] <= ACCENT_COLOR_THRESHOLD) { return linkColor; } else if (y > ACCENT_COLOR_THRESHOLD && yiq[0] > 32) { return linkColor; }/*from w w w.j av a 2s. c om*/ yiq[0] = yiq[0] + (y - yiq[0]) / 2; return TwidereColorUtils.YIQToColor(Color.alpha(linkColor), yiq); }
From source file:com.jaredrummler.android.colorpicker.ColorPickerDialog.java
private void loadPresets() { int alpha = Color.alpha(color); presets = getArguments().getIntArray(ARG_PRESETS); if (presets == null) presets = MATERIAL_COLORS;/*from w w w. j a va 2 s . com*/ boolean isMaterialColors = presets == MATERIAL_COLORS; presets = Arrays.copyOf(presets, presets.length); // don't update the original array when modifying alpha if (alpha != 255) { // add alpha to the presets for (int i = 0; i < presets.length; i++) { int color = presets[i]; int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); presets[i] = Color.argb(alpha, red, green, blue); } } presets = unshiftIfNotExists(presets, color); if (isMaterialColors && presets.length == 19) { // Add black to have a total of 20 colors if the current color is in the material color palette presets = pushIfNotExists(presets, Color.argb(alpha, 0, 0, 0)); } }
From source file:com.waz.zclient.views.images.CircularSeekBar.java
/** * Initialize the CircularSeekBar with the attributes from the XML style. * Uses the defaults defined at the top of this file when an attribute is not specified by the user. * * @param attrArray TypedArray containing the attributes. *///from ww w . j a v a 2 s. com protected void initAttributes(TypedArray attrArray) { circleXRadius = attrArray.getDimension(R.styleable.CircularSeekBar_circle_x_radius, DEFAULT_CIRCLE_X_RADIUS * dpToPxScale); circleYRadius = attrArray.getDimension(R.styleable.CircularSeekBar_circle_y_radius, DEFAULT_CIRCLE_Y_RADIUS * dpToPxScale); pointerRadius = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_radius, DEFAULT_POINTER_RADIUS * dpToPxScale); pointerHaloWidth = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_halo_width, DEFAULT_POINTER_HALO_WIDTH * dpToPxScale); pointerHaloBorderWidth = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_halo_border_width, DEFAULT_POINTER_HALO_BORDER_WIDTH * dpToPxScale); circleStrokeWidth = attrArray.getDimension(R.styleable.CircularSeekBar_circle_stroke_width, DEFAULT_CIRCLE_STROKE_WIDTH * dpToPxScale); String tempColor = attrArray.getString(R.styleable.CircularSeekBar_pointer_color); if (tempColor != null) { try { pointerColor = Color.parseColor(tempColor); } catch (IllegalArgumentException e) { pointerColor = DEFAULT_POINTER_COLOR; } } tempColor = attrArray.getString(R.styleable.CircularSeekBar_pointer_halo_color); if (tempColor != null) { try { pointerHaloColor = Color.parseColor(tempColor); } catch (IllegalArgumentException e) { pointerHaloColor = DEFAULT_POINTER_HALO_COLOR; } } tempColor = attrArray.getString(R.styleable.CircularSeekBar_pointer_halo_color_ontouch); if (tempColor != null) { try { pointerHaloColorOnTouch = Color.parseColor(tempColor); } catch (IllegalArgumentException e) { pointerHaloColorOnTouch = DEFAULT_POINTER_HALO_COLOR_ONTOUCH; } } tempColor = attrArray.getString(R.styleable.CircularSeekBar_circle_color); if (tempColor != null) { try { circleColor = Color.parseColor(tempColor); } catch (IllegalArgumentException e) { circleColor = DEFAULT_CIRCLE_COLOR; } } tempColor = attrArray.getString(R.styleable.CircularSeekBar_circle_progress_color); if (tempColor != null) { try { circleProgressColor = Color.parseColor(tempColor); } catch (IllegalArgumentException e) { circleProgressColor = DEFAULT_CIRCLE_PROGRESS_COLOR; } } tempColor = attrArray.getString(R.styleable.CircularSeekBar_circle_fill); if (tempColor != null) { try { circleFillColor = Color.parseColor(tempColor); } catch (IllegalArgumentException e) { circleFillColor = DEFAULT_CIRCLE_FILL_COLOR; } } pointerAlpha = Color.alpha(pointerHaloColor); pointerAlphaOnTouch = attrArray.getInt(R.styleable.CircularSeekBar_pointer_alpha_ontouch, DEFAULT_POINTER_ALPHA_ONTOUCH); if (pointerAlphaOnTouch > 255 || pointerAlphaOnTouch < 0) { pointerAlphaOnTouch = DEFAULT_POINTER_ALPHA_ONTOUCH; } max = attrArray.getInt(R.styleable.CircularSeekBar_max, DEFAULT_MAX); progress = attrArray.getInt(R.styleable.CircularSeekBar_progress, DEFAULT_PROGRESS); customRadii = attrArray.getBoolean(R.styleable.CircularSeekBar_use_custom_radii, DEFAULT_USE_CUSTOM_RADII); maintainEqualCircle = attrArray.getBoolean(R.styleable.CircularSeekBar_maintain_equal_circle, DEFAULT_MAINTAIN_EQUAL_CIRCLE); moveOutsideCircle = attrArray.getBoolean(R.styleable.CircularSeekBar_move_outside_circle, DEFAULT_MOVE_OUTSIDE_CIRCLE); // Modulo 360 right now to avoid constant conversion startAngle = ((360f + (attrArray.getFloat((R.styleable.CircularSeekBar_start_angle), DEFAULT_START_ANGLE) % 360f)) % 360f); endAngle = ((360f + (attrArray.getFloat((R.styleable.CircularSeekBar_end_angle), DEFAULT_END_ANGLE) % 360f)) % 360f); if (MathUtils.floatEqual(startAngle, endAngle)) { //startAngle = startAngle + 1f; endAngle = endAngle - .1f; } final GestureDetector.SimpleOnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() { @Override public boolean onSingleTapConfirmed(MotionEvent e) { if (onArtClickListener != null) { onArtClickListener.onSingleClick(); return true; } return false; } @Override public boolean onDoubleTap(MotionEvent e) { if (onArtClickListener != null) { onArtClickListener.onDoubleClick(); } return super.onDoubleTap(e); } @Override public void onLongPress(MotionEvent e) { performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); if (onArtLongClickListener != null) { onArtLongClickListener.onLongClick(CircularSeekBar.this); } } }; gestureDetector = new GestureDetectorCompat(getContext(), gestureListener); gestureDetector.setOnDoubleTapListener(gestureListener); }
From source file:de.mrapp.android.preference.AbstractColorPickerPreference.java
/** * Creates and returns a textual representation of a color, according to a specific format. * * @param colorFormat//from w w w . j a v a 2 s .c om * The format, which should be used to format the color, as a value of the enum {@link * ColorFormat}. The format may not be null * @param color * The color, which should be formatted, as an {@link Integer} value * @return A textual representation of the given color as an instance of the type {@link * CharSequence} */ private CharSequence formatColor(final ColorFormat colorFormat, @ColorInt final int color) { ensureNotNull(colorFormat, "The color format may not be null"); if (colorFormat == ColorFormat.RGB) { return String.format(Locale.getDefault(), "R = %d, G = %d, B = %d", Color.red(color), Color.green(color), Color.blue(color)); } else if (colorFormat == ColorFormat.ARGB) { return String.format(Locale.getDefault(), "A = %d, R = %d, G = %d, B = %d", Color.alpha(color), Color.red(color), Color.green(color), Color.blue(color)); } else if (colorFormat == ColorFormat.HEX_3_BYTES) { return String.format("#%06X", (0xFFFFFF & color)); } else { return String.format("#%08X", (color)); } }
From source file:com.viewsforandroid.foundry.sample.indicators.NumericPageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;/* w ww . j a v a 2s. co m*/ } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } // mCurrentPage is -1 on first start and after orientation changed. If // so, retrieve the correct index from viewpager. if (mCurrentPage == -1 && mViewPager != null) { mCurrentPage = mViewPager.getCurrentItem(); } // Handle the first time we draw the view, when onMeasure has not been // called yet if (mTextFirstPart == null) { updateText(); } // Draw the main text (e.g. "Page 1 of 20"). The hardest part is drawing // the page // number itself, because of the animated effect in which the current // page fades // out and the next one fades in. In order to implement this effect we // are forced to // draw the text in four "chunks": the first part ("Page "), the current // page // number ("1"), the next page number ("2"), and the last part // (" of 20"). // To implement the fade in and fade out animations we simply change the // alpha // of the page number text, relative to the view pager scroll final float currentPageWeight = 1 - mPageOffset; final float nextPageWeight = mPageOffset; final float firstPartWidth = mPaintText.measureText(mTextFirstPart); final String currentPageNumber = Integer.toString(mCurrentPage + 1); final String nextPageNumber = Integer.toString(mCurrentPage + 2); final float currentPageNumberWidth = mPaintText.measureText(currentPageNumber); final float nextPageNumberWidth = mPaintText.measureText(nextPageNumber); final float pageNumberWidth = currentPageWeight * currentPageNumberWidth + nextPageWeight * nextPageNumberWidth; final float lastPartWidth = mPaintText.measureText(mTextLastPart); final float totalWidth = firstPartWidth + pageNumberWidth + lastPartWidth; float currentX = (getWidth() - totalWidth) / 2; canvas.drawText(mTextFirstPart, currentX, mTextBottom, mPaintText); currentX += firstPartWidth; final float pageNumberCenterX = currentX + pageNumberWidth / 2; final int startAlpha = Color.alpha(mColorPageNumberText); final int endAlpha = 0; final float currentPageNumberAlpha = currentPageWeight * startAlpha + nextPageWeight * endAlpha; mPaintPageNumberText.setAlpha((int) currentPageNumberAlpha); canvas.drawText(currentPageNumber, pageNumberCenterX - currentPageNumberWidth / 2, mTextBottom, mPaintPageNumberText); final float nextPageNumberAlpha = nextPageWeight * startAlpha + currentPageWeight * endAlpha; mPaintPageNumberText.setAlpha((int) nextPageNumberAlpha); canvas.drawText(nextPageNumber, pageNumberCenterX - nextPageNumberWidth / 2, mTextBottom, mPaintPageNumberText); currentX += pageNumberWidth; canvas.drawText(mTextLastPart, currentX, mTextBottom, mPaintText); // Draw the "start" and "end" buttons if (mShowStartEndButtons) { final int textStartAlpha = Color.alpha(mColorText); final int textEndAlpha = 0; if (mCurrentPage != 0 && mStartDown) { canvas.drawRect(mRectStart, mPaintButtonBackground); } if (mCurrentPage != count - 1 && mEndDown) { canvas.drawRect(mRectEnd, mPaintButtonBackground); } if (mCurrentPage == 0) { mPaintText.setAlpha((int) (nextPageWeight * textStartAlpha + currentPageWeight * textEndAlpha)); } canvas.drawText(mTextStartButton, mRectStart.centerX() - mWidthStartText / 2, mRectStartText.bottom, mPaintText); mPaintText.setAlpha(Color.alpha(mColorText)); if (mCurrentPage < count - 1) { if (mCurrentPage == count - 2) { mPaintText.setAlpha((int) (currentPageWeight * textStartAlpha + nextPageWeight * textEndAlpha)); } canvas.drawText(mTextEndButton, mRectEnd.centerX() - mWidthEndText / 2, mRectEndText.bottom, mPaintText); mPaintText.setAlpha(Color.alpha(mColorText)); } } // Draw the "next" and "previous" buttons if (mShowChangePageButtons) { final int textStartAlpha = Color.alpha(mColorText); final int textEndAlpha = 0; if (mCurrentPage != 0 && mPreviousDown) { canvas.drawRect(mRectPrevious, mPaintButtonBackground); } if (mCurrentPage != count - 1 && mNextDown) { canvas.drawRect(mRectNext, mPaintButtonBackground); } if (mCurrentPage == 0) { mPaintText.setAlpha((int) (nextPageWeight * textStartAlpha + currentPageWeight * textEndAlpha)); } canvas.drawText(mTextPreviousButton, mRectPrevious.centerX() - mWidthPreviousText / 2, mRectPreviousText.bottom, mPaintText); mPaintText.setAlpha(Color.alpha(mColorText)); if (mCurrentPage < count - 1) { if (mCurrentPage == count - 2) { mPaintText.setAlpha((int) (currentPageWeight * textStartAlpha + nextPageWeight * textEndAlpha)); } canvas.drawText(mTextNextButton, mRectNext.centerX() - mWidthNextText / 2, mRectNextText.bottom, mPaintText); mPaintText.setAlpha(Color.alpha(mColorText)); } } }