Example usage for android.graphics Canvas drawLine

List of usage examples for android.graphics Canvas drawLine

Introduction

In this page you can find the example usage for android.graphics Canvas drawLine.

Prototype

public void drawLine(float startX, float startY, float stopX, float stopY, @NonNull Paint paint) 

Source Link

Document

Draw a line segment with the specified start and stop x,y coordinates, using the specified paint.

Usage

From source file:net.coding.program.third.WechatTab.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (isInEditMode() || tabCount == 0) {
        return;/*from   www.j  ava 2 s.com*/
    }

    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;
    //        }

    float padding = 0.0f;
    if (currentTab instanceof TextView) {
        TextView itemTextView = (TextView) currentTab;
        float textWidth = itemTextView.getPaint().measureText(itemTextView.getText().toString());
        padding = (lineRight - lineLeft - textWidth) / 2;
    }
    if (padding <= 0.0f) {
        padding = mMyUnderlinePadding;
    }

    float lineMiddle = (lineLeft + lineRight) / 2;
    //        canvas.drawRect(lineLeft + padding, height - indicatorHeight, lineRight - padding, height, rectPaint);
    canvas.drawRect(lineMiddle - halfIndecatorWidth, height - indicatorHeight, lineMiddle + halfIndecatorWidth,
            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.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java

private void drawSelector(Canvas canvas, int index, Path selectorPath, float alphaMod) {
    final int alpha = (int) (mAlpha[index % 2].getValue() * alphaMod + 0.5f);
    final int color = applyAlpha(mSelectorColor, alpha);

    // Calculate the current radius at which to place the selection circle.
    final int selRadius = mSelectorRadius;
    final int selLength = mCircleRadius - mTextInset[index];
    final double selAngleRad = Math.toRadians(mSelectionDegrees[index % 2]);
    final float selCenterX = mXCenter + selLength * (float) Math.sin(selAngleRad);
    final float selCenterY = mYCenter - selLength * (float) Math.cos(selAngleRad);

    // Draw the selection circle.
    final Paint paint = mPaintSelector[index % 2][SELECTOR_CIRCLE];
    paint.setColor(color);/*w  w w. j  ava 2s  . co m*/
    canvas.drawCircle(selCenterX, selCenterY, selRadius, paint);

    // If needed, set up the clip path for later.
    if (selectorPath != null) {
        selectorPath.reset();
        selectorPath.addCircle(selCenterX, selCenterY, selRadius, Path.Direction.CCW);
    }

    // Draw the dot if we're between two items.
    final boolean shouldDrawDot = mSelectionDegrees[index % 2] % 30 != 0;
    if (shouldDrawDot) {
        final Paint dotPaint = mPaintSelector[index % 2][SELECTOR_DOT];
        dotPaint.setColor(mSelectorDotColor);
        canvas.drawCircle(selCenterX, selCenterY, mSelectorDotRadius, dotPaint);
    }

    // Shorten the line to only go from the edge of the center dot to the
    // edge of the selection circle.
    final double sin = Math.sin(selAngleRad);
    final double cos = Math.cos(selAngleRad);
    final int lineLength = selLength - selRadius;
    final int centerX = mXCenter + (int) (mCenterDotRadius * sin);
    final int centerY = mYCenter - (int) (mCenterDotRadius * cos);
    final float linePointX = centerX + (int) (lineLength * sin);
    final float linePointY = centerY - (int) (lineLength * cos);

    // Draw the line.
    final Paint linePaint = mPaintSelector[index % 2][SELECTOR_LINE];
    linePaint.setColor(color);
    linePaint.setStrokeWidth(mSelectorStroke);
    canvas.drawLine(mXCenter, mYCenter, linePointX, linePointY, linePaint);
}

From source file:com.csdn.pagerslidingtabstrip.view.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.c  o  m
    }

    if (pager == null) {
        rectPaint.setColor(indicatorColor);
        final int height = getHeight();
        /** tab **/
        View currentTab = tabsContainer.getChildAt(currentPosition);
        float lineLeft = currentTab.getLeft();
        float lineRight = currentTab.getRight();
        View lastTab = tabsContainer.getChildAt(lastposition);
        float detalLeft = lineLeft - lastTab.getLeft();
        float detalRight = lineRight - lastTab.getRight();

        if (currentTab != null) {

            canvas.drawRect(lineLeft - detalLeft, height - indicatorHeight,
                    lineLeft + currentTab.getWidth() - detalRight, height, rectPaint);

            Log.i("tteerr", "lineLeft=" + lineLeft + "--" + "lineRight=" + lineRight + "--detalLeft="
                    + detalLeft + "--+detalRight=" + detalRight);
            Log.i("tteerr", "" + "left=" + (lineLeft - detalLeft) + "top=" + (height - indicatorHeight)
                    + "right=" + (lineLeft + currentTab.getWidth() - detalRight) + "bottom=" + height);

            Log.i("tteerr", "currentPosition=" + currentPosition + "lastposition=" + lastposition);

        }
        return;
    }

    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);
    }

    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:com.benefit.buy.library.viewpagerindicator.PagerSlidingTabStrip.java

