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.uphyca.recyclerviewcommons.SimpleDividerItemDecoration.java

@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDraw(c, parent, state);

    final RecyclerView.LayoutManager manager = parent.getLayoutManager();

    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();

    final int childCount = parent.getChildCount();
    if (childCount < 2) {
        return;/* w  ww .  ja  va 2 s  .  com*/
    }

    for (int i = 1; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        if (params.getViewLayoutPosition() <= dividerStartPosition) {
            continue;
        }
        // ViewCompat.getTranslationY() needs for add/delete animation
        final int top = manager.getDecoratedTop(child) - params.topMargin
                + Math.round(ViewCompat.getTranslationY(child));
        final int bottom = top + dividerHeight;
        c.drawRect(left + dividerMargin, top, right - dividerMargin, bottom, paint);
    }
}

From source file:com.viewpagerindicator.UnderlinePageIndicator.java

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

    if (mViewPager == null) {
        return;//from  w  w  w.  ja va2 s .  c o m
    }
    final int count = getTotal();
    if (count == 0) {
        return;
    }

    if (mCurrentPage >= count) {
        setCurrentItem(count - 1);
        return;
    }

    final int paddingLeft = getPaddingLeft();
    final float pageWidth = (getWidth() - paddingLeft - getPaddingRight()) / (1f * count);
    final float left = paddingLeft + pageWidth * (mCurrentPage + mPositionOffset);
    final float right = left + pageWidth;
    final float top = getPaddingTop();
    final float bottom = getHeight() - getPaddingBottom();
    canvas.drawRect(left, top, right, bottom, mPaint);
}

From source file:com.benefit.buy.library.viewpagerindicator.UnderlinePageIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (mViewPager == null) {
        return;/*from  www  .j a  v  a2s .c o m*/
    }
    final int count = mViewPager.getAdapter().getCount();
    if (count == 0) {
        return;
    }
    if (mCurrentPage >= count) {
        setCurrentItem(count - 1);
        return;
    }
    final int paddingLeft = getPaddingLeft();
    final float pageWidth = (getWidth() - paddingLeft - getPaddingRight()) / (1f * count);
    final float left = paddingLeft + (pageWidth * (mCurrentPage + mPositionOffset));
    final float right = left + pageWidth;
    final float top = getPaddingTop();
    final float bottom = getHeight() - getPaddingBottom();
    canvas.drawRect(left, top, right, bottom, mPaint);
}

From source file:com.nshmura.recyclertablayout.RecyclerTabLayout.java

@Override
public void onDraw(Canvas canvas) {
    View view = mLinearLayoutManager.findViewByPosition(mIndicatorPosition);
    if (view == null) {
        if (mRequestScrollToTab) {
            mRequestScrollToTab = false;
            scrollToTab(mViewPager.getCurrentItem());
        }//from  ww w  .  jav a2s . c o  m
        return;
    }
    mRequestScrollToTab = false;

    int left = view.getLeft() + mScrollOffset - mIndicatorOffset;
    int right = view.getRight() + mScrollOffset + mIndicatorOffset;
    int top = getHeight() - mIndicatorHeight;
    int bottom = getHeight();
    canvas.drawRect(left, top, right, bottom, mIndicatorPaint);
}

From source file:com.base.app.widget.indicatorview.UnderlinePageIndicator.java

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

    if (mViewPager == null) {
        return;//w ww .  j av a  2s.  c  om
    }
    final int count = mViewPager.getAdapter().getCount();
    if (count == 0) {
        return;
    }

    if (mCurrentPage >= count) {
        setCurrentItem(count - 1);
        return;
    }

    final int paddingLeft = getPaddingLeft();
    final float pageWidth = (getWidth() - paddingLeft - getPaddingRight()) / (1f * count);
    final float left = paddingLeft + pageWidth * (mCurrentPage + mPositionOffset);
    final float right = left + pageWidth;
    final float top = getPaddingTop();
    final float bottom = getHeight() - getPaddingBottom();
    canvas.drawRect(left, top, right + 10, bottom, mPaint);
}

From source file:com.homechart.app.commont.matertab.MaterialTabs.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();
    // Draw indicator line.
    rectPaint.setColor(indicatorColor);
    Pair<Float, Float> lines = getIndicatorCoordinates();
    canvas.drawRect(lines.first + paddingLeft, height - indicatorHeight, lines.second + paddingLeft, height,
            rectPaint);
    // Draw underline.
    rectPaint.setColor(underlineColor);
    canvas.drawRect(paddingLeft, height - underlineHeight, tabsContainer.getWidth() + paddingRight, height,
            rectPaint);
}

