Example usage for android.graphics Canvas drawRect

List of usage examples for android.graphics Canvas drawRect

Introduction

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

Prototype

public void drawRect(float left, float top, float right, float bottom, @NonNull Paint paint) 

Source Link

Document

Draw the specified Rect using the specified paint.

Usage

From source file:com.example.jit.home.SlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    final int height = getHeight();
    final int childCount = getChildCount();
    final SlidingTabLayout.TabColorizer tabColorizer = mCustomTabColorizer != null ? mCustomTabColorizer
            : mDefaultTabColorizer;//from  w ww.  j a  v  a2s.  c  o  m

    // Thick colored underline below the current selection
    if (childCount > 0) {
        View selectedTitle = getChildAt(mSelectedPosition);
        int left = selectedTitle.getLeft();
        int right = selectedTitle.getRight();
        int color = tabColorizer.getIndicatorColor(mSelectedPosition);

        if (mSelectionOffset > 0f && mSelectedPosition < (getChildCount() - 1)) {
            int nextColor = tabColorizer.getIndicatorColor(mSelectedPosition + 1);
            if (color != nextColor) {
                color = blendColors(nextColor, color, mSelectionOffset);
            }

            // Draw the selection partway between the tabs
            View nextTitle = getChildAt(mSelectedPosition + 1);
            left = (int) (mSelectionOffset * nextTitle.getLeft() + (1.0f - mSelectionOffset) * left);
            right = (int) (mSelectionOffset * nextTitle.getRight() + (1.0f - mSelectionOffset) * right);
        }

        mSelectedIndicatorPaint.setColor(color);

        canvas.drawRect(left, height - mSelectedIndicatorThickness, right, height, mSelectedIndicatorPaint);
    }

    // Thin underline along the entire bottom edge
    canvas.drawRect(0, height - mBottomBorderThickness, getWidth(), height, mBottomBorderPaint);
}

From source file:bigshots.people_helping_people.scroll_iew_lib.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;//from   w w  w . ja va 2  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, 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);
    }

    updateTextColor();
}

From source file:com.machine.custom.viewpagerindicator.TabUnderlinePageIndicator.java

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

    final int childCount = mTabLayout.getChildCount();
    if (isInEditMode() || childCount == 0) {
        return;//from  ww w. jav a  2  s  .c om
    }

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(underlineColor);

    // default: line below current tab
    View currentTab = mTabLayout.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 < childCount - 1) {

        View nextTab = mTabLayout.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);

}

From source file:com.example.android.common.view.SlidingTabLayout2.java

@Override
public void onDraw(Canvas canvas) {
    final int height = getHeight();
    final int childCount = this.getAdapter().getItemCount();

    // Thick colored underline below the current selection
    if (childCount > 0) {
        ViewHolder selectedTitle = this.findViewHolderForAdapterPosition(mSelectedPosition);
        if (selectedTitle != null) {

            System.out.println("childCount:" + childCount + ", mSelectedPosition:" + mSelectedPosition);
            int left = selectedTitle.itemView.getLeft();
            int right = selectedTitle.itemView.getRight();

            if (mSelectionOffset > 0f && mSelectedPosition < (childCount - 1)) {

                // Draw the selection partway between the tabs
                ViewHolder nextTitle = this.findViewHolderForAdapterPosition(mSelectedPosition + 1);
                if (nextTitle != null) {
                    left = (int) (mSelectionOffset * nextTitle.itemView.getLeft()
                            + (1.0f - mSelectionOffset) * left);
                    right = (int) (mSelectionOffset * nextTitle.itemView.getRight()
                            + (1.0f - mSelectionOffset) * right);
                }/*ww  w . j a v  a2  s .c o  m*/
            }

            canvas.drawRect(left, height - 30, right, height, paint);
        }
    }

    // Thin underline along the entire bottom edge
    canvas.drawRect(0, height - 20, getWidth(), height, paint);
    super.onDraw(canvas);
}

From source file:com.tiange.hz.wheelview.widget.WheelView.java

private void drawMask(Canvas canvas) {
    int center = getHeight() / 2;
    int offset = (int) (getItemHeight() / 2 * 1.2);
    /*int maskA = Color.alpha(wheelBackgroundColor);
    int maskR = Color.red(wheelBackgroundColor);
    int maskG = Color.green(wheelBackgroundColor);
    int maskB = Color.blue(wheelBackgroundColor);*/
    int wheelUnSelectedMaskColor = Color.argb((int) (255 * wheelUnselectedMaskAlphaRate), 255, 255, 255);
    Paint paint = new Paint();
    paint.setColor(wheelUnSelectedMaskColor);
    canvas.drawRect(0, 0, getWidth(), center - offset - 1, paint);
    canvas.drawRect(0, center + offset + 1, getWidth(), getHeight(), paint);
}

