Java Code Examples for android.graphics.Paint#getAlpha()
The following examples show how to use
android.graphics.Paint#getAlpha() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoEffect.java From Genius-Android with Apache License 2.0 | 6 votes |
@Override public void draw(Canvas canvas, Paint paint) { // Draw background int preAlpha = setPaintAlpha(paint, mAlpha); if (paint.getAlpha() > 0) { canvas.drawColor(paint.getColor()); } if (mRadius > 0) { // Get double trans color if (preAlpha < 255) { preAlpha = getCircleAlpha(preAlpha, paint.getAlpha()); } // Draw circle paint.setAlpha(preAlpha); setPaintAlpha(paint, mCircleAlpha); if (paint.getAlpha() > 0) { canvas.drawCircle(mPaintX, mPaintY, mRadius, paint); } } }
Example 2
Source File: RippleForeground.java From Carbon with Apache License 2.0 | 6 votes |
@Override protected boolean drawSoftware(Canvas c, Paint p) { boolean hasContent = false; final int origAlpha = p.getAlpha(); final int alpha = (int) (origAlpha * mOpacity + 0.5f); final float radius = getCurrentRadius(); if (alpha > 0 && radius > 0) { final float x = getCurrentX(); final float y = getCurrentY(); p.setAlpha(alpha); c.drawCircle(x, y, radius, p); p.setAlpha(origAlpha); hasContent = true; } return hasContent; }
Example 3
Source File: Ripple.java From RippleDrawable with MIT License | 6 votes |
/** * Draws the ripple centered at (0,0) using the specified paint. */ public boolean draw(Canvas c, Paint p) { boolean hasContent = false; final int paintAlpha = p.getAlpha(); final int alpha = (int) (paintAlpha * mOpacity + 0.5f); final float radius = MathUtils.lerp(0, mOuterRadius, mTweenRadius); if (alpha > 0 && radius > 0) { final float x = MathUtils.lerp( mClampedStartingX - mBounds.exactCenterX(), mOuterX, mTweenX); final float y = MathUtils.lerp( mClampedStartingY - mBounds.exactCenterY(), mOuterY, mTweenY); p.setAlpha(alpha); c.drawCircle(x, y, radius, p); p.setAlpha(paintAlpha); hasContent = true; } return hasContent; }
Example 4
Source File: StatePaintDrawable.java From Genius-Android with Apache License 2.0 | 6 votes |
@Override public void draw(Canvas canvas) { final Paint paint = mPaint; final int prevAlpha = paint.getAlpha(); paint.setAlpha(Ui.modulateAlpha(prevAlpha, getAlpha())); // only draw shape if it may affect output if (paint.getAlpha() != 0 || paint.getXfermode() != null /*|| paint.hasShadowLayer()*/) { final boolean clearColorFilter; if (mTintFilter != null && paint.getColorFilter() == null) { paint.setColorFilter(mTintFilter); clearColorFilter = true; } else { clearColorFilter = false; } // call draw draw(canvas, mPaint); if (clearColorFilter) { paint.setColorFilter(null); } } // restore paint.setAlpha(prevAlpha); }
Example 5
Source File: RippleBackground.java From Carbon with Apache License 2.0 | 5 votes |
@Override protected boolean drawSoftware(Canvas c, Paint p) { boolean hasContent = false; final int origAlpha = p.getAlpha(); final int alpha = (int) (origAlpha * mOpacity + 0.5f); if (alpha > 0) { p.setAlpha(alpha); c.drawCircle(0, 0, mTargetRadius, p); p.setAlpha(origAlpha); hasContent = true; } return hasContent; }
Example 6
Source File: StreamingTextView.java From adt-leanback-support with Apache License 2.0 | 5 votes |
@Override public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) { int width = (int) paint.measureText(text, start, end); int dotWidth = mOneDot.getWidth(); int sliceWidth = 2 * dotWidth; int sliceCount = width / sliceWidth; int excess = width % sliceWidth; int prop = excess / 2; boolean rtl = isLayoutRtl(StreamingTextView.this); mRandom.setSeed(mSeed); int oldAlpha = paint.getAlpha(); for (int i = 0; i < sliceCount; i++) { if (ANIMATE_DOTS_FOR_PENDING) { if (mPosition + i >= mStreamPosition) break; } float left = i * sliceWidth + prop + dotWidth / 2; float dotLeft = rtl ? x + width - left - dotWidth : x + left; // give the dots some visual variety paint.setAlpha((mRandom.nextInt(4) + 1) * 63); if (mRandom.nextBoolean()) { canvas.drawBitmap(mTwoDot, dotLeft, y - mTwoDot.getHeight(), paint); } else { canvas.drawBitmap(mOneDot, dotLeft, y - mOneDot.getHeight(), paint); } } paint.setAlpha(oldAlpha); }
Example 7
Source File: MaterialContainerTransform.java From material-components-android with Apache License 2.0 | 5 votes |
private void maybeDrawContainerColor(Canvas canvas, Paint containerPaint) { // Fill the container at the current layer with a color. Useful when the start or end view // does not have a background or when the container size exceeds the image size which it can // in large start/end size changes. if (containerPaint.getColor() != Color.TRANSPARENT && containerPaint.getAlpha() > 0) { canvas.drawRect(getBounds(), containerPaint); } }
Example 8
Source File: PieChart.java From JNChartDemo with Apache License 2.0 | 5 votes |
/** * Sets the color the transparent-circle should have. * * @param color */ public void setTransparentCircleColor(int color) { Paint p = ((PieChartRenderer) mRenderer).getPaintTransparentCircle(); int alpha = p.getAlpha(); p.setColor(color); p.setAlpha(alpha); }
Example 9
Source File: PieChart.java From NetKnight with Apache License 2.0 | 5 votes |
/** * Sets the color the transparent-circle should have. * * @param color */ public void setTransparentCircleColor(int color) { Paint p = ((PieChartRenderer) mRenderer).getPaintTransparentCircle(); int alpha = p.getAlpha(); p.setColor(color); p.setAlpha(alpha); }
Example 10
Source File: PieChart.java From Stayfit with Apache License 2.0 | 5 votes |
/** * Sets the color the transparent-circle should have. * * @param color */ public void setTransparentCircleColor(int color) { Paint p = ((PieChartRenderer) mRenderer).getPaintTransparentCircle(); int alpha = p.getAlpha(); p.setColor(color); p.setAlpha(alpha); }
Example 11
Source File: PieChart.java From iMoney with Apache License 2.0 | 5 votes |
/** * Sets the color the transparent-circle should have. * * @param color */ public void setTransparentCircleColor(int color) { Paint p = ((PieChartRenderer) mRenderer).getPaintTransparentCircle(); int alpha = p.getAlpha(); p.setColor(color); p.setAlpha(alpha); }
Example 12
Source File: PieChart.java From Ticket-Analysis with MIT License | 5 votes |
/** * Sets the color the transparent-circle should have. * * @param color */ public void setTransparentCircleColor(int color) { Paint p = ((PieChartRenderer) mRenderer).getPaintTransparentCircle(); int alpha = p.getAlpha(); p.setColor(color); p.setAlpha(alpha); }
Example 13
Source File: PieChart.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * Sets the color the transparent-circle should have. * * @param color */ public void setTransparentCircleColor(int color) { Paint p = ((PieChartRenderer) mRenderer).getPaintTransparentCircle(); int alpha = p.getAlpha(); p.setColor(color); p.setAlpha(alpha); }
Example 14
Source File: BarcodeReticleGraphic.java From mlkit-material-android with Apache License 2.0 | 5 votes |
BarcodeReticleGraphic(GraphicOverlay overlay, CameraReticleAnimator animator) { super(overlay); this.animator = animator; Resources resources = overlay.getResources(); ripplePaint = new Paint(); ripplePaint.setStyle(Style.STROKE); ripplePaint.setColor(ContextCompat.getColor(context, R.color.reticle_ripple)); rippleSizeOffset = resources.getDimensionPixelOffset(R.dimen.barcode_reticle_ripple_size_offset); rippleStrokeWidth = resources.getDimensionPixelOffset(R.dimen.barcode_reticle_ripple_stroke_width); rippleAlpha = ripplePaint.getAlpha(); }
Example 15
Source File: ObjectReticleGraphic.java From mlkit-material-android with Apache License 2.0 | 5 votes |
ObjectReticleGraphic(GraphicOverlay overlay, CameraReticleAnimator animator) { super(overlay); this.animator = animator; Resources resources = overlay.getResources(); outerRingFillPaint = new Paint(); outerRingFillPaint.setStyle(Style.FILL); outerRingFillPaint.setColor( ContextCompat.getColor(context, R.color.object_reticle_outer_ring_fill)); outerRingStrokePaint = new Paint(); outerRingStrokePaint.setStyle(Style.STROKE); outerRingStrokePaint.setStrokeWidth( resources.getDimensionPixelOffset(R.dimen.object_reticle_outer_ring_stroke_width)); outerRingStrokePaint.setStrokeCap(Cap.ROUND); outerRingStrokePaint.setColor( ContextCompat.getColor(context, R.color.object_reticle_outer_ring_stroke)); innerRingStrokePaint = new Paint(); innerRingStrokePaint.setStyle(Style.STROKE); innerRingStrokePaint.setStrokeWidth( resources.getDimensionPixelOffset(R.dimen.object_reticle_inner_ring_stroke_width)); innerRingStrokePaint.setStrokeCap(Cap.ROUND); innerRingStrokePaint.setColor(ContextCompat.getColor(context, R.color.white)); ripplePaint = new Paint(); ripplePaint.setStyle(Style.STROKE); ripplePaint.setColor(ContextCompat.getColor(context, R.color.reticle_ripple)); outerRingFillRadius = resources.getDimensionPixelOffset(R.dimen.object_reticle_outer_ring_fill_radius); outerRingStrokeRadius = resources.getDimensionPixelOffset(R.dimen.object_reticle_outer_ring_stroke_radius); innerRingStrokeRadius = resources.getDimensionPixelOffset(R.dimen.object_reticle_inner_ring_stroke_radius); rippleSizeOffset = resources.getDimensionPixelOffset(R.dimen.object_reticle_ripple_size_offset); rippleStrokeWidth = resources.getDimensionPixelOffset(R.dimen.object_reticle_ripple_stroke_width); rippleAlpha = ripplePaint.getAlpha(); }
Example 16
Source File: NativeOpenStreetMapController.java From appinventor-extensions with Apache License 2.0 | 4 votes |
private Drawable rasterizeSVG(MapMarker aiMarker, SVG markerSvg) { SVG.Svg svg = markerSvg.getRootElement(); final float density = view.getContext().getResources().getDisplayMetrics().density; float height = aiMarker.Height() <= 0 ? getBestGuessHeight(svg) : aiMarker.Height(); float width = aiMarker.Width() <= 0 ? getBestGuessWidth(svg) : aiMarker.Width(); float scaleH = height / getBestGuessHeight(svg); float scaleW = width / getBestGuessWidth(svg); float scale = (float) Math.sqrt(scaleH * scaleH + scaleW * scaleW); // update fill color of SVG <path> Paint fillPaint = new Paint(); Paint strokePaint = new Paint(); PaintUtil.changePaint(fillPaint, aiMarker.FillColor()); PaintUtil.changePaint(strokePaint, aiMarker.StrokeColor()); SVG.Length strokeWidth = new SVG.Length(aiMarker.StrokeWidth() / scale); for (SVG.SvgObject element : svg.getChildren()) { if (element instanceof SVG.SvgConditionalElement) { SVG.SvgConditionalElement path = (SVG.SvgConditionalElement) element; path.baseStyle.fill = new SVG.Colour(fillPaint.getColor()); path.baseStyle.fillOpacity = fillPaint.getAlpha()/255.0f; path.baseStyle.stroke = new SVG.Colour(strokePaint.getColor()); path.baseStyle.strokeOpacity = strokePaint.getAlpha()/255.0f; path.baseStyle.strokeWidth = strokeWidth; path.baseStyle.specifiedFlags = 0x3d; if (path.style != null) { if ((path.style.specifiedFlags & SPECIFIED_FILL) == 0) { path.style.fill = new SVG.Colour(fillPaint.getColor()); path.style.specifiedFlags |= SPECIFIED_FILL; } if ((path.style.specifiedFlags & SPECIFIED_FILL_OPACITY) == 0) { path.style.fillOpacity = fillPaint.getAlpha()/255.0f; path.style.specifiedFlags |= SPECIFIED_FILL_OPACITY; } if ((path.style.specifiedFlags & SPECIFIED_STROKE) == 0) { path.style.stroke = new SVG.Colour(strokePaint.getColor()); path.style.specifiedFlags |= SPECIFIED_STROKE; } if ((path.style.specifiedFlags & SPECIFIED_STROKE_OPACITY) == 0) { path.style.strokeOpacity = strokePaint.getAlpha()/255.0f; path.style.specifiedFlags |= SPECIFIED_STROKE_OPACITY; } if ((path.style.specifiedFlags & SPECIFIED_STROKE_WIDTH) == 0) { path.style.strokeWidth = strokeWidth; path.style.specifiedFlags |= SPECIFIED_STROKE_WIDTH; } } } } // draw SVG to Picture and create a BitmapDrawable for rendering Picture picture = markerSvg.renderToPicture(); Picture scaledPicture = new Picture(); Canvas canvas = scaledPicture.beginRecording((int)((width + 2.0f * aiMarker.StrokeWidth()) * density), (int)((height + 2.0f * aiMarker.StrokeWidth()) * density)); canvas.scale(density * scaleW, density * scaleH); canvas.translate(strokeWidth.floatValue(), strokeWidth.floatValue()); picture.draw(canvas); scaledPicture.endRecording(); return new PictureDrawable(scaledPicture); }
Example 17
Source File: AnimationProperties.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
@Override public Integer get(Paint object) { return object.getAlpha(); }
Example 18
Source File: AndroidDisplayer.java From letv with Apache License 2.0 | 4 votes |
public int draw(BaseDanmaku danmaku) { float top = danmaku.getTop(); float left = danmaku.getLeft(); if (this.canvas == null) { return 0; } Paint alphaPaint = null; boolean needRestore = false; if (danmaku.getType() == 7) { if (danmaku.getAlpha() == AlphaValue.TRANSPARENT) { return 0; } if (!(danmaku.rotationZ == 0.0f && danmaku.rotationY == 0.0f)) { saveCanvas(danmaku, this.canvas, left, top); needRestore = true; } if (danmaku.getAlpha() != AlphaValue.MAX) { alphaPaint = this.ALPHA_PAINT; alphaPaint.setAlpha(danmaku.getAlpha()); } } if (alphaPaint != null && alphaPaint.getAlpha() == AlphaValue.TRANSPARENT) { return 0; } boolean cacheDrawn = false; int result = 1; if (danmaku.hasDrawingCache() && danmaku.cache != null) { DrawingCacheHolder holder = ((DrawingCache) danmaku.cache).get(); if (holder != null) { cacheDrawn = holder.draw(this.canvas, left, top, alphaPaint); } } if (!cacheDrawn) { if (alphaPaint != null) { this.PAINT.setAlpha(alphaPaint.getAlpha()); } else { resetPaintAlpha(this.PAINT); } drawDanmaku(danmaku, this.canvas, left, top, false); result = 2; } if (danmaku.isClickZan) { this.sStuffer.drawClickBg(danmaku, this.canvas, left, top); } if (needRestore) { restoreCanvas(this.canvas); } return result; }
Example 19
Source File: AndroidDisplayer.java From DanDanPlayForAndroid with MIT License | 4 votes |
private void resetPaintAlpha(Paint paint) { if (paint.getAlpha() != AlphaValue.MAX) { paint.setAlpha(AlphaValue.MAX); } }
Example 20
Source File: AndroidDisplayer.java From DanDanPlayForAndroid with MIT License | 4 votes |
@Override public int draw(BaseDanmaku danmaku) { float top = danmaku.getTop(); float left = danmaku.getLeft(); if (canvas != null) { Paint alphaPaint = null; boolean needRestore = false; if (danmaku.getType() == BaseDanmaku.TYPE_SPECIAL) { if (danmaku.getAlpha() == AlphaValue.TRANSPARENT) { return IRenderer.NOTHING_RENDERING; } if (danmaku.rotationZ != 0 || danmaku.rotationY != 0) { saveCanvas(danmaku, canvas, left, top); needRestore = true; } int alpha = danmaku.getAlpha(); if (alpha != AlphaValue.MAX) { alphaPaint = mDisplayConfig.ALPHA_PAINT; alphaPaint.setAlpha(danmaku.getAlpha()); } } // skip drawing when danmaku is transparent if (alphaPaint != null && alphaPaint.getAlpha() == AlphaValue.TRANSPARENT) { return IRenderer.NOTHING_RENDERING; } // drawing cache boolean cacheDrawn = sStuffer.drawCache(danmaku, canvas, left, top, alphaPaint, mDisplayConfig.PAINT); int result = IRenderer.CACHE_RENDERING; if (!cacheDrawn) { if (alphaPaint != null) { mDisplayConfig.PAINT.setAlpha(alphaPaint.getAlpha()); mDisplayConfig.PAINT_DUPLICATE.setAlpha(alphaPaint.getAlpha()); } else { resetPaintAlpha(mDisplayConfig.PAINT); } drawDanmaku(danmaku, canvas, left, top, false); result = IRenderer.TEXT_RENDERING; } if (needRestore) { restoreCanvas(canvas); } return result; } return IRenderer.NOTHING_RENDERING; }