@SuppressLint("NewApi")
@Override/*from w  w w .j ava 2s  . co m*/
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (isInEditMode() || (tabCount == 0)) {
        return;
    }
    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 (currentTab.findViewById(R.id.img_click) != null) {
        int counts = tabsContainer.getChildCount();
        View vNow = currentTab.findViewById(R.id.tab_name);
        ImageView imgNowOn = (ImageView) currentTab.findViewById(R.id.img_click);
        View tabViewNext;
        View vNext;
        ImageView imgNextOn;
        if ((currentPosition + 1) == counts) {
            tabViewNext = tabsContainer.getChildAt(0);
            vNext = tabViewNext.findViewById(R.id.tab_name);
            imgNextOn = (ImageView) tabViewNext.findViewById(R.id.img_click);
        } else {
            tabViewNext = tabsContainer.getChildAt(currentPosition + 1);
            vNext = tabViewNext.findViewById(R.id.tab_name);
            imgNextOn = (ImageView) tabViewNext.findViewById(R.id.img_click);
        }
        int colorTo = ToolColor.getChangeColor(80, 84, 98, 255, 0, 0, currentPositionOffset);
        int colorRe = ToolColor.getChangeColor(255, 0, 0, 80, 84, 98, currentPositionOffset);
        TextView tab = (TextView) vNext;
        TextView tab2 = (TextView) vNow;
        tab.setTextColor(colorTo);
        tab2.setTextColor(colorRe);
        if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
            imgNextOn.setAlpha(currentPositionOffset);
            imgNowOn.setAlpha(1 - currentPositionOffset);
        }
    } else {
    }
    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:io.doist.datetimepicker.time.RadialTimePickerView.java

private void drawSelector(Canvas canvas, int index) {
    // Calculate the current radius at which to place the selection circle.
    mLineLength[index] = (int) (mCircleRadius[index] * mNumbersRadiusMultiplier[index]
            * mAnimationRadiusMultiplier[index]);

    double selectionRadians = Math.toRadians(mSelectionDegrees[index]);

    int pointX = mXCenter + (int) (mLineLength[index] * Math.sin(selectionRadians));
    int pointY = mYCenter - (int) (mLineLength[index] * Math.cos(selectionRadians));

    int color;/*from  w  w  w.  j  a  v a  2s.c o  m*/
    int alpha;
    Paint paint;

    // Draw the selection circle
    color = mColorSelector[index % 2][SELECTOR_CIRCLE];
    alpha = mAlphaSelector[index % 2][SELECTOR_CIRCLE].getValue();
    paint = mPaintSelector[index % 2][SELECTOR_CIRCLE];
    paint.setColor(color);
    paint.setAlpha(getMultipliedAlpha(color, alpha));
    canvas.drawCircle(pointX, pointY, mSelectionRadius[index], paint);

    // Draw the dot if needed
    if (mSelectionDegrees[index] % 30 != 0) {
        // We're not on a direct tick
        color = mColorSelector[index % 2][SELECTOR_DOT];
        alpha = mAlphaSelector[index % 2][SELECTOR_DOT].getValue();
        paint = mPaintSelector[index % 2][SELECTOR_DOT];
        paint.setColor(color);
        paint.setAlpha(getMultipliedAlpha(color, alpha));
        canvas.drawCircle(pointX, pointY, (mSelectionRadius[index] * 2 / 7), paint);
    } 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[index] - mSelectionRadius[index];
        pointX = mXCenter + (int) (lineLength * Math.sin(selectionRadians));
        pointY = mYCenter - (int) (lineLength * Math.cos(selectionRadians));
    }

    // Draw the line
    color = mColorSelector[index % 2][SELECTOR_LINE];
    alpha = mAlphaSelector[index % 2][SELECTOR_LINE].getValue();
    paint = mPaintSelector[index % 2][SELECTOR_LINE];
    paint.setColor(color);
    paint.setAlpha(getMultipliedAlpha(color, alpha));
    canvas.drawLine(mXCenter, mYCenter, pointX, pointY, paint);
}

