List of usage examples for android.graphics Canvas drawRect
public void drawRect(float left, float top, float right, float bottom, @NonNull Paint paint)
From source file:base.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*from ww w.j a v a2 s . c om*/ } final int height = getHeight(); // draw indicator line rectPaint.setColor(indicatorColor); Pair<Float, Float> lines = getIndicatorCoordinates(); canvas.drawRect(lines.first + paddingLeft, height - indicatorHeight, lines.second + paddingRight, height, rectPaint); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(paddingLeft, height - underlineHeight, tabsContainer.getWidth() + paddingRight, height, rectPaint); // draw divider if (dividerWidth != 0) { dividerPaint.setStrokeWidth(dividerWidth); 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.wangbb.naruto.app.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. co 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() + iLinePadding; float lineRight = currentTab.getRight() - iLinePadding; // 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() + iLinePadding; final float nextTabRight = nextTab.getRight() - iLinePadding; 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.example.fragmentdemo.views.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/* w ww . j a va2 s.co 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() + iLinePadding; 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() + iLinePadding; 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.tomeokin.widget.jotablayout2.JoTabLayout.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // draw underline if (mUnderlineHeight > 0) { mUnderlinePaint.setColor(mUnderlineColor); // ? GRAVITY_BOTTOM // getMeasuredHeight view // getHeight ? android:clipToPadding="true" getHeight() if (mUnderlineGravity == GRAVITY_BOTTOM) { canvas.drawRect(getPaddingLeft(), getHeight() - mUnderlineHeight, getWidth() + getPaddingLeft(), getHeight(), mUnderlinePaint); } else {/*from w w w . ja v a 2 s. co m*/ canvas.drawRect(getPaddingLeft(), 0, getWidth() + getPaddingLeft(), mUnderlineHeight, mUnderlinePaint); } } // draw divider if (mDividerWidth > 0) { mDividerPaint.setStrokeWidth(mDividerWidth); mDividerPaint.setColor(mDividerColor); View tab; for (int i = 0; i < mTabCount - 1; i++) { tab = getChildAt(i); canvas.drawLine(getPaddingLeft() + tab.getRight(), mDividerVerticalPadding, getPaddingLeft() + tab.getRight(), getHeight() - mDividerVerticalPadding, mDividerPaint); } } calIndicatorRect(); mIndicatorRect.left += mIndicatorAnimOffset; mIndicatorRect.right = mIndicatorRect.left + (int) mIndicatorWidth; if (mIndicatorShape != SHAPE_NONE) { if (mIndicatorShape == SHAPE_TRIANGLE) { mTrianglePaint.setColor(mIndicatorColor); mTrianglePath.reset(); mTrianglePath.moveTo(mIndicatorRect.left, getHeight()); mTrianglePath.lineTo(mIndicatorRect.left / 2 + mIndicatorRect.right / 2, getHeight() - mIndicatorHeight); mTrianglePath.lineTo(mIndicatorRect.right, getHeight()); mTrianglePath.close(); canvas.drawPath(mTrianglePath, mTrianglePaint); } else if (mIndicatorShape == SHAPE_LINE) { mIndicatorDrawable.setColor(mIndicatorColor); if (mIndicatorGravity == GRAVITY_BOTTOM) { mIndicatorDrawable.setBounds(mIndicatorRect.left, getHeight() - (int) mIndicatorHeight, mIndicatorRect.right, getHeight()); } else { mIndicatorDrawable.setBounds(mIndicatorRect.left, 0, mIndicatorRect.right, (int) mIndicatorHeight); } mIndicatorDrawable.setCornerRadius(mIndicatorCornerRadius); mIndicatorDrawable.draw(canvas); } else if (mIndicatorShape == SHAPE_SQUARE) { if (mIndicatorCornerRadius <= 0 || mIndicatorCornerRadius > mIndicatorHeight / 2) { mIndicatorCornerRadius = mIndicatorHeight / 2; } mIndicatorRect.top = (int) ((getHeight() - mIndicatorHeight) / 2); mIndicatorRect.bottom = mIndicatorRect.top + (int) mIndicatorHeight; mIndicatorDrawable.setColor(mIndicatorColor); mIndicatorDrawable.setBounds(mIndicatorRect.left, mIndicatorRect.top, mIndicatorRect.right, mIndicatorRect.bottom); mIndicatorDrawable.setCornerRadius(mIndicatorCornerRadius); mIndicatorDrawable.draw(canvas); } } }
From source file:com.visenze.visearch.camerademo.views.RoundImageView.java
@Override protected void onDraw(Canvas canvas) { if (mBounds == null) { return;/*from w ww .j ava 2 s . co m*/ } int width = mBounds.width(); int height = mBounds.height(); if (width == 0 || height == 0) { return; } canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG)); if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) { // Need to redraw the cache if (width == mCachedWidth && height == mCachedHeight) { // Have a correct-sized bitmap cache already allocated. Just erase it. mCacheBitmap.eraseColor(0); } else { // Allocate a new bitmap with the correct dimensions. mCacheBitmap.recycle(); //noinspection AndroidLintDrawAllocation mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); mCachedWidth = width; mCachedHeight = height; } Canvas cacheCanvas = new Canvas(mCacheBitmap); cacheCanvas .setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG)); if (mMaskDrawable != null) { int sc = cacheCanvas.save(); mMaskDrawable.draw(cacheCanvas); mMaskedPaint.setColorFilter((mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null); cacheCanvas.saveLayer(mBoundsF, mMaskedPaint, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG); super.onDraw(cacheCanvas); cacheCanvas.restoreToCount(sc); } else if (mDesaturateOnPress && isPressed()) { int sc = cacheCanvas.save(); cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint); mMaskedPaint.setColorFilter(mDesaturateColorFilter); cacheCanvas.saveLayer(mBoundsF, mMaskedPaint, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG); super.onDraw(cacheCanvas); cacheCanvas.restoreToCount(sc); } else { super.onDraw(cacheCanvas); } if (mBorderDrawable != null) { mBorderDrawable.draw(cacheCanvas); } } // Draw from cache canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null); }
From source file:com.hua.weget.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); LogUtils2.i("onDraw------------------------"); if (isInEditMode() || tabCount == 0) { return;/*from ww w . j av a2s . co m*/ } final int height = getHeight(); LogUtils2.w("getHeight();==" + getHeight()); // draw underline Tab viewpager 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(); LogUtils2.d("currentPositionOffset==" + currentPositionOffset); LogUtils2.d("nextTabLeft==" + nextTabLeft); LogUtils2.d("lineLeft==" + lineLeft); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); // lineLeft = (currentPositionOffset * nextTabLeft) + (1f - currentPositionOffset) * lineLeft; } 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.ashish.routofy.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//w ww .j av a 2 s .c om } 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); // draw divider if (dividerWidth != 0) { dividerPaint.setStrokeWidth(dividerWidth); 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.lovebridge.library.view.viewpagerindicator.UnderlinePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;/*w ww .j a va 2 s. 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, bottom, mPaint); }
From source file:com.freud.mrzz.views.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from w w w . j ava2 s. com } final int height = getHeight(); // draw indicator line rectPaint.setColor(indicatorColor); Pair<Float, Float> lines = getIndicatorCoordinates(); canvas.drawRect(lines.first + padding, height - indicatorHeight, lines.second + padding, height, rectPaint); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(padding, height - underlineHeight, tabsContainer.getWidth() + padding, height, rectPaint); // draw divider if (dividerWidth != 0) { dividerPaint.setStrokeWidth(dividerWidth); 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.wanikani.androidnotifier.graph.TYPlot.java
/** * Draws a segment without data/*from w w w.ja v a2 s.c om*/ * @param canvas the canvas * @param i the interval size * @return <tt>true</tt> unless this part entirely outside the viewport */ protected boolean drawMissing(Canvas canvas, Pager.Interval i) { int from, to; if (!vp.visible(i)) return false; from = i.start; to = Math.min(i.stop + 1, vp.today); canvas.drawRect(vp.getRelPosition(from), meas.plotArea.top, vp.getRelPosition(to), meas.plotArea.bottom, pas.partial); return true; }