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.android.datetimepicker.time.CircleView.java
@Override public void onDraw(Canvas canvas) { int viewWidth = getWidth(); if (viewWidth == 0 || !mIsInitialized) { return;//from w w w. jav a 2s . co m } if (!mDrawValuesReady) { mXCenter = getWidth() / 2; mYCenter = getHeight() / 2; mCircleRadius = (int) (Math.min(mXCenter, mYCenter) * mCircleRadiusMultiplier); if (!mIs24HourMode) { // We'll need to draw the AM/PM circles, so the main circle will need to have // a slightly higher center. To keep the entire view centered vertically, we'll // have to push it up by half the radius of the AM/PM circles. int amPmCircleRadius = (int) (mCircleRadius * mAmPmCircleRadiusMultiplier); mYCenter -= amPmCircleRadius * 0.75; } mDrawValuesReady = true; } // Draw the white circle. mPaint.setColor(mCircleColor); canvas.drawCircle(mXCenter, mYCenter, mCircleRadius, mPaint); // Draw a small black circle in the center. mPaint.setColor(mDotColor); canvas.drawCircle(mXCenter, mYCenter, 8, mPaint); }
From source file:com.codetroopers.betterpickers.radialtimepicker.CircleView.java
@Override public void onDraw(Canvas canvas) { int viewWidth = getWidth(); if (viewWidth == 0 || !mIsInitialized) { return;/*from w w w. j a v a 2s.c o m*/ } if (!mDrawValuesReady) { mXCenter = getWidth() / 2; mYCenter = getHeight() / 2; mCircleRadius = (int) (Math.min(mXCenter, mYCenter) * mCircleRadiusMultiplier); if (!mIs24HourMode) { // We'll need to draw the AM/PM circles, so the main circle will need to have // a slightly higher center. To keep the entire view centered vertically, we'll // have to push it up by half the radius of the AM/PM circles. int amPmCircleRadius = (int) (mCircleRadius * mAmPmCircleRadiusMultiplier); mYCenter -= amPmCircleRadius / 2; } mDrawValuesReady = true; } // Draw the white circle. mPaint.setColor(mCircleColor); canvas.drawCircle(mXCenter, mYCenter, mCircleRadius, mPaint); // Draw a small black circle in the center. mPaint.setColor(mCentralDotColor); canvas.drawCircle(mXCenter, mYCenter, 2, mPaint); }
From source file:com.kmagic.solitaire.DrawMaster.java
/** * Draw a heart/*from w w w .j a v a2 s. c o m*/ * @param canvas canvas to draw on * @param width width of the heart * @param height height of the heart */ public void drawHeart(final Canvas canvas, final float width, final float height) { final Paint paint = getRedPaint(); final float width_half = width / 2; final float width_quarter = width / 4; final float height_quarter = height / 4; final float height_third = height / 3; canvas.drawCircle(width_quarter, height_quarter, width_quarter, paint); canvas.drawCircle(width_quarter * 3, height_quarter, width_quarter, paint); final Path path = new Path(); path.moveTo(0, height_third); path.lineTo(width_half, height); path.lineTo(width, height_third); path.lineTo(0, height_third); path.close(); canvas.drawPath(path, paint); }
From source file:org.holoeverywhere.widget.datetimepicker.date.SimpleMonthView.java
/** * Draws the week and month day numbers for this week. Override this method * if you need different placement.//from w w w .jav a 2 s .co m * * @param canvas The canvas to draw on */ protected void drawMonthNums(Canvas canvas) { int y = (((mRowHeight + MINI_DAY_NUMBER_TEXT_SIZE) / 2) - DAY_SEPARATOR_WIDTH) + MONTH_HEADER_SIZE; int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2); int j = findDayOffset(); for (int dayNumber = 1; dayNumber <= mNumCells; dayNumber++) { int x = (2 * j + 1) * dayWidthHalf + mPadding; if (mSelectedDay == dayNumber) { canvas.drawCircle(x, y - (MINI_DAY_NUMBER_TEXT_SIZE / 3), DAY_SELECTED_CIRCLE_SIZE, mSelectedCirclePaint); } mMonthNumPaint.setColor(mHasToday && mToday == dayNumber ? mTodayNumberColor : mDayTextColor); canvas.drawText(String.format("%d", dayNumber), x, y, mMonthNumPaint); j++; if (j == mNumDays) { j = 0; y += mRowHeight; } } }
From source file:app.android.datetimepicker.date.SimpleMonthView.java
/** * Draws the week and month day numbers for this week. Override this method * if you need different placement./*from www .j a v a 2 s .c om*/ * * @param canvas The canvas to draw on */ protected void drawMonthNums(Canvas canvas) { int y = (((mRowHeight + MINI_DAY_NUMBER_TEXT_SIZE) / 2) - DAY_SEPARATOR_WIDTH) + MONTH_HEADER_SIZE; int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2); int j = findDayOffset(); for (int dayNumber = 1; dayNumber <= mNumCells; dayNumber++) { int x = (2 * j + 1) * dayWidthHalf + mPadding; if (mSelectedDay == dayNumber) { canvas.drawCircle(x, y - (MINI_DAY_NUMBER_TEXT_SIZE / 3), DAY_SELECTED_CIRCLE_SIZE, mSelectedCirclePaint); } if (mHasToday && mToday == dayNumber) { mMonthNumPaint.setColor(mTodayNumberColor); } else { mMonthNumPaint.setColor(mDayTextColor); } canvas.drawText(String.format("%d", dayNumber), x, y, mMonthNumPaint); j++; if (j == mNumDays) { j = 0; y += mRowHeight; } } }
From source file:android.support.wear.widget.drawer.PageIndicatorView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mNumberOfPositions > 1) { float dotCenterLeft = getPaddingLeft() + (mDotSpacing / 2f); float dotCenterTop = getHeight() / 2f; canvas.save();/* w ww.j a v a 2 s . c o m*/ canvas.translate(dotCenterLeft, dotCenterTop); for (int i = 0; i < mNumberOfPositions; i++) { if (i == mSelectedPosition) { float radius = mDotRadiusSelected + mDotShadowRadius; canvas.drawCircle(mDotShadowDx, mDotShadowDy, radius, mDotPaintShadowSelected); canvas.drawCircle(0, 0, mDotRadiusSelected, mDotPaintSelected); } else { float radius = mDotRadius + mDotShadowRadius; canvas.drawCircle(mDotShadowDx, mDotShadowDy, radius, mDotPaintShadow); canvas.drawCircle(0, 0, mDotRadius, mDotPaint); } canvas.translate(mDotSpacing, 0); } canvas.restore(); } }
From source file:de.dreier.mytargets.features.statistics.StatisticsFragment.java
private void showLineChart() { LineData data = getLineChartDataSet(); if (data == null) { return;//w w w. j a va 2 s .co m } binding.chartView.getXAxis().setTextSize(10); binding.chartView.getXAxis().setTextColor(0xFF848484); binding.chartView.getAxisRight().setEnabled(false); binding.chartView.getLegend().setEnabled(false); binding.chartView.setData(data); final Description desc = new Description(); desc.setText(getString(R.string.average_arrow_score_per_end)); binding.chartView.setDescription(desc); final int maxCeil = (int) Math.ceil(data.getYMax()); binding.chartView.getAxisLeft().setAxisMaximum(maxCeil); binding.chartView.getAxisLeft().setLabelCount(maxCeil); binding.chartView.getAxisLeft().setAxisMinimum(0); binding.chartView.getXAxis().setDrawGridLines(false); binding.chartView.setDoubleTapToZoomEnabled(false); if (animate) { binding.chartView.animateXY(2000, 2000); } binding.chartView.setRenderer(new LineChartRenderer(binding.chartView, binding.chartView.getAnimator(), binding.chartView.getViewPortHandler()) { @Override public void drawHighlighted(Canvas canvas, Highlight[] indices) { mRenderPaint.setStyle(Paint.Style.FILL); List<ILineDataSet> dataSets = mChart.getLineData().getDataSets(); int colorIndex = 0; for (Highlight highlight : indices) { int i = highlight.getDataSetIndex(); ILineDataSet dataSet = dataSets.get(i); mRenderPaint.setColor(dataSet.getCircleColor(colorIndex)); float circleRadius = dataSet.getCircleRadius(); canvas.drawCircle(highlight.getDrawX(), highlight.getDrawY(), circleRadius, mRenderPaint); colorIndex = colorIndex + 1 % dataSet.getCircleColorCount(); } // draws highlight lines (if enabled) super.drawHighlighted(canvas, indices); } }); }
From source file:com.android.yijiang.kzx.widget.betterpickers.calendardatepicker.SimpleMonthView.java
/** * Draws the week and month day numbers for this week. Override this method if you need different placement. * * @param canvas The canvas to draw on/*from ww w. ja va2 s . c om*/ */ protected void drawMonthNums(Canvas canvas) { int y = (((mRowHeight + sMiniDayNumberTextSize) / 2) - DAY_SEPARATOR_WIDTH) + sMonthHeaderSize; int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2); int j = findDayOffset(); for (int dayNumber = 1; dayNumber <= mNumCells; dayNumber++) { int x = (2 * j + 1) * dayWidthHalf + mPadding; if (mSelectedDay == dayNumber) { canvas.drawCircle(x, y - (sMiniDayNumberTextSize / 3), sDaySelectedCircleSize, mSelectedCirclePaint); } if (mHasToday && mToday == dayNumber) { mMonthNumPaint.setColor(mTodayNumberColor); } else { mMonthNumPaint.setColor(mDayTextColor); } canvas.drawText(String.format("%d", dayNumber), x, y, mMonthNumPaint); j++; if (j == mNumDays) { j = 0; y += mRowHeight; } } }
From source file:io.doist.datetimepicker.date.SimpleMonthView.java
/** * Draws the month days.// w w w.j a v a 2s.c om */ private void drawDays(Canvas canvas) { int y = (((mRowHeight + mMiniDayNumberTextSize) / 2) - DAY_SEPARATOR_WIDTH) + mMonthHeaderSize; int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2); int j = findDayOffset(); for (int day = 1; day <= mNumCells; day++) { int x = (2 * j + 1) * dayWidthHalf + mPadding; if (mSelectedDay == day) { canvas.drawCircle(x, y - (mMiniDayNumberTextSize / 3), mDaySelectedCircleSize, mDayNumberSelectedPaint); } if (mHasToday && mToday == day) { mDayNumberPaint.setColor(mSelectedDayColor); } else { mDayNumberPaint.setColor(mNormalTextColor); } final Paint paint = (day < mEnabledDayStart || day > mEnabledDayEnd) ? mDayNumberDisabledPaint : mDayNumberPaint; canvas.drawText(String.format("%d", day), x, y, paint); j++; if (j == mNumDays) { j = 0; y += mRowHeight; } } }
From source file:com.karthikb351.vitinfo2.customwidget.TimeLineView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); width = getWidth();/*from ww w .j a v a 2 s. c o m*/ height = getHeight(); cx = width / 2; cy = PADDING_TOP + CIRCLE_RADIUS; switch (widgetState) { case STATE_CURRENT: rectF.set(cx - BORDER_THICKNESS, cy - BORDER_THICKNESS, cx + BORDER_THICKNESS, cy + BORDER_THICKNESS); mPath.reset(); for (int i = 0; i <= 360; i++) { mPath.addArc(rectF, i, 1); } canvas.drawPath(mPath, paintBorder); case STATE_SCHEDULED: rectF.set(cx - CIRCLE_RADIUS, cy - CIRCLE_RADIUS, cx + CIRCLE_RADIUS, cy + CIRCLE_RADIUS); mPath.reset(); for (int i = 0; i <= 360; i += 1) { mPath.addArc(rectF, i, 1); } canvas.drawPath(mPath, paintRing); break; case STATE_FINISHED: canvas.drawCircle(cx, cy, CIRCLE_RADIUS, paintDot); break; } switch (widgetType) { case TYPE_INITIAL: canvas.drawLine(cx, cy + (11 * density), cx, height, paintLine); break; case TYPE_INNER: canvas.drawLine(cx, cy - (11 * density), cx, 0, paintLine); canvas.drawLine(cx, cy + (11 * density), cx, height, paintLine); break; case TYPE_END: canvas.drawLine(cx, cy - (11 * density), cx, 0, paintLine); break; } }