List of usage examples for android.graphics Canvas drawRoundRect
public void drawRoundRect(@NonNull RectF rect, float rx, float ry, @NonNull Paint paint)
From source file:com.ymt.demo1.customViews.widget.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/* w w w . j av a 2s . com*/ } final int height = 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); } // RectF rectF = new RectF(lineLeft + 28, 28, lineRight - 28, height - 28); canvas.drawRoundRect(rectF, 45, 45, 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); } }
From source file:org.getlantern.firetweet.view.ShapedImageView.java
private void drawBorder(@NonNull final Canvas canvas, @NonNull final RectF dest) { if (mBorderColors == null) return;//ww w . ja v a2 s . co m final RectF transitionSrc = mTransitionSource, transitionDst = mTransitionDestination; final float strokeWidth; if (transitionSrc != null && transitionDst != null) { final float progress = 1 - (dest.width() - transitionDst.width()) / (transitionSrc.width() - transitionDst.width()); strokeWidth = mStrokeWidth * progress; mBorderPaint.setAlpha(Math.round(mBorderAlpha * progress)); ViewCompat.setTranslationZ(this, -ViewCompat.getElevation(this) * (1 - progress)); } else { strokeWidth = mStrokeWidth; mBorderPaint.setAlpha(mBorderAlpha); ViewCompat.setTranslationZ(this, 0); } mBorderPaint.setStrokeWidth(strokeWidth); if (getStyle() == SHAPE_CIRCLE) { final float circleRadius = Math.min(dest.width(), dest.height()) / 2f - strokeWidth / 2; canvas.drawCircle(dest.centerX(), dest.centerY(), circleRadius, mBorderPaint); } else { final float radius = getCalculatedCornerRadius(); final float inset = mStrokeWidth / 2; dest.inset(inset, inset); canvas.drawRoundRect(dest, radius, radius, mBorderPaint); dest.inset(-inset, -inset); } }
From source file:de.vanita5.twittnuker.view.ColorPickerView.java
private void drawHuePanel(final Canvas canvas) { final RectF rect = mHueRect; if (BORDER_WIDTH_PX > 0) { mBorderPaint.setColor(mBorderColor); canvas.drawRect(rect.left - BORDER_WIDTH_PX, rect.top - BORDER_WIDTH_PX, rect.right + BORDER_WIDTH_PX, rect.bottom + BORDER_WIDTH_PX, mBorderPaint); }//from ww w.ja va 2 s. c o m if (mHueShader == null) { mHueShader = new LinearGradient(rect.left, rect.top, rect.left, rect.bottom, buildHueColorArray(), null, TileMode.CLAMP); mHuePaint.setShader(mHueShader); } canvas.drawRect(rect, mHuePaint); final float rectHeight = 4 * mDensity / 2; final Point p = hueToPoint(mHue); final RectF r = new RectF(); r.left = rect.left - RECTANGLE_TRACKER_OFFSET; r.right = rect.right + RECTANGLE_TRACKER_OFFSET; r.top = p.y - rectHeight; r.bottom = p.y + rectHeight; canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint); }
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)); }//w w w . j a v a 2 s . co 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.gm.common.ui.widget.pageindicator.PageIndicatorView.java
private void drawWithWormAnimation(@NonNull Canvas canvas, int x, int y) { int radius = radiusPx; if (orientation == Orientation.HORIZONTAL) { rect.left = frameFrom;// w ww. j ava 2 s. co m rect.right = frameTo; rect.top = y - radius; rect.bottom = y + radius; } else { rect.left = x - radiusPx; rect.right = x + radiusPx; rect.top = frameFrom; rect.bottom = frameTo; } fillPaint.setColor(unselectedColor); canvas.drawCircle(x, y, radius, fillPaint); fillPaint.setColor(selectedColor); canvas.drawRoundRect(rect, radiusPx, radiusPx, fillPaint); }
From source file:com.gm.common.ui.widget.pageindicator.PageIndicatorView.java
private void drawWithThinWormAnimation(@NonNull Canvas canvas, int x, int y) { int radius = radiusPx; if (orientation == Orientation.HORIZONTAL) { rect.left = frameFrom;//from w w w .j av a 2s.c o m rect.right = frameTo; rect.top = y - (frameHeight / 2); rect.bottom = y + (frameHeight / 2); } else { rect.left = x - (frameHeight / 2); rect.right = x + (frameHeight / 2); rect.top = frameFrom; rect.bottom = frameTo; } fillPaint.setColor(unselectedColor); canvas.drawCircle(x, y, radius, fillPaint); fillPaint.setColor(selectedColor); canvas.drawRoundRect(rect, radiusPx, radiusPx, fillPaint); }
From source file:org.smart.library.widget.SlideSwitch.java
@Override protected void onDraw(Canvas canvas) { int radius = backRect.height() / 2 - RIM_SIZE; if (shape == SHAPE_RECT) { paint.setAlpha(255 - alpha);/*from ww w .j a v a2 s . co m*/ if (bitmap_off_theme != null) { canvas.drawBitmap(bitmap_off_theme, backRect.left, backRect.top, paint); } else { paint.setColor(color_off_theme); canvas.drawRect(backRect, paint); } paint.setColor(color_on_theme); paint.setAlpha(alpha); if (bitmap_on_theme != null) { canvas.drawBitmap(bitmap_on_theme, backRect.left, backRect.top, paint); } else canvas.drawRect(backRect, paint); drawText(canvas, radius); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + getMeasuredWidth() / 2 - RIM_SIZE, getMeasuredHeight() - RIM_SIZE); paint.setColor(isOpen ? circle_on_color : circle_off_color); if (isOpen && circle_on_bitmap != null) canvas.drawBitmap(circle_on_bitmap, frontRect.left + space, frontRect.top + space, paint); else if (!isOpen && circle_off_bitmap != null) canvas.drawBitmap(circle_off_bitmap, frontRect.left + space, frontRect.top + space, paint); else canvas.drawRect(frontRect, paint); } else { // draw circle backCircleRect.set(backRect); paint.setAlpha(255 - alpha); if (bitmap_off_theme != null) { canvas.drawBitmap(bitmap_off_theme, backCircleRect.left, backCircleRect.top, paint); } else { paint.setColor(color_off_theme); canvas.drawRoundRect(backCircleRect, radius, radius, paint); } paint.setColor(color_on_theme); paint.setAlpha(alpha); if (bitmap_on_theme != null) { canvas.drawBitmap(bitmap_on_theme, backCircleRect.left, backCircleRect.top, paint); } else { canvas.drawRoundRect(backCircleRect, radius, radius, paint); } drawText(canvas, radius); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + backRect.height() - 2 * RIM_SIZE, backRect.height() - RIM_SIZE); frontCircleRect.set(frontRect); paint.setColor(isOpen ? circle_on_color : circle_off_color); if (isOpen && circle_on_bitmap != null) canvas.drawBitmap(circle_on_bitmap, frontCircleRect.left + space, frontCircleRect.top + space, paint); else if (!isOpen && circle_off_bitmap != null) canvas.drawBitmap(circle_off_bitmap, frontCircleRect.left + space, frontCircleRect.top + space, paint); else canvas.drawRoundRect(frontCircleRect, radius, radius, paint); } }
From source file:org.smart.library.widget.SlideSwitch.java
/** * ???//from w w w . j a v a 2 s. co m * * @param canvas */ protected void onDrawDisenable(Canvas canvas) { int radius = backRect.height() / 2 - RIM_SIZE; if (shape == SHAPE_RECT) { if (bitmap_off_theme != null) { canvas.drawBitmap(bitmap_off_theme, backRect.left, backRect.top, paint); } else { paint.setColor(ImageUtils.colorBurn(color_off_theme, 0.1f)); canvas.drawRect(backRect, paint); } paint.setColor(ImageUtils.colorBurn(color_on_theme, 0.1f)); paint.setAlpha(alpha); if (bitmap_on_theme != null) { canvas.drawBitmap(bitmap_on_theme, backRect.left, backRect.top, paint); } else canvas.drawRect(backRect, paint); drawText(canvas, radius); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + getMeasuredWidth() / 2 - RIM_SIZE, getMeasuredHeight() - RIM_SIZE); paint.setColor(ImageUtils.colorBurn(isOpen ? circle_on_color : circle_off_color, 0.1f)); if (isOpen && circle_on_bitmap != null) canvas.drawBitmap(circle_on_bitmap, frontRect.left + space, frontRect.top + space, paint); else if (!isOpen && circle_off_bitmap != null) canvas.drawBitmap(circle_off_bitmap, frontRect.left + space, frontRect.top + space, paint); else canvas.drawRect(frontRect, paint); } else { // draw circle backCircleRect.set(backRect); if (bitmap_off_theme != null) { canvas.drawBitmap(bitmap_off_theme, backCircleRect.left, backCircleRect.top, paint); } else { paint.setColor(color_off_theme); canvas.drawRoundRect(backCircleRect, radius, radius, paint); } paint.setColor(ImageUtils.colorBurn(color_on_theme, 0.1f)); paint.setAlpha(alpha); if (bitmap_on_theme != null) { canvas.drawBitmap(bitmap_on_theme, backCircleRect.left, backCircleRect.top, paint); } else { canvas.drawRoundRect(backCircleRect, radius, radius, paint); } drawText(canvas, radius); frontRect.set(frontRect_left, RIM_SIZE, frontRect_left + backRect.height() - 2 * RIM_SIZE, backRect.height() - RIM_SIZE); frontCircleRect.set(frontRect); paint.setColor(ImageUtils.colorBurn(isOpen ? circle_on_color : circle_off_color, 0.1f)); if (isOpen && circle_on_bitmap != null) canvas.drawBitmap(circle_on_bitmap, frontCircleRect.left + space, frontCircleRect.top + space, paint); else if (!isOpen && circle_off_bitmap != null) canvas.drawBitmap(circle_off_bitmap, frontCircleRect.left + space, frontCircleRect.top + space, paint); else canvas.drawRoundRect(frontCircleRect, radius, radius, paint); } }
From source file:de.vanita5.twittnuker.view.ColorPickerView.java
private void drawAlphaPanel(final Canvas canvas) { if (!mShowAlphaPanel || mAlphaRect == null || mAlphaPattern == null) return;/*from w w w .j a v a 2 s . c om*/ final RectF rect = mAlphaRect; if (BORDER_WIDTH_PX > 0) { mBorderPaint.setColor(mBorderColor); canvas.drawRect(rect.left - BORDER_WIDTH_PX, rect.top - BORDER_WIDTH_PX, rect.right + BORDER_WIDTH_PX, rect.bottom + BORDER_WIDTH_PX, mBorderPaint); } mAlphaPattern.draw(canvas); final float[] hsv = new float[] { mHue, mSat, mVal }; final int color = Color.HSVToColor(hsv); final int acolor = Color.HSVToColor(0, hsv); mAlphaShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top, color, acolor, TileMode.CLAMP); mAlphaPaint.setShader(mAlphaShader); canvas.drawRect(rect, mAlphaPaint); if (mAlphaSliderText != null && mAlphaSliderText != "") { canvas.drawText(mAlphaSliderText, rect.centerX(), rect.centerY() + 4 * mDensity, mAlphaTextPaint); } final float rectWidth = 4 * mDensity / 2; final Point p = alphaToPoint(mAlpha); final RectF r = new RectF(); r.left = p.x - rectWidth; r.right = p.x + rectWidth; r.top = rect.top - RECTANGLE_TRACKER_OFFSET; r.bottom = rect.bottom + RECTANGLE_TRACKER_OFFSET; canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint); }
From source file:com.sflib.CustomView.baseview.RoundRecPagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from w ww.j ava 2s . c om } final int height = 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, doRefresh 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); } float indicator_top = getPaddingTop(); float indicator_botom = currentTab.getHeight() + indicator_top; float indicator_left = lineLeft + getPaddingLeft(); // L.info(this,"indicator_left: "+indicator_left+" lineLeft: "+lineLeft+" padding: "+currentTab.getPaddingLeft()+" currentPositionOffset: "+currentPositionOffset); RectF indicatorRec = new RectF(indicator_left - indicatorLeftRightPadding + tabPadding, indicator_top - indicatorTopBottomPadding, lineRight + indicatorLeftRightPadding - tabPadding, indicator_botom + indicatorTopBottomPadding); canvas.drawRoundRect(indicatorRec, indicatorRectCorner, indicatorRectCorner, rectPaint); // draw underline rectPaint.setColor(underlineColor); RectF rect = new RectF(0, height - underlineHeight, tabsContainer.getWidth(), height); canvas.drawRect(rect, 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); } }