List of usage examples for android.graphics Canvas clipRect
public boolean clipRect(@NonNull Rect rect)
From source file:org.akop.ararat.view.CrosswordView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); constrainTranslation();// ww w . ja v a 2 s . co m canvas.save(); canvas.clipRect(mContentRect); canvas.translate(mBitmapOffset.x, mBitmapOffset.y); canvas.scale(mBitmapScale, mBitmapScale); if (mPuzzleBitmap != null) { canvas.drawBitmap(mPuzzleBitmap, 0, 0, mBitmapPaint); } else { // Perform a fast, barebones render so that the screen doesn't // look completely empty mInPlaceRenderer.renderPuzzle(canvas, mRenderScale, true); } canvas.restore(); }
From source file:org.chromium.chrome.browser.toolbar.ToolbarPhone.java
/** * When entering and exiting the TabSwitcher mode, we fade out or fade in the browsing * mode of the toolbar on top of the TabSwitcher mode version of it. We do this by * drawing all of the browsing mode views on top of the android view. *//*from w w w. j av a 2s. c o m*/ private void drawTabSwitcherAnimationOverlay(Canvas canvas, float animationProgress) { if (!isNativeLibraryReady()) return; float floatAlpha = 1 - animationProgress; int rgbAlpha = (int) (255 * floatAlpha); canvas.save(); canvas.translate(0, -animationProgress * mBackgroundOverlayBounds.height()); canvas.clipRect(mBackgroundOverlayBounds); float previousAlpha = 0.f; if (mHomeButton.getVisibility() != View.GONE) { // Draw the New Tab button used in the URL view. previousAlpha = mHomeButton.getAlpha(); mHomeButton.setAlpha(previousAlpha * floatAlpha); drawChild(canvas, mHomeButton, SystemClock.uptimeMillis()); mHomeButton.setAlpha(previousAlpha); } // Draw the location/URL bar. previousAlpha = mLocationBar.getAlpha(); mLocationBar.setAlpha(previousAlpha * floatAlpha); // If the location bar is now fully transparent, do not bother drawing it. if (mLocationBar.getAlpha() != 0) { drawChild(canvas, mLocationBar, SystemClock.uptimeMillis()); } mLocationBar.setAlpha(previousAlpha); // Draw the tab stack button and associated text. translateCanvasToView(this, mToolbarButtonsContainer, canvas); if (mTabSwitcherAnimationTabStackDrawable != null && mToggleTabStackButton != null && mUrlExpansionPercent != 1f) { // Draw the tab stack button image. canvas.save(); translateCanvasToView(mToolbarButtonsContainer, mToggleTabStackButton, canvas); int backgroundWidth = mToggleTabStackButton.getDrawable().getIntrinsicWidth(); int backgroundHeight = mToggleTabStackButton.getDrawable().getIntrinsicHeight(); int backgroundLeft = (mToggleTabStackButton.getWidth() - mToggleTabStackButton.getPaddingLeft() - mToggleTabStackButton.getPaddingRight() - backgroundWidth) / 2; backgroundLeft += mToggleTabStackButton.getPaddingLeft(); int backgroundTop = (mToggleTabStackButton.getHeight() - mToggleTabStackButton.getPaddingTop() - mToggleTabStackButton.getPaddingBottom() - backgroundHeight) / 2; backgroundTop += mToggleTabStackButton.getPaddingTop(); canvas.translate(backgroundLeft, backgroundTop); mTabSwitcherAnimationTabStackDrawable.setAlpha(rgbAlpha); mTabSwitcherAnimationTabStackDrawable.draw(canvas); canvas.restore(); } // Draw the menu button if necessary. if (!mShowMenuBadge && mTabSwitcherAnimationMenuDrawable != null && mUrlExpansionPercent != 1f) { mTabSwitcherAnimationMenuDrawable.setBounds(mMenuButton.getPaddingLeft(), mMenuButton.getPaddingTop(), mMenuButton.getWidth() - mMenuButton.getPaddingRight(), mMenuButton.getHeight() - mMenuButton.getPaddingBottom()); translateCanvasToView(mToolbarButtonsContainer, mMenuButton, canvas); mTabSwitcherAnimationMenuDrawable.setAlpha(rgbAlpha); int color = mUseLightDrawablesForTextureCapture ? mLightModeDefaultColor : mDarkModeDefaultColor; mTabSwitcherAnimationMenuDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN); mTabSwitcherAnimationMenuDrawable.draw(canvas); } // Draw the menu badge if necessary. Drawable badgeDrawable = mUseLightDrawablesForTextureCapture ? mTabSwitcherAnimationMenuBadgeLightDrawable : mTabSwitcherAnimationMenuBadgeDarkDrawable; if (mShowMenuBadge && badgeDrawable != null && mUrlExpansionPercent != 1f) { badgeDrawable.setBounds(mMenuBadge.getPaddingLeft(), mMenuBadge.getPaddingTop(), mMenuBadge.getWidth() - mMenuBadge.getPaddingRight(), mMenuBadge.getHeight() - mMenuBadge.getPaddingBottom()); translateCanvasToView(mToolbarButtonsContainer, mMenuBadge, canvas); badgeDrawable.setAlpha(rgbAlpha); badgeDrawable.draw(canvas); } mLightDrawablesUsedForLastTextureCapture = mUseLightDrawablesForTextureCapture; canvas.restore(); }
From source file:cn.bingoogolapple.swipebacklayout.BGASwipeBackLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); boolean result; final int save = canvas.save(Canvas.CLIP_SAVE_FLAG); if (mCanSlide && !lp.slideable && mSlideableView != null) { // Clip against the slider; no sense drawing what will immediately be covered. canvas.getClipBounds(mTmpRect);// ww w . jav a2s .c o m if (isLayoutRtlSupport()) { mTmpRect.left = Math.max(mTmpRect.left, mSlideableView.getRight()); } else { mTmpRect.right = Math.min(mTmpRect.right, mSlideableView.getLeft()); } canvas.clipRect(mTmpRect); } if (Build.VERSION.SDK_INT >= 11) { // HC result = super.drawChild(canvas, child, drawingTime); } else { if (lp.dimWhenOffset && mSlideOffset > 0) { if (!child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(true); } final Bitmap cache = child.getDrawingCache(); if (cache != null) { canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint); result = false; } else { Log.e(TAG, "drawChild: child view " + child + " returned null drawing cache"); result = super.drawChild(canvas, child, drawingTime); } } else { if (child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(false); } result = super.drawChild(canvas, child, drawingTime); } } canvas.restoreToCount(save); return result; }
From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java
public void drawCompareImage(Canvas canvas, Bitmap image) { MasterImage master = MasterImage.getImage(); boolean showsOriginal = master.showsOriginal(); if (!showsOriginal && !mTouchShowOriginal) return;// ww w. j av a 2s . c o m canvas.save(); if (image != null) { if (mShowOriginalDirection == 0) { if (Math.abs(mTouch.y - mTouchDown.y) > Math.abs(mTouch.x - mTouchDown.x)) { mShowOriginalDirection = UNVEIL_VERTICAL; } else { mShowOriginalDirection = UNVEIL_HORIZONTAL; } } int px = 0; int py = 0; if (mShowOriginalDirection == UNVEIL_VERTICAL) { px = mImageBounds.width(); py = mTouch.y - mImageBounds.top; } else { px = mTouch.x - mImageBounds.left; py = mImageBounds.height(); if (showsOriginal) { px = mImageBounds.width(); } } Rect d = new Rect(mImageBounds.left, mImageBounds.top, mImageBounds.left + px, mImageBounds.top + py); if (mShowOriginalDirection == UNVEIL_HORIZONTAL) { if (mTouchDown.x - mTouch.x > 0) { d.set(mImageBounds.left + px, mImageBounds.top, mImageBounds.right, mImageBounds.top + py); } } else { if (mTouchDown.y - mTouch.y > 0) { d.set(mImageBounds.left, mImageBounds.top + py, mImageBounds.left + px, mImageBounds.bottom); } } canvas.clipRect(d); Matrix m = master.computeImageToScreen(image, 0, false); canvas.drawBitmap(image, m, mPaint); Paint paint = new Paint(); paint.setColor(Color.BLACK); paint.setStrokeWidth(3); if (mShowOriginalDirection == UNVEIL_VERTICAL) { canvas.drawLine(mImageBounds.left, mTouch.y, mImageBounds.right, mTouch.y, paint); } else { canvas.drawLine(mTouch.x, mImageBounds.top, mTouch.x, mImageBounds.bottom, paint); } Rect bounds = new Rect(); paint.setAntiAlias(true); paint.setTextSize(mOriginalTextSize); paint.getTextBounds(mOriginalText, 0, mOriginalText.length(), bounds); paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(3); canvas.drawText(mOriginalText, mImageBounds.left + mOriginalTextMargin, mImageBounds.top + bounds.height() + mOriginalTextMargin, paint); paint.setStyle(Paint.Style.FILL); paint.setStrokeWidth(1); paint.setColor(Color.WHITE); canvas.drawText(mOriginalText, mImageBounds.left + mOriginalTextMargin, mImageBounds.top + bounds.height() + mOriginalTextMargin, paint); } canvas.restore(); }
From source file:com.huewu.pla.lib.internal.PLAListView.java
void drawOverscrollFooter(final Canvas canvas, final Drawable drawable, final Rect bounds) { final int height = drawable.getMinimumHeight(); canvas.save();/*from www .ja v a2 s .c om*/ canvas.clipRect(bounds); final int span = bounds.bottom - bounds.top; if (span < height) { bounds.bottom = bounds.top + height; } drawable.setBounds(bounds); drawable.draw(canvas); canvas.restore(); }
From source file:com.huewu.pla.lib.internal.PLAListView.java
void drawOverscrollHeader(final Canvas canvas, final Drawable drawable, final Rect bounds) { final int height = drawable.getMinimumHeight(); canvas.save();//from w w w. ja va 2 s . c o m canvas.clipRect(bounds); final int span = bounds.bottom - bounds.top; if (span < height) { bounds.top = bounds.bottom - height; } drawable.setBounds(bounds); drawable.draw(canvas); canvas.restore(); }
From source file:cl.monsoon.s1next.widget.PhotoView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // draw the photo if (mDrawable != null) { int saveCount = canvas.getSaveCount(); canvas.save();//from w ww . j a va 2s. c o m if (mDrawMatrix != null) { canvas.concat(mDrawMatrix); } mDrawable.draw(canvas); canvas.restoreToCount(saveCount); if (mVideoBlob != null) { final Bitmap videoImage = (mVideoReady ? sVideoImage : sVideoNotReadyImage); final int drawLeft = (getWidth() - videoImage.getWidth()) / 2; final int drawTop = (getHeight() - videoImage.getHeight()) / 2; canvas.drawBitmap(videoImage, drawLeft, drawTop, null); } // Extract the drawable's bounds (in our own copy, to not alter the image) mTranslateRect.set(mDrawable.getBounds()); if (mDrawMatrix != null) { mDrawMatrix.mapRect(mTranslateRect); } if (mAllowCrop) { int previousSaveCount = canvas.getSaveCount(); canvas.drawRect(0, 0, getWidth(), getHeight(), sCropDimPaint); canvas.save(); canvas.clipRect(mCropRect); if (mDrawMatrix != null) { canvas.concat(mDrawMatrix); } mDrawable.draw(canvas); canvas.restoreToCount(previousSaveCount); canvas.drawRect(mCropRect, sCropPaint); } } }
From source file:martin.app.bitunion.widget.PhotoView.java
@Override protected void onDraw(@NonNull Canvas canvas) { super.onDraw(canvas); // draw the photo if (mDrawable != null) { int saveCount = canvas.getSaveCount(); canvas.save();//from ww w. ja v a2 s .com if (mDrawMatrix != null) { canvas.concat(mDrawMatrix); } mDrawable.draw(canvas); canvas.restoreToCount(saveCount); if (mVideoBlob != null) { final Bitmap videoImage = (mVideoReady ? sVideoImage : sVideoNotReadyImage); final int drawLeft = (getWidth() - videoImage.getWidth()) / 2; final int drawTop = (getHeight() - videoImage.getHeight()) / 2; canvas.drawBitmap(videoImage, drawLeft, drawTop, null); } // Extract the drawable's bounds (in our own copy, to not alter the image) mTranslateRect.set(mDrawable.getBounds()); if (mDrawMatrix != null) { mDrawMatrix.mapRect(mTranslateRect); } if (mAllowCrop) { int previousSaveCount = canvas.getSaveCount(); canvas.drawRect(0, 0, getWidth(), getHeight(), sCropDimPaint); canvas.save(); canvas.clipRect(mCropRect); if (mDrawMatrix != null) { canvas.concat(mDrawMatrix); } mDrawable.draw(canvas); canvas.restoreToCount(previousSaveCount); canvas.drawRect(mCropRect, sCropPaint); } } }
From source file:org.chromium.chrome.browser.toolbar.ToolbarPhone.java
@Override public void draw(Canvas canvas) { // If capturing a texture of the toolbar, ensure the alpha is set prior to draw(...) being // called. The alpha is being used prior to getting to draw(...), so updating the value // after this point was having no affect. if (mTextureCaptureMode) assert getAlpha() == 1f; // mClipRect can change in the draw call, so cache this value to ensure the canvas is // restored correctly. boolean shouldClip = !mTextureCaptureMode && mClipRect != null; if (shouldClip) { canvas.save();/* www .j av a 2 s . c o m*/ canvas.clipRect(mClipRect); } super.draw(canvas); if (shouldClip) { canvas.restore(); // Post an invalidate when the clip rect becomes null to ensure another draw pass occurs // and the full toolbar is drawn again. if (mClipRect == null) postInvalidate(); } }
From source file:com.huewu.pla.lib.internal.PLAListView.java
/** * Draws a divider for the given child in the given bounds. * /* w w w . j a v a 2 s .c o m*/ * @param canvas The canvas to draw to. * @param bounds The bounds of the divider. * @param childIndex The index of child (of the View) above the divider. * This will be -1 if there is no child above the divider to be * drawn. */ void drawDivider(final Canvas canvas, final Rect bounds, final int childIndex) { // This widget draws the same divider for all children final Drawable divider = mDivider; final boolean clipDivider = mClipDivider; if (!clipDivider) { divider.setBounds(bounds); } else { canvas.save(); canvas.clipRect(bounds); } divider.draw(canvas); if (clipDivider) { canvas.restore(); } }