List of usage examples for android.graphics Canvas clipRect
public boolean clipRect(@NonNull Rect rect)
From source file:org.androfarsh.widget.DragGridLayout.java
private void drawCellGrid(Canvas canvas) { if (mCellDrawable != null) { int i = 0; for (final Cell cell : mCells) { mTmpRect.set(cell.rect);/*from w ww.ja v a 2 s.com*/ final int[] stateSet = new int[] { (mEditMode ? 1 : -1) * R.attr.state_editing, (mPressedCell == cell ? 1 : -1) * android.R.attr.state_pressed }; canvas.save(); canvas.clipRect(cell.rect); mCellDrawable.setState(stateSet); mCellDrawable.setBounds(cell.rect); mCellDrawable.draw(canvas); if (mDebugMode) { mPaint.setTextAlign(Align.CENTER); mPaint.setTextSize(30); mPaint.setTypeface(Typeface.DEFAULT_BOLD); mPaint.setColor(Color.GREEN); canvas.drawText(Integer.toString(i), cell.rect.centerX(), cell.rect.centerY(), mPaint); ++i; } canvas.restore(); } } if (mDebugMode) { mPaint.setColor(Color.GREEN); mPaint.setStyle(Style.STROKE); mPaint.setStrokeWidth(1.5f); canvas.drawPath(mCellsRegion.getBoundaryPath(), mPaint); } }
From source file:rp3.widget.SlidingPaneLayout.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. j a v a2 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.quran.labs.androidquran.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, // 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()); }/* w ww. j a v a2s . c o m*/ 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:com.example.zhaozhu.practisecustomview.customviewgroup.HSlidingPaneLayout.java
@Override protected boolean drawChild(final Canvas canvas, final View child, final long drawingTime) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); boolean result; final int save = canvas.save(Canvas.CLIP_SAVE_FLAG); if (this.mCanSlide && !lp.slideable && (this.mSlideableView != null)) { // Clip against the slider; no sense drawing what will immediately // be covered. canvas.getClipBounds(this.mTmpRect); this.mTmpRect.right = Math.min(this.mTmpRect.right, this.mSlideableView.getLeft()); canvas.clipRect(this.mTmpRect); }//from w ww . j av a2 s . c o m if (Build.VERSION.SDK_INT >= 11) { // HC result = super.drawChild(canvas, child, drawingTime); } else { if (lp.dimWhenOffset && (this.mSlideOffset > 0)) { if (!child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(true); } Bitmap cache = child.getDrawingCache(); if (cache != null && !cache.isRecycled()) { canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint); result = false; } else { Log.e(HSlidingPaneLayout.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.example.zhaozhu.practisecustomview.customviewgroup.HSlidingPaneLayout2.java
@Override protected boolean drawChild(final Canvas canvas, final View child, final long drawingTime) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); boolean result; final int save = canvas.save(Canvas.CLIP_SAVE_FLAG); if (this.mCanSlide && !lp.slideable && (this.mSlideableView != null)) { // Clip against the slider; no sense drawing what will immediately // be covered. canvas.getClipBounds(this.mTmpRect); this.mTmpRect.right = Math.min(this.mTmpRect.right, this.mSlideableView.getLeft()); canvas.clipRect(this.mTmpRect); }// w ww . j a v a 2 s.c o m if (Build.VERSION.SDK_INT >= 11) { // HC result = super.drawChild(canvas, child, drawingTime); } else { if (lp.dimWhenOffset && (this.mSlideOffset > 0)) { if (!child.isDrawingCacheEnabled()) { child.setDrawingCacheEnabled(true); } Bitmap cache = child.getDrawingCache(); if (cache != null && !cache.isRecycled()) { canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint); result = false; } else { Log.e(HSlidingPaneLayout2.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:co.codecrunch.musicplayerlite.slidinguppanelhelper.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);/*from ww w .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; }
From source file:com.waz.zclient.pages.main.conversationpager.SlidingPaneLayout.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 (canSlide && !lp.slideable && slideableView != null) { // Clip against the slider; no sense drawing what will immediately be covered. canvas.getClipBounds(tmpRect);/*from w w w.j av a2s .c o m*/ if (isLayoutRtlSupport()) { tmpRect.left = Math.max(tmpRect.left, slideableView.getRight()); } else { tmpRect.right = Math.min(tmpRect.right, slideableView.getLeft()); } canvas.clipRect(tmpRect); } if (Build.VERSION.SDK_INT >= 11) { // HC result = super.drawChild(canvas, child, drawingTime); } else { if (lp.dimWhenOffset && slideOffset > 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 { Timber.e("drawChild: child view %s returned null drawing cache", child); 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:cn.zmdx.kaka.locker.widget.SlidingPaneLayout.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.ja va 2s .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.ruesga.timelinechart.TimelineChartView.java
/** {@inheritDoc} */ @Override/*from w ww . j ava2 s .c o m*/ protected void onDraw(Canvas c) { // 1.- Clip to padding c.clipRect(mViewArea); // 2.- Draw the backgrounds areas c.drawRect(mGraphArea, mGraphAreaBgPaint); if (mShowFooter) { c.drawRect(mFooterArea, mFooterAreaBgPaint); } final LongSparseArray<Pair<double[], int[]>> data; final double maxValue; synchronized (mLock) { data = mData; maxValue = mMaxValue; } boolean hasData = data.size() > 0; if (hasData && mIsDataComputed) { // 3.- Compute viewport and draw the data computeItemsOnScreen(data); drawBarItems(c, data, maxValue); // 4.- Draw tick labels and current position if (mShowFooter) { drawTickLabels(c, data); c.drawPath(mCurrentPositionPath, mFooterAreaBgPaint); } } // Draw the edge scrolling effects drawEdgeEffects(c); }
From source file:com.mark.quick.ui.view.swipebacklayout.SwipeBackLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); boolean result; final int save = canvas.save(); if (mCanSlide && !lp.slideable && mSlideableView != null) { // Clip against the slider; no sense drawing what will immediately be covered. canvas.getClipBounds(mTmpRect);//from ww w. j a va 2 s .com 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; }