Java Code Examples for android.graphics.Canvas#drawLines()
The following examples show how to use
android.graphics.Canvas#drawLines() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatisticChart.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
private void a(Canvas canvas) { RectF rectf = l.getRect(); int i1 = l.getMaxItemValue(); float f1 = rectf.bottom; if (i1 > 0 && cn.com.smartdevices.bracelet.chart.q.a(l) > 0.0F) { f1 -= ChartUtil.itemLevelSize(i1, f, cn.com.smartdevices.bracelet.chart.q.a(l), cn.com.smartdevices.bracelet.chart.q.b(l)); } float af[] = new float[200]; float f2 = mRect.width() / (float)50; float f3 = (2.0F * f2) / 3F; for (int j1 = 0; j1 < 50; j1++) { float f4 = mRect.left + f2 * (float)j1; float f5 = f4 + f3; af[j1 * 4] = f4; af[1 + j1 * 4] = f1; af[2 + j1 * 4] = f5; af[3 + j1 * 4] = f1; } canvas.drawLines(af, v); }
Example 2
Source File: MusicWave.java From MusicWave with Apache License 2.0 | 6 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mBytes == null) { return; } if (mPoints == null || mPoints.length < mBytes.length * size) { mPoints = new float[mBytes.length * size]; } mRect.set(0, 0, getWidth(), getHeight()); for (int i = 0; i < mBytes.length - 1; i++) { mPoints[i * size] = mRect.width() * i / (mBytes.length - 1); mPoints[i * size + 1] = mRect.height() / 2 + ((byte) (mBytes[i] + 128)) * (mRect.height() / 2) / 128; mPoints[i * size + 2] = mRect.width() * (i + 1) / (mBytes.length - 1); mPoints[i * size + 3] = mRect.height() / 2 + ((byte) (mBytes[i + 1] + 128)) * (mRect.height() / 2) / 128; } if (config.getColorGradient()) { config.reSetupPaint(); config.setGradients(this); } else { config.reSetupPaint(); } canvas.drawLines(mPoints, config.getPaintWave()); }
Example 3
Source File: LineVisualizer.java From android-audio-visualizer with Apache License 2.0 | 6 votes |
@Override protected void onDraw(Canvas canvas) { if (bytes != null) { if (points == null || points.length < bytes.length * 4) { points = new float[bytes.length * 4]; } paint.setStrokeWidth(getHeight() * strokeWidth); rect.set(0, 0, getWidth(), getHeight()); for (int i = 0; i < bytes.length - 1; i++) { points[i * 4] = rect.width() * i / (bytes.length - 1); points[i * 4 + 1] = rect.height() / 2 + ((byte) (bytes[i] + 128)) * (rect.height() / 3) / 128; points[i * 4 + 2] = rect.width() * (i + 1) / (bytes.length - 1); points[i * 4 + 3] = rect.height() / 2 + ((byte) (bytes[i + 1] + 128)) * (rect.height() / 3) / 128; } canvas.drawLines(points, paint); } super.onDraw(canvas); }
Example 4
Source File: CustomSubpatch.java From PdDroidPublisher with GNU General Public License v3.0 | 6 votes |
@Override protected void drawEdges(Canvas canvas) { paint.setStyle(Paint.Style.STROKE); paint.setColor(fgcolor); paint.setStrokeWidth(1); canvas.drawLines(new float[]{ x + labelWidth + alinea + 5, y, x + zoneWidth, y, x + zoneWidth, y, x + zoneWidth, y + zoneHeight, x + zoneWidth, y + zoneHeight, x, y + zoneHeight, x, y + zoneHeight, x, y, x, y, x + alinea, y }, paint); }
Example 5
Source File: EqualizerView.java From Sky31Radio with Apache License 2.0 | 6 votes |
private void drawFFT(Canvas canvas) { if (waveformBytes == null) { return; } if (mFFTPoints == null || fftBytes.length < fftBytes.length * 4) { mFFTPoints = new float[fftBytes.length * 4]; } int mDivisions = (int) waveDividerWidth; mWaveRect.set(0, 0, getWidth(), getHeight()); for (int i = 0; i < fftBytes.length / mDivisions; i++) { mFFTPoints[i * 4] = i * 4 * mDivisions; mFFTPoints[i * 4 + 2] = i * 4 * mDivisions; byte rfk = fftBytes[mDivisions * i]; byte ifk = fftBytes[mDivisions * i + 1]; float magnitude = (rfk * rfk + ifk * ifk); int dbValue = (int) (10 * Math.log10(magnitude)); mFFTPoints[i * 4 + 1] = mWaveRect.height(); mFFTPoints[i * 4 + 3] = mWaveRect.height() - (dbValue * 8 - 10); } canvas.drawLines(mFFTPoints, wavePaint); }
Example 6
Source File: AxisDrawing.java From InteractiveChart with Apache License 2.0 | 5 votes |
@Override public void onComputeOver(Canvas canvas, int begin, int end, float[] extremum) { for (int i = 1; i < attribute.axisCount; i++) { pointCache[1] = lineBuffer[1] = lineBuffer[3] = viewRect.top + i * regionHeight; render.invertMapPoints(pointCache); String text = ValueUtils.format(pointCache[1], render.getAdapter().getScale()); // 绘制横向网格线 if (attribute.axisLabelLocation == AxisLabelLocation.ALL) { lineBuffer[5] = lineBuffer[7] = lineBuffer[1]; lineBuffer[0] = viewRect.left; lineBuffer[2] = left - attribute.axisLabelLRMargin; lineBuffer[4] = right + attribute.axisLabelLRMargin; lineBuffer[6] = viewRect.right; canvas.drawLines(lineBuffer, axisPaint); canvas.drawText(text, left, lineBuffer[1] + textCenter, axisLabelPaintLeft); canvas.drawText(text, right, lineBuffer[5] + textCenter, axisLabelPaintRight); } else { lineBuffer[0] = viewRect.left; lineBuffer[2] = viewRect.right; canvas.drawLine(lineBuffer[0], lineBuffer[1], lineBuffer[2], lineBuffer[3], axisPaint); if (attribute.axisLabelLocation == AxisLabelLocation.LEFT) { canvas.drawText(text, left, lineBuffer[1] - rect.top + attribute.axisLabelTBMargin, axisLabelPaintLeft); } else { canvas.drawText(text, right, lineBuffer[1] - rect.top + attribute.axisLabelTBMargin, axisLabelPaintRight); } } } }
Example 7
Source File: ColorWheelView.java From SimpleDialogFragments with Apache License 2.0 | 5 votes |
void draw(Canvas canvas) { canvas.save(); canvas.rotate(-90, canvas.getWidth() / 2, canvas.getHeight() / 2); canvas.drawArc(boundingBox, 0, 360, false, paint); canvas.drawLines(marker, markerPaint); canvas.restore(); }
Example 8
Source File: InsetDividerDecoration.java From android-proguards with Apache License 2.0 | 5 votes |
@Override public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) { int childCount = parent.getChildCount(); if (childCount < 2) return; RecyclerView.LayoutManager lm = parent.getLayoutManager(); float[] lines = new float[childCount * 4]; boolean hasDividers = false; for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(child); if (viewHolder.getClass() == dividedClass) { // skip if this *or next* view is activated if (child.isActivated() || (i + 1 < childCount && parent.getChildAt(i + 1).isActivated())) { continue; } lines[i * 4] = inset + lm.getDecoratedLeft(child); lines[(i * 4) + 2] = lm.getDecoratedRight(child); int y = lm.getDecoratedBottom(child) + (int) child.getTranslationY() - height; lines[(i * 4) + 1] = y; lines[(i * 4) + 3] = y; hasDividers = true; } } if (hasDividers) { canvas.drawLines(lines, paint); } }
Example 9
Source File: Plot2D.java From audio-analyzer-for-android with Apache License 2.0 | 5 votes |
void plotBarThick(Canvas c, double[] y_value, double[] x_values, int i_begin, int i_end, double x_inc, Paint linePainter) { if (tmpLineXY.length < 4*(y_value.length)) { Log.d(TAG, "plotBar(): new tmpLineXY"); tmpLineXY = new float[4*(y_value.length)]; } final double minYCanvas = axisY.pixelNoZoomFromV(AnalyzerGraphic.minDB); int pixelStep = 2; // each bar occupy this virtual pixel c.save(); matrix.reset(); double extraPixelAlignOffset = 0.0f; // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // // There is an shift for Android 4.4, while no shift for Android 2.3 // // I guess that is relate to GL ES acceleration // if (c.isHardwareAccelerated()) { // extraPixelAlignOffset = 0.5f; // } // } matrix.setTranslate((float)(-axisX.getShift() * (y_value.length - 1) * pixelStep - extraPixelAlignOffset), (float)(-axisY.getShift() * axisY.nCanvasPixel)); matrix.postScale((float)(axisX.nCanvasPixel / ((axisX.vMaxInView() - axisX.vMinInView()) / x_inc * pixelStep)), (float)axisY.getZoom()); c.concat(matrix); // fill interval same as canvas pixel width. for (int i = i_begin; i < i_end; i++) { float x = x_values == null ? i * pixelStep : (float)(x_values[i] / x_inc * pixelStep); float y = (float)axisY.pixelNoZoomFromV(clampDB(y_value[i])); tmpLineXY[4*i ] = x; tmpLineXY[4*i+1] = (float)minYCanvas; tmpLineXY[4*i+2] = x; tmpLineXY[4*i+3] = y; } c.drawLines(tmpLineXY, 4*i_begin, 4*(i_end-i_begin), linePainter); c.restore(); }
Example 10
Source File: CircleBarRenderer.java From Mp3Cutter with GNU General Public License v3.0 | 5 votes |
@Override public void onRender(Canvas canvas, FFTData data, Rect rect) { if(mCycleColor) { cycleColor(); } for (int i = 0; i < data.bytes.length / mDivisions; i++) { // Calculate dbValue byte rfk = data.bytes[mDivisions * i]; byte ifk = data.bytes[mDivisions * i + 1]; float magnitude = (rfk * rfk + ifk * ifk); float dbValue = 75 * (float)Math.log10(magnitude); float[] cartPoint = { (float)(i * mDivisions) / (data.bytes.length - 1), rect.height() / 2 - dbValue / 4 }; float[] polarPoint = toPolar(cartPoint, rect); mFFTPoints[i * 4] = polarPoint[0]; mFFTPoints[i * 4 + 1] = polarPoint[1]; float[] cartPoint2 = { (float)(i * mDivisions) / (data.bytes.length - 1), rect.height() / 2 + dbValue }; float[] polarPoint2 = toPolar(cartPoint2, rect); mFFTPoints[i * 4 + 2] = polarPoint2[0]; mFFTPoints[i * 4 + 3] = polarPoint2[1]; } canvas.drawLines(mFFTPoints, mPaint); // Controls the pulsing rate modulation += 0.13; angleModulation += 0.28; }
Example 11
Source File: VMWaveformView.java From VMLibrary with Apache License 2.0 | 5 votes |
/** * 绘制线性波形图 */ private void drawLine(Canvas canvas) { // 设置画笔颜色 waveformPaint.setColor(waveformColor); // 设置画笔末尾样式 waveformPaint.setStrokeCap(Paint.Cap.ROUND); // 设置画笔宽度 waveformPaint.setStrokeWidth(waveformWidth / 2); // 波形数据如果为 null 直接 return if (waveformBytes == null) { canvas.drawLine(0, viewHeight / 2, viewWidth, viewHeight / 2, waveformPaint); return; } if (waveformPoints == null || waveformPoints.length < waveformBytes.length * 4) { waveformPoints = new float[waveformBytes.length * 4]; } float baseX = 0; float baseY = viewHeight / 2; // 绘制时域型波形图 float interval = viewWidth / (waveformBytes.length - 1); for (int i = 0; i < waveformBytes.length - 1; i++) { // 计算第i个点的x坐标 waveformPoints[i * 4] = baseX + i * interval; // 根据bytes[i]的值(波形点的值)计算第i个点的y坐标 waveformPoints[i * 4 + 1] = baseY + ((byte) (waveformBytes[i] + 128)) * (viewHeight / 2) / 128; // 计算第i+1个点的x坐标 waveformPoints[i * 4 + 2] = baseX + interval * (i + 1); // 根据bytes[i+1]的值(波形点的值)计算第i+1个点的y坐标 waveformPoints[i * 4 + 3] = baseY + ((byte) (waveformBytes[i + 1] + 128)) * (viewHeight / 2) / 128; } canvas.drawLines(waveformPoints, waveformPaint); }
Example 12
Source File: LineRenderer.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
@Override public void render(Canvas canvas, byte[] data, int w, int h) { super.render(canvas, data, w, h); for (int i = 0; i < data.length - 1; i++) { points[i * 4] = w * i / (data.length - 1); points[i * 4 + 1] = (float) (h / 2 + ((byte) (data[i] + 128) * ampValue) * (h / 2) / 128); points[i * 4 + 2] = w * (i + 1) / (data.length - 1); points[i * 4 + 3] = (float) (h / 2 + ((byte) (data[i + 1] + 128) * ampValue) * (h / 2) / 128); } canvas.drawLines(points, paint); }
Example 13
Source File: ColorfulBarRenderer.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
@Override public void render(Canvas canvas, byte[] data, int width, int height) { super.render(canvas, data, width, height); if (colorInterpolatePercentage > 1.0) { colorInterpolatePercentage = 0; int tempColor = startColor; startColor = endColor; endColor = tempColor; } for (int i = 0; i < data.length / divisions; i++) { points[i * 4] = i * 4 * divisions; points[i * 4 + 2] = i * 4 * divisions; byte rfk = data[divisions * i]; byte ifk = data[divisions * i + 1]; float magnitude = (rfk * rfk + ifk * ifk); int dbValue = (int) ((int) (10 * Math.log10(magnitude)) * ampValue); points[i * 4 + 1] = height; points[i * 4 + 3] = height - (dbValue * 2 - 10); } changeColor(interpolateColor(startColor, endColor, colorInterpolatePercentage)); canvas.drawLines(points, paint); colorInterpolatePercentage += 0.05; }
Example 14
Source File: GalleryGuideView.java From MHViewer with Apache License 2.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(mBgColor); if (0 == mStep) { canvas.drawLines(mPoints, mPaint); } }
Example 15
Source File: GravityDefiedVisualizerView.java From NEON with Apache License 2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (this.mainBytes == null) { return; } if (this.mainPoints == null || this.mainPoints.length < this.mainBytes.length * 4) { this.mainRect.set(0, 0, getWidth(), getHeight()); this.mainPoints = new float[this.mainBytes.length * 4]; this.upperPoints = new float[this.mainBytes.length * 4]; this.mergePoints = new float[this.mainBytes.length * 4]; // 30 it`s our distance between merge lines this.halfSize = ((this.mainBytes.length) / 30) / 2; this.offsetCounter = this.offset * this.halfSize; } for (int i = 0; i < this.mainBytes.length; i += 30) { if (i == 0) { // Get main line points this.mainPoints[i * 4] = this.mainRect.width() * i / (this.mainBytes.length - 1); this.mainPoints[i * 4 + 1] = this.mainRect.height() / 2 + ((byte) (this.mainBytes[i] + 128)) * (this.mainRect.height() / 2) / 128; // Get upper line points this.upperPoints[i * 4] = this.mainRect.width() * i / (this.mainBytes.length - 1) + this.offsetCounter; this.upperPoints[i * 4 + 1] = (this.mainRect.height() / 2 + ((byte) (this.mainBytes[i] + 128)) * (this.mainRect.height() / 2) / 128) - 35; } else { this.mainPoints[i * 4] = this.mainPoints[(i - 30) * 4 + 2]; this.mainPoints[i * 4 + 1] = this.mainPoints[(i - 30) * 4 + 3]; this.upperPoints[i * 4] = this.upperPoints[(i - 30) * 4 + 2]; this.upperPoints[i * 4 + 1] = this.upperPoints[(i - 30) * 4 + 3]; } // this.mainPoints[i * 4 + 2] = this.mainRect.width() * (i + 1) / (this.mainBytes.length - 1); this.mainPoints[i * 4 + 3] = this.mainRect.height() / 2 + ((byte) (this.mainBytes[i + 1] + 128)) * (this.mainRect.height() / 2) / 128; this.upperPoints[i * 4 + 2] = this.mainRect.width() * (i + 1) / (this.mainBytes.length - 1) + this.offsetCounter; this.upperPoints[i * 4 + 3] = (this.mainRect.height() / 2 + ((byte) (this.mainBytes[i + 1] + 128)) * (this.mainRect.height() / 2) / 128) - 35; // Get merge line points this.mergePoints[i * 4] = this.mainPoints[i * 4]; this.mergePoints[i * 4 + 1] = this.mainPoints[i * 4 + 1]; this.mergePoints[i * 4 + 2] = this.upperPoints[i * 4]; this.mergePoints[i * 4 + 3] = this.upperPoints[i * 4 + 1]; this.offsetCounter -= this.offset; } // Refresh offset counter for next draws this.offsetCounter = this.halfSize * this.offset; // Set data for dynamics and float track changing setData(this.mainPoints); setUpperData(this.upperPoints); setMergeData(this.mergePoints); // Get dynamics points for (int i = 0; i < this.mainBytes.length; i += 30) { this.mainPoints[i * 4] = this.data[i * 4].getPosition(); this.mainPoints[i * 4 + 1] = this.data[i * 4 + 1].getPosition(); this.mainPoints[i * 4 + 2] = this.data[i * 4 + 2].getPosition(); this.mainPoints[i * 4 + 3] = this.data[i * 4 + 3].getPosition(); this.upperPoints[i * 4] = this.upperData[i * 4].getPosition(); this.upperPoints[i * 4 + 1] = this.upperData[i * 4 + 1].getPosition(); this.upperPoints[i * 4 + 2] = this.upperData[i * 4 + 2].getPosition(); this.upperPoints[i * 4 + 3] = this.upperData[i * 4 + 3].getPosition(); this.mergePoints[i * 4] = this.mergeData[i * 4].getPosition(); this.mergePoints[i * 4 + 1] = this.mergeData[i * 4 + 1].getPosition(); this.mergePoints[i * 4 + 2] = this.mergeData[i * 4 + 2].getPosition(); this.mergePoints[i * 4 + 3] = this.mergeData[i * 4 + 3].getPosition(); } // Draw out track canvas.drawLines(this.mainPoints, this.linePaint); canvas.drawLines(this.upperPoints, this.linePaint); canvas.drawLines(this.mergePoints, this.linePaint); }
Example 16
Source File: LinearChartView.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
@Override protected void drawPickerChart(Canvas canvas) { int bottom = getMeasuredHeight() - PICKER_PADDING; int top = getMeasuredHeight() - pikerHeight - PICKER_PADDING; int nl = lines.size(); if (chartData != null) { for (int k = 0; k < nl; k++) { LineViewData line = lines.get(k); if (!line.enabled && line.alpha == 0) continue; line.bottomLinePath.reset(); int n = chartData.xPercentage.length; int j = 0; int[] y = line.line.y; line.chartPath.reset(); for (int i = 0; i < n; i++) { if (y[i] < 0) continue; float xPoint = chartData.xPercentage[i] * pickerWidth; float h = ANIMATE_PICKER_SIZES ? pickerMaxHeight : chartData.maxValue; float hMin = ANIMATE_PICKER_SIZES ? pickerMinHeight : chartData.minValue; float yPercentage = (y[i] - hMin) / (h - hMin); float yPoint = (1f - yPercentage) * pikerHeight; if (USE_LINES) { if (j == 0) { line.linesPathBottom[j++] = xPoint; line.linesPathBottom[j++] = yPoint; } else { line.linesPathBottom[j++] = xPoint; line.linesPathBottom[j++] = yPoint; line.linesPathBottom[j++] = xPoint; line.linesPathBottom[j++] = yPoint; } } else { if (i == 0) { line.bottomLinePath.moveTo(xPoint, yPoint); } else { line.bottomLinePath.lineTo(xPoint, yPoint); } } } line.linesPathBottomSize = j; if (!line.enabled && line.alpha == 0) continue; line.bottomLinePaint.setAlpha((int) (255 * line.alpha)); if (USE_LINES) canvas.drawLines(line.linesPathBottom, 0, line.linesPathBottomSize, line.bottomLinePaint); else canvas.drawPath(line.bottomLinePath, line.bottomLinePaint); } } }
Example 17
Source File: HistoryGraph.java From Intra with Apache License 2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // Normally the coordinate system puts 0,0 at the top left. This puts it at the bottom right, // with positive axes pointed up and left. canvas.rotate(180, getWidth() / 2, getHeight() / 2); // Scale factors based on current window size. float xoffset = (float) (getWidth()) * RIGHT_MARGIN_FRACTION; float usableWidth = getWidth() - xoffset; float yoffset = getHeight() * BOTTOM_MARGIN_FRACTION; // Make graph fit in the available height and never be taller than the width. float usableHeight = Math.min(getWidth(), getHeight() - (DATA_STROKE_WIDTH + yoffset)); now = SystemClock.elapsedRealtime(); float rightEndY; if (updateCurve()) { updateMax(); float xscale = usableWidth / (curve.length - 1); float yscale = max == 0 ? 0 : usableHeight / max; // Convert the curve into lines in the appropriate scale, and draw it. // |lines| has 4 values (x0, y0, x1, y1) for every interval in |curve|. // We use drawLines instead of drawPath for performance, even though it creates some visual // artifacts. See https://developer.android.com/topic/performance/vitals/render. for (int i = 1; i < curve.length; ++i) { int j = (i - 1) * 4; lines[j] = (i - 1) * xscale + xoffset; lines[j + 1] = curve[i - 1] * yscale + yoffset; lines[j + 2] = i * xscale + xoffset; lines[j + 3] = curve[i] * yscale + yoffset; } canvas.drawLines(lines, dataPaint); rightEndY = lines[1]; } else { max = 0; // Draw a horizontal line at y = 0. canvas.drawLine(xoffset, yoffset, xoffset + usableWidth, yoffset, dataPaint); rightEndY = yoffset; } // Draw a circle at the right end of the line. float tagRadius = 2 * DATA_STROKE_WIDTH; float tagX = xoffset - tagRadius; canvas.drawCircle(tagX, rightEndY, tagRadius, dataPaint); // Draw pulses at regular intervals, growing and fading with age. float maxRadius = getWidth() - tagX; for (long age = now % PULSE_INTERVAL_MS; age < WINDOW_MS; age += PULSE_INTERVAL_MS) { float fraction = ((float) age) / WINDOW_MS; float radius = tagRadius + fraction * (maxRadius - tagRadius); int alpha = (int) (255 * (1 - fraction)); pulsePaint.setAlpha(alpha); canvas.drawCircle(tagX, yoffset, radius, pulsePaint); } // Queue up the next animation frame. if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) { // Redraw the UI at its preferred update frequency. postInvalidateOnAnimation(); } else { // postInvalidateOnAnimation is only available in Jelly Bean and higher. On older devices, // update every RESOLUTION_MS (currently 10 FPS, which is choppy but good enough). postInvalidateDelayed(RESOLUTION_MS); } }
Example 18
Source File: CircleBarVisualizer.java From Bop with Apache License 2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { if (radius == -1) { radius = getHeight() < getWidth() ? getHeight() : getWidth(); radius = (int) (radius * 0.65 / 2); double circumference = 2 * Math.PI * radius; paint.setStrokeWidth((float) (circumference / 120)); circlePaint.setStyle(Paint.Style.STROKE); circlePaint.setStrokeWidth(4); } circlePaint.setColor(color); canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius, circlePaint); if (bytes != null) { if (points == null || points.length < bytes.length * 4) { points = new float[bytes.length * 4]; } double angle = 0; for (int i = 0; i < 120; i++, angle += 3) { int x = (int) Math.ceil(i * 8.5); int t = ((byte) (-Math.abs(bytes[x]) + 128)) * (getHeight() / 4) / 128; points[i * 4] = (float) (getWidth() / 2 + radius * Math.cos(Math.toRadians(angle))); points[i * 4 + 1] = (float) (getHeight() / 2 + radius * Math.sin(Math.toRadians(angle))); points[i * 4 + 2] = (float) (getWidth() / 2 + (radius + t) * Math.cos(Math.toRadians(angle))); points[i * 4 + 3] = (float) (getHeight() / 2 + (radius + t) * Math.sin(Math.toRadians(angle))); } canvas.drawLines(points, paint); } super.onDraw(canvas); }
Example 19
Source File: AxesRenderer.java From SmartChart with Apache License 2.0 | 4 votes |
private void drawAxisLines(Canvas canvas, Axis axis, int position) { final Rect contentRectMargins = computator.getContentRectMinusAxesMargins(); float separationX1, separationY1, separationX2, separationY2; separationX1 = separationY1 = separationX2 = separationY2 = 0; float lineX1, lineY1, lineX2, lineY2; lineX1 = lineY1 = lineX2 = lineY2 = 0; boolean isAxisVertical = isAxisVertical(position); if (LEFT == position || RIGHT == position) { separationX1 = separationX2 = separationLineTab[position]; separationY1 = contentRectMargins.bottom; separationY2 = contentRectMargins.top; lineX1 = contentRectMargins.left; lineX2 = contentRectMargins.right; } else if (TOP == position || BOTTOM == position) { separationX1 = contentRectMargins.left; separationX2 = contentRectMargins.right; separationY1 = separationY2 = separationLineTab[position]; lineY1 = contentRectMargins.top; lineY2 = contentRectMargins.bottom; } // Draw separation line with the same color as axis labels and name. if (axis.hasSeparationLine()) { labelPaintTab[position].setColor(axis.getHasSeparationLineColor()); canvas.drawLine(separationX1, separationY1, separationX2, separationY2, labelPaintTab[position]); } labelPaintTab[position].setColor(axis.getTextColor()); if (axis.hasLines()) { int valueToDrawIndex = 0; for (; valueToDrawIndex < valuesToDrawNumTab[position]; ++valueToDrawIndex) { if (isAxisVertical) { lineY1 = lineY2 = rawValuesTab[position][valueToDrawIndex]; } else { lineX1 = lineX2 = rawValuesTab[position][valueToDrawIndex]; } linesDrawBufferTab[position][valueToDrawIndex * 4 + 0] = lineX1; linesDrawBufferTab[position][valueToDrawIndex * 4 + 1] = lineY1; linesDrawBufferTab[position][valueToDrawIndex * 4 + 2] = lineX2; linesDrawBufferTab[position][valueToDrawIndex * 4 + 3] = lineY2; } canvas.drawLines(linesDrawBufferTab[position], 0, valueToDrawIndex * 4, linePaintTab[position]); } }
Example 20
Source File: LineGraphSeries.java From analyzer-of-android-for-Apache-Weex with Apache License 2.0 | 2 votes |
/** * just a wrapper to draw lines on canvas * * @param canvas * @param pts * @param paint */ private void renderLine(Canvas canvas, float[] pts, Paint paint) { canvas.drawLines(pts, paint); }