List of usage examples for android.graphics Canvas restore
public void restore()
From source file:ir.hatamiarash.calendar.view.QiblaCompassView.java
public void drawDial(Canvas canvas) { // over here// w w w . j a va 2 s . co m circlePaint.reset(); circlePaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color)); circlePaint.setStrokeWidth(1); circlePaint.setStyle(Paint.Style.STROKE); // Sadece Cember ciziyor. int textHeight = (int) textPaint.measureText("yY"); markerPaint.reset(); markerPaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color)); // Draw the background canvas.drawCircle(px, py, Radius, circlePaint); canvas.drawCircle(px, py, Radius - 20, circlePaint); // Rotate our perspective so that the "top" is // facing the current bearing. int textWidth = (int) textPaint.measureText("W"); int cardinalX = px - textWidth / 2; int cardinalY = py - Radius + textHeight; // Draw the marker every 15 degrees and text every 45. for (int i = 0; i < 24; i++) { // Draw a marker. canvas.drawLine(px, py - Radius, px, py - Radius + 10, markerPaint); canvas.save(); canvas.translate(0, textHeight); // Draw the cardinal points if (i % 6 == 0) { String dirString = ""; switch (i) { case (0): { dirString = northString; break; } case (6): dirString = eastString; break; case (12): dirString = southString; break; case (18): dirString = westString; break; } canvas.drawText(dirString, cardinalX, cardinalY, textPaint); } else if (i % 3 == 0) { // Draw the text every alternate 45deg String angle = String.valueOf(i * 15); float angleTextWidth = textPaint.measureText(angle); int angleTextX = (int) (px - angleTextWidth / 2); int angleTextY = py - Radius + textHeight; canvas.drawText(angle, angleTextX, angleTextY, textPaint); } canvas.restore(); canvas.rotate(15, px, py); } }
From source file:com.camnter.easyrecyclerviewsidebar.EasyRecyclerViewSidebar.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int viewWidth = this.getWidth(); int viewHeight = this.getHeight(); int viewHalfWidth = viewWidth / 2; this.sectionHeight = viewHeight / MAX_SECTION_COUNT; boolean isPreviousImage = false; boolean isPreviousLetter = false; float allSectionHeight; if (this.sections.size() > 0) { allSectionHeight = this.sectionHeight * this.sections.size(); this.drawBeginY = (viewHeight - allSectionHeight) / 2; this.drawEndY = this.drawBeginY + allSectionHeight; float top = viewHeight / 2 - allSectionHeight / 2 + this.sectionHeight / 2 - this.sectionFontSize / 2; for (int i = 0; i < this.sections.size(); i++) { EasySection section = this.sections.get(i); if (section instanceof EasyImageSection) { EasyImageSection imageSection = (EasyImageSection) section; this.setPaintShader(imageSection); if (isPreviousLetter) { top -= this.letterSize - (Math.max(this.letterHeight, this.sectionHeight) - Math.min(this.letterHeight, this.sectionHeight)); }/*from w ww. j a v a 2 s .c o m*/ canvas.save(); canvas.translate(viewHalfWidth - this.letterSize / 2, top + this.sectionHeight * i); Paint imagePaint = this.imagePaints.get(imageSection.hashCode()); switch (imageSection.imageType) { case EasyImageSection.ROUND: { canvas.drawRoundRect(this.imageSectionRect, this.imageSectionBorderRadius, this.imageSectionBorderRadius, imagePaint); break; } case EasyImageSection.CIRCLE: { canvas.drawRoundRect(this.imageSectionRect, this.imageSectionCircleBorderRadius, this.imageSectionCircleBorderRadius, imagePaint); break; } } canvas.restore(); isPreviousImage = true; isPreviousLetter = false; } else { if (isPreviousImage) { top = top + this.letterSize; } canvas.drawText(section.letter, viewHalfWidth, top + this.sectionHeight * i, this.letterPaint); isPreviousImage = false; isPreviousLetter = true; } } } else { this.sectionHeight = 0; } }
From source file:com.byagowi.persiancalendar.view.QiblaCompassView.java
public void drawDial(Canvas canvas) { // over here//from w ww . j ava 2 s .c o m circlePaint.reset(); circlePaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color)); circlePaint.setStrokeWidth(1); circlePaint.setStyle(Paint.Style.STROKE); // Sadece Cember ciziyor. int textHeight = (int) textPaint.measureText("yY"); markerPaint.reset(); markerPaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color)); // Draw the background canvas.drawCircle(px, py, Radius, circlePaint); canvas.drawCircle(px, py, Radius - 20, circlePaint); // Rotate our perspective so that the "top" is // facing the current bearing. int textWidth = (int) textPaint.measureText("W"); int cardinalX = px - textWidth / 2; int cardinalY = py - Radius + textHeight; // Draw the marker every 15 degrees and text every 45. for (int i = 0; i < 24; i++) { // Draw a marker. canvas.drawLine(px, py - Radius, px, py - Radius + 10, markerPaint); canvas.save(); canvas.translate(0, textHeight); // Draw the cardinal points if (i % 6 == 0) { String dirString = ""; switch (i) { case (0): { dirString = northString; break; } case (6): dirString = eastString; break; case (12): dirString = southString; break; case (18): dirString = westString; break; } canvas.drawText(dirString, cardinalX, cardinalY, textPaint); } else if (i % 3 == 0) { // Draw the text every alternate 45deg String angle = String.valueOf(i * 15); float angleTextWidth = textPaint.measureText(angle); int angleTextX = (int) (px - angleTextWidth / 2); int angleTextY = py - Radius + textHeight; canvas.drawText(angle, angleTextX, angleTextY, textPaint); } canvas.restore(); canvas.rotate(15, px, py); } }
From source file:com.mylikes.likes.etchasketch.Slate.java
@Override protected void onDraw(Canvas canvas) { if (mTiledCanvas != null) { canvas.save(Canvas.MATRIX_SAVE_FLAG); if (mPanX != 0 || mPanY != 0 || !mZoomMatrix.isIdentity()) { canvas.translate(mPanX, mPanY); canvas.concat(mZoomMatrix);/*from w w w. j av a 2s . c o m*/ canvas.drawRect(-20000, -20000, 20000, 0, mWorkspacePaint); canvas.drawRect(-20000, 0, 0, mTiledCanvas.getHeight(), mWorkspacePaint); canvas.drawRect(mTiledCanvas.getWidth(), 0, 20000, mTiledCanvas.getHeight(), mWorkspacePaint); canvas.drawRect(-20000, mTiledCanvas.getHeight(), 20000, 20000, mWorkspacePaint); } if (!mDirtyRegion.isEmpty()) { canvas.clipRegion(mDirtyRegion); mDirtyRegion.setEmpty(); } // TODO: tune this threshold based on the device density mBlitPaint.setFilterBitmap(getScale(mZoomMatrix) < 3f); mTiledCanvas.drawTo(canvas, 0, 0, mBlitPaint, false); // @@ set to true for dirty tile updates if (0 != (mDebugFlags & FLAG_DEBUG_STROKES)) { drawStrokeDebugInfo(canvas); } for (MoveableDrawing drawing : overlays) { drawing.renderInto(canvas, moveMode && drawing == selectedDrawing); } canvas.restore(); if (0 != (mDebugFlags & FLAG_DEBUG_PRESSURE)) { mPressureCooker.drawDebug(canvas); } } }
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 ww w .j a v a2s . c o m*/ 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:io.doist.datetimepicker.time.RadialTimePickerView.java
@Override public void onDraw(Canvas canvas) { if (!mInputEnabled) { canvas.saveLayerAlpha(0, 0, getWidth(), getHeight(), mDisabledAlpha, Canvas.ALL_SAVE_FLAG); } else {/* ww w. j a v a 2s .c o m*/ canvas.save(); } calculateGridSizesHours(); calculateGridSizesMinutes(); drawCircleBackground(canvas); drawSelector(canvas); drawTextElements(canvas, mTextSize[HOURS], mTypeface, mOuterTextHours, mTextGridWidths[HOURS], mTextGridHeights[HOURS], mPaint[HOURS], mColor[HOURS], mAlpha[HOURS].getValue()); if (mIs24HourMode && mInnerTextHours != null) { drawTextElements(canvas, mInnerTextSize, mTypeface, mInnerTextHours, mInnerTextGridWidths, mInnerTextGridHeights, mPaint[HOURS], mColor[HOURS], mAlpha[HOURS].getValue()); } drawTextElements(canvas, mTextSize[MINUTES], mTypeface, mOuterTextMinutes, mTextGridWidths[MINUTES], mTextGridHeights[MINUTES], mPaint[MINUTES], mColor[MINUTES], mAlpha[MINUTES].getValue()); drawCenter(canvas); if (DEBUG) { drawDebug(canvas); } canvas.restore(); }
From source file:pl.motyczko.scrollheader.PagerSlidingTabStrip.java
private void drawTabs(Canvas canvas) { canvas.save();/*from w w w. ja v a2s .c om*/ canvas.translate(0, getHeight() - tabsContainer.getHeight()); if (isInEditMode() || tabCount == 0) { return; } final int height = tabsContainer.getHeight(); // draw indicator line rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates between current and next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); // draw divider dividerPaint.setColor(dividerColor); for (int i = 0; i < tabCount - 1; i++) { View tab = tabsContainer.getChildAt(i); canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint); } canvas.restore(); }
From source file:com.yanzhenjie.durban.view.OverlayView.java
/** * This method draws crop bounds (empty rectangle) * and crop guidelines (vertical and horizontal lines inside the crop bounds) if needed. * * @param canvas - valid canvas object/*w w w.ja va 2s . c om*/ */ protected void drawCropGrid(@NonNull Canvas canvas) { if (mShowCropGrid) { if (mGridPoints == null && !mCropViewRect.isEmpty()) { mGridPoints = new float[(mCropGridRowCount) * 4 + (mCropGridColumnCount) * 4]; int index = 0; for (int i = 0; i < mCropGridRowCount; i++) { mGridPoints[index++] = mCropViewRect.left; mGridPoints[index++] = (mCropViewRect.height() * (((float) i + 1.0f) / (float) (mCropGridRowCount + 1))) + mCropViewRect.top; mGridPoints[index++] = mCropViewRect.right; mGridPoints[index++] = (mCropViewRect.height() * (((float) i + 1.0f) / (float) (mCropGridRowCount + 1))) + mCropViewRect.top; } for (int i = 0; i < mCropGridColumnCount; i++) { mGridPoints[index++] = (mCropViewRect.width() * (((float) i + 1.0f) / (float) (mCropGridColumnCount + 1))) + mCropViewRect.left; mGridPoints[index++] = mCropViewRect.top; mGridPoints[index++] = (mCropViewRect.width() * (((float) i + 1.0f) / (float) (mCropGridColumnCount + 1))) + mCropViewRect.left; mGridPoints[index++] = mCropViewRect.bottom; } } if (mGridPoints != null) canvas.drawLines(mGridPoints, mCropGridPaint); } if (mShowCropFrame) canvas.drawRect(mCropViewRect, mCropFramePaint); if (mFreestyleCropMode != FREESTYLE_CROP_MODE_DISABLE) { canvas.save(); mTempRect.set(mCropViewRect); mTempRect.inset(mCropRectCornerTouchAreaLineLength, -mCropRectCornerTouchAreaLineLength); canvas.clipRect(mTempRect, Region.Op.DIFFERENCE); mTempRect.set(mCropViewRect); mTempRect.inset(-mCropRectCornerTouchAreaLineLength, mCropRectCornerTouchAreaLineLength); canvas.clipRect(mTempRect, Region.Op.DIFFERENCE); canvas.drawRect(mCropViewRect, mCropFrameCornersPaint); canvas.restore(); } }
From source file:com.am.pagergradienttab.view.PagerGradientTabStrip.java
/** * // w w w. jav a2 s . c om * * @param canvas */ private void drawText(Canvas canvas) { float x = getPaddingLeft() + itemWidth / 2; int y = getHeight() - getPaddingBottom() - indicatorHeight - underLineHeight; int position = 0; for (String text : tabs) { canvas.save(); mTextPaint.setColor(textColorNormal); mTextPaint.setTextAlign(Align.LEFT); mTextPaint.setTextSize(textSize); if (showTextGradient) { if (position == nextPager) { mTextPaint.setColor(getColor(textColorNormal, textColorSelected, textSizeOffset)); } else if (position == currectPager) { mTextPaint.setColor(getColor(textColorNormal, textColorSelected, 1 - textSizeOffset)); } else { mTextPaint.setColor(textColorNormal); } } if (showTextScale) { if (position == nextPager) { canvas.translate(x - mTextPaint.measureText(text) * (1 + textSizeOffset * magnification) / 2, y - textTop); canvas.scale(1 + textSizeOffset * magnification, 1 + textSizeOffset * magnification); } else if (position == currectPager) { canvas.translate( x - mTextPaint.measureText(text) * (1 + (1 - textSizeOffset) * magnification) / 2, y - textTop); canvas.scale(1 + (1 - textSizeOffset) * magnification, 1 + (1 - textSizeOffset) * magnification); } else { canvas.translate(x - mTextPaint.measureText(text) / 2, y - textTop); canvas.scale(1, 1); } } else { canvas.translate(x - mTextPaint.measureText(text) / 2, y - textTop); } canvas.drawText(text, 0, 0, mTextPaint); x += itemWidth + intervalWidth; position++; canvas.restore(); } }
From source file:im.ene.lab.design.widget.coverflow.FeatureCoverFlow.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { canvas.save();/*from w w w . ja va 2 s .c o m*/ //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); 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; }