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:com.kmagic.solitaire.DrawMaster.java
/** * Draw light shade background// www . j a va 2 s . c om * @param canvas canvas to draw on */ public void drawLightShade(final Canvas canvas) { canvas.drawRect(0, 0, mScreenWidth, mScreenHeight, mLightShadePaint); }
From source file:com.shawnway.nav.app.wtw.view.PagerSlidingTabStrip.java
private void drawNormalUnderLine(Canvas canvas, int height, View currentTab, float lineLeft, float lineRight) { canvas.drawRect(lineLeft, height * (1 - indicatorHeight), lineRight, height, rectPaint); // draw underline rectPaint.setColor(underlineColor);//from w ww .j a va2s . c om 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.shawnway.nav.app.wtw.view.PagerSlidingTabStrip.java
private void drawRectangle(Canvas canvas, final int height, View currentTab, float lineLeft, float lineRight) { canvas.drawRect(lineLeft, currentTab.getTop(), lineRight, currentTab.getBottom(), rectPaint); // draw underline rectPaint.setColor(underlineColor);//from www .j a v a 2 s. co m 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.hobby.uiframework.widget.PagerSlidingTab.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*from w w w .java2 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(); 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); } if (lineIndicator) { canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint); } else { rectPaint.setStyle(Style.FILL); Path path = new Path(); float mid = (lineLeft + lineRight) * 0.5f; float triangleheight = getContext().getResources().getDimension(R.dimen.indicator_triangle_height); float left = mid - triangleheight; float right = mid + triangleheight; path.moveTo(left, height); path.lineTo(mid, height - triangleheight); path.lineTo(right, height); path.close(); canvas.drawPath(path, 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.mwm.loyal.libs.zxing.ViewfinderView.java
@SuppressLint("DrawAllocation") @Override/*from w w w . j a va2 s . c om*/ public void onDraw(Canvas canvas) { if (cameraManager == null) { return; // not ready yet, early draw before done configuring } Rect frame = cameraManager.getFramingRect(); Rect previewFrame = cameraManager.getFramingRectInPreview(); if (frame == null || previewFrame == null) { return; } int width = canvas.getWidth(); int height = canvas.getHeight(); // Draw the exterior (i.e. outside the framing rect) darkened paint.setColor(resultBitmap != null ? resultColor : maskColor); canvas.drawRect(0, 0, width, frame.top, paint); canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint); canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint); canvas.drawRect(0, frame.bottom + 1, width, height, paint); if (resultBitmap != null) { // Draw the opaque result bitmap over the scanning rectangle paint.setAlpha(CURRENT_POINT_OPACITY); canvas.drawBitmap(resultBitmap, null, frame, paint); } else { // Draw a red "laser scanner" line through the middle to permissionDialog decoding is active paint.setColor(laserColor); paint.setAlpha(SCANNER_ALPHA[scannerAlpha]); scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length; int middle = frame.height() / 2 + frame.top; canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint); float scaleX = frame.width() / (float) previewFrame.width(); float scaleY = frame.height() / (float) previewFrame.height(); List<ResultPoint> currentPossible = possibleResultPoints; List<ResultPoint> currentLast = lastPossibleResultPoints; int frameLeft = frame.left; int frameTop = frame.top; if (currentPossible.isEmpty()) { lastPossibleResultPoints = null; } else { possibleResultPoints = new ArrayList<>(5); lastPossibleResultPoints = currentPossible; paint.setAlpha(CURRENT_POINT_OPACITY); paint.setColor(resultPointColor); synchronized (currentPossible) { for (ResultPoint point : currentPossible) { canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), POINT_SIZE, paint); } } } if (currentLast != null) { paint.setAlpha(CURRENT_POINT_OPACITY / 2); paint.setColor(resultPointColor); synchronized (currentLast) { float radius = POINT_SIZE / 2.0f; for (ResultPoint point : currentLast) { canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), radius, paint); } } } // Request another update at the animation interval, but only repaint the laser line, // not the entire viewfinder mask. postInvalidateDelayed(ANIMATION_DELAY, frame.left - POINT_SIZE, frame.top - POINT_SIZE, frame.right + POINT_SIZE, frame.bottom + POINT_SIZE); } }
From source file:cn.bingoogol.tabhost.ui.view.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from ww w .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, 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.accessibility.ListenerView.java
@Override public void onDraw(Canvas canvas) { paintWhite.setStrokeWidth(4);//from w w w .j av a 2 s.c o m paintWhite.setARGB(128, 255, 255, 255); paintWhite.setStyle(Paint.Style.FILL_AND_STROKE); paintWhite.setAntiAlias(true); paintBlack.setStrokeWidth(4); paintBlack.setARGB(128, 0, 0, 0); paintBlack.setStyle(Paint.Style.FILL_AND_STROKE); paintBlack.setAntiAlias(true); int left = getPaddingLeft(); //int top = getPaddingTop(); int right = getWidth() - getPaddingRight(); int bottom = getHeight() - getPaddingBottom(); //-----------------------------------------------------------------------------// //Drawing general buttons canvas.drawRect(right - 80, bottom - 90, right, bottom - 10, paintWhite); canvas.drawRect(right - 70, bottom - 55, right - 10, bottom - 20, paintBlack); canvas.drawRect(left, bottom - 90, left + 80, bottom - 10, paintWhite); a.set(right - 70, bottom - 55); b.set(right - 10, bottom - 55); c.set(right - 40, bottom - 80); path.moveTo(a.x, a.y); path.lineTo(b.x, b.y); path.lineTo(c.x, c.y); path.lineTo(a.x, a.y); path.close(); canvas.drawPath(path, paintBlack); paintBlack.setStyle(Paint.Style.STROKE); canvas.drawRect(left + 30, bottom - 40, left + 60, bottom - 40, paintBlack); oval.set(left + 50, bottom - 60, left + 70, bottom - 40); canvas.drawArc(oval, 270, 180, true, paintBlack); canvas.drawRect(left + 10, bottom - 60, left + 60, bottom - 60, paintBlack); //canvas.drawRect(left+10, bottom-70, left+20, bottom-60, paintBlack); //canvas.drawRect(left+10, bottom-60, left+20, bottom-50, paintBlack); a.set(left + 20, bottom - 50); b.set(left + 10, bottom - 60); c.set(left + 20, bottom - 70); path.moveTo(a.x, a.y); path.lineTo(b.x, b.y); path.moveTo(b.x, b.y); path.lineTo(c.x, c.y); canvas.drawPath(path, paintBlack); paintBlack.setStyle(Paint.Style.FILL_AND_STROKE); }
From source file:com.popdeem.sdk.uikit.widget.PDUIBezelImageView.java
@Override protected void onDraw(Canvas canvas) { if (mBounds == null) { return;/*from w ww . j av a2 s. c om*/ } int width = mBounds.width(); int height = mBounds.height(); if (width == 0 || height == 0) { return; } 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); if (mMaskDrawable != null) { int sc = cacheCanvas.save(); mMaskDrawable.draw(cacheCanvas); mMaskedPaint.setColorFilter((mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null); cacheCanvas.saveLayer(mBoundsF, mMaskedPaint, Canvas.ALL_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.ALL_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.github.shareme.gwsmaterialuikit.library.material.widget.TabPageIndicator.java
@Override public void draw(@NonNull Canvas canvas) { super.draw(canvas); int x = mIndicatorOffset + getPaddingLeft(); int y = mIndicatorAtTop ? 0 : getHeight() - mIndicatorHeight; canvas.drawRect(x, y, x + mIndicatorWidth, y + mIndicatorHeight, mPaint); if (isInEditMode()) canvas.drawRect(getPaddingLeft(), y, getPaddingLeft() + mTabContainer.getChildAt(0).getWidth(), y + mIndicatorHeight, mPaint); }
From source file:com.ljz.base.widget.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from w w w .ja va 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, onStart 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); } }