From source file:com.cssweb.android.view.TrendView.java

private void drawWin(Canvas canvas) {
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(1);/*  ww  w .ja  v  a 2 s .c  o m*/

    mpaint = new Paint();
    mpaint.setTypeface(Typeface.DEFAULT_BOLD);
    mpaint.setAntiAlias(true);
    mpaint.setTextAlign(Paint.Align.LEFT);
    mpaint.setStyle(Paint.Style.STROKE);
    mpaint.setTextSize(dTextSize);

    /**
     * ?
     */
    closeLeft = Utils.dataFormation(high, stockdigit);
    closeRight = "00.00%";

    LSpace = (int) (Math.max(mpaint.measureText(closeLeft), mpaint.measureText(closeRight)));
    //???
    //RSpace = (int)(paint.measureText(closeRight) + 10);
    RSpace = 0;

    axisLabelHeight = Font.getFontHeight(dTextSize);

    graphicsQuoteWidth = width - LSpace - RSpace;
    SPACE = graphicsQuoteWidth / MINUTES;
    topTitleHeight = axisLabelHeight;
    graphicsQuoteHeight = height - axisLabelHeight - topTitleHeight;
    price_row_num = 2;//(int)graphicsQuoteHeight/3/25;
    volume_row_num = price_row_num;
    price_row_height = graphicsQuoteHeight / price_row_num / 3;
    volume_row_height = price_row_height;

    calc_zf();

    title1 = ":";
    title7 = ":";
    title8 = "";
    title2 = "";

    mpaint.setColor(GlobalColor.colorLabelName);

    canvas.drawText(title7 + title8, LSpace, axisLabelHeight - 5, mpaint);
    canvas.drawText(title1, LSpace + mpaint.measureText(":00:0000"), axisLabelHeight - 5, mpaint);
    canvas.drawText(title2, LSpace + mpaint.measureText(":00:0000:"), axisLabelHeight - 5, mpaint);

    if (isZs()) {
        if (close == 0)
            close = 1000;
    } else {
        if (close == 0)
            close = 1;
    }

    low = Math.min(low, close);
    //upPrice = close * (1+max_zf);
    //downPrice = close * (1-max_zf);

    paint.setColor(GlobalColor.clrLine);
    canvas.drawLine(LSpace + graphicsQuoteWidth, topTitleHeight, LSpace + graphicsQuoteWidth,
            graphicsQuoteHeight + topTitleHeight, paint);

    // 
    upQuoteX = LSpace;
    upQuoteY = topTitleHeight;
    upQuoteWidth = (int) graphicsQuoteWidth;
    upQuoteHeight = price_row_num * price_row_height;
    for (int i = 0; i < price_row_num; i++) {
        if (i == 0) {
            canvas.drawLine(upQuoteX, upQuoteY + price_row_height * i, upQuoteX + upQuoteWidth,
                    upQuoteY + price_row_height * i, paint);
        } else
            Graphics.drawDashline(canvas, upQuoteX, upQuoteY + price_row_height * i, upQuoteX + upQuoteWidth,
                    upQuoteY + price_row_height * i, paint);
    }

    for (int i = 0; i < DIVIDE_COUNT; i++) {
        if (i == 0) {
            canvas.drawLine(upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY,
                    upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY + upQuoteHeight, paint);
        } else
            Graphics.drawDashline(canvas, upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY,
                    upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY + upQuoteHeight, paint);
    }

    // 
    downQuoteX = LSpace;
    downQuoteY = topTitleHeight + upQuoteHeight;
    downQuoteWidth = (int) graphicsQuoteWidth;

    downQuoteHeight = upQuoteHeight;

    paint.setColor(GlobalColor.clrLine);
    for (int i = 0; i < price_row_num; i++) {
        if (i == 0) {
            canvas.drawLine(downQuoteX, downQuoteY + price_row_height * i, downQuoteX + downQuoteWidth,
                    downQuoteY + price_row_height * i, paint);
        } else
            Graphics.drawDashline(canvas, downQuoteX, downQuoteY + price_row_height * i,
                    downQuoteX + downQuoteWidth, downQuoteY + price_row_height * i, paint);
    }

    for (int i = 0; i < DIVIDE_COUNT; i++) {
        if (i == 0) {
            canvas.drawLine(downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY,
                    downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY + downQuoteHeight + 1, paint);
        } else
            Graphics.drawDashline(canvas, downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY,
                    downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY + downQuoteHeight, paint);
    }

    // ??
    volumeX = LSpace;
    volumeY = topTitleHeight + upQuoteHeight + downQuoteHeight;
    volumeWidth = (int) graphicsQuoteWidth;
    volumeHeight = graphicsQuoteHeight - upQuoteHeight - downQuoteHeight;

    volume_row_height = volumeHeight / volume_row_num;

    paint.setColor(GlobalColor.clrLine);
    for (int i = 0; i <= volume_row_num; i++) {
        if (i == 0) {
            canvas.drawLine(volumeX, volumeY + volume_row_height * i, volumeX + volumeWidth,
                    volumeY + volume_row_height * i, paint);
        } else {
            if (i != volume_row_num)
                Graphics.drawDashline(canvas, volumeX, volumeY + volume_row_height * i, volumeX + volumeWidth,
                        volumeY + volume_row_height * i, paint);
        }
    }

    for (int i = 0; i < DIVIDE_COUNT; i++) {
        if (i == 0) {
            canvas.drawLine(volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY,
                    volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY + volumeHeight, paint);
        } else
            Graphics.drawDashline(canvas, volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY,
                    volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY + volumeHeight, paint);
    }
    // 
    canvas.drawLine(LSpace, graphicsQuoteHeight + topTitleHeight, LSpace + graphicsQuoteWidth,
            graphicsQuoteHeight + topTitleHeight, paint);
}

