Java Code Examples for android.graphics.Canvas#drawPaint()
The following examples show how to use
android.graphics.Canvas#drawPaint() .
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: CropAreaView.java From GestureViews with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") private void drawRoundedHole(Canvas canvas) { paint.setStyle(Paint.Style.FILL); paint.setColor(backColor); // Punching hole in background color requires offscreen drawing if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { canvas.saveLayer(0, 0, canvas.getWidth(), canvas.getHeight(), null); } else { canvas.saveLayer(0, 0, canvas.getWidth(), canvas.getHeight(), null, 0); } canvas.drawPaint(paint); final float rx = rounding * 0.5f * areaRect.width(); final float ry = rounding * 0.5f * areaRect.height(); canvas.drawRoundRect(areaRect, rx, ry, paintClear); canvas.restore(); }
Example 2
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 3
Source File: MidView.java From FimiX8-RE with MIT License | 5 votes |
@NonNull private void removeAll(Canvas canvas) { Paint paint = new Paint(); paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR)); canvas.drawPaint(paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC)); }
Example 4
Source File: PictureRendererStrategy.java From SVG-Android with Apache License 2.0 | 5 votes |
private void updateCachedPicture(int width, int height, ColorFilter filter) { Canvas canvas = mCachedPicture.beginRecording(width, height); Paint paint = getPaint(filter); if (paint != null) { canvas.drawPaint(paint); } mRenderer.render(canvas, width, height, null); mCachedPicture.endRecording(); }
Example 5
Source File: ShaderDrawable.java From libcommon with Apache License 2.0 | 5 votes |
@Override public void draw(@NonNull final Canvas canvas) { if (mShader != null) { final int count = canvas.save(); final DrawFilter org = canvas.getDrawFilter(); canvas.setDrawFilter(mDrawFilter); mPaint.setShader(mShader); canvas.drawPaint(mPaint); canvas.setDrawFilter(org); canvas.restoreToCount(count); } }
Example 6
Source File: RippleValidatorEditText.java From RippleValidatorEditText with Apache License 2.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); switch (rippleType){ case IsEnded: rippleType = RippleType.Nothing; mCircleRadius = 0; canvas.drawPaint(mTransparentPaint); //canvas.drawColor(Color.parseColor("#00000000")); mLastBorderDrawable.draw(canvas); break; case IsPlaying: // canvas.drawCircle(0,getHeight()/2,mCircleRadius,mCirclePaint); drawEffectWithBorder(canvas,mCirclePaint); mLastBorderDrawable.draw(canvas); break; case IsClearing: canvas.drawColor(mValidColor); // canvas.drawCircle(0, getHeight() / 2, mCircleRadius, mTransparentPaint); drawEffectWithBorder(canvas,mTransparentPaint); mLastBorderDrawable.draw(canvas); break; case Nothing: mCircleRadius = 0; canvas.drawPaint(mTransparentPaint); mLastBorderDrawable.draw(canvas); break; } }
Example 7
Source File: ShowCaseView.java From show-case-card-view with Apache License 2.0 | 5 votes |
@Override public void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawPaint(overlayPaint); if (!hideCard) { canvas.drawCircle(position.x, position.y, radius, circlePaint); } }
Example 8
Source File: MyView.java From journaldev with MIT License | 5 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawRoundRect(mRectF, 10, 10, otherPaint); canvas.clipRect(mRectF, Region.Op.DIFFERENCE); canvas.drawPaint(outerPaint); canvas.drawLine(250, 250, 400, 400, mPaint); canvas.drawRect(mPadding, mPadding, getWidth() - mPadding, getHeight() - mPadding, mPaint); canvas.drawArc(arcLeft, arcTop, arcRight, arcBottom, 75, 45, true, mPaint); otherPaint.setColor(Color.GREEN); otherPaint.setStyle(Paint.Style.FILL); canvas.drawRect( getLeft() + (getRight() - getLeft()) / 3, getTop() + (getBottom() - getTop()) / 3, getRight() - (getRight() - getLeft()) / 3, getBottom() - (getBottom() - getTop()) / 3, otherPaint); canvas.drawPath(mPath, mPaint); otherPaint.setColor(Color.BLACK); canvas.drawCircle(getWidth() / 2, getHeight() / 2, arcLeft, otherPaint); canvas.drawText("Canvas basics", (float) (getWidth() * 0.3), (float) (getHeight() * 0.8), mTextPaint); }
Example 9
Source File: ComplicationWatchFaceService.java From complications with Apache License 2.0 | 5 votes |
private void drawBackground(Canvas canvas) { if (mAmbient && (mLowBitAmbient || mBurnInProtection)) { canvas.drawColor(Color.BLACK); } else { canvas.drawPaint(mBackgroundPaint); } }
Example 10
Source File: ModeOptions.java From Camera2 with Apache License 2.0 | 5 votes |
@Override public void onDraw(Canvas canvas) { if (mDrawCircle) { canvas.drawCircle(mAnimateFrom.centerX(), mAnimateFrom.centerY(), mRadius, mPaint); } else if (mFill) { canvas.drawPaint(mPaint); } super.onDraw(canvas); }
Example 11
Source File: MyView.java From mil-sym-android with Apache License 2.0 | 5 votes |
@Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub if (_points==null || _points.size() < 1) { return; } super.onDraw(canvas); Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE); canvas.drawPaint(paint); utility.set_displayPixelsWidth(canvas.getWidth()); utility.set_displayPixelsHeight(canvas.getHeight()); //utility.SetExtents(50, 51, 5, 4); utility.SetExtents(50, 55, 10, 4); if(extents.isEmpty()==false) { String ex[]=extents.split(","); double left=Double.parseDouble(ex[0]); double right=Double.parseDouble(ex[1]); double top=Double.parseDouble(ex[2]); double bottom=Double.parseDouble(ex[3]); utility.SetExtents(left, right, top, bottom); } //utility.SetExtents(178, -178, 32, 28); utility.DoubleClickGE(_points, linetype, canvas, context); String kmlStr=utility.DoubleClickSECRenderer(_points, linetype, canvas); String fileName="temp"; //String body="put this in file"; this.writeToFile(fileName, kmlStr); _points.clear(); }
Example 12
Source File: RecognitionScoreView.java From AndroidDemoProjects with Apache License 2.0 | 5 votes |
@Override public void onDraw(final Canvas canvas) { final int x = 10; int y = (int) (fgPaint.getTextSize() * 1.5f); canvas.drawPaint(bgPaint); if (results != null) { for (final Recognition recog : results) { canvas.drawText(recog.getTitle() + ": " + recog.getConfidence(), x, y, fgPaint); y += fgPaint.getTextSize() * 1.5f; } } }
Example 13
Source File: ComplicationWatchFaceService.java From complications with Apache License 2.0 | 5 votes |
private void drawBackground(Canvas canvas) { if (mAmbient && (mLowBitAmbient || mBurnInProtection)) { canvas.drawColor(Color.BLACK); } else { canvas.drawPaint(mBackgroundPaint); } }
Example 14
Source File: ENLoadingView.java From ENViews with Apache License 2.0 | 5 votes |
private void clearCanvas() { Canvas canvas = surfaceHolder.lockCanvas(); if(canvas == null) return; mPaint[0].setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.CLEAR)); canvas.drawPaint(mPaint[0]); mPaint[0].setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_OVER)); surfaceHolder.unlockCanvasAndPost(canvas); mThread.interrupt(); mThread = null; }
Example 15
Source File: ComplicationWatchFaceService.java From complications with Apache License 2.0 | 5 votes |
private void drawBackground(Canvas canvas) { if (mAmbient && (mLowBitAmbient || mBurnInProtection)) { canvas.drawColor(Color.BLACK); } else { canvas.drawPaint(mBackgroundPaint); } }
Example 16
Source File: RepoHandlerAdapter.java From Stringlate with MIT License | 4 votes |
private static Bitmap getBitmap(String name, int size) { Random random = new Random(name.hashCode()); Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); // Let the name be the first and last capital letters Character first = null; Character last = null; char c; for (int i = 0; i < name.length(); i++) { c = name.charAt(i); if (Character.isUpperCase(c)) { if (first == null) first = c; else last = c; } } if (first == null) { if (name.isEmpty()) { name = ""; } else { name = String.valueOf(name.charAt(0)).toUpperCase(); } } else { name = String.valueOf(first); if (last != null) name += String.valueOf(last); } Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setColor(MATERIAL_COLORS[random.nextInt(MATERIAL_COLORS.length)]); paint.setStyle(Paint.Style.FILL); canvas.drawPaint(paint); // Center text: http://stackoverflow.com/a/11121873/4759433 paint.setColor(Color.WHITE); paint.setAntiAlias(true); paint.setTextSize(size / (float) name.length()); paint.setTextAlign(Paint.Align.CENTER); float xPos = (canvas.getWidth() / 2f); float yPos = (canvas.getHeight() / 2f) - ((paint.descent() + paint.ascent()) / 2f); canvas.drawText(name, xPos, yPos, paint); return bitmap; }
Example 17
Source File: FolderIcon.java From LaunchEnr with GNU General Public License v3.0 | 4 votes |
public void drawBackground(Context context, Canvas canvas) { mPaint.setStyle(Paint.Style.FILL); int alpha = (int) Math.min(MAX_BG_OPACITY, BG_OPACITY * mColorMultiplier); //set the theme attributes to the folder preview circle (stroke and inner bg) int accent = ThemeUtils.getColorAccent(context); int defaultColor = PreferencesState.isDarkThemeEnabled(context)? Color.argb(alpha, BG_INTENSITY_DARK, BG_INTENSITY_DARK, BG_INTENSITY_DARK) : Color.argb(alpha, BG_INTENSITY, BG_INTENSITY, BG_INTENSITY); int color = PreferencesState.areColoredFoldersEnabled(context)? ColorUtils.setAlphaComponent(accent, alpha) : defaultColor; mPaint.setColor(color); drawCircle(canvas, 0 /* deltaRadius */); // Draw shadow. if (mShadowShader == null) { return; } float radius = getScaledRadius(); float shadowRadius = radius + mStrokeWidth; mPaint.setColor(Color.BLACK); int offsetX = getOffsetX(); int offsetY = getOffsetY(); final int saveCount; if (canvas.isHardwareAccelerated()) { saveCount = canvas.saveLayer(offsetX - mStrokeWidth, offsetY, offsetX + radius + shadowRadius, offsetY + shadowRadius + shadowRadius, null, Canvas.CLIP_TO_LAYER_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG); } else { saveCount = canvas.save(Canvas.CLIP_SAVE_FLAG); clipCanvasSoftware(canvas, Region.Op.DIFFERENCE); } mShaderMatrix.setScale(shadowRadius, shadowRadius); mShaderMatrix.postTranslate(radius + offsetX, shadowRadius + offsetY); mShadowShader.setLocalMatrix(mShaderMatrix); mPaint.setShader(mShadowShader); canvas.drawPaint(mPaint); mPaint.setShader(null); if (canvas.isHardwareAccelerated()) { mPaint.setXfermode(mShadowPorterDuffXfermode); canvas.drawCircle(radius + offsetX, radius + offsetY, radius, mPaint); mPaint.setXfermode(null); } canvas.restoreToCount(saveCount); }
Example 18
Source File: GameView.java From wearabird with MIT License | 4 votes |
public void render(Canvas canvas) { canvas.drawPaint(backgroundPaint); clouds.draw(canvas); coins.draw(canvas); player.draw(canvas); }
Example 19
Source File: NoiseEffect.java From HaiNaBaiChuan with Apache License 2.0 | 4 votes |
@Override public void draw(Canvas canvas) { canvas.drawPaint(paint); }
Example 20
Source File: NoiseEffect.java From Android-Plugin-Framework with MIT License | 2 votes |
@Override public void draw(Canvas canvas) { canvas.drawPaint(paint); }