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.example.yh.myapplication.widget.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from www . j a v a2 s . co 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); } int marginH = 60; if (tabCount <= 2) { marginH = 140; } canvas.drawRect(lineLeft + marginH, height - indicatorHeight, lineRight - marginH, 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); } }
From source file:com.jjoe64.graphview.GridLabelRenderer.java
/** * draws the vertical steps/* www. jav a 2s . c om*/ * horizontal lines and vertical labels * * @param canvas canvas */ protected void drawVerticalSteps(Canvas canvas) { // draw vertical steps (horizontal lines and vertical labels) float startLeft = mGraphView.getGraphContentLeft(); mPaintLabel.setColor(getVerticalLabelsColor()); mPaintLabel.setTextAlign(getVerticalLabelsAlign()); for (Map.Entry<Integer, Double> e : mStepsVertical.entrySet()) { // draw line if (mStyles.highlightZeroLines) { if (e.getValue() == 0d) { mPaintLine.setStrokeWidth(5); } else { mPaintLine.setStrokeWidth(0); } } if (mStyles.gridStyle.drawHorizontal()) { canvas.drawLine(startLeft, e.getKey(), startLeft + mGraphView.getGraphContentWidth(), e.getKey(), mPaintLine); } // draw label if (isVerticalLabelsVisible()) { int labelsWidth = mLabelVerticalWidth; int labelsOffset = 0; if (getVerticalLabelsAlign() == Paint.Align.RIGHT) { labelsOffset = labelsWidth; labelsOffset -= mStyles.labelsSpace; } else if (getVerticalLabelsAlign() == Paint.Align.CENTER) { labelsOffset = labelsWidth / 2; } labelsOffset += mStyles.padding + getVerticalAxisTitleWidth(); float y = e.getKey(); String label = mLabelFormatter.formatLabel(e.getValue(), false); if (label == null) { label = ""; } String[] lines = label.split("\n"); y += (lines.length * getTextSize() * 1.1f) / 2; // center text vertically for (int li = 0; li < lines.length; li++) { // for the last line y = height float y2 = y - (lines.length - li - 1) * getTextSize() * 1.1f; canvas.drawText(lines[li], labelsOffset, y2, mPaintLabel); } } } }
From source file:com.tedkim.android.tviews.slidingtab.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/* ww w . j a v a 2 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); // canvas.drawRect(lineLeft, 0, lineRight, indicatorHeight, rectPaint);//@justlikehee ?? ?? // 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:com.mingle.discolor.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from ww w.j a v a 2s. 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 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:com.yiqixue.utils.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*from w w w . j a v a 2 s . co 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); } //+x indicator canvas.drawRect(lineLeft + getResources().getDimension(R.dimen.indicator_margin), height - indicatorHeight, lineRight - getResources().getDimension(R.dimen.indicator_margin), 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:com.liushengfan.test.customerviewgroup.view.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from w w w .jav a2 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); } canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); canvas.drawRect(0, 0, tabsContainer.getWidth(), underlineHeight, 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.AbstractCategoryItemRenderer.java
/** * Draws a grid line against the range axis. * /*from w w w . j a v a 2 s. c o m*/ * @param g2 * the graphics device. * @param plot * the plot. * @param axis * the value axis. * @param dataArea * the area for plotting data (not yet adjusted for any 3D * effect). * @param value * the value at which the grid line should be drawn. * * @see #drawDomainGridline(Graphics2D, CategoryPlot, Rectangle2D, double) */ public void drawRangeGridline(Canvas g2, CategoryPlot plot, ValueAxis axis, Rectangle2D dataArea, double value) { Range range = axis.getRange(); if (!range.contains(value)) { return; } PlotOrientation orientation = plot.getOrientation(); double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge()); 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 paint = plot.getRangeGridlinePaint(); if (paint == null) { paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT; } float stroke = plot.getRangeGridlineStroke(); paint.setStrokeWidth(stroke); g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), paint); }
From source file:com.hcy.suzhoubusquery.utils.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*w ww . j ava 2s . c om*/ } final int height = getHeight(); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, 0, tabsContainer.getWidth(), underlineHeight, 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); // } // // 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:scroll.com.rdemo.scroll.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*from ww w . j a v a 2 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 + 10, height - indicatorHeight, lineRight - 10, 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); } }
From source file:com.cssweb.android.view.FTrendView.java
public void drawChart(Canvas canvas) throws JSONException { paint = new Paint(Paint.ANTI_ALIAS_FLAG); // paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(1);/*w w w .j a va 2 s . c o m*/ tPaint = new Paint(); tPaint.setStyle(Paint.Style.STROKE); tPaint.setTypeface(Typeface.DEFAULT_BOLD); tPaint.setAntiAlias(true); // dataPaint = new Paint(Paint.ANTI_ALIAS_FLAG); // dataPaint.setStyle(Paint.Style.STROKE); dataPaint.setStrokeWidth(3); tPaint.setTextSize(dTextSize); axisLabelHeight = Font.getFontHeight(dTextSize); axisLabelWidth = (int) tPaint.measureText("0.00000") + offSet; klineWidth = width - axisLabelWidth; klineHeight = height - axisLabelHeight * 2 - iSLowerScreen; klineX = axisLabelWidth; klineY = axisLabelHeight; SPACE = Arith.div(klineWidth, count); //klineWidth/count; scale = klineHeight / (highPrice - lowPrice); // double ratio = (highPrice - lowPrice) / rowNum; // rowHeight = klineHeight / rowNum; colWeight = klineWidth / colNum; tPaint.setColor(GlobalColor.colorLabelName); tPaint.setTextAlign(Paint.Align.LEFT); /** * */ canvas.drawText(":" + quoteData.getJSONArray(isTrackNumber).getString(0), axisLabelWidth, axisLabelHeight - 5, tPaint); canvas.drawText(":" + quoteData.getJSONArray(isTrackNumber).getDouble(3), axisLabelWidth + width / 2, axisLabelHeight - 5, tPaint); paint.setColor(GlobalColor.clrGrayLine); /** * */ tPaint.setTextAlign(Paint.Align.RIGHT); for (int i = 0; i <= rowNum; i++) { if (i == 0 || i == rowNum) { canvas.drawLine(klineX, klineY + rowHeight * i, klineX + klineWidth, klineY + rowHeight * i, paint); } else { Graphics.drawDashline(canvas, klineX, klineY + rowHeight * i, klineX + klineWidth, klineY + rowHeight * i, paint); } if (i == 0) { canvas.drawText(Utils.dataFormation(highPrice, 3), klineX, klineY + rowHeight * i + axisLabelHeight / 2, tPaint); } else if (i == rowNum) { canvas.drawText(Utils.dataFormation(lowPrice, 3), klineX, klineY + rowHeight * i, tPaint); } else { double AxisLabelPrice = highPrice - ratio * i; canvas.drawText(Utils.dataFormation(AxisLabelPrice, 3), klineX, klineY + rowHeight * i + axisLabelHeight / 2, tPaint); } } /** * */ for (int i = 0; i <= colNum; i++) { if (i == 0) { canvas.drawLine(klineX, klineY, klineX, klineY + klineHeight, paint); } else if (i == colNum) { canvas.drawLine(width - 1, klineY, width - 1, klineY + klineHeight, paint); } else { Graphics.drawDashline(canvas, klineX + colWeight * i, klineY, klineX + colWeight * i, klineY + klineHeight, paint); } } /** * ? */ double x1 = 0; double y1 = 0; double x2 = 0; double y2 = 0; double temp = 0; double tHeight = 0; dataPaint.setColor(GlobalColor.colorStockName); dataPaint.setStrokeWidth(3); for (int i = begin; i < (begin + count); i++) { temp = quoteData.getJSONArray(i).getDouble(3); if (i - begin == 0) { x1 = klineX + SPACE * (i - begin); x2 = klineX + SPACE * (i - begin + 1); tHeight = (temp - lowPrice) * scale; // tHeight = ( - ) * y1 = axisLabelHeight + klineHeight - tHeight; // - tHeight y2 = axisLabelHeight + klineHeight - tHeight; } else { canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, dataPaint); x1 = x2; x2 = klineX + SPACE * (i - begin + 1); tHeight = (temp - lowPrice) * scale; y1 = y2; y2 = axisLabelHeight + klineHeight - tHeight; } } /** * */ tPaint.setColor(GlobalColor.colorLabelName); tPaint.setTextAlign(Paint.Align.LEFT); canvas.drawText(quoteData.getJSONArray(begin).getString(0), axisLabelWidth, klineHeight + axisLabelHeight * 2 - 5, tPaint); canvas.drawText(quoteData.getJSONArray(begin + count - 1).getString(0), (float) (width - tPaint.measureText(quoteData.getJSONArray(begin + count - 1).getString(0))), klineHeight + axisLabelHeight * 2 - 5, tPaint); /** * */ if (isTrackStatus) { canvas.save(); //?? paint.setColor(GlobalColor.colorLine); canvas.drawLine(trackLineV, axisLabelHeight, trackLineV, klineHeight + axisLabelHeight, paint); canvas.restore(); } }