List of usage examples for android.graphics Canvas getSaveCount
public int getSaveCount()
From source file:com.lab47billion.appchooser.HorizontalPicker.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int saveCount = canvas.getSaveCount(); canvas.save();/*from ww w . j a va2 s . c o m*/ int selectedItem = mSelectedItem; float itemWithPadding = mItemWidth + mDividerSize; // translate horizontal to center canvas.translate(itemWithPadding * mSideItems, 0); if (mValues != null) { for (int i = 0; i < mValues.length; i++) { mTextPaint.setColor(getTextColor(i)); // get text layout View layout = mLayouts[i][0]; // layout.draw(canvas); //NEW View layoutSub = mLayouts[i][1]; int saveCountHeight = canvas.getSaveCount(); canvas.save(); float x = 0; float lineWidth = 40f; if (lineWidth > mItemWidth) { if (isRtl(mValues[i])) { x += (lineWidth - mItemWidth) / 2; } else { x -= (lineWidth - mItemWidth) / 2; } } /*set select item top padding */ int yTranslate; if (!isScrollingStart && i == selectedItem) { mTextPaint.setTextSize(mSelectedTextSize); } else { mTextPaint.setTextSize(mNormalTextSize); } // translate vertically to center if (layoutSub != null) { yTranslate = (canvas.getHeight() - (layout.getHeight() + layoutSub.getHeight())) / 2; } else { yTranslate = (canvas.getHeight() - layout.getHeight()) / 2; } if (i == selectedItem && topPadding != -1) { yTranslate = topPadding; } canvas.translate(-x, yTranslate); RectF clipBounds; if (x == 0) { clipBounds = mItemClipBounds; } else { clipBounds = mItemClipBoundsOffser; clipBounds.set(mItemClipBounds); clipBounds.offset(x, 0); } canvas.clipRect(clipBounds); layout.draw(canvas); if (layoutSub != null) { Paint.FontMetrics fontMetrics = mTextPaint.getFontMetrics(); int heightText = (int) (Math.abs(fontMetrics.ascent) + Math.abs(fontMetrics.descent)); canvas.translate(-x, (layout.getHeight() + heightText - getTopPadding()) / 2); canvas.clipRect(clipBounds); layoutSub.draw(canvas); } // restore vertical translation canvas.restoreToCount(saveCountHeight); // translate horizontal for 1 item canvas.translate(itemWithPadding, 0); } } // restore horizontal translation canvas.restoreToCount(saveCount); drawEdgeEffect(canvas, mLeftEdgeEffect, 270); drawEdgeEffect(canvas, mRightEdgeEffect, 90); }
From source file:com.bitflake.counter.HorizontalPicker.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int saveCount = canvas.getSaveCount(); canvas.save();/* ww w . ja va 2 s. c o m*/ int selectedItem = this.selectedItem; float itemWithPadding = itemWidth + dividerSize; // translate horizontal to center canvas.translate(itemWithPadding * sideItems, 0); if (values != null) { for (int i = 0; i < values.length; i++) { // set text color for item textPaint.setColor(getTextColor(i)); // get text layout BoringLayout layout = layouts[i]; int saveCountHeight = canvas.getSaveCount(); canvas.save(); float x = 0; float lineWidth = layout.getLineWidth(0); if (lineWidth > itemWidth) { if (isRtl(values[i])) { x += (lineWidth - itemWidth) / 2; } else { x -= (lineWidth - itemWidth) / 2; } } if (marquee != null && i == selectedItem) { x += marquee.getScroll(); } // translate vertically to center canvas.translate(-x, (canvas.getHeight() - layout.getHeight()) / 2); RectF clipBounds; if (x == 0) { clipBounds = itemClipBounds; } else { clipBounds = itemClipBoundsOffset; clipBounds.set(itemClipBounds); clipBounds.offset(x, 0); } canvas.clipRect(clipBounds); layout.draw(canvas); if (marquee != null && i == selectedItem && marquee.shouldDrawGhost()) { canvas.translate(marquee.getGhostOffset(), 0); layout.draw(canvas); } // restore vertical translation canvas.restoreToCount(saveCountHeight); // translate horizontal for 1 item canvas.translate(itemWithPadding, 0); } } // restore horizontal translation canvas.restoreToCount(saveCount); drawEdgeEffect(canvas, leftEdgeEffect, 270); drawEdgeEffect(canvas, rightEdgeEffect, 90); }
From source file:kr.selfcontrol.selflocklauncher.picker.HorizontalPicker.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int saveCount = canvas.getSaveCount(); canvas.save();//from w w w. ja va 2 s. com int selectedItem = mSelectedItem; float itemWithPadding = mItemWidth + mDividerSize; // translate horizontal to center canvas.translate(itemWithPadding * mSideItems, 0); if (mValues != null) { for (int i = 0; i < mValues.length; i++) { // set text color for item mTextPaint.setColor(getTextColor(i)); // get text layout BoringLayout layout = mLayouts[i]; int saveCountHeight = canvas.getSaveCount(); canvas.save(); float x = 0; float lineWidth = layout.getLineWidth(0); if (lineWidth > mItemWidth) { if (isRtl(mValues[i])) { x += (lineWidth - mItemWidth) / 2; } else { x -= (lineWidth - mItemWidth) / 2; } } if (mMarquee != null && i == selectedItem) { x += mMarquee.getScroll(); } // translate vertically to center canvas.translate(-x, (canvas.getHeight() - layout.getHeight()) / 2); RectF clipBounds; if (x == 0) { clipBounds = mItemClipBounds; } else { clipBounds = mItemClipBoundsOffser; clipBounds.set(mItemClipBounds); clipBounds.offset(x, 0); } canvas.clipRect(clipBounds); layout.draw(canvas); if (mMarquee != null && i == selectedItem && mMarquee.shouldDrawGhost()) { canvas.translate(mMarquee.getGhostOffset(), 0); layout.draw(canvas); } // restore vertical translation canvas.restoreToCount(saveCountHeight); // translate horizontal for 1 item canvas.translate(itemWithPadding, 0); } } // restore horizontal translation canvas.restoreToCount(saveCount); drawEdgeEffect(canvas, mLeftEdgeEffect, 270); drawEdgeEffect(canvas, mRightEdgeEffect, 90); }
From source file:de.tud.nhd.petimo.libs.HorizontalPicker.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int saveCount = canvas.getSaveCount(); canvas.save();//from w ww . j av a2s . c om int selectedItem = this.selectedItem; float itemWithPadding = itemWidth + dividerSize; // translate horizontal to center canvas.translate(itemWithPadding * sideItems, 0); if (values != null) { for (int i = 0; i < values.length; i++) { if (i == selectedItem) { textPaint.setColor(getResources().getColor(R.color.colorAccent)); //textPaint.setTextSize(40); textPaint.setFakeBoldText(true); } else { textPaint.setColor(getTextColor(i)); //textPaint.setTextSize(textSize); textPaint.setFakeBoldText(false); } // get text layout BoringLayout layout = layouts[i]; int saveCountHeight = canvas.getSaveCount(); canvas.save(); float x = 0; float lineWidth = layout.getLineWidth(0); if (lineWidth > itemWidth) { if (isRtl(values[i])) { x += (lineWidth - itemWidth) / 2; } else { x -= (lineWidth - itemWidth) / 2; } } if (marquee != null && i == selectedItem) { x += marquee.getScroll(); } // translate vertically to center canvas.translate(-x, (canvas.getHeight() - layout.getHeight()) / 2); RectF clipBounds; if (x == 0) { clipBounds = itemClipBounds; } else { clipBounds = itemClipBoundsOffset; clipBounds.set(itemClipBounds); clipBounds.offset(x, 0); } canvas.clipRect(clipBounds); layout.draw(canvas); if (marquee != null && i == selectedItem && marquee.shouldDrawGhost()) { canvas.translate(marquee.getGhostOffset(), 0); layout.draw(canvas); } // restore vertical translation canvas.restoreToCount(saveCountHeight); // translate horizontal for 1 item canvas.translate(itemWithPadding, 0); } } // restore horizontal translation canvas.restoreToCount(saveCount); drawEdgeEffect(canvas, leftEdgeEffect, 270); drawEdgeEffect(canvas, rightEdgeEffect, 90); }
From source file:com.ionesmile.variousdemo.view.HorizontalPicker.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int saveCount = canvas.getSaveCount(); canvas.save();/* w w w. ja v a 2s. c o m*/ int selectedItem = this.selectedItem; float itemWithPadding = itemWidth + dividerSize; // translate horizontal to center canvas.translate(itemWithPadding * sideItems, 0); if (values != null) { for (int i = 0; i < values.length; i++) { // set text color for item textPaint.setColor(getTextColor(i)); textPaint.setTextSize(getTextSize(i)); // get text layout BoringLayout layout = layouts[i]; int saveCountHeight = canvas.getSaveCount(); canvas.save(); float x = 0; float lineWidth = layout.getLineWidth(0); if (lineWidth > itemWidth) { if (isRtl(values[i])) { x += (lineWidth - itemWidth) / 2; } else { x -= (lineWidth - itemWidth) / 2; } } if (marquee != null && i == selectedItem) { x += marquee.getScroll(); } // translate vertically to center canvas.translate(-x, (canvas.getHeight() - layout.getHeight()) / 2); RectF clipBounds; if (x == 0) { clipBounds = itemClipBounds; } else { clipBounds = itemClipBoundsOffset; clipBounds.set(itemClipBounds); clipBounds.offset(x, 0); } canvas.clipRect(clipBounds); layout.draw(canvas); if (marquee != null && i == selectedItem && marquee.shouldDrawGhost()) { canvas.translate(marquee.getGhostOffset(), 0); layout.draw(canvas); } // restore vertical translation canvas.restoreToCount(saveCountHeight); // translate horizontal for 1 item canvas.translate(itemWithPadding, 0); } } // restore horizontal translation canvas.restoreToCount(saveCount); drawEdgeEffect(canvas, leftEdgeEffect, 270); drawEdgeEffect(canvas, rightEdgeEffect, 90); }
From source file:com.bitflake.counter.HorizontalPicker.java
private void drawEdgeEffect(Canvas canvas, EdgeEffect edgeEffect, int degrees) { if (canvas == null || edgeEffect == null || (degrees != 90 && degrees != 270)) { return;// w w w .j a v a 2s. com } if (!edgeEffect.isFinished()) { final int restoreCount = canvas.getSaveCount(); final int width = getWidth(); final int height = getHeight(); canvas.rotate(degrees); if (degrees == 270) { canvas.translate(-height, Math.max(0, getScrollX())); } else { // 90 canvas.translate(0, -(Math.max(getScrollRange(), getScaleX()) + width)); } edgeEffect.setSize(height, width); if (edgeEffect.draw(canvas)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { postInvalidateOnAnimation(); } else { postInvalidate(); } } canvas.restoreToCount(restoreCount); } }
From source file:pl.motyczko.scrollheader.PagerSlidingTabStrip.java
private void drawBackground(Canvas canvas) { if (mViewBackground == null) return;// www .ja va2s . co m if (mViewBackground instanceof KenBurnsDrawable && !((KenBurnsDrawable) mViewBackground).isAnimating()) { mViewBackground.setBounds(0, 0, getWidth(), getHeight()); ((KenBurnsDrawable) mViewBackground).animate(); mKenBurnsInitialized = true; } if (mDrawMatrix == null && !(mViewBackground instanceof KenBurnsDrawable)) { calculateBackgroundBounds(); } int saveCount = canvas.getSaveCount(); canvas.save(); float translation = mParallaxForBackground ? getTranslationY() / 2 : 0; canvas.translate(getScrollX(), getScrollY() - translation); if (mDrawMatrix != null) canvas.concat(mDrawMatrix); float fraction = Math.abs(getTranslationY() / getAllowedVerticalScrollLength()); int color = (Integer) mColorEvaluator.evaluate(fraction, mOverlayColorExpanded, mOverlayColorCollapsed); mViewBackground.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); mViewBackground.draw(canvas); canvas.restoreToCount(saveCount); }
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 www.j av a 2 s.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();// w w w. ja va 2 s . co 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:com.guodong.sun.guodong.widget.ZoomImageView.java
@Override protected void onDraw(Canvas canvas) { if (getDrawable() == null) { return; // couldn't resolve the URI }/*from w ww .j a v a 2s . com*/ if (mState == STATE_TRANSFORM_IN || mState == STATE_TRANSFORM_OUT) { if (mTransformStart) { initTransform(); } if (mTransfrom == null) { super.onDraw(canvas); return; } if (mTransformStart) { if (mState == STATE_TRANSFORM_IN) { mTransfrom.initStartIn(); } else { mTransfrom.initStartOut(); } } if (mTransformStart) { Log.d("Dean", "mTransfrom.startScale:" + mTransfrom.startScale); Log.d("Dean", "mTransfrom.startScale:" + mTransfrom.endScale); Log.d("Dean", "mTransfrom.scale:" + mTransfrom.scale); Log.d("Dean", "mTransfrom.startRect:" + mTransfrom.startRect.toString()); Log.d("Dean", "mTransfrom.endRect:" + mTransfrom.endRect.toString()); Log.d("Dean", "mTransfrom.rect:" + mTransfrom.rect.toString()); } mPaint.setAlpha(mBgAlpha); canvas.drawPaint(mPaint); int saveCount = canvas.getSaveCount(); canvas.save(); // ?Matrix getBmpMatrix(); canvas.translate(mTransfrom.rect.left, mTransfrom.rect.top); canvas.clipRect(0, 0, mTransfrom.rect.width, mTransfrom.rect.height); canvas.concat(mSmoothMatrix); getDrawable().draw(canvas); canvas.restoreToCount(saveCount); if (mTransformStart) { mTransformStart = false; startTransform(mState); } } else { //Transform In???Activity?? mPaint.setAlpha(255); canvas.drawPaint(mPaint); super.onDraw(canvas); } }