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:com.android.view.ScrollView.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;//from   w  w  w.  ja v  a  2s  .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 + indicator_leftpadding, height - indicatorHeight,
            lineRight - indicator_rightpadding, 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 + 20, tab.getRight(), height - dividerPadding - 20,
                dividerPaint);
    }
}

From source file:com.cplatform.xhxw.ui.ui.base.view.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;/*  w  ww. 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);
    }

    //      canvas.drawRect(lineLeft + 20, (int) (height * 0.8), lineRight - 20,
    //            (int) (height * 0.8) + 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.pinthecloud.item.view.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;// ww w.  java 2s  .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);
    }

    lineLeft += indicatorPadding;
    lineRight -= indicatorPadding;

    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.zhongsou.souyue.circle.view.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;/*  w  w w. j a  va 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 - underlineHeight, lineRight, height, rectPaint);

    // draw underline
    rectPaint.setColor(Color.parseColor("#BCBCBC"));
    canvas.drawRect(0, height - underlineHeight + 1 / 2, 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.coding.program.common.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;/*from www  .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 + 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.newshotsift.PagerSlidingTab.java

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

    if (isInEditMode() || tabCount == 0) {
        return;//from w  ww  . ja v a  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);

    // 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:dk.dr.radio.diverse.PagerSlidingTabStrip.java

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

      if (isInEditMode() || tabCount == 0) {
          return;
      }//from ww 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.bobomee.android.tab_navigator.recyclerview.FlexibleDividerDecoration.java

@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    RecyclerView.Adapter adapter = parent.getAdapter();
    if (adapter == null) {
        return;//from  w w w . j a v a2s  . co m
    }

    int itemCount = adapter.getItemCount();
    int lastDividerOffset = getLastDividerOffset(parent);
    int validChildCount = parent.getChildCount();
    int lastChildPosition = -1;
    for (int i = 0; i < validChildCount; i++) {
        View child = parent.getChildAt(i);
        int childPosition = parent.getChildAdapterPosition(child);

        if (childPosition < lastChildPosition) {
            // Avoid remaining divider when animation starts
            continue;
        }
        lastChildPosition = childPosition;

        if (!mShowLastDivider && childPosition >= itemCount - lastDividerOffset) {
            // Don't draw divider for last line if mShowLastDivider = false
            continue;
        }

        if (wasDividerAlreadyDrawn(childPosition, parent)) {
            // No need to draw divider again as it was drawn already by previous column
            continue;
        }

        int groupIndex = getGroupIndex(childPosition, parent);
        if (mVisibilityProvider.shouldHideDivider(groupIndex, parent)) {
            continue;
        }

        Rect bounds = getDividerBound(groupIndex, parent, child);
        switch (mDividerType) {
        case DRAWABLE:
            Drawable drawable = mDrawableProvider.drawableProvider(groupIndex, parent);
            drawable.setBounds(bounds);
            drawable.draw(c);
            break;
        case PAINT:
            mPaint = mPaintProvider.dividerPaint(groupIndex, parent);
            c.drawLine(bounds.left, bounds.top, bounds.right, bounds.bottom, mPaint);
            break;
        case COLOR:
            mPaint.setColor(mColorProvider.dividerColor(groupIndex, parent));
            mPaint.setStrokeWidth(mSizeProvider.dividerSize(groupIndex, parent));
            c.drawLine(bounds.left, bounds.top, bounds.right, bounds.bottom, mPaint);
            break;
        }
    }
}

From source file:com.xujun.funapp.widget.TabPagerIndicator.java

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

    if (isInEditMode() || tabCount == 0) {
        return;//from   w ww .  j av 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);
        if (!isSame) {
            canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding,
                    dividerPaint);
        } else {
            canvas.drawLine(tab.getRight() + horizontalPadding, dividerPadding,
                    tab.getRight() + horizontalPadding, height - dividerPadding, dividerPaint);
        }
    }
}

From source file:com.little.pager.PagerSlidingTabStrip.java

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

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

    final int height = getHeight();

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

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

    //
    if (hasDivier) {
        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);
        }
    }
}