List of usage examples for android.graphics Canvas drawLine
public void drawLine(float startX, float startY, float stopX, float stopY, @NonNull Paint paint)
From source file:com.dirkgassen.wator.ui.view.RangeSlider.java
/** * Draws the view/*from w ww.ja v a 2 s . c o m*/ * @param canvas canvas to paint on */ @Override protected void onDraw(Canvas canvas) { int paddingLeft = getPaddingLeft(); int paddingTop = getPaddingTop(); int paddingRight = getPaddingRight(); int paddingBottom = getPaddingBottom(); int sliderY = (getHeight() - paddingTop - paddingBottom) / 2 + paddingTop; canvas.drawLine(paddingLeft + thumbSize / 2, sliderY, getWidth() - paddingRight - thumbSize / 2, sliderY, sliderPaint); String valueString = String.format(Locale.getDefault(), thumbFormat, value); final float valueWidth = (thumbTextPaint.measureText(valueString, 0, valueString.length())); float thumbTip = positionFromValue(paddingLeft, paddingRight); if (thumbPath.isEmpty()) { thumbPath.addCircle(thumbTip, sliderY, thumbSize / 2, Path.Direction.CW); } else { thumbPath.offset(thumbTip, 0); } canvas.drawPath(thumbPath, thumbBackgroundPaint); canvas.drawText(valueString, thumbTip - valueWidth / 2, sliderY + (-thumbTextPaint.ascent()) / 2, thumbTextPaint); thumbPath.offset(-thumbTip, 0); }
From source file:kr.co.nqk.rfa.customview.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/* www . ja v a2s . c o m*/ } final int height = getHeight(); // 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); } // draw underline rectPaint.setColor(underlineColor); if (indicatorTop) { canvas.drawRect(0, 0, tabsContainer.getWidth(), underlineHeight, rectPaint); } else { canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); } // 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); } if (indicatorTop) { canvas.drawRect(lineLeft, 0, lineRight, indicatorHeight, rectPaint); } else { canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint); } }
From source file:com.richtodd.android.quiltdesign.block.PaperPiecedBlockPiece.java
private void renderShadow(Canvas canvas, RenderOptions renderOptions) { List<PointF> points = getPoints(renderOptions.getWidth(), renderOptions.getHeight()); PointF fromPoint = points.get(0);/* www .j a va2s.co m*/ PointF toPoint = points.get(1); if (fromPoint.y != 0f || toPoint.y != 0f) { float fromX = renderOptions.getLeft() + fromPoint.x; float fromY = renderOptions.getTop() + fromPoint.y; float toX = renderOptions.getLeft() + toPoint.x; float toY = renderOptions.getTop() + toPoint.y; canvas.drawLine(fromX, fromY, toX, toY, getShadowPaint(renderOptions.getLeft(), renderOptions.getTop(), renderOptions.getWidth(), renderOptions.getHeight(), 20)); } }
From source file:com.morninz.ninepinview.widget.NinePINView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // draw circles around center points and connection line int drawnCount = mDrawnPoints.size(); for (int j = 0; j < drawnCount; j++) { Point p1 = mDrawnPoints.get(j); canvas.drawCircle(p1.x, p1.y, mCircleRadius, mCirclePaint); if (j + 1 < drawnCount) { Point p2 = mDrawnPoints.get(j + 1); canvas.drawCircle(p2.x, p2.y, mCircleRadius, mCirclePaint); canvas.drawLine(p1.x, p1.y, p2.x, p2.y, mLinePaint); if (mWillDrawWrongTriangle) { // compute the wrong triangle's direction of this point. float angle = 0.f; if (p2.y == p1.y) {// x-axis angle = p2.x > p1.x ? 0.f : 180.f; } else if (p2.x == p1.x) { // y-axis angle = p2.y > p1.y ? 90.f : -90.f; } else {// in quadrants double tanA = ((double) p2.y - (double) p1.y) / ((double) p2.x - (double) p1.x); // in 1 or 4 quadrant angle = (float) (Math.atan(tanA) * 180 / Math.PI); // in 2 or 3 quadrant if (p2.x < p1.x) { angle += 180.f;//from www. j a v a 2 s. c o m } } Log.d(TAG, "angle " + angle); canvas.save(); canvas.rotate(angle, p1.x, p1.y); canvas.drawPath(mWrongPaths[p1.index], mWrongPaint); canvas.restore(); } } } // draw extra connection line if (mLastDrawnPoint != null) { canvas.drawLine(mLastDrawnPoint.x, mLastDrawnPoint.y, mCurrX, mCurrY, mLinePaint); } // draw 9 center points for (int i = 0; i < POINT_COUNT; i++) { Point p = mCenterPoints[i]; canvas.drawCircle(p.x, p.y, mPointSize, mPointPaint); } }
From source file:com.ryann10.pagerslidingtabstripsample.PagerSlidingTabStrip.java
@Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from w w w . j a v a 2s. c o m } final int height = getHeight(); // 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); } // 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); }
From source file:com.example.view.wheel.WheelView.java
/** * Draws rect for current value/*w ww. j a v a2s . c o m*/ * @param canvas the canvas for drawing */ private void drawCenterRect(Canvas canvas) { int center = getHeight() / 2; int offset = getItemHeight() / 2; // centerDrawable.setBounds(0, center - offset, getWidth(), center + offset); // centerDrawable.draw(canvas); canvas.drawLine(getWidth() / 2 - 100, center - offset, getWidth() / 2 + 100, center - offset, linePaint); canvas.drawLine(getWidth() / 2 - 100, center + offset, getWidth() / 2 + 100, center + offset, linePaint); }
From source file:com.wanikani.androidnotifier.graph.TYPlot.java
/** * Draws the grinds on the canvas. Since they are "over" the plot, this * method should be called last//from ww w . j ava 2s. c om * @param canvas the canvas */ protected void drawGrid(Canvas canvas) { float f, dateLabelBaseline, levelupBaseline; Map<Integer, Pager.Marker> markers; Pager.Marker marker; int d, lo, hi, ascent; DateFormat df; String s; Calendar cal; canvas.drawLine(meas.plotArea.left, meas.plotArea.bottom, meas.plotArea.right, meas.plotArea.bottom, pas.axisPaint); f = vp.getRelPosition(0); lo = vp.leftmostDay(); hi = vp.rightmostDay(); cal = taxis.dayToCalendar(lo); markers = pager.dsource.getMarkers(); ascent = (int) pas.dateLabels.getFontMetrics().ascent; dateLabelBaseline = meas.plotArea.bottom - ascent + meas.tickSize / 2; levelupBaseline = meas.plotArea.top - meas.tickSize / 2; for (d = meas.yaxisGrid; vp.getY(d) >= meas.plotArea.top; d += meas.yaxisGrid) canvas.drawLine(meas.plotArea.left, vp.getY(d), meas.plotArea.right, vp.getY(d), pas.gridPaint); for (d = lo; d <= hi; d++) { f = vp.getRelPosition(d); if (d == 0 || d == taxis.today) canvas.drawLine(f, meas.plotArea.top, f, meas.plotArea.bottom, pas.axisPaint); else if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) canvas.drawLine(f, meas.plotArea.top, f, meas.plotArea.bottom, pas.gridPaint); if (cal.get(Calendar.DAY_OF_MONTH) == 1) { df = cal.get(Calendar.MONTH) == Calendar.JANUARY ? janf : datef; s = df.format(cal.getTime()); canvas.drawLine(f, meas.plotArea.bottom - meas.tickSize / 2, f, meas.plotArea.bottom + meas.tickSize / 2, pas.axisPaint); canvas.drawText(s, f, dateLabelBaseline, pas.dateLabels); } marker = markers.get(d); if (marker != null) { pas.levelup.setColor(marker.color); canvas.drawLine(f, meas.plotArea.top, f, meas.plotArea.bottom, pas.levelup); canvas.drawText(marker.name, f, levelupBaseline, pas.levelup); } cal.add(Calendar.DATE, 1); } }
From source file:de.tlabs.ssr.g1.client.SourcesView.java
private void recalculateSizeScale() { float sizeInMeters; double upperBoundingPowOfTen; double scaleLengthInMeters; float scaleLengthInPixels; float scaleStartInPixels = 20.0f; // get size of short display edge in meters sizeInMeters = inverseViewportTransformation .mapRadius(Math.min(getWidth(), getHeight()) - scaleStartInPixels * 2.0f); // find upper bounding power of ten (0.01, 0.1, 1, 10, 100, etc.) if (sizeInMeters > 1.0) { upperBoundingPowOfTen = 10.0;//from w w w. j a va 2 s . c o m while (true) { if (sizeInMeters / upperBoundingPowOfTen > 1.0f) { upperBoundingPowOfTen *= 10.0; } else { break; } } } else { upperBoundingPowOfTen = 1.0; while (true) { if (sizeInMeters / upperBoundingPowOfTen >= 0.1f) { break; } else { upperBoundingPowOfTen *= 0.1; } } } // map to subdivisions scaleLengthInMeters = sizeInMeters / upperBoundingPowOfTen; if (scaleLengthInMeters > 0.75) scaleLengthInMeters = 0.75; else if (scaleLengthInMeters > 0.5) scaleLengthInMeters = 0.5; else if (scaleLengthInMeters > 0.3) scaleLengthInMeters = 0.3; else if (scaleLengthInMeters > 0.2) scaleLengthInMeters = 0.2; else if (scaleLengthInMeters > 0.15) scaleLengthInMeters = 0.15; else scaleLengthInMeters = 0.1; scaleLengthInMeters *= upperBoundingPowOfTen; // get corresponding scale length in pixels scaleLengthInPixels = viewportTransformation.mapRadius((float) scaleLengthInMeters); // generate picture Canvas canvas = sizeScalePicture.beginRecording(0, 0); float y = getHeight() - 5.0f; float xHalf = scaleStartInPixels + scaleLengthInPixels / 2.0f; float scaleEndInPixels = scaleStartInPixels + scaleLengthInPixels; SourcesView.paint.setARGB(255, 255, 255, 255); SourcesView.paint.setAntiAlias(true); canvas.drawLine(scaleStartInPixels - 1.0f, y, scaleEndInPixels + 1.0f, y, SourcesView.paint); canvas.drawLine(scaleStartInPixels, y, scaleStartInPixels, y - 5.0f, SourcesView.paint); canvas.drawLine(xHalf, y, xHalf, y - 5.0f, SourcesView.paint); canvas.drawLine(scaleEndInPixels, y, scaleEndInPixels, y - 5.0f, SourcesView.paint); canvas.drawText("0m", scaleStartInPixels, y - 8.0f, SourcesView.paint); canvas.drawText(String.valueOf((float) scaleLengthInMeters / 2.0f) + "m", xHalf, y - 8.0f, SourcesView.paint); canvas.drawText(String.valueOf((float) scaleLengthInMeters) + "m", scaleEndInPixels, y - 8.0f, SourcesView.paint); }
From source file:com.shawnway.nav.app.wtw.view.PagerSlidingTabStrip.java
private void drawNormalUnderLine(Canvas canvas, int height, View currentTab, float lineLeft, float lineRight) { canvas.drawRect(lineLeft, height * (1 - indicatorHeight), lineRight, height, rectPaint); // draw underline rectPaint.setColor(underlineColor);// w w w.j a v a 2 s .com 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); } }