List of usage examples for android.graphics Canvas restore
public void restore()
From source file:ru.mahortov.listviewcustom.ListView.PinnedSectionListView.java
@Override protected void dispatchDraw(@NonNull Canvas canvas) { super.dispatchDraw(canvas); if (mPinnedSection != null) { // prepare variables int pLeft = getListPaddingLeft(); int pTop = getListPaddingTop(); View view = mPinnedSection.view; // draw child canvas.save();//from w ww . j a va 2 s .c o m int clipHeight = view.getHeight() + (mShadowDrawable == null ? 0 : Math.min(mShadowHeight, mSectionsDistanceY)); canvas.clipRect(pLeft, pTop, pLeft + view.getWidth(), pTop + clipHeight); canvas.translate(pLeft, pTop + mTranslateY); drawChild(canvas, mPinnedSection.view, getDrawingTime()); if (mShadowDrawable != null && mSectionsDistanceY > 0) { mShadowDrawable.setBounds(mPinnedSection.view.getLeft(), mPinnedSection.view.getBottom(), mPinnedSection.view.getRight(), mPinnedSection.view.getBottom() + mShadowHeight); mShadowDrawable.draw(canvas); } canvas.restore(); } }
From source file:com.yanzhenjie.recyclerview.swipe.widget.StickyNestedScrollView.java
@Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); if (currentlyStickingView != null) { canvas.save();/* ww w . j a v a 2 s.com*/ canvas.translate(getPaddingLeft() + stickyViewLeftOffset, getScrollY() + stickyViewTopOffset + (clippingToPadding ? getPaddingTop() : 0)); canvas.clipRect(0, (clippingToPadding ? -stickyViewTopOffset : 0), getWidth() - stickyViewLeftOffset, currentlyStickingView.getHeight() + mShadowHeight + 1); if (mShadowDrawable != null) { int left = 0; int top = currentlyStickingView.getHeight(); int right = currentlyStickingView.getWidth(); int bottom = currentlyStickingView.getHeight() + mShadowHeight; mShadowDrawable.setBounds(left, top, right, bottom); mShadowDrawable.draw(canvas); } canvas.clipRect(0, (clippingToPadding ? -stickyViewTopOffset : 0), getWidth(), currentlyStickingView.getHeight()); if (getStringTagForView(currentlyStickingView).contains(FLAG_HASTRANSPARENCY)) { showView(currentlyStickingView); currentlyStickingView.draw(canvas); hideView(currentlyStickingView); } else { currentlyStickingView.draw(canvas); } canvas.restore(); } }
From source file:com.pax.view.keyboard.CustomKeyboardView.java
@Override public void onDraw(Canvas canvas) { List<Keyboard.Key> keys = getKeyboard().getKeys(); for (Keyboard.Key key : keys) { canvas.save();/*from w w w . j a v a 2 s .c o m*/ int offsetY = 0; if (key.y == 0) { offsetY = 1; } int initDrawY = key.y + offsetY; Rect rect = new Rect(key.x, initDrawY, key.x + key.width, key.y + key.height); canvas.clipRect(rect); Drawable drawable = null; if (null != key.codes && key.codes.length != 0) { int primaryCode = key.codes[0]; if (primaryCode < 0) { drawable = mOpKeyBgDrawable; } else { drawable = mKeyBgDrawable; } } if (null != drawable && null == key.icon) { int[] state = key.getCurrentDrawableState(); drawable.setState(state); drawable.setBounds(rect); drawable.draw(canvas); } paint.setAntiAlias(true); paint.setTextAlign(Paint.Align.CENTER); paint.setTextSize(50); paint.setColor(Color.BLACK); if (key.icon != null) { int[] state = key.getCurrentDrawableState(); key.icon.setState(state); key.icon.setBounds(rect); key.icon.draw(canvas); } if (key.label != null) { canvas.drawText(key.label.toString(), key.x + (key.width / 2), initDrawY + (key.height + paint.getTextSize() - paint.descent()) / 2, paint); } canvas.restore(); } }
From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java
/** * Divider/*from w w w.j a va 2s . co m*/ * * @param canvas */ protected void drawDivider(Canvas canvas) { if (mDivider == null || mDivider.getIntrinsicHeight() <= 0) return; final int dividerWidth = mDivider.getIntrinsicWidth() > 0 ? mDivider.getIntrinsicWidth() : getWidth() - ViewCompat.getPaddingStart(this) - ViewCompat.getPaddingEnd(this); final int dividerHeight = mDivider.getIntrinsicHeight(); mDivider.setBounds(0, 0, dividerWidth, dividerHeight); final float moveX = ViewCompat.getPaddingStart(this); final float moveY = getItemHeight() + getPaddingTop(); canvas.save(); canvas.translate(moveX, moveY); mDivider.draw(canvas); canvas.restore(); }
From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java
/** * //from ww w . j av a2 s . c om * * @param canvas * @param position ??? * @param itemWidth ? * @param itemHeight ? */ protected void drawItemBackground(Canvas canvas, int position, int itemWidth, int itemHeight) { if (!hasItemBackgrounds()) return; Drawable tag = getItemBackground(position); if (position == getItemCount() - 1) { int restWidth = getLastItemWidth(); tag.setBounds(0, 0, restWidth, itemHeight); } else { tag.setBounds(0, 0, itemWidth, itemHeight); } final float moveX = ViewCompat.getPaddingStart(this) + (itemWidth + getIntervalWidth()) * position; final float moveY = getPaddingTop(); canvas.save(); canvas.translate(moveX, moveY); tag.draw(canvas); canvas.restore(); }
From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java
/** * //from w w w . j a v a 2s . co m * * @param canvas * @param position ??? * @param itemWidth ? * @param itemHeight ? */ protected void drawInterval(Canvas canvas, int position, int itemWidth, int itemHeight) { if (mInterval == null || mInterval.getIntrinsicWidth() <= 0 || position == getItemCount() - 1) return; final int intervalHeight = mInterval.getIntrinsicHeight() <= 0 ? itemHeight : mInterval.getIntrinsicHeight(); mInterval.setBounds(0, 0, getIntervalWidth(), intervalHeight); final int moveX = ViewCompat.getPaddingStart(this) + itemWidth * position; final float moveY = getPaddingTop() + (itemHeight - intervalHeight) * 0.5f; canvas.save(); canvas.translate(moveX, moveY); mInterval.draw(canvas); canvas.restore(); }
From source file:com.achep.acdisplay.ui.widgets.CircleView.java
@Override protected void onDraw(Canvas canvas) { final float ratio = calculateRatio(); // Draw all corners drawCornerIcon(canvas, mDrawableLeftTopCorner, 0, 0 /* left top */); drawCornerIcon(canvas, mDrawableRightTopCorner, 1, 0 /* right top */); drawCornerIcon(canvas, mDrawableLeftBottomCorner, 0, 1 /* left bottom */); drawCornerIcon(canvas, mDrawableRightBottomCorner, 1, 1 /* right bottom */); // Darkening background int alpha = (int) (mDarkening * 255); alpha += (int) ((255 - alpha) * ratio * 0.7f); // Change alpha dynamically canvas.drawColor(/* ww w. j a va 2 s . co m*/ Color.argb(alpha, Color.red(mOuterColor), Color.green(mOuterColor), Color.blue(mOuterColor))); // Draw unlock circle mPaint.setColor(mInnerColor); mPaint.setAlpha((int) (255 * Math.pow(ratio, 1f / 3f))); canvas.drawCircle(mPoint[0], mPoint[1], mRadiusDrawn, mPaint); if (ratio >= 0.5f) { // Draw unlock icon at the center of circle float scale = 0.5f + 0.5f * ratio; canvas.save(); canvas.translate(mPoint[0] - mDrawable.getMinimumWidth() / 2 * scale, mPoint[1] - mDrawable.getMinimumHeight() / 2 * scale); canvas.scale(scale, scale); mDrawable.draw(canvas); canvas.restore(); } }
From source file:com.am.pagergradienttab.view.PagerGradientTabStrip.java
/** * Tab/*from www .j a v a 2 s . c o m*/ * * @param canvas */ private void drawTabBG(Canvas canvas) { if (showTabColor) { mTextPaint.setColor(tabColorNormal); canvas.save(); canvas.translate(getPaddingLeft(), 0); if (tabs.size() > 0) for (int i = 0; i < tabs.size(); i++) { if (i == nextPager) { mTextPaint.setColor(getColor(tabColorNormal, tabColorSelected, textSizeOffset)); } else if (i == currectPager) { mTextPaint.setColor(getColor(tabColorNormal, tabColorSelected, 1 - textSizeOffset)); } else { mTextPaint.setColor(tabColorNormal); } canvas.drawRect(0, getPaddingTop(), itemWidth, getHeight() - getPaddingBottom(), mTextPaint); canvas.translate(itemWidth + intervalWidth, 0); } else { mTextPaint.setColor(tabColorSelected); canvas.drawRect(0, getPaddingTop(), itemWidth + intervalWidth + getPaddingLeft(), getHeight() - getPaddingBottom(), mTextPaint); } canvas.restore(); } }
From source file:com.crs4.roodin.moduletester.CustomView.java
/** * @return/*from www .j a va 2 s.co m*/ */ private Picture drawBarreds() { Picture pictureContent = new Picture(); Canvas canvasContent = pictureContent.beginRecording(getWidth(), getHeight()); Paint paintContent = new Paint(Paint.ANTI_ALIAS_FLAG); canvasContent.save(); paintContent.setColor(Color.BLUE); paintContent.setStyle(Style.STROKE); paintContent.setStrokeWidth(2); paintContent.setAlpha(50); try { cellDimension = block.getCellDimension(); JSONArray barred = block.getBarred(); int rows = block.getShape().getInt(0); int cols = block.getShape().getInt(1); // this code draws all the shape: for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { canvasContent.drawRect(cellDimension * j, cellDimension * i, cellDimension * j + cellDimension, cellDimension * i + cellDimension, paintContent); } } paintContent.setColor(Color.RED); paintContent.setStyle(Style.FILL); paintContent.setAlpha(50); for (int i = 0; i < barred.length(); i++) { JSONArray pos = barred.getJSONArray(i); canvasContent.drawRect(cellDimension * pos.getInt(1), cellDimension * pos.getInt(0), cellDimension * pos.getInt(1) + cellDimension, cellDimension * pos.getInt(0) + cellDimension, paintContent); } this.paintBoxList(canvasContent, paintContent); } catch (JSONException e) { e.printStackTrace(); Log.e("Exception in DrawComponents.drawBarreds", "" + e.getMessage()); } canvasContent.restore(); pictureContent.endRecording(); return pictureContent; }
From source file:com.android.launcher3.folder.FolderIcon.java
private void drawPreviewItem(Canvas canvas, PreviewItemDrawingParams params) { canvas.save();// w w w . java 2 s . com canvas.translate(params.transX, params.transY); canvas.scale(params.scale, params.scale); Drawable d = params.drawable; if (d != null) { mOldBounds.set(d.getBounds()); d.setBounds(0, 0, mIntrinsicIconSize, mIntrinsicIconSize); if (d instanceof FastBitmapDrawable) { FastBitmapDrawable fd = (FastBitmapDrawable) d; float oldBrightness = fd.getBrightness(); fd.setBrightness(params.overlayAlpha); d.draw(canvas); fd.setBrightness(oldBrightness); } else { d.setColorFilter(Color.argb((int) (params.overlayAlpha * 255), 255, 255, 255), PorterDuff.Mode.SRC_ATOP); d.draw(canvas); d.clearColorFilter(); } d.setBounds(mOldBounds); } canvas.restore(); }