From source file:com.example.SmartBoard.DrawingView.java

@Override
protected void onDraw(Canvas canvas) {

    drawCanvas.drawPath(drawPath, drawPaint);
    drawCanvas.drawPath(drawPathRecv, drawPaintSender);

    if (rectMode) {
        //draw rectangle
        drawPaint.setXfermode(null);//from w  w w . j av  a2 s .  co  m
        onDrawRectangle(canvas);
    } else if (circleMode) {
        drawPaint.setXfermode(null);
        onDrawCircle(canvas);
    } else if (lineMode) {
        drawPaint.setXfermode(null);
        onDrawLine(canvas);
    } else if (textMode) {
        drawPaint.setXfermode(null);
        onDrawText(canvas);
    } else if (dragMode && !dragFinished) {
        drawPaint.setXfermode(null);
        onDragDraw(canvas, dragX, dragY);
    } else if (colorDropperMode) {
        drawPaint.setXfermode(null);
        onDrawColorDropper(canvas, dropperX, dropperY);
    } else if (textSizeMode) {
        drawPaint.setXfermode(null);
    }

    canvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint);

    //redraw objects

    Paint tempPaint = new Paint();
    tempPaint.setStyle(Paint.Style.STROKE);

    for (String key : textObjects.keySet()) {
        if (key.compareTo("") == 0) {
            continue;
        }
        JSONObject o = textObjects.get(key);

        tempPaint.setColor(o.optInt("color"));
        tempPaint.setStrokeWidth(o.optInt("size"));

        canvas.drawBitmap(mqtt.stringToBitmap(o.optString("textBitmap")), o.optInt("x"), o.optInt("y"),
                tempPaint);

    }

    for (String key : objectDrawables.keySet()) {
        //hashtable problems no time to explain. But it creates a duplicate of last item I add to the table.
        //So dont print duplicates which have empty string key values
        if (key.compareTo("") == 0) {
            continue;
        }
        JSONObject o = objectDrawables.get(key);

        String objectType = o.optString("type");
        tempPaint.setColor(o.optInt("color"));
        tempPaint.setStrokeWidth(o.optInt("size"));

        if (objectType.compareTo("Circle") == 0) {
            canvas.drawCircle(o.optInt("x"), o.optInt("y"), o.optInt("radius"), tempPaint);

        } else if (objectType.compareTo("Line") == 0) {
            canvas.drawLine(o.optInt("startx"), o.optInt("starty"), o.optInt("stopx"), o.optInt("stopy"),
                    tempPaint);

        } else if (objectType.compareTo("Rectangle") == 0) {
            canvas.drawRect(Rect.unflattenFromString(o.optString("dimens")), tempPaint);
        } else if (objectType.compareTo("Text") == 0) {
            //canvas.drawRect(Rect.unflattenFromString(o.optString("region")), drawPaint);
            canvas.drawBitmap(mqtt.stringToBitmap(o.optString("textBitmap")), o.optInt("x"), o.optInt("y"),
                    tempPaint);

        }
    }

}

