Java Code Examples for android.graphics.Canvas#restoreToCount()
The following examples show how to use
android.graphics.Canvas#restoreToCount() .
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: ReflectItemView.java From AndroidTVWidget with Apache License 2.0 | 6 votes |
/** * 绘制倒影. */ public void drawReflection(Canvas reflectionCanvas) { int width = getWidth(); int height = getHeight(); int count = reflectionCanvas.save(); int count2 = reflectionCanvas.saveLayer(0, 0, width, mRefHeight, null, Canvas.ALL_SAVE_FLAG); // reflectionCanvas.save(); reflectionCanvas.clipRect(0, 0, getWidth(), mRefHeight); reflectionCanvas.save(); reflectionCanvas.scale(1, -1); reflectionCanvas.translate(0, -getHeight()); super.draw(reflectionCanvas); if (mIsDrawShape) { Path path = getShapePath(width, height, mRadius); reflectionCanvas.drawPath(path, mShapePaint); } reflectionCanvas.restore(); reflectionCanvas.drawRect(0, 0, getWidth(), mRefHeight, mRefPaint); reflectionCanvas.restore(); // if (count2 > 0) { reflectionCanvas.restoreToCount(count2); } reflectionCanvas.restoreToCount(count); }
Example 2
Source File: OptRoundRectDrawableWithShadow.java From OptionRoundCardview with Apache License 2.0 | 6 votes |
private void drawLeftEdgeShadow(Canvas canvas, float top, float inset, boolean suggest) { if (suggest && leftEdgeShadow) { int saved = canvas.save(); canvas.translate(mCardBounds.left + inset, mCardBounds.bottom - inset); canvas.rotate(270.0f); canvas.drawRect(0.0f, top, mCardBounds.height() - inset * 2.0f, -mCornerRadius, mEdgeShadowPaint); canvas.restoreToCount(saved); if (leftTopRect) { saved = canvas.save(); canvas.translate(mCardBounds.left + inset, mCardBounds.top + inset); canvas.rotate(270.0f); canvas.drawRect(0.0f, top, inset, -mCornerRadius, mEdgeShadowPaint); canvas.restoreToCount(saved); } if (leftBottomRect) { saved = canvas.save(); canvas.translate(mCardBounds.left + inset, mCardBounds.bottom); canvas.rotate(270.0f); canvas.drawRect(0.0f, top, inset, -mCornerRadius, mEdgeShadowPaint); canvas.restoreToCount(saved); } } }
Example 3
Source File: AppBarRelativeLayout.java From cathode with Apache License 2.0 | 5 votes |
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { if (child == toolbar) { contentScrim.mutate().setAlpha(scrimAlpha); contentScrim.draw(canvas); } else if (child.getId() == R.id.backdrop) { final int save = canvas.save(); canvas.clipRect(child.getLeft(), child.getTop(), child.getRight(), child.getBottom()); boolean result = super.drawChild(canvas, child, drawingTime); canvas.restoreToCount(save); return result; } return super.drawChild(canvas, child, drawingTime); }
Example 4
Source File: RoundImpl.java From TvWidget with Apache License 2.0 | 5 votes |
public static Bitmap getRoundBitmap(Bitmap bitmap, int roundWidth, int roundHeight) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); int count = canvas.save(Canvas.ALL_SAVE_FLAG); final Paint paint = new Paint(); final RectF rectF = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight()); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); canvas.drawRoundRect(rectF, roundWidth, roundHeight, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, 0, 0, paint); canvas.restoreToCount(count); return output; }
Example 5
Source File: TransformedLayout.java From Carbon with Apache License 2.0 | 5 votes |
@Override protected void dispatchDraw(@NonNull Canvas canvas) { int saveCount = canvas.save(); canvas.setMatrix(matrix); super.dispatchDraw(canvas); canvas.restoreToCount(saveCount); }
Example 6
Source File: MaterialMenuView.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override public void draw(Canvas canvas) { super.draw(canvas); if (getPaddingLeft() != 0 || getPaddingTop() != 0) { int saveCount = canvas.getSaveCount(); canvas.save(); canvas.translate(getPaddingLeft(), getPaddingTop()); drawable.draw(canvas); canvas.restoreToCount(saveCount); } else { drawable.draw(canvas); } }
Example 7
Source File: DepthContainerManager.java From Android-3D-Layout with MIT License | 5 votes |
private void drawBottomEdge(DepthLayout dl, Canvas canvas, float[] src) { final float[] dst = new float[]{dl.getDepthManager().getBottomLeft().x, dl.getDepthManager().getBottomLeft().y, dl.getDepthManager().getBottomRight().x, dl.getDepthManager().getBottomRight().y, dl.getDepthManager().getBottomRightBack().x, dl.getDepthManager().getBottomRightBack().y, dl.getDepthManager().getBottomLeftBack().x, dl.getDepthManager().getBottomLeftBack().y}; final int count = canvas.save(); matrix.setPolyToPoly(src, 0, dst, 0, dst.length >> 1); canvas.concat(matrix); drawRectangle(dl, canvas); drawShadow(dl.getDepthManager().getBottomLeft(), dl.getDepthManager().getBottomRight(), 0, canvas, dl); canvas.restoreToCount(count); }
Example 8
Source File: WindowBackgroundPaddingInsetsFrameLayout.java From PainlessMusicPlayer with Apache License 2.0 | 5 votes |
@Override protected void onDraw(@NonNull final Canvas canvas) { super.onDraw(canvas); final int width = getWidth(); final int height = getHeight(); if (mWindowBackground != null) { int sc = canvas.save(); canvas.translate(getScrollX(), getScrollY()); // Top mTempRect.set(0, 0, width, getPaddingTop()); mWindowBackground.setBounds(mTempRect); mWindowBackground.draw(canvas); // Bottom mTempRect.set(0, height - getPaddingBottom(), width, height); mWindowBackground.setBounds(mTempRect); mWindowBackground.draw(canvas); // Left mTempRect.set(0, getPaddingTop(), getPaddingLeft(), height - getPaddingBottom()); mWindowBackground.setBounds(mTempRect); mWindowBackground.draw(canvas); // Right mTempRect.set( width - getPaddingRight(), getPaddingTop(), width, height - getPaddingBottom()); mWindowBackground.setBounds(mTempRect); mWindowBackground.draw(canvas); canvas.restoreToCount(sc); } }
Example 9
Source File: SlidingUpPanelLayout.java From AndroidSlidingUpPanel-ScrollView with Apache License 2.0 | 5 votes |
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result; final int save = canvas.save(Canvas.CLIP_SAVE_FLAG); if (isSlidingEnabled() && mSlideableView != child) { // Clip against the slider; no sense drawing what will immediately be covered, // Unless the panel is set to overlay content if (!mOverlayContent) { canvas.getClipBounds(mTmpRect); if (mIsSlidingUp) { mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop()); } else { mTmpRect.top = Math.max(mTmpRect.top, mSlideableView.getBottom()); } canvas.clipRect(mTmpRect); } } result = super.drawChild(canvas, child, drawingTime); canvas.restoreToCount(save); if (mCoveredFadeColor != 0 && mSlideOffset > 0) { final int baseAlpha = (mCoveredFadeColor & 0xff000000) >>> 24; final int imag = (int) (baseAlpha * mSlideOffset); final int color = imag << 24 | (mCoveredFadeColor & 0xffffff); mCoveredFadePaint.setColor(color); canvas.drawRect(mTmpRect, mCoveredFadePaint); } return result; }
Example 10
Source File: RevealFrameLayout.java From NHentai-android with GNU General Public License v3.0 | 4 votes |
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { if(!mClipOutlines && child != mTarget) return super.drawChild(canvas, child, drawingTime); final int state = canvas.save(); mRevealPath.reset(); mRevealPath.addCircle(mCenterX, mCenterY, mRadius, Path.Direction.CW); canvas.clipPath(mRevealPath); boolean isInvalided = super.drawChild(canvas, child, drawingTime); canvas.restoreToCount(state); return isInvalided; }
Example 11
Source File: CollapsingTextHelper.java From GpCollapsingToolbar with Apache License 2.0 | 4 votes |
public void draw(Canvas canvas) { final int saveCount = canvas.save(); if (mTextToDraw != null && mDrawTitle) { float x = mCurrentDrawX; float y = mCurrentDrawY; final boolean drawTexture = mUseTexture && mExpandedTitleTexture != null; final float ascent; final float descent; if (drawTexture) { ascent = mTextureAscent * mScale; descent = mTextureDescent * mScale; } else { ascent = mTextPaint.ascent() * mScale; descent = mTextPaint.descent() * mScale; } if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(mCurrentBounds.left, y + ascent, mCurrentBounds.right, y + descent, DEBUG_DRAW_PAINT); } if (drawTexture) { y += ascent; } if (mScale != 1f) { canvas.scale(mScale, mScale, x, y); } if (drawTexture) { // If we should use a texture, draw it instead of text canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint); } else { canvas.drawText(mTextToDraw, 0, mTextToDraw.length(), x, y, mTextPaint); } } canvas.restoreToCount(saveCount); }
Example 12
Source File: StoreHouseHeader.java From RvHelper with Apache License 2.0 | 4 votes |
@Override public void onDraw(Canvas canvas) { super.onDraw(canvas); float progress = mProgress; int c1 = canvas.save(); int len = mItemList.size(); for (int i = 0; i < len; i++) { canvas.save(); StoreHouseBarItem storeHouseBarItem = mItemList.get(i); float offsetX = mOffsetX + storeHouseBarItem.midPoint.x; float offsetY = mOffsetY + storeHouseBarItem.midPoint.y; if (mIsInLoading) { storeHouseBarItem.getTransformation(getDrawingTime(), mTransformation); canvas.translate(offsetX, offsetY); } else { if (progress == 0) { storeHouseBarItem.resetPosition(mHorizontalRandomness); continue; } float startPadding = (1 - mInternalAnimationFactor) * i / len; float endPadding = 1 - mInternalAnimationFactor - startPadding; // done if (progress == 1 || progress >= 1 - endPadding) { canvas.translate(offsetX, offsetY); storeHouseBarItem.setAlpha(mBarDarkAlpha); } else { float realProgress; if (progress <= startPadding) { realProgress = 0; } else { realProgress = Math.min(1, (progress - startPadding) / mInternalAnimationFactor); } offsetX += storeHouseBarItem.translationX * (1 - realProgress); offsetY += -mDropHeight * (1 - realProgress); Matrix matrix = new Matrix(); matrix.postRotate(360 * realProgress); matrix.postScale(realProgress, realProgress); matrix.postTranslate(offsetX, offsetY); storeHouseBarItem.setAlpha(mBarDarkAlpha * realProgress); canvas.concat(matrix); } } storeHouseBarItem.draw(canvas); canvas.restore(); } if (mIsInLoading) { invalidate(); } canvas.restoreToCount(c1); }
Example 13
Source File: BulletListItemSpan.java From Markwon with Apache License 2.0 | 4 votes |
@Override public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, CharSequence text, int start, int end, boolean first, Layout layout) { // if there was a line break, we don't need to draw anything if (!first || !LeadingMarginUtils.selfStart(start, text, this)) { return; } paint.set(p); theme.applyListItemStyle(paint); final int save = c.save(); try { final int width = theme.getBlockMargin(); // @since 1.0.6 we no longer rely on (bottom-top) calculation in order to detect line height // it lead to bad rendering as first & last lines received different results even // if text size is the same (first line received greater amount and bottom line -> less) final int textLineHeight = (int) (paint.descent() - paint.ascent() + .5F); final int side = theme.getBulletWidth(textLineHeight); final int marginLeft = (width - side) / 2; // in order to support RTL final int l; final int r; { // @since 4.2.1 to correctly position bullet // when nested inside other LeadingMarginSpans (sorry, Nougat) if (IS_NOUGAT) { // @since 2.0.2 // There is a bug in Android Nougat, when this span receives an `x` that // doesn't correspond to what it should be (text is placed correctly though). // Let's make this a general rule -> manually calculate difference between expected/actual // and add this difference to resulting left/right values. If everything goes well // we do not encounter a bug -> this `diff` value will be 0 final int diff; if (dir < 0) { // rtl diff = x - (layout.getWidth() - (width * level)); } else { diff = (width * level) - x; } final int left = x + (dir * marginLeft); final int right = left + (dir * side); l = Math.min(left, right) + (dir * diff); r = Math.max(left, right) + (dir * diff); } else { if (dir > 0) { l = x + marginLeft; } else { l = x - width + marginLeft; } r = l + side; } } final int t = baseline + (int) ((paint.descent() + paint.ascent()) / 2.F + .5F) - (side / 2); final int b = t + side; if (level == 0 || level == 1) { circle.set(l, t, r, b); final Paint.Style style = level == 0 ? Paint.Style.FILL : Paint.Style.STROKE; paint.setStyle(style); c.drawOval(circle, paint); } else { rectangle.set(l, t, r, b); paint.setStyle(Paint.Style.FILL); c.drawRect(rectangle, paint); } } finally { c.restoreToCount(save); } }
Example 14
Source File: RoundedCornersDrawable.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 4 votes |
@Override public void draw(Canvas canvas) { Rect bounds = getBounds(); switch (mType) { case CLIPPING: // clip, note: doesn't support anti-aliasing int saveCount = canvas.save(); mPath.setFillType(Path.FillType.EVEN_ODD); canvas.clipPath(mPath); super.draw(canvas); canvas.restoreToCount(saveCount); break; case OVERLAY_COLOR: super.draw(canvas); mPaint.setColor(mOverlayColor); mPaint.setStyle(Paint.Style.FILL); mPath.setFillType(Path.FillType.INVERSE_EVEN_ODD); canvas.drawPath(mPath, mPaint); if (mIsCircle) { // INVERSE_EVEN_ODD will only draw inverse circle within its bounding box, so we need to // fill the rest manually if the bounds are not square. float paddingH = (bounds.width() - bounds.height() + mBorderWidth) / 2f; float paddingV = (bounds.height() - bounds.width() + mBorderWidth) / 2f; if (paddingH > 0) { canvas.drawRect(bounds.left, bounds.top, bounds.left + paddingH, bounds.bottom, mPaint); canvas.drawRect( bounds.right - paddingH, bounds.top, bounds.right, bounds.bottom, mPaint); } if (paddingV > 0) { canvas.drawRect(bounds.left, bounds.top, bounds.right, bounds.top + paddingV, mPaint); canvas.drawRect( bounds.left, bounds.bottom - paddingV, bounds.right, bounds.bottom, mPaint); } } break; } if (mBorderColor != Color.TRANSPARENT) { mPaint.setStyle(Paint.Style.STROKE); mPaint.setColor(mBorderColor); mPaint.setStrokeWidth(mBorderWidth); mPath.setFillType(Path.FillType.EVEN_ODD); canvas.drawPath(mPath, mPaint); } }
Example 15
Source File: AppBarLayout.java From Carbon with Apache License 2.0 | 4 votes |
@SuppressLint("MissingSuperCall") @Override public void draw(@NonNull Canvas canvas) { drawCalled = true; boolean r = revealAnimator != null; boolean c = !Carbon.isShapeRect(shapeModel, boundsRect); if (Carbon.IS_PIE_OR_HIGHER) { if (spotShadowColor != null) super.setOutlineSpotShadowColor(spotShadowColor.getColorForState(getDrawableState(), spotShadowColor.getDefaultColor())); if (ambientShadowColor != null) super.setOutlineAmbientShadowColor(ambientShadowColor.getColorForState(getDrawableState(), ambientShadowColor.getDefaultColor())); } if (isInEditMode() && (r || c) && getWidth() > 0 && getHeight() > 0) { Bitmap layer = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888); Canvas layerCanvas = new Canvas(layer); drawInternal(layerCanvas); Bitmap mask = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888); Canvas maskCanvas = new Canvas(mask); Paint maskPaint = new Paint(0xffffffff); maskCanvas.drawPath(cornersMask, maskPaint); for (int x = 0; x < getWidth(); x++) { for (int y = 0; y < getHeight(); y++) { int maskPixel = mask.getPixel(x, y); layer.setPixel(x, y, Color.alpha(maskPixel) > 0 ? layer.getPixel(x, y) : 0); } } canvas.drawBitmap(layer, 0, 0, paint); } else if (getWidth() > 0 && getHeight() > 0 && (((r || c) && !Carbon.IS_LOLLIPOP_OR_HIGHER) || !shapeModel.isRoundRect(boundsRect))) { int saveCount = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG); if (r) { int saveCount2 = canvas.save(); canvas.clipRect(revealAnimator.x - revealAnimator.radius, revealAnimator.y - revealAnimator.radius, revealAnimator.x + revealAnimator.radius, revealAnimator.y + revealAnimator.radius); drawInternal(canvas); canvas.restoreToCount(saveCount2); } else { drawInternal(canvas); } paint.setXfermode(Carbon.CLEAR_MODE); if (c) { cornersMask.setFillType(Path.FillType.INVERSE_WINDING); canvas.drawPath(cornersMask, paint); } if (r) canvas.drawPath(revealAnimator.mask, paint); paint.setXfermode(null); canvas.restoreToCount(saveCount); paint.setXfermode(null); } else { drawInternal(canvas); } }
Example 16
Source File: SlidingUpPanelLayout.java From AndroidSlidingUpPanel with Apache License 2.0 | 4 votes |
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result; if (mCanvasSaveProxy == null || !mCanvasSaveProxy.isFor(canvas)) { mCanvasSaveProxy = mCanvasSaveProxyFactory.create(canvas); } final int save = mCanvasSaveProxy.save(); if (mSlideableView != null && mSlideableView != child) { // if main view // Clip against the slider; no sense drawing what will immediately be covered, // Unless the panel is set to overlay content canvas.getClipBounds(mTmpRect); if (!mOverlayContent) { if (mIsSlidingUp) { mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop()); } else { mTmpRect.top = Math.max(mTmpRect.top, mSlideableView.getBottom()); } } if (mClipPanel) { canvas.clipRect(mTmpRect); } result = super.drawChild(canvas, child, drawingTime); if (mCoveredFadeColor != 0 && mSlideOffset > 0) { final int baseAlpha = (mCoveredFadeColor & 0xff000000) >>> 24; final int imag = (int) (baseAlpha * mSlideOffset); final int color = imag << 24 | (mCoveredFadeColor & 0xffffff); mCoveredFadePaint.setColor(color); canvas.drawRect(mTmpRect, mCoveredFadePaint); } } else { result = super.drawChild(canvas, child, drawingTime); } canvas.restoreToCount(save); return result; }
Example 17
Source File: SubtitlePainter.java From K-Sonic with MIT License | 4 votes |
private void drawTextLayout(Canvas canvas) { StaticLayout layout = textLayout; if (layout == null) { // Nothing to draw. return; } int saveCount = canvas.save(); canvas.translate(textLeft, textTop); if (Color.alpha(windowColor) > 0) { paint.setColor(windowColor); canvas.drawRect(-textPaddingX, 0, layout.getWidth() + textPaddingX, layout.getHeight(), paint); } if (Color.alpha(backgroundColor) > 0) { paint.setColor(backgroundColor); float previousBottom = layout.getLineTop(0); int lineCount = layout.getLineCount(); for (int i = 0; i < lineCount; i++) { lineBounds.left = layout.getLineLeft(i) - textPaddingX; lineBounds.right = layout.getLineRight(i) + textPaddingX; lineBounds.top = previousBottom; lineBounds.bottom = layout.getLineBottom(i); previousBottom = lineBounds.bottom; canvas.drawRoundRect(lineBounds, cornerRadius, cornerRadius, paint); } } if (edgeType == CaptionStyleCompat.EDGE_TYPE_OUTLINE) { textPaint.setStrokeJoin(Join.ROUND); textPaint.setStrokeWidth(outlineWidth); textPaint.setColor(edgeColor); textPaint.setStyle(Style.FILL_AND_STROKE); layout.draw(canvas); } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_DROP_SHADOW) { textPaint.setShadowLayer(shadowRadius, shadowOffset, shadowOffset, edgeColor); } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED || edgeType == CaptionStyleCompat.EDGE_TYPE_DEPRESSED) { boolean raised = edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED; int colorUp = raised ? Color.WHITE : edgeColor; int colorDown = raised ? edgeColor : Color.WHITE; float offset = shadowRadius / 2f; textPaint.setColor(foregroundColor); textPaint.setStyle(Style.FILL); textPaint.setShadowLayer(shadowRadius, -offset, -offset, colorUp); layout.draw(canvas); textPaint.setShadowLayer(shadowRadius, offset, offset, colorDown); } textPaint.setColor(foregroundColor); textPaint.setStyle(Style.FILL); layout.draw(canvas); textPaint.setShadowLayer(0, 0, 0, 0); canvas.restoreToCount(saveCount); }
Example 18
Source File: ActionBarLayout.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { int width = getWidth() - getPaddingLeft() - getPaddingRight(); int translationX = (int) innerTranslationX + getPaddingRight(); int clipLeft = getPaddingLeft(); int clipRight = width + getPaddingLeft(); if (child == containerViewBack) { clipRight = translationX; } else if (child == containerView) { clipLeft = translationX; } final int restoreCount = canvas.save(); if (!transitionAnimationInProgress && !inPreviewMode) { canvas.clipRect(clipLeft, 0, clipRight, getHeight()); } if ((inPreviewMode || transitionAnimationPreviewMode) && child == containerView) { View view = containerView.getChildAt(0); if (view != null) { previewBackgroundDrawable.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight()); previewBackgroundDrawable.draw(canvas); int x = (getMeasuredWidth() - AndroidUtilities.dp(24)) / 2; int y = (int) (view.getTop() + containerView.getTranslationY() - AndroidUtilities.dp(12 + (Build.VERSION.SDK_INT < 21 ? 20 : 0))); Theme.moveUpDrawable.setBounds(x, y, x + AndroidUtilities.dp(24), y + AndroidUtilities.dp(24)); Theme.moveUpDrawable.draw(canvas); } } final boolean result = super.drawChild(canvas, child, drawingTime); canvas.restoreToCount(restoreCount); if (translationX != 0) { if (child == containerView) { final float alpha = Math.max(0, Math.min((width - translationX) / (float) AndroidUtilities.dp(20), 1.0f)); layerShadowDrawable.setBounds(translationX - layerShadowDrawable.getIntrinsicWidth(), child.getTop(), translationX, child.getBottom()); layerShadowDrawable.setAlpha((int) (0xff * alpha)); layerShadowDrawable.draw(canvas); } else if (child == containerViewBack) { float opacity = Math.min(0.8f, (width - translationX) / (float) width); if (opacity < 0) { opacity = 0; } scrimPaint.setColor((int) (((0x99000000 & 0xff000000) >>> 24) * opacity) << 24); canvas.drawRect(clipLeft, 0, clipRight, getHeight(), scrimPaint); } } return result; }
Example 19
Source File: MotionLayout.java From Carbon with Apache License 2.0 | 4 votes |
@Override public void drawShadow(@NotNull Canvas canvas) { float alpha = getAlpha() * Carbon.getBackgroundTintAlpha(this) / 255.0f; if (alpha == 0 || !hasShadow()) return; float z = getElevation() + getTranslationZ(); int saveCount; boolean maskShadow = getBackground() != null && alpha != 1; boolean r = revealAnimator != null && revealAnimator.isRunning(); if (alpha != 255) { paint.setAlpha((int) (127 * alpha)); saveCount = canvas.saveLayer(0, 0, canvas.getWidth(), canvas.getHeight(), paint, Canvas.ALL_SAVE_FLAG); } else { saveCount = canvas.save(); } Matrix matrix = getMatrix(); canvas.setMatrix(matrix); if (r) { canvas.clipRect( getLeft() + revealAnimator.x - revealAnimator.radius, getTop() + revealAnimator.y - revealAnimator.radius, getLeft() + revealAnimator.x + revealAnimator.radius, getTop() + revealAnimator.y + revealAnimator.radius); } shadowDrawable.setFillColor(spotShadowColor); shadowDrawable.setShadowColor(spotShadowColor != null ? spotShadowColor.getColorForState(getDrawableState(), spotShadowColor.getDefaultColor()) : 0xff000000); shadowDrawable.setShadowCompatibilityMode(MaterialShapeDrawable.SHADOW_COMPAT_MODE_ALWAYS); shadowDrawable.setAlpha(0x44); shadowDrawable.setElevation(z); shadowDrawable.setShadowVerticalOffset(0); shadowDrawable.setBounds(getLeft(), (int) (getTop() + z / 4), getRight(), (int) (getBottom() + z / 4)); shadowDrawable.draw(canvas); canvas.translate(this.getLeft(), this.getTop()); canvas.concat(matrix); paint.setXfermode(Carbon.CLEAR_MODE); if (maskShadow) { cornersMask.setFillType(Path.FillType.WINDING); canvas.drawPath(cornersMask, paint); } if (r) canvas.drawPath(revealAnimator.mask, paint); canvas.restoreToCount(saveCount); paint.setXfermode(null); paint.setAlpha(255); }
Example 20
Source File: SubtitlePainter.java From no-player with Apache License 2.0 | 4 votes |
@SuppressWarnings("PMD.NPathComplexity") // TODO break this method up private void drawTextLayout(Canvas canvas) { StaticLayout layout = textLayout; if (layout == null) { // Nothing to draw. return; } int saveCount = canvas.save(); canvas.translate(textLeft, textTop); if (Color.alpha(windowColor) > 0) { paint.setColor(windowColor); canvas.drawRect(-textPaddingX, 0, layout.getWidth() + textPaddingX, layout.getHeight(), paint); } if (Color.alpha(backgroundColor) > 0) { paint.setColor(backgroundColor); float previousBottom = layout.getLineTop(0); int lineCount = layout.getLineCount(); for (int i = 0; i < lineCount; i++) { lineBounds.left = layout.getLineLeft(i) - textPaddingX; lineBounds.right = layout.getLineRight(i) + textPaddingX; lineBounds.top = previousBottom; lineBounds.bottom = layout.getLineBottom(i); previousBottom = lineBounds.bottom; canvas.drawRoundRect(lineBounds, cornerRadius, cornerRadius, paint); } } if (edgeType == CaptionStyleCompat.EDGE_TYPE_OUTLINE) { textPaint.setStrokeJoin(Join.ROUND); textPaint.setStrokeWidth(outlineWidth); textPaint.setColor(edgeColor); textPaint.setStyle(Style.FILL_AND_STROKE); layout.draw(canvas); } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_DROP_SHADOW) { textPaint.setShadowLayer(shadowRadius, shadowOffset, shadowOffset, edgeColor); } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED || edgeType == CaptionStyleCompat.EDGE_TYPE_DEPRESSED) { boolean raised = edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED; int colorUp = raised ? Color.WHITE : edgeColor; int colorDown = raised ? edgeColor : Color.WHITE; float offset = shadowRadius / 2; textPaint.setColor(foregroundColor); textPaint.setStyle(Style.FILL); textPaint.setShadowLayer(shadowRadius, -offset, -offset, colorUp); layout.draw(canvas); textPaint.setShadowLayer(shadowRadius, offset, offset, colorDown); } textPaint.setColor(foregroundColor); textPaint.setStyle(Style.FILL); layout.draw(canvas); textPaint.setShadowLayer(0, 0, 0, 0); canvas.restoreToCount(saveCount); }