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.helloandroid.animation.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from ww w.ja v a 2 s . c o m } final int height = getHeight(); // draw indicator line rectPaint.setColor(indicatorColor); Utility.logd("onDraw : currentPosition = " + currentPosition); // 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 Utility.logd("currentPositionOffset = " + currentPositionOffset); Utility.logd("tabCount = " + tabCount); 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); } Utility.logd("lineLeft = " + lineLeft + ", indicatorHeight = " + indicatorHeight + ", " + "lineRight = " + lineRight + ", height=" + height); //canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint); // draw underline Utility.logd("height=" + height + ", underlineHeight = " + underlineHeight + ", " + "tabsContainer.getWidth() = " + tabsContainer.getWidth()); 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:net.droidsolutions.droidcharts.core.renderer.xy.AbstractXYItemRenderer.java
/** * Draws a vertical line on the chart to represent a 'range marker'. * * @param g2 the graphics device./*w w w .j a v a 2s .c o m*/ * @param plot the plot. * @param domainAxis the domain axis. * @param marker the marker line. * @param dataArea the axis data area. */ public void drawDomainMarker(Canvas g2, XYPlot plot, ValueAxis domainAxis, Marker marker, Rectangle2D dataArea) { if (marker instanceof ValueMarker) { ValueMarker vm = (ValueMarker) marker; double value = vm.getValue(); Range range = domainAxis.getRange(); if (!range.contains(value)) { return; } double v = domainAxis.valueToJava2D(value, dataArea, plot.getDomainAxisEdge()); PlotOrientation orientation = plot.getOrientation(); Line2D line = null; if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); } Paint paint = marker.getPaint(); int oldAlpha = paint.getAlpha(); paint.setAlpha(marker.getAlpha()); Float stroke = marker.getStroke(); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(stroke); g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(), (float) line.getY2(), paint); String label = marker.getLabel(); RectangleAnchor anchor = marker.getLabelAnchor(); if (label != null) { Font labelFont = marker.getLabelFont(); Paint lPaint = marker.getLabelPaint(); lPaint.setTypeface(labelFont.getTypeFace()); lPaint.setTextSize(labelFont.getSize()); int lOldAlpha = lPaint.getAlpha(); lPaint.setAlpha(marker.getAlpha()); Point2D coordinates = calculateDomainMarkerTextAnchorPoint(g2, orientation, dataArea, line.getBounds2D(), marker.getLabelOffset(), LengthAdjustmentType.EXPAND, anchor); TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor(), lPaint); lPaint.setAlpha(lOldAlpha); } paint.setAlpha(oldAlpha); } else if (marker instanceof IntervalMarker) { IntervalMarker im = (IntervalMarker) marker; double start = im.getStartValue(); double end = im.getEndValue(); Range range = domainAxis.getRange(); if (!(range.intersects(start, end))) { return; } double start2d = domainAxis.valueToJava2D(start, dataArea, plot.getDomainAxisEdge()); double end2d = domainAxis.valueToJava2D(end, dataArea, plot.getDomainAxisEdge()); double low = Math.min(start2d, end2d); double high = Math.max(start2d, end2d); PlotOrientation orientation = plot.getOrientation(); Rectangle2D rect = null; if (orientation == PlotOrientation.HORIZONTAL) { // 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); } else if (orientation == PlotOrientation.VERTICAL) { // 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()); } 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 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); } else { // PlotOrientation.HORIZONTAL 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); } } 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 = calculateDomainMarkerTextAnchorPoint(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:com.astuetz.PagerSlidingTabStripExtends.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from w w w . j a v a2 s. com } 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); } //indicator // canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint); Path path = new Path(); float x1 = (lineRight + lineLeft) / 2; float y1 = height - indicatorHeight; // int triangleWidth = (int) ((lineRight - lineLeft) * 0.40f); float x2 = x1 + triangleWidth / 2; float y2 = height; float x3 = x1 - triangleWidth / 2; float y3 = height; path.moveTo(x1, y1); path.lineTo(x2, y2); path.lineTo(x3, y3); path.lineTo(x1, y1); canvas.drawPath(path, 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.astuetz.PagerSlidingTabStripCustom.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*from ww w . j av 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); } canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint); //draw triangle float bianchang = indicatorHeight + 10; float x1 = (lineRight + lineLeft) / 2; float y1 = height - bianchang; float x2 = x1 + bianchang * 2; float y2 = y1 + bianchang; float x3 = x1 - bianchang * 2; float y3 = y1 + bianchang; Path path = new Path(); path.moveTo(x1, y1); path.lineTo(x2, y2); path.lineTo(x3, y3); path.close(); canvas.drawPath(path, rectPaint); // draw underline tabcontent rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); // draw divider tab 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:ingbank.com.tr.happybanking.common.ui.controls.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*ww 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); if (triangleIndicator) { Rect r = new Rect(); int left = (int) lineLeft + (int) (((lineRight - lineLeft) / 2) - (indicatorHeight / 2)) - 20; int top = height - indicatorHeight; int right = (int) left + indicatorHeight + 30; int bottom = height; r.set(left, top, right, bottom); Path path = getEquilateralTriangle(r); canvas.drawPath(path, rectPaint); } else { 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:PagerSlidingTab.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from w w w .j a va 2 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); } canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint); // // canvas.drawRect(lineLeft, 0, lineRight, indicatorHeight, rectPaint); // // canvas.drawRect(lineLeft,height/2-indicatorHeight/2, lineRight, height/2+indicatorHeight/2, rectPaint); // // rectPaint.setColor(Color.parseColor("#66006BCE")); // canvas.drawRect(lineLeft,0, lineRight, height, rectPaint); // // RectF rect = new RectF(lineLeft, 0, lineRight, height); // canvas.drawRoundRect(rect, 8, 8, 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.dashihui.afford.ui.widget.WdtPagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from w w w . j av a 2s. c om } final int height = getHeight(); // draw indicator line //tab rectPaint.setColor(getResources().getColor(R.color.btfontBlue)); // 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) { //?tab? View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); if (lineLeft != nextTabLeft && yesBoolean < 3) { //??tab //? // Log.i(TAG, "??===TTT==nextTabLeft=====>"+nextTabLeft); // Log.i(TAG, "??===TTT==lineLeft=====>"+lineLeft); yesBoolean++; } else { lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); yesBoolean++; } } 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.nicolas.coding.third.WechatTab.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*w w w. j a v a2s . 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); } // TextView tv = ((TextView) currentTab); // String s = tv.getText().toString(); // float widths[] = new float[s.length()]; // tv.getPaint().getTextWidths(s, widths); // float StringWidth = 0; // for (float item : widths) { // StringWidth += item; // } // int padding = (int) ((tv.getWidth() - StringWidth) / 2 - mMyUnderlinePadding); // if (padding < 0) { // padding = 0; // } canvas.drawRect(lineLeft + mMyUnderlinePadding, height - indicatorHeight, lineRight - mMyUnderlinePadding, 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.next.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from w ww . j ava 2s.c om } final int height = getHeight(); // draw indicator line rectPaint.setColor(indicatorColor); updateTabColor(tabsContainer.getChildAt(currentPosition), 1.0f); // 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(currentPositionOffset > 0.5) { updateTabColor(currentTab, tabTextColorNormal); updateTabColor(nextTab, tabTextColor); } else { updateTabColor(currentTab, tabTextColor); updateTabColor(nextTab, tabTextColorNormal); } */ updateTabColor(currentTab, 1 - currentPositionOffset); updateTabColor(nextTab, currentPositionOffset); } 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.inspiron.googlegoogle.UI.View.PagerSlidingTab.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*from www . j ava 2s .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); // // canvas.drawRect(lineLeft, 0, lineRight,indicatorHeight, rectPaint); // // canvas.drawRect(lineLeft,height/2-indicatorHeight/2, lineRight,height/2+indicatorHeight/2, rectPaint); // // rectPaint.setColor(Color.parseColor("#660077E5")); // canvas.drawRect(lineLeft,0, lineRight,height, rectPaint); // // RectF rect = new RectF(lineLeft,0, lineRight,height); // canvas.drawRoundRect(rect, 6, 6, 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); } }