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:co.paulburke.android.textviewpager.TextViewPagerIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) return;/*from www.j av a2 s . c om*/ final int count = mViewPager.getAdapter().getCount(); if (count == 0) return; if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } float left = 0f, top = 0f, right = 0f, bottom = 0f; final int paddingTop = getPaddingTop(); final int paddingBottom = getPaddingBottom(); final int paddingRight = getPaddingRight(); final int paddingLeft = getPaddingLeft(); if (isHorizontal()) { final float pageWidth = (getWidth() - paddingLeft - paddingRight) / (1f * count); left = paddingLeft + pageWidth * (mCurrentPage + mPositionOffset); right = left + pageWidth; top = 0f; bottom = getHeight(); } else if (isVertical()) { final float pageHeight = (getHeight() - paddingTop - paddingBottom) / (1f * count); top = paddingTop + pageHeight * (mCurrentPage + mPositionOffset); bottom = top + pageHeight; left = 0f; right = getWidth(); } canvas.drawRect(left, top, right, bottom, mPaint); }
From source file:com.huyn.demogroup.relativetop.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 + tabPadding, height - indicatorHeight, lineRight - tabPadding, height, rectPaint); }
From source file:com.csdn.pagerslidingtabstrip.view.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from ww w . java 2s . c om } if (pager == null) { rectPaint.setColor(indicatorColor); final int height = getHeight(); /** tab **/ View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); View lastTab = tabsContainer.getChildAt(lastposition); float detalLeft = lineLeft - lastTab.getLeft(); float detalRight = lineRight - lastTab.getRight(); if (currentTab != null) { canvas.drawRect(lineLeft - detalLeft, height - indicatorHeight, lineLeft + currentTab.getWidth() - detalRight, height, rectPaint); Log.i("tteerr", "lineLeft=" + lineLeft + "--" + "lineRight=" + lineRight + "--detalLeft=" + detalLeft + "--+detalRight=" + detalRight); Log.i("tteerr", "" + "left=" + (lineLeft - detalLeft) + "top=" + (height - indicatorHeight) + "right=" + (lineLeft + currentTab.getWidth() - detalRight) + "bottom=" + height); Log.i("tteerr", "currentPosition=" + currentPosition + "lastposition=" + lastposition); } return; } 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.tr4android.support.extension.widget.CollapsingTextHelper.java
public void draw(Canvas canvas) { final int saveCount = canvas.save(); if (mTextToDraw != null && mDrawTitle) { float x = mCurrentDrawX; float y = mCurrentDrawY; final boolean drawTexture = mUseTexture && mExpandedTitleTexture != null; final float ascent; final float descent; // Update the TextPaint to the current text size mTextPaint.setTextSize(mCurrentTextSize); if (drawTexture) { ascent = mTextureAscent * mScale; descent = mTextureDescent * mScale; } else {// w w w.j a va2s . co m ascent = mTextPaint.ascent() * mScale; descent = mTextPaint.descent() * mScale; } if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(mCurrentBounds.left, y + ascent, mCurrentBounds.right, y + descent, DEBUG_DRAW_PAINT); } if (drawTexture) { y += ascent; } if (mScale != 1f) { canvas.scale(mScale, mScale, x, y); } if (drawTexture) { // If we should use a texture, draw it instead of text canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint); } else { canvas.drawText(mTextToDraw, 0, mTextToDraw.length(), x, y, mTextPaint); } } canvas.restoreToCount(saveCount); }
From source file:com.eccyan.widget.SpinningTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from w ww .j a va 2 s . c o m } final int height = getHeight(); // draw indicator line, and draw indicator line for next dummy tab rectPaint.setColor(indicatorColor); Pair<Float, Float> lines = getIndicatorCoordinates(); final float left = lines.first; final float right = lines.second; final float tabsWidth = getTabsWidth(); for (int i = 0; i < DUMMY_TAB_RATE; ++i) { final float padding = tabsWidth * i; canvas.drawRect(left + padding, height - indicatorHeight, right + padding, height, rectPaint); } // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); // draw divider if (dividerWidth != 0) { dividerPaint.setStrokeWidth(dividerWidth); dividerPaint.setColor(dividerColor); for (int i = 0; i < realTabCount - 1; i++) { View tab = tabsContainer.getChildAt(i); canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint); } } }
From source file:com.mylikes.likes.etchasketch.Slate.java
@Override protected void onDraw(Canvas canvas) { if (mTiledCanvas != null) { canvas.save(Canvas.MATRIX_SAVE_FLAG); if (mPanX != 0 || mPanY != 0 || !mZoomMatrix.isIdentity()) { canvas.translate(mPanX, mPanY); canvas.concat(mZoomMatrix);//from w w w . j av a 2s .c o m canvas.drawRect(-20000, -20000, 20000, 0, mWorkspacePaint); canvas.drawRect(-20000, 0, 0, mTiledCanvas.getHeight(), mWorkspacePaint); canvas.drawRect(mTiledCanvas.getWidth(), 0, 20000, mTiledCanvas.getHeight(), mWorkspacePaint); canvas.drawRect(-20000, mTiledCanvas.getHeight(), 20000, 20000, mWorkspacePaint); } if (!mDirtyRegion.isEmpty()) { canvas.clipRegion(mDirtyRegion); mDirtyRegion.setEmpty(); } // TODO: tune this threshold based on the device density mBlitPaint.setFilterBitmap(getScale(mZoomMatrix) < 3f); mTiledCanvas.drawTo(canvas, 0, 0, mBlitPaint, false); // @@ set to true for dirty tile updates if (0 != (mDebugFlags & FLAG_DEBUG_STROKES)) { drawStrokeDebugInfo(canvas); } for (MoveableDrawing drawing : overlays) { drawing.renderInto(canvas, moveMode && drawing == selectedDrawing); } canvas.restore(); if (0 != (mDebugFlags & FLAG_DEBUG_PRESSURE)) { mPressureCooker.drawDebug(canvas); } } }
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 av 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.jingzhongjie.tabbarviewtest.widget.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*from w w w . ja v a 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); } canvas.drawRect(lineLeft + indicatorPadding, height - indicatorHeight, lineRight - indicatorPadding, 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.microsoft.mimickeralarm.mimics.ProgressButton.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mState == State.ReadyCamera) { prepareDrawFill(sYellow);//from w ww.ja v a2 s .c o m canvas.drawCircle(mCenterX, mCenterY, mRadius, mBrush); canvas.drawBitmap(mCameraIcon, mCenterX - (mCameraIcon.getWidth() / 2), mCenterY - (mCameraIcon.getHeight() / 2), mBrush); } else if (mState == State.ReadyAudio) { prepareDrawFill(sYellow); canvas.drawCircle(mCenterX, mCenterY, mRadius, mBrush); canvas.drawBitmap(mMicrophoneIcon, mCenterX - (mMicrophoneIcon.getWidth() / 2), mCenterY - (mMicrophoneIcon.getHeight() / 2), mBrush); } else if (mState == State.Loading) { prepareDrawFill(sBlue); canvas.drawCircle(mCenterX, mCenterY, mRadius, mBrush); prepareDrawStroke(sWhite); canvas.drawArc(mLoadingAnimationRect, mLoadingAnimationProgress, 300f, false, mBrush); } else if (mState == State.Waiting) { prepareDrawFill(sGrey); canvas.drawCircle(mCenterX, mCenterY, mRadius, mBrush); prepareDrawFill(sWhite); canvas.drawCircle(mCenterX, mCenterY, (float) (mRadius * 0.7), mBrush); prepareDrawFill(sGrey); float w = (float) (mRadius * 0.3); canvas.drawRect(mCenterX - w, mCenterY - w, mCenterX + w, mCenterY + w, mBrush); } }
From source file:com.gc.materialdesign.views.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/* www . j a va 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); } }