From source file:com.runmit.sweedee.view.UnderlinePageIndicator.java

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

    if (mViewPager == null) {
        return;//from w w  w  . j a v a2 s .  c  om
    }
    final int count = ((RecyclingPagerAdapter) mViewPager.getAdapter()).getRealCount();
    if (count == 0) {
        return;
    }

    final int paddingLeft = getPaddingLeft();
    final float pageWidth = (getWidth() - paddingLeft - getPaddingRight()) / (1f * count);
    final float left = paddingLeft + pageWidth * (mCurrentPage % count + mPositionOffset);
    final float right = left + pageWidth;
    final float top = getPaddingTop();
    final float bottom = getHeight() - getPaddingBottom();
    int width = getWidth();
    if (right <= width) {
        canvas.drawRect(left, top, right, bottom, mPaint);
    } else {
        canvas.drawRect(left, top, width, bottom, mPaint);
        canvas.drawRect(0, top, right - width, bottom, mPaint);

    }
}

From source file:android.hqs.view.pager.indicator.UnderlinePageIndicator.java

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

    if (mViewPager == null) {
        return;//from w  ww  .ja  va  2  s .  c o  m
    }
    final int count = mViewPager.getAdapter().getCount();
    if (count == 0) {
        return;
    }

    if (mCurrentPage >= count) {
        setCurrentItem(count - 1);
        return;
    }

    final int paddingLeft = getPaddingLeft();
    final float pageWidth = (getWidth() - paddingLeft - getPaddingRight()) / (1f * count);
    final float left = paddingLeft + pageWidth * (mCurrentPage + mPositionOffset);
    final float right = left + pageWidth;
    final float top = getPaddingTop();
    final float bottom = getHeight() - getPaddingBottom();
    canvas.drawRect(left, top, right, bottom, mPaint);
}

From source file:com.ameron32.apps.tapnotes._trial.ui.CollapsingTitleLayout.java

@Override
public void draw(Canvas canvas) {
    final int saveCount = canvas.save();

    final int toolbarHeight = mToolbar.getHeight();
    canvas.clipRect(0, 0, canvas.getWidth(), interpolate(canvas.getHeight(), toolbarHeight, mScrollOffset));

    // Now call super and let it draw the background, etc
    super.draw(canvas);

    if (mTitleToDraw != null) {
        float x = mTextLeft;
        float y = mTextTop;

        final float ascent = mTextPaint.ascent() * mScale;
        final float descent = mTextPaint.descent() * mScale;
        final float h = descent - ascent;

        if (DEBUG_DRAW) {
            // Just a debug tool, which drawn a Magneta rect in the text bounds
            canvas.drawRect(mTextLeft, y - h + descent, mTextRight, y + descent, DEBUG_DRAW_PAINT);
        }/*from   w  w w . j a v  a  2s .c  om*/

        if (mUseTexture) {
            y = y - h + descent;
        }

        if (mScale != 1f) {
            canvas.scale(mScale, mScale, x, y);
        }

        if (mUseTexture && mExpandedTitleTexture != null) {
            // If we should use a texture, draw it instead of text
            canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint);
        } else {
            canvas.drawText(mTitleToDraw, x, y, mTextPaint);
        }
    }

    canvas.restoreToCount(saveCount);
}

From source file:com.cosmicsubspace.nerdyaudio.visuals.PlayControlsView.java

@Override
protected void onDraw(Canvas canvas) {

    //Log2.log(2,this,buttonFollower.getInfluence().getValue(),playBtnRestPosition.getInfluence().getValue());

    currentFrameTime = System.currentTimeMillis();

    pt.setColor(menuColor);/* w w w .j a  va  2s .c o  m*/
    canvas.drawRect(0, h - barHeight.getValue(currentFrameTime).getValue("Height"), w, h, pt);

    titleAnimatable.draw(canvas, pt, currentFrameTime);

    artistAnimatable.draw(canvas, pt, currentFrameTime);

    filePath.draw(canvas, pt, currentFrameTime);
    if (albumArt != null) {
        pt.setAlpha(Math.round(albumArtColor.getValue(currentFrameTime).getValue("alpha")));
        canvas.drawBitmap(albumArt, null, artBoundsAnim.getRectF(currentFrameTime), pt);
        //Log2.log(1,this, "trying to draw..");
        pt.setAlpha(255);
    }

    waveform.draw(canvas, pt, currentFrameTime);

    pt.setColor(Color.argb(50, 0, 0, 0));

    pt.setColor(buttonColor);

    playBtn.draw(canvas, pt, currentFrameTime);

    pauseBtn.draw(canvas, pt, currentFrameTime);

    prevBtn.draw(canvas, pt, currentFrameTime);
    nextBtn.draw(canvas, pt, currentFrameTime);

    if (wf != null && ap != null && wf.isReady() && wf.getFilename().equals(ap.getSourceString())) {
        setCurrentPosition((float) (ap.getMusicCurrentFrame() / (double) wf.getNumOfFrames()));

        if (!dragMode) {
            timestampAnim.setText(wf.frameNumberToTimeStamp(ap.getMusicCurrentFrame()));
        }

        timestampAnim.draw(canvas, pt, currentFrameTime);

        buttonFollowerProgress.getBasis().setValue("X", w * currentPosition);
    }

    invalidate();

}