List of usage examples for android.graphics Canvas save
public int save()
From source file:org.telegram.ui.Components.Switch.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final Rect padding = mTempRect; final Drawable trackDrawable = mTrackDrawable; if (trackDrawable != null) { trackDrawable.getPadding(padding); } else {/*from w w w .ja va 2 s . com*/ padding.setEmpty(); } final int switchTop = mSwitchTop; final int switchBottom = mSwitchBottom; final Drawable thumbDrawable = mThumbDrawable; if (trackDrawable != null) { if (mSplitTrack && thumbDrawable != null) { final Insets insets = Insets.NONE; thumbDrawable.copyBounds(padding); padding.left += insets.left; padding.right -= insets.right; final int saveCount = canvas.save(); canvas.clipRect(padding, Region.Op.DIFFERENCE); trackDrawable.draw(canvas); canvas.restoreToCount(saveCount); } else { trackDrawable.draw(canvas); } } final int saveCount = canvas.save(); if (thumbDrawable != null) { thumbDrawable.draw(canvas); } canvas.restoreToCount(saveCount); }
From source file:com.bitflake.counter.HorizontalPicker.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int saveCount = canvas.getSaveCount(); canvas.save(); 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();//from w w w . j a va2s .c o m 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.actionbarsherlock.internal.widget.IcsProgressBar.java
@Override protected synchronized void onDraw(Canvas canvas) { super.onDraw(canvas); Drawable d = mCurrentDrawable;//from www. j a v a 2s . co m if (d != null) { // Translate canvas so a indeterminate circular progress bar with padding // rotates properly in its animation canvas.save(); canvas.translate(getPaddingLeft() + mIndeterminateRealLeft, getPaddingTop() + mIndeterminateRealTop); long time = getDrawingTime(); if (mAnimation != null) { mAnimation.getTransformation(time, mTransformation); float scale = mTransformation.getAlpha(); try { mInDrawing = true; d.setLevel((int) (scale * MAX_LEVEL)); } finally { mInDrawing = false; } if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) { mLastDrawTime = SystemClock.uptimeMillis(); postInvalidateDelayed(mAnimationResolution); } } d.draw(canvas); canvas.restore(); if (mShouldStartAnimationDrawable && d instanceof Animatable) { ((Animatable) d).start(); mShouldStartAnimationDrawable = false; } } }
From source file:kr.selfcontrol.selflocklauncher.picker.HorizontalPicker.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int saveCount = canvas.getSaveCount(); canvas.save(); 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();/* w w w . j av a 2 s .c om*/ 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(); 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); }/*ww w .j a v a 2s . c o m*/ // 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(); 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();/* w w w . j ava 2 s . co m*/ 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.example.stickablelistview.StickListView.java
/** Draws the overscroll edge glow effect on the left and right sides of the horizontal list */ private void drawEdgeGlow(Canvas canvas) { if (mEdgeGlowTop != null && !mEdgeGlowTop.isFinished() && isEdgeGlowEnabled()) { // The Edge glow is meant to come from the top of the screen, so rotate it to draw on the left side. final int restoreCount = canvas.save(); final int width = getWidth(); canvas.rotate(-90, 0, 0);/* w ww.ja v a 2 s .co m*/ canvas.translate(0, -width + getPaddingRight()); mEdgeGlowTop.setSize(getRenderWidth(), getRenderHeight()); if (mEdgeGlowTop.draw(canvas)) { invalidate(); } canvas.restoreToCount(restoreCount); } else if (mEdgeGlowBottom != null && !mEdgeGlowBottom.isFinished() && isEdgeGlowEnabled()) { // The Edge glow is meant to come from the top of the screen, so rotate it to draw on the right side. final int restoreCount = canvas.save(); final int width = getWidth(); canvas.rotate(90, 0, 0); canvas.translate(getPaddingTop(), -width); mEdgeGlowBottom.setSize(getRenderWidth(), getRenderHeight()); if (mEdgeGlowBottom.draw(canvas)) { invalidate(); } canvas.restoreToCount(restoreCount); } }
From source file:com.simon.catkins.views.HorizontalListView.java
/** Draws the overscroll edge glow effect on the top and bottom sides of the vertical list */ private void drawEdgeGlow(Canvas canvas) { if (mEdgeGlowLeft != null && !mEdgeGlowLeft.isFinished() && isEdgeGlowEnabled()) { // The Edge glow is meant to come from the top of the screen, so rotate it to draw on the top side. final int restoreCount = canvas.save(); final int height = getHeight(); canvas.rotate(-90, 0, 0);//from ww w . ja v a 2s . c om canvas.translate(-height + getPaddingBottom(), 0); mEdgeGlowLeft.setSize(getRenderHeight(), getRenderWidth()); if (mEdgeGlowLeft.draw(canvas)) { invalidate(); } canvas.restoreToCount(restoreCount); } else if (mEdgeGlowRight != null && !mEdgeGlowRight.isFinished() && isEdgeGlowEnabled()) { // The Edge glow is meant to come from the top of the screen, so rotate it to draw on the bottom side. final int restoreCount = canvas.save(); final int width = getWidth(); canvas.rotate(90, 0, 0); canvas.translate(getPaddingTop(), -width); mEdgeGlowRight.setSize(getRenderHeight(), getRenderWidth()); if (mEdgeGlowRight.draw(canvas)) { invalidate(); } canvas.restoreToCount(restoreCount); } }
From source file:im.ene.lab.design.widget.coverflow.FeatureCoverFlow.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { canvas.save(); //set matrix to child's transformation setChildTransformation(child, mMatrix); //Generate child bitmap Bitmap bitmap = child.getDrawingCache(); //initialize canvas state. Child 0,0 coordinates will match canvas 0,0 canvas.translate(child.getLeft(), child.getTop()); //set child transformation on canvas canvas.concat(mMatrix);/* ww w . j av a2s .com*/ final Bitmap rfCache = ((CoverFrame) child).mReflectionCache; if (mReflectionBackgroundColor != Color.TRANSPARENT) { final int top = bitmap.getHeight() + mReflectionGap - 2; final float frame = 1.0f; mReflectionPaint.setColor(mReflectionBackgroundColor); canvas.drawRect(frame, top + frame, rfCache.getWidth() - frame, top + rfCache.getHeight() - frame, mReflectionPaint); } mPaint.reset(); mPaint.setAntiAlias(true); mPaint.setFilterBitmap(true); //Draw child bitmap with applied transforms canvas.drawBitmap(bitmap, 0.0f, 0.0f, mPaint); //Draw reflection canvas.drawBitmap(rfCache, 0.0f, bitmap.getHeight() - 2 + mReflectionGap, mPaint); canvas.restore(); return false; }
From source file:pl.motyczko.scrollheader.PagerSlidingTabStrip.java
private void drawBackground(Canvas canvas) { if (mViewBackground == null) return;//from w w w . j a v a 2 s. c o 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); }