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:ar.com.xpasta.Controls.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0)
        return;//from   w  w  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.googlecode.eyesfree.widget.RadialMenuView.java

private void drawCancel(Canvas canvas, int width, int height, float center) {
    final float centerX = mCenter.x;
    final float centerY = mCenter.y;
    final float radius = mInnerRadius;
    final float iconRadius = (radius / 4.0f);

    final RectF dotBounds = new RectF((centerX - radius), (centerY - radius), (centerX + radius),
            (centerY + radius));/*from www.j av  a 2s.  c  om*/

    // Apply the appropriate color filters.
    final boolean selected = (mFocusedItem == null);

    mPaint.setStyle(Style.FILL);
    mPaint.setColor(selected ? mSelectionColor : mCenterFillColor);
    mPaint.setShadowLayer(mShadowRadius, 0, 0, (selected ? mSelectionShadowColor : mTextShadowColor));
    canvas.drawOval(dotBounds, mPaint);
    mPaint.setShadowLayer(0, 0, 0, 0);

    mPaint.setStyle(Style.STROKE);
    mPaint.setColor(selected ? mSelectionTextFillColor : mCenterTextFillColor);
    mPaint.setStrokeCap(Cap.SQUARE);
    mPaint.setStrokeWidth(10.0f);
    canvas.drawLine((centerX - iconRadius), (centerY - iconRadius), (centerX + iconRadius),
            (centerY + iconRadius), mPaint);
    canvas.drawLine((centerX + iconRadius), (centerY - iconRadius), (centerX - iconRadius),
            (centerY + iconRadius), mPaint);
}

From source file:com.gc.materialdesign.views.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (isInEditMode() || tabCount == 0) {
        return;//from  w w 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.anniu.shandiandaojia.view.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (isInEditMode() || tabCount == 0) {
        return;/* www  . j  a  va2 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);
    // 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:cn.bingoogol.tabhost.ui.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*/
    }
    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.xxjwd.libs.PagerSlidingTabStrip.java

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

   if (isInEditMode() || tabCount == 0) {
      return;/*from   w  w w  . j  av a  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);

   // 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:lollipop.util.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;//from   w  w  w.  jav  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 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.example.dhruvil.geleza_teacherconsole.CustomViews.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;/*from   w w w. java2 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, 0, lineRight, indicatorHeight, 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.muzima.view.custom.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;/*from w ww  .jav  a2s .  c o m*/
    }

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(indicatorColor);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    int lineLeft = currentTab.getLeft();
    int 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);
        int nextTabLeft = nextTab.getLeft();
        int nextTabRight = nextTab.getRight();

        lineLeft = (int) (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (int) (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.contentful.discovery.ui.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;/*from   w  w w  .  j  a  v  a2 s .c o  m*/
    }

    final int height = getHeight();

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

    // draw underline
    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw indicator
    rectPaint.setColor(indicatorColor);
    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);
    }
}