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.chrynan.guitarchords.view.GuitarChordView.java
@Override protected void onDraw(Canvas canvas) { //This method handles a lot of work, possibly too much for an onDraw method, but since I'm not animating //or updating the view often, it should be capable of performing the tasks without too much effort. //I can optimize this later. //First draw the strings and fret markers //Fret markers; not worrying about whether or not to show the bridge nut now (since that wasn't calculated //in to the drawing size) //TODO need to take into account whether or not to show bridgeNut int fretCount = chord.getFretCount(); fretCount = (fretCount < 4) ? 4 : fretCount; for (int i = 0; i < fretCount + 1; i++) { canvas.drawLine(drawingBounds.left + fretNumberBounds.width(), (drawingBounds.top + stringMarkerBounds.height()) + (i * fretSize) + (i * fretMarkerSize), drawingBounds.right - stringSize, (drawingBounds.top + stringMarkerBounds.height()) + (i * fretSize) + (i * fretMarkerSize), fretMarkerPaint);/* www .j a v a2 s.c o m*/ } //Strings for (int i = 0; i < stringCount; i++) { canvas.drawLine((stringMarkerBounds.left) + (i * stringDistance) + (i * stringSize), drawingBounds.top + stringMarkerBounds.height(), (stringMarkerBounds.left) + (i * stringDistance) + (i * stringSize), drawingBounds.bottom - fretMarkerSize, stringPaint); } //Next draw the fret numbers and string markers //Fret numbers; check if we are showing them or not if (showFretNumbers) { for (int i = 0; i < fretCount; i++) { canvas.drawText(String.valueOf(i + 1), drawingBounds.left + fretNumberBounds.width() / 2, getVerticalCenterTextPosition( stringMarkerBounds.bottom + (i * fretMarkerSize) + (i * fretSize) + (fretSize / 2), String.valueOf(i + 1), fretNumberPaint), fretNumberPaint); } } //String markers for (int i : chord.getMutedStrings()) { canvas.drawText(mutedText, (drawingBounds.left + fretNumberBounds.width()) + ((stringCount - i) * stringDistance) + ((stringCount - i) * stringSize), getVerticalCenterTextPosition(drawingBounds.top + (stringMarkerBounds.height() / 2), mutedText, stringMarkerPaint), stringMarkerPaint); } for (int i : chord.getOpenStrings()) { canvas.drawText(openStringText, (drawingBounds.left + fretNumberBounds.width()) + ((stringCount - i) * stringDistance) + ((stringCount - i) * stringSize), getVerticalCenterTextPosition(drawingBounds.top + (stringMarkerBounds.height() / 2), openStringText, stringMarkerPaint), stringMarkerPaint); } //Finally, draw all the notes and the note text //Bars float startCenterX; float startCenterY; for (ChordMarker cm : chord.getBars()) { startCenterX = (drawingBounds.left + fretNumberBounds.width()) + ((stringCount - cm.getStartString()) * stringDistance) + ((stringCount - cm.getStartString()) * stringSize); startCenterY = stringMarkerBounds.bottom + (((cm.getFret() * fretSize) + (cm.getFret() * fretMarkerSize)) - (fretSize / 2)); float endCenterX = (drawingBounds.left + fretNumberBounds.width()) + ((stringCount - cm.getEndString()) * stringDistance) + ((stringCount - cm.getEndString()) * stringSize); float endCenterY = startCenterY; canvas.drawCircle(startCenterX, startCenterY, noteSize / 2, notePaint); canvas.drawCircle(endCenterX, endCenterY, noteSize / 2, notePaint); if (showFingerNumbers) { canvas.drawText(String.valueOf(cm.getFinger()), startCenterX, getVerticalCenterTextPosition( startCenterY, String.valueOf(cm.getFinger()), noteNumberPaint), noteNumberPaint); canvas.drawText(String.valueOf(cm.getFinger()), endCenterX, getVerticalCenterTextPosition(endCenterY, String.valueOf(cm.getFinger()), noteNumberPaint), noteNumberPaint); } barLinePath = new Path(); barLinePath.moveTo(startCenterX, startCenterY - (noteSize / 2)); barLinePath.quadTo((startCenterX + endCenterX) / 2, (startCenterY + endCenterY - (noteSize / 2)) / 4, endCenterX, endCenterY - (noteSize / 2)); canvas.drawPath(barLinePath, barLinePaint); } //Individual notes for (ChordMarker cm : chord.getIndividualNotes()) { startCenterX = (drawingBounds.left + fretNumberBounds.width()) + ((stringCount - cm.getStartString()) * stringDistance) + ((stringCount - cm.getStartString()) * stringSize); startCenterY = stringMarkerBounds.bottom + (((cm.getFret() * fretSize) + (cm.getFret() * fretMarkerSize)) - (fretSize / 2)); canvas.drawCircle(startCenterX, startCenterY, noteSize / 2, notePaint); if (showFingerNumbers) { canvas.drawText(String.valueOf(cm.getFinger()), startCenterX, getVerticalCenterTextPosition( startCenterY, String.valueOf(cm.getFinger()), noteNumberPaint), noteNumberPaint); } } }
From source file:com.robert.library.view.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*from w ww . ja v a 2 s . 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, 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); } // 1. ?? // canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint); // ?? canvas.drawRect(lineLeft, 3 * underlineHeight, lineRight, height - 3 * underlineHeight, rectPaint); // draw underline rectPaint.setColor(underlineColor); // canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); // 2. ??? canvas.drawRect(0, 0, tabsContainer.getWidth(), 3 * underlineHeight, rectPaint); canvas.drawRect(0, height - 3 * underlineHeight, tabsContainer.getWidth(), height, rectPaint); // 3. draw divider?? dividerPaint.setColor(dividerColor); // dividerPaint.setColor(R.color.red); for (int i = 0; i < tabCount - 1; i++) { View tab = tabsContainer.getChildAt(i); canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint); // canvas.drawRect(tab.getRight(), 3 * underlineHeight, tab.getRight(), height - 3 * underlineHeight, dividerPaint); } }
From source file:com.hua.weget.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); LogUtils2.i("onDraw------------------------"); if (isInEditMode() || tabCount == 0) { return;//w w w . j av a 2 s. com } final int height = getHeight(); LogUtils2.w("getHeight();==" + getHeight()); // draw underline Tab viewpager rectPaint.setColor(underlineColor); 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(); LogUtils2.d("currentPositionOffset==" + currentPositionOffset); LogUtils2.d("nextTabLeft==" + nextTabLeft); LogUtils2.d("lineLeft==" + lineLeft); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); // lineLeft = (currentPositionOffset * nextTabLeft) + (1f - currentPositionOffset) * lineLeft; } canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, 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:net.droidsolutions.droidcharts.core.renderer.xy.AbstractXYItemRenderer.java
/** * Draws a horizontal line across the chart to represent a 'range marker'. * * @param g2 the graphics device./*from w w w. jav a 2 s . c om*/ * @param plot the plot. * @param rangeAxis the range axis. * @param marker the marker line. * @param dataArea the axis data area. */ public void drawRangeMarker(Canvas g2, XYPlot plot, ValueAxis rangeAxis, Marker marker, Rectangle2D dataArea) { if (marker instanceof ValueMarker) { ValueMarker vm = (ValueMarker) marker; double value = vm.getValue(); Range range = rangeAxis.getRange(); if (!range.contains(value)) { return; } double v = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge()); PlotOrientation orientation = plot.getOrientation(); Line2D line = null; if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); } Paint oPiant = marker.getPaint(); oPiant.setStyle(Paint.Style.STROKE); int oOldAlpha = oPiant.getAlpha(); oPiant.setAlpha(marker.getAlpha()); oPiant.setStrokeWidth(marker.getStroke()); g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), oPiant); oPiant.setAlpha(oOldAlpha); String label = marker.getLabel(); RectangleAnchor anchor = marker.getLabelAnchor(); if (label != null) { Font labelFont = marker.getLabelFont(); Paint paint = marker.getLabelPaint(); paint.setTypeface(labelFont.getTypeFace()); paint.setTextSize(labelFont.getSize()); Point2D coordinates = calculateRangeMarkerTextAnchorPoint(g2, orientation, dataArea, line.getBounds2D(), marker.getLabelOffset(), LengthAdjustmentType.EXPAND, anchor); TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor(), paint); } } else if (marker instanceof IntervalMarker) { IntervalMarker im = (IntervalMarker) marker; double start = im.getStartValue(); double end = im.getEndValue(); Range range = rangeAxis.getRange(); if (!(range.intersects(start, end))) { return; } double start2d = rangeAxis.valueToJava2D(start, dataArea, plot.getRangeAxisEdge()); double end2d = rangeAxis.valueToJava2D(end, dataArea, plot.getRangeAxisEdge()); double low = Math.min(start2d, end2d); double high = Math.max(start2d, end2d); PlotOrientation orientation = plot.getOrientation(); Rectangle2D rect = null; if (orientation == PlotOrientation.HORIZONTAL) { // clip left and right bounds to data area low = Math.max(low, dataArea.getMinX()); high = Math.min(high, dataArea.getMaxX()); rect = new Rectangle2D.Double(low, dataArea.getMinY(), high - low, dataArea.getHeight()); } else if (orientation == PlotOrientation.VERTICAL) { // clip top and bottom bounds to data area low = Math.max(low, dataArea.getMinY()); high = Math.min(high, dataArea.getMaxY()); rect = new Rectangle2D.Double(dataArea.getMinX(), low, dataArea.getWidth(), high - low); } Paint p = marker.getPaint(); int oldAlpha = p.getAlpha(); p.setAlpha(marker.getAlpha()); p.setStyle(Paint.Style.FILL); g2.drawRect((float) rect.getMinX(), (float) rect.getMinY(), (float) rect.getMaxX(), (float) rect.getMaxY(), p); p.setAlpha(oldAlpha); // now draw the outlines, if visible... if (im.getOutlinePaint() != null && im.getOutlineStroke() != null) { if (orientation == PlotOrientation.VERTICAL) { Line2D line = new Line2D.Double(); double x0 = dataArea.getMinX(); double x1 = dataArea.getMaxX(); Paint oPiant = im.getOutlinePaint(); oPiant.setStyle(Paint.Style.STROKE); int oOldAlpha = oPiant.getAlpha(); oPiant.setAlpha(marker.getAlpha()); oPiant.setStrokeWidth(im.getOutlineStroke()); if (range.contains(start)) { line.setLine(x0, start2d, x1, start2d); g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), oPiant); } if (range.contains(end)) { line.setLine(x0, end2d, x1, end2d); g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), oPiant); } oPiant.setAlpha(oOldAlpha); } else { // PlotOrientation.HORIZONTAL Line2D line = new Line2D.Double(); double y0 = dataArea.getMinY(); double y1 = dataArea.getMaxY(); Paint oPiant = im.getOutlinePaint(); oPiant.setStyle(Paint.Style.STROKE); int oOldAlpha = oPiant.getAlpha(); oPiant.setAlpha(marker.getAlpha()); oPiant.setStrokeWidth(im.getOutlineStroke()); if (range.contains(start)) { line.setLine(start2d, y0, start2d, y1); g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), oPiant); } if (range.contains(end)) { line.setLine(end2d, y0, end2d, y1); g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), oPiant); } oPiant.setAlpha(oOldAlpha); } } String label = marker.getLabel(); RectangleAnchor anchor = marker.getLabelAnchor(); if (label != null) { Font labelFont = marker.getLabelFont(); Paint paint = marker.getLabelPaint(); paint.setTypeface(labelFont.getTypeFace()); paint.setTextSize(labelFont.getSize()); Point2D coordinates = calculateRangeMarkerTextAnchorPoint(g2, orientation, dataArea, rect, marker.getLabelOffset(), marker.getLabelOffsetType(), anchor); TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor(), paint); } } }
From source file:pl.motyczko.scrollheader.PagerSlidingTabStrip.java
private void drawTabs(Canvas canvas) { canvas.save();/*from w w w . j a v a 2 s. c o m*/ canvas.translate(0, getHeight() - tabsContainer.getHeight()); if (isInEditMode() || tabCount == 0) { return; } final int height = tabsContainer.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); } canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, 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); } canvas.restore(); }
From source file:com.codetroopers.betterpickers.radialtimepicker.RadialSelectorView.java
@Override public void onDraw(Canvas canvas) { int viewWidth = getWidth(); if (viewWidth == 0 || !mIsInitialized) { return;//from ww w. j a v a2 s. 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 / 2; } mSelectionRadius = (int) (mCircleRadius * mSelectionRadiusMultiplier); mDrawValuesReady = true; } // Calculate the current radius at which to place the selection circle. mLineLength = (int) (mCircleRadius * mNumbersRadiusMultiplier * mAnimationRadiusMultiplier); int pointX = mXCenter + (int) (mLineLength * Math.sin(mSelectionRadians)); int pointY = mYCenter - (int) (mLineLength * Math.cos(mSelectionRadians)); // Draw the selection circle. mPaint.setAlpha(mSelectionAlpha); canvas.drawCircle(pointX, pointY, mSelectionRadius, mPaint); if (mForceDrawDot | mSelectionDegrees % 30 != 0) { // We're not on a direct tick (or we've been told to draw the dot anyway). mPaint.setAlpha(FULL_ALPHA); canvas.drawCircle(pointX, pointY, (mSelectionRadius * 2 / 7), mPaint); } else { // We're not drawing the dot, so shorten the line to only go as far as the edge of the // selection circle. int lineLength = mLineLength; lineLength -= mSelectionRadius; pointX = mXCenter + (int) (lineLength * Math.sin(mSelectionRadians)); pointY = mYCenter - (int) (lineLength * Math.cos(mSelectionRadians)); } // Draw the line from the center of the circle. mPaint.setAlpha(255); mPaint.setStrokeWidth(1); canvas.drawLine(mXCenter, mYCenter, pointX, pointY, mPaint); }
From source file:com.binu.LogarithmicGraph.DrawGraphAsyncTask.java
@Override protected Object doInBackground(Object[] params) { Bitmap bitmapBackground = Bitmap.createBitmap(mViewWidth, mViewHeight, Bitmap.Config.ARGB_8888); Canvas canvasBackground = new Canvas(bitmapBackground); Paint paint = new Paint(); paint.setStrokeWidth(1f);/* ww w . j a v a2 s .co m*/ int starty = 0; int endy = mViewHeight; canvasBackground.drawColor(Color.BLACK); double ratio = Math.pow(Math.E, Math.log(MAX_FREQUENCY / MIN_FREQUENCY) / mViewWidth); mLogScaledX_values = new double[mViewWidth]; for (int i = 0; i < mViewWidth; i++) { if (i == 0) { mLogScaledX_values[i] = 20; } else { mLogScaledX_values[i] = mLogScaledX_values[i - 1] * ratio; } } //Major lines for (int i = 0; i < MAJOR_GRIDLINE_POINTS.length; i++) { paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color)); float xStart = (float) findNearestNumberPosition(mLogScaledX_values, MAJOR_GRIDLINE_POINTS[i]); float textSize = (getPixelDensity(mContext) * mLabelTextSize) / 480; paint.setTextSize(textSize); Log.i("Density", "" + getPixelDensity(mContext)); if (Math.round(MAJOR_GRIDLINE_POINTS[i]) == 20) { if (isShowLabels()) canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]), xStart + (getPixelDensity(mContext) * 10) / 480, endy - (getPixelDensity(mContext) * 10) / 480, paint); } else if (Math.round(MAJOR_GRIDLINE_POINTS[i]) == 20000) { if (isShowLabels()) canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]), xStart - (getPixelDensity(mContext) * 70) / 480, endy - (getPixelDensity(mContext) * 10) / 480, paint); } else { if (isShowLabels()) canvasBackground.drawText(getFormattedLabel(MAJOR_GRIDLINE_POINTS[i]), xStart - (getPixelDensity(mContext) * 30) / 480, endy - (getPixelDensity(mContext) * 10) / 480, paint); canvasBackground.drawLine(xStart, starty, xStart + 1, endy, paint); } } //Minor lines for (int i = 0; i < MINOR_GRIDLINE_POINTS.length; i++) { paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color_dull)); float xStart = (float) findNearestNumberPosition(mLogScaledX_values, MINOR_GRIDLINE_POINTS[i]); canvasBackground.drawLine(xStart, starty, xStart + 1, endy, paint); if (isShowLabels()) { paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color)); if (MINOR_GRIDLINE_POINTS[i] == 50 || MINOR_GRIDLINE_POINTS[i] == 500 || MINOR_GRIDLINE_POINTS[i] == 5000) canvasBackground.drawText(getFormattedLabel(MINOR_GRIDLINE_POINTS[i]), xStart - (getPixelDensity(mContext) * 30) / 480, endy - (getPixelDensity(mContext) * 10) / 480, paint); } } float[] Y_points = calculateGraphYAxis(); float div = mViewHeight / (Y_points.length - 1); //Level lines for (int i = 0; i < Y_points.length - 1; i++) { paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color_dull)); canvasBackground.drawLine(0, div * (i + 1), mViewWidth, (div * (i + 1)) + 1, paint); } //Level labels if (isShowLabels()) { for (int i = 0; i < Y_points.length; i++) { paint.setColor(ContextCompat.getColor(mContext, R.color.graph_grid_color)); if (i == 0) canvasBackground.drawText("dB", 0, (div * i) + (getPixelDensity(mContext) * 50) / 480, paint); else if (i == Y_points.length - 1) canvasBackground.drawText("", 0, div * i, paint); else canvasBackground.drawText("" + Math.round(Y_points[i]), 0, div * i, paint); } } BitmapDrawable drawable = new BitmapDrawable(mContext.getResources(), bitmapBackground); mDrawableBackground = drawable; //Plotting the curve points Bitmap bitmapForeground = Bitmap.createBitmap(mViewWidth, mViewHeight, Bitmap.Config.ARGB_8888); Canvas canvasForeground = new Canvas(bitmapForeground); Paint plotPaint = new Paint(); plotPaint.setStyle(Paint.Style.STROKE); plotPaint.setStrokeCap(Paint.Cap.ROUND); plotPaint.setStrokeWidth(PLOT_THICKNESS); plotPaint.setAntiAlias(true); plotPaint.setColor(ContextCompat.getColor(mContext, R.color.graph_plot_color)); for (int i = 0; i < X_values.length; i++) { // canvasForeground.drawCircle(i, mViewHeight - mPlotPoint[i], 2f, plotPaint); /*float startX, float startY, float stopX, float stopY, @NonNull Paint paint*/ float startX = (float) getGetPixelValueForX(X_values[i]); float startY = mViewHeight - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i]); float stopX; float stopY; if (i == X_values.length - 1) { stopX = (float) getGetPixelValueForX(X_values[i]); stopY = mViewHeight - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i]); } else { stopX = (float) getGetPixelValueForX(X_values[i + 1]); stopY = mViewHeight - getPixelValueFromdB((int) GAIN_MAX, (int) GAIN_MIN, mViewHeight, Y_values[i + 1]); } canvasForeground.drawLine(startX, startY, stopX, stopY, plotPaint); } BitmapDrawable drawableFore = new BitmapDrawable(mContext.getResources(), bitmapForeground); mDrawableForeground = drawableFore; return null; }
From source file:org.telegram.ui.Cells.SharedLinkCell.java
@Override protected void onDraw(Canvas canvas) { if (titleLayout != null) { canvas.save();/*from w w w . ja va 2 s . c o m*/ canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), titleY); titleLayout.draw(canvas); canvas.restore(); } if (descriptionLayout != null) { descriptionTextPaint.setColor(TEXT_COLOR); canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), descriptionY); descriptionLayout.draw(canvas); canvas.restore(); } if (descriptionLayout2 != null) { descriptionTextPaint.setColor(TEXT_COLOR); canvas.save(); canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), description2Y); descriptionLayout2.draw(canvas); canvas.restore(); } if (!linkLayout.isEmpty()) { descriptionTextPaint.setColor(Theme.MSG_LINK_TEXT_COLOR); int offset = 0; for (int a = 0; a < linkLayout.size(); a++) { StaticLayout layout = linkLayout.get(a); if (layout.getLineCount() > 0) { canvas.save(); canvas.translate( AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), linkY + offset); if (pressedLink == a) { canvas.drawPath(urlPath, urlPaint); } layout.draw(canvas); canvas.restore(); offset += layout.getLineBottom(layout.getLineCount() - 1); } } } letterDrawable.draw(canvas); if (drawLinkImageView) { linkImageView.draw(canvas); } if (needDivider) { if (LocaleController.isRTL) { canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, paint); } else { canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, paint); } } }
From source file:com.hobby.uiframework.widget.PagerSlidingTab.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from w w w . j av a2s . c o m } final int height = getHeight(); // draw underline rectPaint.setColor(underlineColor); 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 (lineIndicator) { canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint); } else { rectPaint.setStyle(Style.FILL); Path path = new Path(); float mid = (lineLeft + lineRight) * 0.5f; float triangleheight = getContext().getResources().getDimension(R.dimen.indicator_triangle_height); float left = mid - triangleheight; float right = mid + triangleheight; path.moveTo(left, height); path.lineTo(mid, height - triangleheight); path.lineTo(right, height); path.close(); canvas.drawPath(path, 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:com.astuetz.PagerSlidingTabStripMy.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/* w w w . j a v a2 s. 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, 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); // draw underline // Path path = new Path(); float len = 30; //???? float x1 = lineLeft + (lineRight - lineLeft) / 2; float y1 = height - indicatorHeight; float x2 = x1 + len / 2; float y2 = height; float x3 = x1 - len / 2; float y3 = height; path.moveTo(x1, y1); path.lineTo(x2, y3); path.lineTo(x3, y3); path.lineTo(x1, y1); canvas.drawPath(path, rectPaint); 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); } }