From source file:cn.edu.qzu.face.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (isInEditMode() || tabCount == 0) {
        return;/*w  ww .  ja  va 2  s . c om*/
    }

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(indicatorColor);

    for (int i = 0; i < tabsContainer.getChildCount(); ++i) {
        View tab = tabsContainer.getChildAt(i);
        tab.setSelected(i == selectedPosition);
    }

    // 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);

    //Indicator
    /*View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();
    if (currentTab instanceof TextView) {
       TextView textView = (TextView) currentTab;
    bound.setEmpty();
       Paint textPaint = textView.getPaint();
       textPaint.getTextBounds(textView.getText().toString(), 0, textView.getText().length(), bound);
       int padding = (textView.getWidth() - bound.width()) / 2;
       lineLeft = lineLeft + padding;
       lineRight = lineRight - padding;
    }
            
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {
            
       View nextTab = tabsContainer.getChildAt(currentPosition + 1);
       float nextTabLeft = nextTab.getLeft();
       float nextTabRight = nextTab.getRight();
       if (nextTab instanceof TextView) {
    TextView textView = (TextView) nextTab;
    Rect bound = new Rect();
    Paint textPaint = textView.getPaint();
    textPaint.getTextBounds(textView.getText().toString(), 0, textView.getText().length(), bound);
    int padding = (textView.getWidth() - bound.width()) / 2;
    nextTabLeft = nextTabLeft + padding;
    nextTabRight = nextTabRight - padding;
       }
            
       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:net.droidsolutions.droidcharts.core.renderer.category.LineAndShapeRenderer.java

/**
 * Draw a single data item./*w w w . ja  va2  s.com*/
 * 
 * @param g2
 *            the graphics device.
 * @param state
 *            the renderer state.
 * @param dataArea
 *            the area in which the data is drawn.
 * @param plot
 *            the plot.
 * @param domainAxis
 *            the domain axis.
 * @param rangeAxis
 *            the range axis.
 * @param dataset
 *            the dataset.
 * @param row
 *            the row index (zero-based).
 * @param column
 *            the column index (zero-based).
 * @param pass
 *            the pass index.
 */
