List of usage examples for android.graphics Canvas clipRect
public boolean clipRect(@NonNull Rect rect)
From source file:com.android.dialer.widget.OverlappingPaneLayout.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);//w w w . j a v a 2 s. com mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop()); canvas.clipRect(mTmpRect); } if (Build.VERSION.SDK_INT >= 11) { // HC 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:org.androfarsh.widget.DragGridLayout.java
private boolean drawChildDrawable(BitmapDrawable childDrawable, Canvas canvas, View child, long drawingTime) { canvas.save();/*from w w w .jav a 2 s . co m*/ requestCurrentRect(mTmpRect, child); if (child.getAnimation() == null) { canvas.clipRect(mTmpRect); } final boolean result; if (mEditMode && (childDrawable != null) && !childDrawable.getBitmap().isRecycled()) { childDrawable.setBounds(mTmpRect); childDrawable.draw(canvas); result = false; } else { result = super.drawChild(canvas, child, drawingTime); } canvas.restore(); return result; }
From source file:im.ene.lab.design.widget.coverflow.FeatureCoverFlow.java
@Override protected void dispatchDraw(Canvas canvas) { mInvalidated = false; //last invalidate which marked redrawInProgress, caused this // dispatchDraw. Clear flag to prevent creating loop mReverseOrderIndex = -1;/*w w w.j a va2 s.c o m*/ canvas.getClipBounds(mTempRect); mTempRect.top = 0; mTempRect.bottom = getHeight(); canvas.clipRect(mTempRect); super.dispatchDraw(canvas); if (mScrollToPositionOnNextInvalidate != -1 && mAdapter != null && mAdapter.getCount() > 0) { final int lastCenterItemPosition = (mFirstItemPosition + mLastCenterItemIndex) % mAdapter.getCount(); final int di = lastCenterItemPosition - mScrollToPositionOnNextInvalidate; mScrollToPositionOnNextInvalidate = -1; if (di != 0) { final int dst = (int) (di * mCoverWidth * mSpacing) - mCenterItemOffset; scrollBy(-dst, 0); shouldRepeat = true; postInvalidate(); return; } } if (mTouchState == TOUCH_STATE_RESTING) { if (mAdapter != null) { final int lastCenterItemPosition = (mFirstItemPosition + mLastCenterItemIndex) % mAdapter.getCount(); if (mLastTouchState != TOUCH_STATE_RESTING || mlastCenterItemPosition != lastCenterItemPosition) { mLastTouchState = TOUCH_STATE_RESTING; mlastCenterItemPosition = lastCenterItemPosition; if (mOnScrollPositionListener != null) mOnScrollPositionListener.onScrolledToPosition(lastCenterItemPosition); } } } if (mTouchState == TOUCH_STATE_SCROLLING && mLastTouchState != TOUCH_STATE_SCROLLING) { mLastTouchState = TOUCH_STATE_SCROLLING; if (mOnScrollPositionListener != null) mOnScrollPositionListener.onScrolling(); } if (mTouchState == TOUCH_STATE_FLING && mLastTouchState != TOUCH_STATE_FLING) { mLastTouchState = TOUCH_STATE_FLING; if (mOnScrollPositionListener != null) mOnScrollPositionListener.onScrolling(); } //make sure we never stay unaligned after last draw in resting state if (mTouchState == TOUCH_STATE_RESTING && mCenterItemOffset != 0) { scrollBy(mCenterItemOffset, 0); postInvalidate(); } try { View v = getChildAt(mLastCenterItemIndex); if (v != null) v.requestFocus(FOCUS_FORWARD); } catch (Exception e) { e.printStackTrace(); } }
From source file:ca.mymenuapp.ui.widgets.SlidingUpPanelLayout.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); boolean drawScrim = false; if (mCanSlide && !lp.slideable && mSlideableView != null) { // Clip against the slider; no sense drawing what will immediately be covered. canvas.getClipBounds(mTmpRect);/*from ww w .ja v a 2 s. c om*/ if (mIsSlidingUp) { mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop()); } else { mTmpRect.top = Math.max(mTmpRect.top, mSlideableView.getBottom()); } canvas.clipRect(mTmpRect); if (mSlideOffset < 1) { drawScrim = true; } } result = super.drawChild(canvas, child, drawingTime); canvas.restoreToCount(save); if (drawScrim) { final int baseAlpha = (mCoveredFadeColor & 0xff000000) >>> 24; final int imag = (int) (baseAlpha * (1 - mSlideOffset)); final int color = imag << 24 | (mCoveredFadeColor & 0xffffff); mCoveredFadePaint.setColor(color); canvas.drawRect(mTmpRect, mCoveredFadePaint); } return result; }
From source file:org.androfarsh.widget.DragGridLayout.java
private void drawHighlight(final View child, final Canvas canvas) { if ((mHighlightDrawable != null)) { requestFreeCellRegion(mDragNode.view); if (!requestHoverRect(mTmpRect)) { return; }//from ww w .j a va2 s. c o m canvas.save(); canvas.clipRect(mTmpRect); mHighlightDrawable.setBounds(mTmpRect); mTmpRegion.set(mFreeCellsRegion); mTmpRegion.op(mTmpRect, Op.INTERSECT); mTmpRegion.getBounds(mTmpRect); final boolean allowed = mTmpRegion.isRect() && (child.getWidth() <= mTmpRect.width()) && (child.getHeight() <= mTmpRect.height()); final int[] stateSet = new int[] { (allowed ? 1 : -1) * R.attr.state_drop_allow }; mHighlightDrawable.setState(stateSet); mHighlightDrawable.draw(canvas); canvas.restore(); } }
From source file:com.zenithed.core.widget.scaledimageview.ScaledImageView.java
/** * Draw method should not be called until the view has dimensions so the first calls are used as triggers to calculate * the scaling and tiling required. Once the view is setup, tiles are displayed as they are loaded. *//* www. j a v a 2 s .c o m*/ @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // If image or view dimensions are not known yet, abort. if (mContentWidth == 0 || mContentHeight == 0 || mBitmapRegionDecoder == null || getWidth() == 0 || getHeight() == 0) { return; } // On first render with no tile map ready, initialise it and kick off async base image loading. if (mTileMap == null) { initialiseBaseLayer(); return; } // On first display of base image set up position, and in other cases make sure scale is correct. fitToBounds(); // Everything is set up and coordinates are valid. Inform subclasses. if (!mImageReadyNotified) { setEnabled(true); onImageReady(); mImageReadyNotified = true; } canvas.clipRect(mViewPortRect); // Optimum sample size for current scale final int sampleSize = Math.min(mFullImageSampleSize, calculateInSampleSize((int) (mContentWidth * mScale), (int) (mContentHeight * mScale))); // First check for missing tiles - if there are any we need the base layer underneath to avoid gaps boolean hasMissingTiles = false; final SparseArray<List<Tile>> tileMap = mTileMap; final int SIZE = mTileMap.size(); for (int i = 0; i < SIZE; i++) { if (tileMap.keyAt(i) == sampleSize) { final List<Tile> tileList = tileMap.valueAt(i); for (Tile tile : tileList) { if (tile.visible && (tile.loading || tile.bitmap == null)) { hasMissingTiles = true; } } } } // Render all loaded tiles. LinkedHashMap used for bottom up rendering - lower res tiles underneath. for (int i = 0; i < SIZE; i++) { if (tileMap.keyAt(i) == sampleSize || hasMissingTiles) { final List<Tile> tileList = tileMap.valueAt(i); for (Tile tile : tileList) { if (!tile.loading && tile.bitmap != null) { canvas.drawBitmap(tile.bitmap, null, convertRect(sourceToViewRect(tile.sRect)), sDrawingPaint); } } } } }
From source file:org.akop.crosswords.view.CrosswordView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mPuzzleBitmap != null) { canvas.save();//from w w w. j av a2 s . com canvas.clipRect(mContentRect); canvas.translate(mBitmapOffset.x, mBitmapOffset.y); canvas.scale(mBitmapScale, mBitmapScale); canvas.drawBitmap(mPuzzleBitmap, 0, 0, mBitmapPaint); canvas.restore(); } }
From source file:cn.emagsoftware.ui.BugFixedSlidingPaneLayout.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);//w ww . ja va2 s . c o m 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.akshay.protocol10.asplayer.widget.SlidingUpPanelLayout.java
@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()); }/*from w w w. ja v a 2 s.c o m*/ 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; }
From source file:mega.privacy.android.app.components.SlidingUpPanelLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result; final int save = canvas.save(Canvas.CLIP_SAVE_FLAG); if (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);/* w ww . j a v a 2 s . c o m*/ 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; }