List of usage examples for android.graphics Canvas drawCircle
public void drawCircle(float cx, float cy, float radius, @NonNull Paint paint)
From source file:com.shawnway.nav.app.wtw.view.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { if (isInEditMode() || tabCount == 0) { return;/*from w w w. j a va 2s. c o m*/ } 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, startWeChat 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); } switch (indicatorStyle) { case STYLE_CIRCLE: canvas.drawCircle((lineLeft + lineRight) / 2, (currentTab.getTop() + currentTab.getBottom()) / 2, circleSize, rectPaint); break; case STYLE_RECTANGLE: drawRectangle(canvas, height, currentTab, lineLeft, lineRight); break; case STYLE_NORMAL: drawNormalUnderLine(canvas, height, currentTab, lineLeft, lineRight); default: break; } super.onDraw(canvas); // // 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:info.bartowski.easteregg.MLand.java
@Override public void onDraw(Canvas c) { super.onDraw(c); if (SHOW_TOUCHES) { for (Player p : mPlayers) { if (p.mTouchX > 0) { mTouchPaint.setColor(0x80FFFFFF & p.color); mPlayerTracePaint.setColor(0x80FFFFFF & p.color); float x1 = p.mTouchX; float y1 = p.mTouchY; c.drawCircle(x1, y1, 100, mTouchPaint); float x2 = p.getX() + p.getPivotX(); float y2 = p.getY() + p.getPivotY(); float angle = PI_2 - (float) Math.atan2(x2 - x1, y2 - y1); x1 += 100 * Math.cos(angle); y1 += 100 * Math.sin(angle); c.drawLine(x1, y1, x2, y2, mPlayerTracePaint); }//from w w w . j av a2s.c o m } } if (!DEBUG_DRAW) return; final Paint pt = new Paint(); pt.setColor(0xFFFFFFFF); for (Player p : mPlayers) { final int L = p.corners.length; final int N = L / 2; for (int i = 0; i < N; i++) { final int x = (int) p.corners[i * 2]; final int y = (int) p.corners[i * 2 + 1]; c.drawCircle(x, y, 4, pt); c.drawLine(x, y, p.corners[(i * 2 + 2) % L], p.corners[(i * 2 + 3) % L], pt); } } pt.setStyle(Paint.Style.STROKE); pt.setStrokeWidth(getResources().getDisplayMetrics().density); final int M = getChildCount(); pt.setColor(0x8000FF00); for (int i = 0; i < M; i++) { final View v = getChildAt(i); if (v instanceof Player) continue; if (!(v instanceof GameView)) continue; if (v instanceof Pop) { final Pop pop = (Pop) v; c.drawCircle(pop.cx, pop.cy, pop.r, pt); } else { final Rect r = new Rect(); v.getHitRect(r); c.drawRect(r, pt); } } pt.setColor(Color.BLACK); final StringBuilder sb = new StringBuilder("obstacles: "); for (Obstacle ob : mObstaclesInPlay) { sb.append(ob.hitRect.toShortString()); sb.append(" "); } pt.setTextSize(20f); c.drawText(sb.toString(), 20, 100, pt); }
From source file:org.akvo.caddisfly.sensor.colorimetry.strip.widget.PercentageMeterView.java
@Override public void onDraw(@NonNull Canvas canvas) { if (Float.isNaN(percentage)) { return;/* w ww.ja v a2 s. c o m*/ } double number = (100 - percentage) * NUMBER_OF_BARS * PERCENT; canvas.save(); // Set each dot's diameter to half the canvas height canvas.translate( canvas.getWidth() / 2f - ((canvas.getHeight() / 2f + GUTTER_SPACE) * ((NUMBER_OF_BARS - 1) / 2f)), 0); for (double i = 0; i < NUMBER_OF_BARS; i++) { // Reset color paint.setColor(Color.LTGRAY); if (number >= 0) { if (i < 2) { // Red if number is lower than i + 1 // 2 red dots if number < 1 or 1 red dot if number > 1 if (number <= i + 1) { paint.setColor(red); } } else if (i < 4) { // Orange if number between 1 and 4 // if number == 1.5 then 1 red followed by orange dot // if number == 2.5 then 2 orange dots // if number == 3.5 then 1 orange dot if (number >= i - 1 && number <= i + 2) { paint.setColor(orange); } } else { if (number > i) { // Green if number larger than 3 but yellow if number exceeds optimum if (number > NUMBER_OF_BARS) { paint.setColor(Color.YELLOW); } else { paint.setColor(green); } } } } canvas.drawCircle(0, canvas.getHeight() / 2f, canvas.getHeight() / 4f, paint); // Position next circle canvas.translate(canvas.getHeight() / 2f + GUTTER_SPACE, 0); } canvas.restore(); super.onDraw(canvas); }
From source file:com.savvasdalkitsis.betwixt.demo.InterpolatorView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(Color.WHITE); int inset = (getHeight() - rectHeight()) / 2; canvas.drawRect(getPaddingLeft(), getPaddingTop() + inset, getWidth() - getPaddingRight(), getHeight() - inset - getPaddingBottom(), rectPaint); float x = 0;/*from ww w . j a v a 2 s . c o m*/ float y = 0; for (int i = 0; i < STEPS; i++) { float newX = i / (float) STEPS; float newY = interpolator.getInterpolation(newX); if (i == 0) { x = newX; y = newY; } canvas.drawLine(x(x), y(y), x(newX), y(newY), paint); x = newX; y = newY; } canvas.drawText(description, getPaddingLeft() + textPaddingLeft, getHeight() - textHeight, textPaint); if (animating) { canvas.drawRect(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(), getHeight() - getPaddingBottom(), dim); int areaWidth = getWidth() - getPaddingLeft() - getPaddingRight() - animationInset * 2; float circleX = getPaddingLeft() + animationInset + areaWidth * progress; linePath.reset(); linePath.moveTo(getPaddingLeft() + animationInset, getPaddingTop()); linePath.lineTo(getPaddingLeft() + animationInset, getHeight() - getPaddingBottom()); linePath.moveTo(getWidth() - getPaddingRight() - animationInset, getPaddingTop()); linePath.lineTo(getWidth() - getPaddingRight() - animationInset, getHeight() - getPaddingBottom()); canvas.drawPath(linePath, linePaint); canvas.drawCircle(circleX, getHeight() / 2, radius, circlePaint); } }
From source file:com.androtex.viewpagerindicator.CirclePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int longSize; int longPaddingBefore; int longPaddingAfter; int shortPaddingBefore; if (mOrientation == HORIZONTAL) { longSize = getWidth();/*from ww w . jav a 2 s .c om*/ longPaddingBefore = getPaddingLeft(); longPaddingAfter = getPaddingRight(); shortPaddingBefore = getPaddingTop(); } else { longSize = getHeight(); longPaddingBefore = getPaddingTop(); longPaddingAfter = getPaddingBottom(); shortPaddingBefore = getPaddingLeft(); } final int count = mViewPager.getAdapter().getCount(); final float threeRadius = mRadius * 3; final float shortOffset = shortPaddingBefore + mRadius; float longOffset = longPaddingBefore + mRadius; if (mCentered) { longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((count * threeRadius) / 2.0f); } float dX; float dY; //Draw stroked circles for (int iLoop = 0; iLoop < count; iLoop++) { float drawLong = longOffset + (iLoop * threeRadius); if (mOrientation == HORIZONTAL) { dX = drawLong; dY = shortOffset; } else { dX = shortOffset; dY = drawLong; } canvas.drawCircle(dX, dY, mRadius, mPaintStroke); } //Draw the filled circle according to the current scroll float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius; if (!mSnap && (mPageSize != 0)) { cx += (mCurrentOffset * 1.0f / mPageSize) * threeRadius; } if (mOrientation == HORIZONTAL) { dX = longOffset + cx; dY = shortOffset; } else { dX = shortOffset; dY = longOffset + cx; } canvas.drawCircle(dX, dY, mRadius, mPaintFill); }
From source file:radialdemo.RadialMenuWidget.java
@Override protected void onDraw(Canvas c) { Paint paint = new Paint(); paint.setAntiAlias(true);/*from w w w. j a v a2s .c o m*/ paint.setStrokeWidth(3); // draws a dot at the source of the press if (showSource == true) { paint.setColor(outlineColor); paint.setAlpha(outlineAlpha); paint.setStyle(Paint.Style.STROKE); c.drawCircle(xSource, ySource, cRadius / 10, paint); paint.setColor(selectedColor); paint.setAlpha(selectedAlpha); paint.setStyle(Paint.Style.FILL); c.drawCircle(xSource, ySource, cRadius / 10, paint); } //inner for (int i = 0; i < Wedges.length; i++) { RadialMenuWedge f = Wedges[i]; paint.setColor(outlineColor); paint.setAlpha(outlineAlpha); paint.setStyle(Paint.Style.STROKE); c.drawPath(f, paint); if (f == enabled && Wedge2Shown == true) { paint.setColor(wedge2Color); paint.setAlpha(wedge2Alpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } else if (f != enabled && Wedge2Shown == true) { paint.setColor(disabledColor); paint.setAlpha(disabledAlpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } else if (f == enabled && Wedge2Shown == false) { paint.setColor(wedge2Color); paint.setAlpha(wedge2Alpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } else if (f == selected) { paint.setColor(wedge2Color); paint.setAlpha(wedge2Alpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } else { paint.setColor(defaultColor); paint.setAlpha(defaultAlpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } //button content Rect rf = iconRect[i]; if ((menuEntries.get(i).getIcon() != 0) && (menuEntries.get(i).getLabel() != null)) { // This will look for a "new line" and split into multiple lines String menuItemName = menuEntries.get(i).getLabel(); String[] stringArray = menuItemName.split("\n"); paint.setColor(textColor); if (f != enabled && Wedge2Shown == true) { paint.setAlpha(disabledAlpha); } else { paint.setAlpha(textAlpha); } paint.setStyle(Paint.Style.FILL); paint.setTextSize(textSize); Rect rect = new Rect(); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); textHeight = textHeight + (rect.height() + 3); } Rect rf2 = new Rect(); rf2.set(rf.left, rf.top - ((int) textHeight / 2), rf.right, rf.bottom - ((int) textHeight / 2)); float textBottom = rf2.bottom; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); float textLeft = rf.centerX() - rect.width() / 2; textBottom = textBottom + (rect.height() + 3); c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint); } // Puts in the Icon Drawable drawable = getResources().getDrawable(menuEntries.get(i).getIcon()); drawable.setBounds(rf2); if (f != enabled && Wedge2Shown == true) { drawable.setAlpha(disabledAlpha); } else { drawable.setAlpha(pictureAlpha); } drawable.draw(c); // Icon Only } else if (menuEntries.get(i).getIcon() != 0) { // Puts in the Icon Drawable drawable = getResources().getDrawable(menuEntries.get(i).getIcon()); drawable.setBounds(rf); if (f != enabled && Wedge2Shown == true) { drawable.setAlpha(disabledAlpha); } else { drawable.setAlpha(pictureAlpha); } drawable.draw(c); // Text Only } else { // Puts in the Text if no Icon paint.setColor(textColor); if (f != enabled && Wedge2Shown == true) { paint.setAlpha(disabledAlpha); } else { paint.setAlpha(textAlpha); } paint.setStyle(Paint.Style.FILL); paint.setTextSize(textSize + 10); // This will look for a "new line" and split into multiple lines String menuItemName = menuEntries.get(i).getLabel(); String[] stringArray = menuItemName.split("\n"); // gets total height Rect rect = new Rect(); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); textHeight = textHeight + (rect.height() + 3); } float textBottom = rf.centerY() - (textHeight / 2); for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); float textLeft = rf.centerX() - rect.width() / 2; textBottom = textBottom + (rect.height() + 3); c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint); } } } // Animate the outer ring in/out if (animateOuterIn == true) { animateOuterWedges(ANIMATE_IN); } else if (animateOuterOut == true) { animateOuterWedges(ANIMATE_OUT); } //outer if (Wedge2Shown == true) { for (int i = 0; i < Wedges2.length; i++) { RadialMenuWedge f = Wedges2[i]; paint.setColor(outlineColor); paint.setAlpha(20); paint.setStyle(Paint.Style.STROKE); c.drawPath(f, paint); if (f == selected2) { paint.setColor(selectedColor); paint.setAlpha(selectedAlpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } else { paint.setColor(wedge2Color); paint.setAlpha(wedge2Alpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } Rect rf = iconRect2[i]; if ((wedge2Data.getChildren().get(i).getIcon() != 0) && (wedge2Data.getChildren().get(i).getLabel() != null)) { // This will look for a "new line" and split into multiple // lines String menuItemName = wedge2Data.getChildren().get(i).getLabel(); String[] stringArray = menuItemName.split("\n"); paint.setColor(textColor); paint.setAlpha(textAlpha); paint.setStyle(Paint.Style.FILL); paint.setTextSize(animateTextSize); Rect rect = new Rect(); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); textHeight = textHeight + (rect.height() + 3); } Rect rf2 = new Rect(); rf2.set(rf.left, rf.top - ((int) textHeight / 2), rf.right, rf.bottom - ((int) textHeight / 2)); float textBottom = rf2.bottom; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); float textLeft = rf.centerX() - rect.width() / 2; textBottom = textBottom + (rect.height() + 3); c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint); } // Puts in the Icon Drawable drawable = getResources().getDrawable(wedge2Data.getChildren().get(i).getIcon()); drawable.setBounds(rf2); drawable.setAlpha(pictureAlpha); drawable.draw(c); // Icon Only } else if (wedge2Data.getChildren().get(i).getIcon() != 0) { // Puts in the Icon Drawable drawable = getResources().getDrawable(wedge2Data.getChildren().get(i).getIcon()); drawable.setBounds(rf); drawable.setAlpha(pictureAlpha); drawable.draw(c); // Text Only } else { // Puts in the Text if no Icon paint.setColor(textColor); paint.setAlpha(textAlpha); paint.setStyle(Paint.Style.FILL); paint.setTextSize(animateTextSize); // This will look for a "new line" and split into multiple // lines String menuItemName = wedge2Data.getChildren().get(i).getLabel(); String[] stringArray = menuItemName.split("\n"); // gets total height Rect rect = new Rect(); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); textHeight = textHeight + (rect.height() + 3); } float textBottom = rf.centerY() - (textHeight / 2); for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); float textLeft = rf.centerX() - rect.width() / 2; textBottom = textBottom + (rect.height() + 3); c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint); } } } } //Check if the user has given input for centre circle if (centerCircle != null) { // Draws the Middle Circle paint.setColor(outlineColor); paint.setAlpha(outlineAlpha); paint.setStyle(Paint.Style.STROKE); c.drawCircle(xPosition, yPosition, cRadius, paint); if (inCircle == true) { paint.setColor(selectedColor); paint.setAlpha(selectedAlpha); paint.setStyle(Paint.Style.FILL); c.drawCircle(xPosition, yPosition, cRadius, paint); helper.onCloseAnimation(this, xPosition, yPosition, xSource, ySource); } else { paint.setColor(defaultColor); paint.setAlpha(defaultAlpha); paint.setStyle(Paint.Style.FILL); c.drawCircle(xPosition, yPosition, cRadius, paint); } // Draw the circle picture if ((centerCircle.getIcon() != 0) && (centerCircle.getLabel() != null)) { // This will look for a "new line" and split into multiple lines String menuItemName = centerCircle.getLabel(); String[] stringArray = menuItemName.split("\n"); paint.setColor(textColor); paint.setAlpha(textAlpha); paint.setStyle(Paint.Style.FILL); paint.setTextSize(textSize); Rect rectText = new Rect(); Rect rectIcon = new Rect(); Drawable drawable = getResources().getDrawable(centerCircle.getIcon()); int h = getIconSize(drawable.getIntrinsicHeight(), MinIconSize, MaxIconSize); int w = getIconSize(drawable.getIntrinsicWidth(), MinIconSize, MaxIconSize); rectIcon.set(xPosition - w / 2, yPosition - h / 2, xPosition + w / 2, yPosition + h / 2); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rectText); textHeight = textHeight + (rectText.height() + 3); } rectIcon.set(rectIcon.left, rectIcon.top - ((int) textHeight / 2), rectIcon.right, rectIcon.bottom - ((int) textHeight / 2)); float textBottom = rectIcon.bottom; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rectText); float textLeft = xPosition - rectText.width() / 2; textBottom = textBottom + (rectText.height() + 3); c.drawText(stringArray[j], textLeft - rectText.left, textBottom - rectText.bottom, paint); } // Puts in the Icon drawable.setBounds(rectIcon); drawable.setAlpha(pictureAlpha); drawable.draw(c); // Icon Only } else if (centerCircle.getIcon() != 0) { Rect rect = new Rect(); Drawable drawable = getResources().getDrawable(centerCircle.getIcon()); int h = getIconSize(drawable.getIntrinsicHeight(), MinIconSize, MaxIconSize); int w = getIconSize(drawable.getIntrinsicWidth(), MinIconSize, MaxIconSize); rect.set(xPosition - w / 2, yPosition - h / 2, xPosition + w / 2, yPosition + h / 2); drawable.setBounds(rect); drawable.setAlpha(pictureAlpha); drawable.draw(c); // Text Only } else { // Puts in the Text if no Icon paint.setColor(textColor); paint.setAlpha(textAlpha); paint.setStyle(Paint.Style.FILL); paint.setTextSize(textSize); // This will look for a "new line" and split into multiple lines String menuItemName = centerCircle.getLabel(); String[] stringArray = menuItemName.split("\n"); // gets total height Rect rect = new Rect(); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); textHeight = textHeight + (rect.height() + 3); } float textBottom = yPosition - (textHeight / 2); for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); float textLeft = xPosition - rect.width() / 2; textBottom = textBottom + (rect.height() + 3); c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint); } } } // Draws Text in TextBox if (headerString != null) { paint.setTextSize(headerTextSize); paint.getTextBounds(headerString, 0, headerString.length(), this.textRect); if (HeaderBoxBounded == false) { determineHeaderBox(); HeaderBoxBounded = true; } paint.setColor(outlineColor); paint.setAlpha(outlineAlpha); paint.setStyle(Paint.Style.STROKE); c.drawRoundRect(this.textBoxRect, scalePX(5), scalePX(5), paint); paint.setColor(headerBackgroundColor); paint.setAlpha(headerBackgroundAlpha); paint.setStyle(Paint.Style.FILL); c.drawRoundRect(this.textBoxRect, scalePX(5), scalePX(5), paint); paint.setColor(headerTextColor); paint.setAlpha(headerTextAlpha); paint.setStyle(Paint.Style.FILL); paint.setTextSize(headerTextSize); c.drawText(headerString, headerTextLeft, headerTextBottom, paint); } }
From source file:de.vanita5.twittnuker.view.ColorPickerView.java
private void drawSatValPanel(final Canvas canvas) { final RectF rect = mSatValRect; if (BORDER_WIDTH_PX > 0) { mBorderPaint.setColor(mBorderColor); canvas.drawRect(mDrawingRect.left, mDrawingRect.top, rect.right + BORDER_WIDTH_PX, rect.bottom + BORDER_WIDTH_PX, mBorderPaint); }/* w w w . jav a2 s . c o m*/ if (mValShader == null) { mValShader = new LinearGradient(rect.left, rect.top, rect.left, rect.bottom, 0xffffffff, 0xff000000, TileMode.CLAMP); } final int rgb = Color.HSVToColor(new float[] { mHue, 1f, 1f }); mSatShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top, 0xffffffff, rgb, TileMode.CLAMP); final ComposeShader mShader = new ComposeShader(mValShader, mSatShader, PorterDuff.Mode.MULTIPLY); mSatValPaint.setShader(mShader); canvas.drawRect(rect, mSatValPaint); final Point p = satValToPoint(mSat, mVal); mSatValTrackerPaint.setColor(0xff000000); canvas.drawCircle(p.x, p.y, PALETTE_CIRCLE_TRACKER_RADIUS - 1f * mDensity, mSatValTrackerPaint); mSatValTrackerPaint.setColor(0xffdddddd); canvas.drawCircle(p.x, p.y, PALETTE_CIRCLE_TRACKER_RADIUS, mSatValTrackerPaint); }
From source file:com.tr4android.support.extension.picker.date.SimpleMonthView.java
/** * Draws the month days./*w w w.j a v a 2 s . c o m*/ */ private void drawDays(Canvas canvas) { final TextPaint p = mDayPaint; final int headerHeight = mMonthHeight + mDayOfWeekHeight; final int rowHeight = mDayHeight; final int colWidth = mCellWidth; // Text is vertically centered within the row height. final float halfLineHeight = (p.ascent() + p.descent()) / 2f; int rowCenter = headerHeight + rowHeight / 2; for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) { final int colCenter = colWidth * col + colWidth / 2; final int colCenterRtl; if (ViewCompatUtils.isLayoutRtl(this)) { colCenterRtl = mPaddedWidth - colCenter; } else { colCenterRtl = colCenter; } int state = 0; final boolean isDayEnabled = isDayEnabled(day); final boolean isDayActivated = mActivatedDay == day; if (isDayActivated) { state = VIEW_STATE_SELECTED; // Adjust the circle to be centered on the row. canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDaySelectorPaint); } else if (mTouchedItem == day) { state = VIEW_STATE_PRESSED; if (isDayEnabled) { // Adjust the circle to be centered on the row. canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDayHighlightPaint); } } final boolean isDayToday = mToday == day; final int dayTextColor; if (isDayToday && !isDayActivated) { dayTextColor = mDaySelectorPaint.getColor(); } else { final int[] stateSet = buildState(isDayEnabled, state); dayTextColor = mDayTextColor.getColorForState(stateSet, 0); } p.setColor(dayTextColor); canvas.drawText(mDayFormatter.format(day), colCenterRtl, rowCenter - halfLineHeight, p); col++; if (col == DAYS_IN_WEEK) { col = 0; rowCenter += rowHeight; } } }
From source file:com.brookmanholmes.bma.wizard.ui.StepPagerStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (pageCount == 0) { return;//from w w w . ja v a2s .com } float totalWidth = pageCount * (tabWidth + indicatorSpacing) - indicatorSpacing; float totalcx; float cy; boolean fillHorizontal = false; switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: totalcx = (getWidth() - totalWidth) / 2; break; case Gravity.RIGHT: totalcx = getWidth() - getPaddingRight() - totalWidth; break; case Gravity.FILL_HORIZONTAL: totalcx = getPaddingLeft(); fillHorizontal = true; break; default: totalcx = getPaddingLeft(); } switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.CENTER_VERTICAL: cy = (int) (getHeight() - tabHeight) / 2; break; case Gravity.BOTTOM: cy = getHeight() - getPaddingBottom() - tabHeight; break; default: cy = getPaddingTop(); } float center = cy + tabHeight / 2; float tabWidth = this.tabWidth; if (fillHorizontal) { tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft() - (pageCount - 1) * indicatorSpacing) / pageCount; } for (int i = 0; i < pageCount; i++) { float cx = totalcx + (i * (tabWidth + indicatorSpacing)); Paint tempPaint; if (i < currentPage) tempPaint = prevTabPaint; else if (i > currentPage) tempPaint = nextTabPaint; else tempPaint = selectedTabPaint; canvas.drawCircle(cx, center, i == currentPage ? radius : nonCurrentRadius, tempPaint); } }
From source file:com.rexmtorres.android.patternlock.PatternLockView.java
/** * @param partOfPattern Whether this circle is part of the pattern. */// w ww . j av a2 s.co m private void drawDot(Canvas canvas, float centerX, float centerY, float radius, boolean partOfPattern, float alpha, Bitmap oDotBitmap) { mPaint.setColor(getCurrentColor(partOfPattern)); mPaint.setAlpha((int) (alpha * 255)); // If the bitmap is set, draw it. If not, draw a circle. if (oDotBitmap != null) { float nBitmapCenterX = centerX - (oDotBitmap.getScaledHeight(canvas) / 2f); float nBitmapCenterY = centerY - (oDotBitmap.getScaledWidth(canvas) / 2f); canvas.drawBitmap(oDotBitmap, nBitmapCenterX, nBitmapCenterY, mPaint); } else { canvas.drawCircle(centerX, centerY, radius, mPaint); } }