android.graphics.Canvas Java Examples
The following examples show how to use
android.graphics.Canvas.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SampleItemizedOverlay.java From osmdroid with Apache License 2.0 | 6 votes |
@Override public void draw(Canvas c, MapView mapView, boolean shadow) { if (mFocusChanged) { mFocusChanged = false; // Remove any current focus if (mPopupView != null) mapView.removeView(mPopupView); SampleOverlayItem item = this.getFocus(); if (item != null) { mPopupView = getPopupView(mapView.getContext(), item); MapView.LayoutParams lp = new MapView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, item.getPoint(), MapView.LayoutParams.TOP_CENTER, 0, 0); mapView.addView(mPopupView, lp); } } super.draw(c, mapView, shadow); }
Example #2
Source File: ColorFilterTransformation.java From giffun with Apache License 2.0 | 6 votes |
@Override public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { Bitmap source = resource.get(); int width = source.getWidth(); int height = source.getHeight(); Bitmap.Config config = source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888; Bitmap bitmap = mBitmapPool.get(width, height, config); if (bitmap == null) { bitmap = Bitmap.createBitmap(width, height, config); } Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP)); canvas.drawBitmap(source, 0, 0, paint); return BitmapResource.obtain(bitmap, mBitmapPool); }
Example #3
Source File: X8TabItem.java From FimiX8-RE with MIT License | 6 votes |
public void onDraw(Canvas canvas) { super.onDraw(canvas); Log.i("zdy", "......" + getWidth() + " " + getHeight()); if (getWidth() != 0) { int count = this.textArr.length; Paint p = new Paint(); p.setColor(this.lineColor); p.setStyle(Style.FILL); float with = (((float) getWidth()) * 1.0f) / ((float) this.textArr.length); for (int i = 1; i < count; i++) { RectF r1 = new RectF(); float nPos = with * ((float) i); r1.left = nPos - (((float) this.space) / 2.0f); r1.right = (((float) this.space) / 2.0f) + nPos; r1.top = (float) (this.lineStroke + 0); r1.bottom = (float) (getHeight() - this.lineStroke); canvas.drawRect(r1, p); } } }
Example #4
Source File: LeafBuilder.java From AndroidWallet with GNU General Public License v3.0 | 6 votes |
@Override protected void onDraw(Canvas canvas) { canvas.save(); //旋转 canvas.rotate(mRotateAngle, getViewCenterX(), getViewCenterY()); //路径 createStarPath(mStarPath, 5, -18); //路径加入中心圆 mStarPath.addCircle(getViewCenterX(), getViewCenterY(), mCenterCircleR, Path.Direction.CW); //这个很关键,选择路径填充方式 mStarPath.setFillType(Path.FillType.EVEN_ODD); //绘制 canvas.drawPath(mStarPath, mFullPaint); canvas.restore(); }
Example #5
Source File: RecyclerviewListDecorator.java From LNMOnlineAndroidSample with Apache License 2.0 | 6 votes |
/** * Drawing only virtical lines in Android */ private void drawVertical(Canvas c, RecyclerView parent) { final int left = parent.getPaddingLeft(); final int right = parent.getWidth() - parent.getPaddingRight(); final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child .getLayoutParams(); final int top = child.getBottom() + params.bottomMargin; final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } }
Example #6
Source File: MyDividerItemDecoration.java From styT with Apache License 2.0 | 6 votes |
/** * 绘制间隔 */ private void drawVertical(Canvas c, RecyclerView parent) { final int left = parent.getPaddingLeft(); final int right = parent.getWidth() - parent.getPaddingRight(); final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child .getLayoutParams(); final int top = child.getBottom() + params.bottomMargin + Math.round(ViewCompat.getTranslationY(child)); final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } }
Example #7
Source File: PlayPauseDrawable.java From PlayPauseDrawable with Apache License 2.0 | 6 votes |
@Override public void draw(Canvas canvas) { canvas.drawCircle(mBounds.centerX(), mBounds.centerY(), mBounds.centerX(), mBackgroundPaint); Picture picture = new Picture() ; picture.draw(canvas); canvas.save(); canvas.rotate(180 * mRotation, (x(0) + x(1))/2, (y(0) + y(1))/2); canvas.drawLine(x(0), y(0), x(1), y(1), mLinePaint); canvas.restore(); canvas.save(); canvas.rotate(180 * mRotation, (x(2) + x(3)) / 2, (y(2) + y(3)) / 2); canvas.drawLine(x(2), y(2), x(3), y(3), mLinePaint); canvas.restore(); canvas.save(); canvas.rotate(180 * mRotation, (x(4) + x(5)) / 2, (y(4) + y(5)) / 2); canvas.drawLine(x(4), y(4), x(5), y(5), mLinePaint); canvas.restore(); }
Example #8
Source File: RoundedTransformation.java From InstaMaterial with Apache License 2.0 | 6 votes |
@Override public Bitmap transform(Bitmap source) { int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size); if (squaredBitmap != source) { source.recycle(); } Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig()); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); paint.setShader(shader); paint.setAntiAlias(true); float r = size / 2f; canvas.drawCircle(r, r, r, paint); squaredBitmap.recycle(); return bitmap; }
Example #9
Source File: UndoView.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override protected void onDraw(Canvas canvas) { if (currentAction == ACTION_DELETE || currentAction == ACTION_CLEAR) { int newSeconds = timeLeft > 0 ? (int) Math.ceil(timeLeft / 1000.0f) : 0; if (prevSeconds != newSeconds) { prevSeconds = newSeconds; timeLeftString = String.format("%d", Math.max(1, newSeconds)); textWidth = (int) Math.ceil(textPaint.measureText(timeLeftString)); } canvas.drawText(timeLeftString, rect.centerX() - textWidth / 2, AndroidUtilities.dp(28.2f), textPaint); canvas.drawArc(rect, -90, -360 * (timeLeft / 5000.0f), false, progressPaint); } long newTime = SystemClock.elapsedRealtime(); long dt = newTime - lastUpdateTime; timeLeft -= dt; lastUpdateTime = newTime; if (timeLeft <= 0) { hide(true, 1); } invalidate(); }
Example #10
Source File: LeafLineRenderer.java From LeafChart with Apache License 2.0 | 6 votes |
/** * 画折线 * * @param canvas */ public void drawLines(Canvas canvas, Line line) { if (line != null && isShow) { linePaint.setColor(line.getLineColor()); linePaint.setStrokeWidth(LeafUtil.dp2px(mContext, line.getLineWidth())); linePaint.setStyle(Paint.Style.STROKE); List<PointValue> values = line.getValues(); Path path = line.getPath(); int size = values.size(); for (int i = 0; i < size; i++) { PointValue point = values.get(i); if (i == 0) path.moveTo(point.getOriginX(), point.getOriginY()); else path.lineTo(point.getOriginX(), point.getOriginY()); } measure = new PathMeasure(path, false); linePaint.setPathEffect(createPathEffect(measure.getLength(), phase, 0.0f)); canvas.drawPath(path, linePaint); } }
Example #11
Source File: VerticalButton.java From SlideLayout with GNU General Public License v2.0 | 6 votes |
@Override protected void onDraw(Canvas canvas){ TextPaint textPaint = getPaint(); textPaint.setColor(getCurrentTextColor()); textPaint.drawableState = getDrawableState(); canvas.save(); if(topDown){ canvas.translate(getWidth(), 0); canvas.rotate(90); }else { canvas.translate(0, getHeight()); canvas.rotate(-90); } canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop()); getLayout().draw(canvas); canvas.restore(); }
Example #12
Source File: GridDividerDecoration.java From UltimateAndroid with Apache License 2.0 | 6 votes |
/** Draw dividers to the right of each child view */ public void drawHorizontal(Canvas c, RecyclerView parent) { final int top = parent.getPaddingTop(); final int bottom = parent.getHeight() - parent.getPaddingBottom(); final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); final int left = child.getRight() + params.rightMargin + mInsets; final int right = left + mDivider.getIntrinsicWidth(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } }
Example #13
Source File: CircleImageView.java From MissZzzReader with Apache License 2.0 | 6 votes |
@Override protected void onDraw(Canvas canvas) { if (mBitmap == null) { return; } if (mFillColor != Color.TRANSPARENT) { canvas.drawCircle(getWidth() / 2.0f, getHeight() / 2.0f, mDrawableRadius, mFillPaint); } canvas.drawCircle(getWidth() / 2.0f, getHeight() / 2.0f, mDrawableRadius, mBitmapPaint); if (mBorderWidth != 0) { canvas.drawCircle(getWidth() / 2.0f, getHeight() / 2.0f, mBorderRadius, mBorderPaint); } }
Example #14
Source File: RoundedCornerTransformation.java From data-binding-sample with Apache License 2.0 | 6 votes |
public static Bitmap getRoundedCornerBitmap(Bitmap input, float cornerRadius, int w, int h) { Bitmap output = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, w, h); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, cornerRadius, cornerRadius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(input, 0, 0, paint); return output; }
Example #15
Source File: MeterNumberPicker.java From meter-number-picker with Apache License 2.0 | 6 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int measuredHeight = getMeasuredHeight(); float x = (getRight() - getLeft()) / 2; float y = (getBottom() - getTop()) / 2 + textHeight / 2; int currentValueStart = (int) (y + currentScrollOffset); int prevValueStart = currentValueStart - measuredHeight; int nextValueStart = currentValueStart + measuredHeight; canvas.drawText(getValue(currentValueOffset + 1) + "", x, prevValueStart, textPaint); canvas.drawText(getValue(currentValueOffset) + "", x, currentValueStart, textPaint); canvas.drawText(getValue(currentValueOffset - 1) + "", x, nextValueStart, textPaint); }
Example #16
Source File: CustomViewBehind.java From BigApp_WordPress_Android with Apache License 2.0 | 6 votes |
public void drawSelector(View content, Canvas canvas, float openPercent) { if (!mSelectorEnabled) return; if (mSelectorDrawable != null && mSelectedView != null) { String tag = (String) mSelectedView.getTag(R.id.selected_view); if (tag.equals(TAG+"SelectedView")) { canvas.save(); int left, right, offset; offset = (int) (mSelectorDrawable.getWidth() * openPercent); if (mMode == SlidingMenu.LEFT) { right = content.getLeft(); left = right - offset; canvas.clipRect(left, 0, right, getHeight()); canvas.drawBitmap(mSelectorDrawable, left, getSelectorTop(), null); } else if (mMode == SlidingMenu.RIGHT) { left = content.getRight(); right = left + offset; canvas.clipRect(left, 0, right, getHeight()); canvas.drawBitmap(mSelectorDrawable, right - mSelectorDrawable.getWidth(), getSelectorTop(), null); } canvas.restore(); } } }
Example #17
Source File: ImageUtils.java From AndroidCacheFoundation with Apache License 2.0 | 6 votes |
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap .getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = pixels; //圆角 paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); //Mode.SRC_IN 用前面画的“圆角矩形”对bitmap进行裁剪。 canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
Example #18
Source File: DrawingCacheHolder.java From letv with Apache License 2.0 | 6 votes |
public final synchronized boolean draw(Canvas canvas, float left, float top, Paint paint) { boolean z = true; synchronized (this) { if (this.bitmapArray != null) { for (int i = 0; i < this.bitmapArray.length; i++) { for (int j = 0; j < this.bitmapArray[i].length; j++) { Bitmap bmp = this.bitmapArray[i][j]; if (bmp != null) { float dleft = left + ((float) (bmp.getWidth() * j)); if (dleft <= ((float) canvas.getWidth()) && ((float) bmp.getWidth()) + dleft >= 0.0f) { float dtop = top + ((float) (bmp.getHeight() * i)); if (dtop <= ((float) canvas.getHeight()) && ((float) bmp.getHeight()) + dtop >= 0.0f) { canvas.drawBitmap(bmp, dleft, dtop, paint); } } } } } } else if (this.bitmap != null) { canvas.drawBitmap(this.bitmap, left, top, paint); } else { z = false; } } return z; }
Example #19
Source File: NumberProgressBar.java From okhttp-OkGo with Apache License 2.0 | 6 votes |
@Override protected void onDraw(Canvas canvas) { if (mIfDrawText) { calculateDrawRectF(); } else { calculateDrawRectFWithoutProgressText(); } if (mDrawReachedBar) { canvas.drawRect(mReachedRectF, mReachedBarPaint); } if (mDrawUnreachedBar) { canvas.drawRect(mUnreachedRectF, mUnreachedBarPaint); } if (mIfDrawText) canvas.drawText(mCurrentDrawText, mDrawTextStart, mDrawTextEnd, mTextPaint); }
Example #20
Source File: SlidingPaneLayout.java From letv with Apache License 2.0 | 6 votes |
public void draw(Canvas c) { Drawable shadowDrawable; super.draw(c); if (isLayoutRtlSupport()) { shadowDrawable = this.mShadowDrawableRight; } else { shadowDrawable = this.mShadowDrawableLeft; } View shadowView = getChildCount() > 1 ? getChildAt(1) : null; if (shadowView != null && shadowDrawable != null) { int left; int right; int top = shadowView.getTop(); int bottom = shadowView.getBottom(); int shadowWidth = shadowDrawable.getIntrinsicWidth(); if (isLayoutRtlSupport()) { left = shadowView.getRight(); right = left + shadowWidth; } else { right = shadowView.getLeft(); left = right - shadowWidth; } shadowDrawable.setBounds(left, top, right, bottom); shadowDrawable.draw(c); } }
Example #21
Source File: PopupButton.java From PopupCircleMenu with MIT License | 6 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mBitmap == null) { mPaint.setStyle(Paint.Style.STROKE); canvas.drawCircle(mWidth / 2, mWidth / 2, mCircleRadius, mPaint); } else { if (isChecked()) { mPaint.setColor(mColorChecked); if (mBackgroundChecked != null) mBitmap = Bitmap.createScaledBitmap(mBackgroundChecked, mCircleRadius, mCircleRadius, true); } else { mPaint.setColor(mColorNormal); if (mBackground != null) mBitmap = Bitmap.createScaledBitmap(mBackground, mCircleRadius, mCircleRadius, true); } mPaint.setStyle(Paint.Style.FILL); canvas.drawCircle(mWidth / 2, mWidth / 2, mCircleRadius, mPaint); canvas.drawBitmap(mBitmap, mCircleRadius + mMargin - mBitmap.getWidth() / 2, mCircleRadius + mMargin - mBitmap.getHeight() / 2, mPaint); } }
Example #22
Source File: OverlayView.java From Matisse-Kotlin with Apache License 2.0 | 6 votes |
/** * This method draws dimmed area around the crop bounds. * * @param canvas - valid canvas object */ protected void drawDimmedLayer(@NonNull Canvas canvas) { canvas.save(); if (mCircleDimmedLayer) { canvas.clipPath(mCircularPath, Region.Op.DIFFERENCE); } else { canvas.clipRect(mCropViewRect, Region.Op.DIFFERENCE); } canvas.drawColor(mDimmedColor); canvas.restore(); if (mCircleDimmedLayer) { // Draw 1px stroke to fix antialias canvas.drawCircle(mCropViewRect.centerX(), mCropViewRect.centerY(), Math.min(mCropViewRect.width(), mCropViewRect.height()) / 2.f, mDimmedStrokePaint); } }
Example #23
Source File: DanMuSurfaceView.java From LLApp with Apache License 2.0 | 5 votes |
@Override public void surfaceCreated(SurfaceHolder holder) { isSurfaceCreated = true; Canvas canvas = mSurfaceHolder.lockCanvas(); prepare(canvas); mSurfaceHolder.unlockCanvasAndPost(canvas); }
Example #24
Source File: RoundedCornersTransformation2.java From ImageLoader with Apache License 2.0 | 5 votes |
private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) { canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius, mRadius, paint); canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom), mRadius, mRadius, paint); canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint); canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint); }
Example #25
Source File: FocusedBasePositionManager.java From android-tv-launcher with MIT License | 5 votes |
private void drawFirstFrame(Canvas paramCanvas, boolean paramBoolean1, boolean paramBoolean2) { boolean bool = paramBoolean2; if (FOCUS_ASYNC_DRAW == this.mode) { bool = false; } this.mIsLastFrame = false; Rect localRect; if (bool) { localRect = getDstRectBeforeScale(!bool); if (null == localRect) { return; } this.mFocusRect = localRect; } else { localRect = getDstRectAfterScale(!bool); if (null == localRect) { return; } this.mFocusRect = localRect; } this.mCurrentRect = this.mFocusRect; drawScale(paramBoolean1); if (hasFocus()) { drawFocus(paramCanvas, paramBoolean2); } this.mIsFirstFrame = false; this.mCurrentFrame += 1; this.mContainerView.invalidate(); }
Example #26
Source File: DragSortListView.java From chromadoze with GNU General Public License v3.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mTrackDragSort) { mDragSortTracker.appendState(); } }
Example #27
Source File: AbsHListView.java From letv with Apache License 2.0 | 5 votes |
private void drawSelector(Canvas canvas) { if (!this.mSelectorRect.isEmpty()) { Drawable selector = this.mSelector; selector.setBounds(this.mSelectorRect); selector.draw(canvas); } }
Example #28
Source File: CircleTransformation.java From TvRemoteControl with Apache License 2.0 | 5 votes |
@Override public Bitmap transform(Bitmap source) { int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; Bitmap squaredBtimap = Bitmap.createBitmap(source, x, y, size, size); if (squaredBtimap != source){ source.recycle(); } Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig()); Canvas canvas = new Canvas(bitmap); Paint avatarPaint = new Paint(); BitmapShader shader = new BitmapShader(squaredBtimap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); avatarPaint.setShader(shader); Paint outlinePaint = new Paint(); outlinePaint.setColor(Color.WHITE); outlinePaint.setStyle(Paint.Style.STROKE); outlinePaint.setStrokeWidth(STROKE_WIDTH); outlinePaint.setAntiAlias(true); float r = size / 2f; canvas.drawCircle(r, r, r, avatarPaint); canvas.drawCircle(r, r, r - STROKE_WIDTH / 2, outlinePaint); squaredBtimap.recycle(); return bitmap; }
Example #29
Source File: MCTileProvider.java From blocktopograph with GNU Affero General Public License v3.0 | 5 votes |
public static Bitmap drawText(String text, Bitmap b, int textColor, int bgColor) { // Get text dimensions TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG); textPaint.setStyle(Paint.Style.FILL); textPaint.setColor(textColor); textPaint.setTextSize(b.getHeight() / 16f); StaticLayout mTextLayout = new StaticLayout(text, textPaint, b.getWidth() / 2, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); // Create bitmap and canvas to draw to Canvas c = new Canvas(b); if(bgColor != 0){ // Draw background Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG); paint.setStyle(Paint.Style.FILL); paint.setColor(bgColor); c.drawPaint(paint); } // Draw text c.save(); c.translate(0, 0); mTextLayout.draw(c); c.restore(); return b; }
Example #30
Source File: SwitchButton.java From SmartOrnament with Apache License 2.0 | 5 votes |
/** * @param canvas * @param x px * @param y px */ private void drawButton(Canvas canvas, float x, float y) { canvas.drawCircle(x, y, buttonRadius, buttonPaint); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(1); paint.setColor(0XffDDDDDD); canvas.drawCircle(x, y, buttonRadius, paint); }