From source file:com.xiaosu.lib.base.widget.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (isInEditMode() || mTabCount == 0) {
        return;/* ww w  .j  av a  2s. c o m*/
    }

    final int height = getHeight();
    // draw divider
    if (mDividerWidth > 0) {
        mDividerPaint.setStrokeWidth(mDividerWidth);
        mDividerPaint.setColor(mDividerColor);
        for (int i = 0; i < mTabCount - 1; i++) {
            View tab = mTabsContainer.getChildAt(i);
            canvas.drawLine(tab.getRight(), mDividerPadding, tab.getRight(), height - mDividerPadding,
                    mDividerPaint);
        }
    }

    // draw underline
    if (mUnderlineHeight > 0) {
        mRectPaint.setColor(mUnderlineColor);
        canvas.drawRect(mPaddingLeft, height - mUnderlineHeight, mTabsContainer.getWidth() + mPaddingRight,
                height, mRectPaint);
    }

    // draw indicator line
    if (mIndicatorHeight > 0) {
        mRectPaint.setColor(mIndicatorColor);
        Pair<Float, Float> lines = getIndicatorCoordinates();
        canvas.drawRect(lines.first + mPaddingLeft + mIndicatorPadding, height - mIndicatorHeight,
                lines.second + mPaddingLeft - mIndicatorPadding, height, mRectPaint);
    }
}

From source file:com.bei.test.view.tab.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (isInEditMode() || mTabCount == 0) {
        return;//from   www .ja  v a2s .c o m
    }

    final int height = getHeight();
    // draw divider
    if (mDividerWidth > 0) {
        mDividerPaint.setStrokeWidth(mDividerWidth);
        mDividerPaint.setColor(mDividerColor);
        for (int i = 0; i < mTabCount - 1; i++) {
            View tab = mTabsContainer.getChildAt(i);
            canvas.drawLine(tab.getRight(), mDividerPadding, tab.getRight(), height - mDividerPadding,
                    mDividerPaint);
        }
    }

    // draw underline
    if (mUnderlineHeight > 0) {
        mRectPaint.setColor(mUnderlineColor);
        canvas.drawRect(mPaddingLeft, height - mUnderlineHeight, mTabsContainer.getWidth() + mPaddingRight,
                height, mRectPaint);
    }

    // draw indicator line
    if (mIndicatorHeight > 0) {
        mRectPaint.setColor(mIndicatorColor);
        Pair<Float, Float> lines = getIndicatorCoordinates();
        canvas.drawRect(lines.first + mPaddingLeft, height - mIndicatorHeight, lines.second + mPaddingLeft,
                height, mRectPaint);
    }
}

From source file:com.ecomnationmobile.library.Control.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (isInEditMode() || mTabCount == 0) {
        return;//from  w ww  . j a va  2  s  .c om
    }

    final int height = getHeight();
    // draw horizontal_divider
    if (mDividerWidth > 0) {
        mDividerPaint.setStrokeWidth(mDividerWidth);
        mDividerPaint.setColor(mDividerColor);
        for (int i = 0; i < mTabCount - 1; i++) {
            View tab = mTabsContainer.getChildAt(i);
            canvas.drawLine(tab.getRight(), mDividerPadding, tab.getRight(), height - mDividerPadding,
                    mDividerPaint);
        }
    }

    // draw underline
    if (mUnderlineHeight > 0) {
        mRectPaint.setColor(mUnderlineColor);
        canvas.drawRect(mPaddingLeft, height - mUnderlineHeight, mTabsContainer.getWidth() + mPaddingRight,
                height, mRectPaint);
    }

    // draw indicator line
    if (mIndicatorHeight > 0) {
        mRectPaint.setColor(mIndicatorColor);
        Pair<Float, Float> lines = getIndicatorCoordinates();
        canvas.drawRect(lines.first + mPaddingLeft, height - mIndicatorHeight, lines.second + mPaddingLeft,
                height, mRectPaint);
    }
}

From source file:com.jumeng.shop.view.PagerSlidingTabStrip.java

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

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

    final int height = getHeight();

    rectPaint.setColor(indicatorColor);

    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.wunding.mlplayer.ui.PagerSlidingTabStrip.java

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

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