public void drawItem(Canvas g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // do nothing if item is not visible
    if (!getItemVisible(row, column)) {
        return;
    }

    // do nothing if both the line and shape are not visible
    if (!getItemLineVisible(row, column) && !getItemShapeVisible(row, column)) {
        return;
    }

    // nothing is drawn for null...
    Number v = dataset.getValue(row, column);
    if (v == null) {
        return;
    }

    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    int visibleRowCount = state.getVisibleSeriesCount();

    PlotOrientation orientation = plot.getOrientation();

    // current data point...
    double x1;
    if (this.useSeriesOffset) {
        x1 = domainAxis.getCategorySeriesMiddle(column, dataset.getColumnCount(), visibleRow, visibleRowCount,
                this.itemMargin, dataArea, plot.getDomainAxisEdge());
    } else {
        x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    }
    double value = v.doubleValue();
    double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());

    if (pass == 0 && getItemLineVisible(row, column)) {
        if (column != 0) {
            Number previousValue = dataset.getValue(row, column - 1);
            if (previousValue != null) {
                // previous data point...
                double previous = previousValue.doubleValue();
                double x0;
                if (this.useSeriesOffset) {
                    x0 = domainAxis.getCategorySeriesMiddle(column - 1, dataset.getColumnCount(), visibleRow,
                            visibleRowCount, this.itemMargin, dataArea, plot.getDomainAxisEdge());
                } else {
                    x0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea,
                            plot.getDomainAxisEdge());
                }
                double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge());

                Line2D line = null;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    line = new Line2D.Double(y0, x0, y1, x1);
                } else if (orientation == PlotOrientation.VERTICAL) {
                    line = new Line2D.Double(x0, y0, x1, y1);
                }
                Paint paint = getItemPaint(row, column);
                Float stroke = getItemStroke(row, column);

                paint.setStyle(Paint.Style.STROKE);
                paint.setStrokeWidth(stroke);
                paint.setStrokeCap(Paint.Cap.ROUND);
                g2.drawLine((float) line.getX1(), (float) line.getY1(), (float) line.getX2(),
                        (float) line.getY2(), paint);
            }
        }
    }

    if (pass == 1) {
        Shape shape = getItemShape(row, column);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
        }

        if (getItemShapeVisible(row, column)) {
            if (getItemShapeFilled(row, column)) {
                Paint paint;
                if (this.useFillPaint) {
                    paint = getItemFillPaint(row, column);
                } else {
                    paint = getItemPaint(row, column);
                }
                paint.setStyle(Paint.Style.FILL_AND_STROKE);
                Path path = convertAwtPathToAndroid(shape.getPathIterator(null));
                g2.drawPath(path, paint);

            }
            if (this.drawOutlines) {
                Paint paint;
                if (this.useOutlinePaint) {
                    paint = getItemOutlinePaint(row, column);
                } else {
                    paint = getItemPaint(row, column);
                }
                paint.setStyle(Paint.Style.STROKE);
                paint.setStrokeWidth(getItemOutlineStroke(row, column));
                Path path = convertAwtPathToAndroid(shape.getPathIterator(null));
                g2.drawPath(path, paint);
            }
        }

        // draw the item label if there is one...
        if (isItemLabelVisible(row, column)) {
            if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, row, column, y1, x1, (value < 0.0));
            } else if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, row, column, x1, y1, (value < 0.0));
            }
        }

        // submit the current data point as a crosshair candidate
        int datasetIndex = plot.indexOf(dataset);
        updateCrosshairValues(state.getCrosshairState(), dataset.getRowKey(row), dataset.getColumnKey(column),
                value, datasetIndex, x1, y1, orientation);

        // add an item entity, if this information is being collected
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            addItemEntity(entities, dataset, row, column, shape);
        }
    }

}

From source file:com.lovely3x.eavlibrary.EasyAdapterView.java

@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    drawDivider(canvas);//from w  w w .  j a v a  2 s . co  m
    if (DEBUG) {
        switch (mLayoutDirectly) {
        case LAYOUT_DIRECTLY_HORIZONTAL:
            canvas.drawLine(getXSel(), 0, getXSel(), getHeight(), mDebugPaint);
            break;
        case LAYOUT_DIRECTLY_VERTICAL:
            canvas.drawLine(0, getYSel(), getWidth(), getYSel(), mDebugPaint);
            break;
        }
        canvas.drawText(String.valueOf(mFirstPosition), 100, 100, mDebugPaint);
    }

}