List of usage examples for android.graphics Canvas drawPath
public void drawPath(@NonNull Path path, @NonNull Paint paint)
From source file:ee.ioc.phon.android.speak.Utils.java
static Bitmap bytesToBitmap(byte[] byteBuffer, int w, int h, int startPosition, int endPosition) { final ShortBuffer waveBuffer = ByteBuffer.wrap(byteBuffer).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer(); final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); final Canvas c = new Canvas(b); final Paint paint = new Paint(); paint.setColor(0xFFFFFFFF); // 0xAARRGGBB paint.setAntiAlias(true);//w w w . ja v a 2 s . co m paint.setStyle(Paint.Style.STROKE); paint.setAlpha(80); final PathEffect effect = new CornerPathEffect(3); paint.setPathEffect(effect); final int numSamples = waveBuffer.remaining(); int endIndex; if (endPosition == 0) { endIndex = numSamples; } else { endIndex = Math.min(endPosition, numSamples); } int startIndex = startPosition - 2000; // include 250ms before speech if (startIndex < 0) { startIndex = 0; } final int numSamplePerWave = 200; // 8KHz 25ms = 200 samples final float scale = 10.0f / 65536.0f; final int count = (endIndex - startIndex) / numSamplePerWave; final float deltaX = 1.0f * w / count; int yMax = h / 2; Path path = new Path(); c.translate(0, yMax); float x = 0; path.moveTo(x, 0); for (int i = 0; i < count; i++) { final int avabs = getAverageAbs(waveBuffer, startIndex, i, numSamplePerWave); int sign = ((i & 01) == 0) ? -1 : 1; final float y = Math.min(yMax, avabs * h * scale) * sign; path.lineTo(x, y); x += deltaX; path.lineTo(x, y); } if (deltaX > 4) { paint.setStrokeWidth(2); } else { paint.setStrokeWidth(Math.max(0, (int) (deltaX - .05))); } c.drawPath(path, paint); return b; }
From source file:com.github.shareme.gwsmaterialuikit.library.material.drawable.LineMorphingDrawable.java
@Override public void draw(Canvas canvas) { int restoreCount = canvas.save(); float degrees = (mClockwise ? 180 : -180) * ((mPrevState < mCurState ? 0f : 1f) + mAnimProgress); if (mIsRtl)// ww w .j a v a2s .c om canvas.scale(-1f, 1f, mDrawBound.centerX(), mDrawBound.centerY()); canvas.rotate(degrees, mDrawBound.centerX(), mDrawBound.centerY()); canvas.drawPath(mPath, mPaint); canvas.restoreToCount(restoreCount); }
From source file:cc.kenai.common.AnimatedSvgView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mState == STATE_NOT_STARTED || mGlyphData == null) { return;//from w ww.ja va 2 s .c om } long t = System.currentTimeMillis() - mStartTime; for (int i = 0; i < mGlyphData.length; i++) { float phase = MathUtil.constrain(0, 1, (t - (mTraceTime - mTraceTimePerGlyph) * i * 1f / mGlyphData.length) * 1f / mTraceTimePerGlyph); float distance = INTERPOLATOR.getInterpolation(phase) * mGlyphData[i].length; mGlyphData[i].paint.setColor(mTraceResidueColors[i]); mGlyphData[i].paint .setPathEffect(new DashPathEffect(new float[] { distance, mGlyphData[i].length }, 0)); canvas.drawPath(mGlyphData[i].path, mGlyphData[i].paint); mGlyphData[i].paint.setColor(mTraceColors[i]); mGlyphData[i].paint.setPathEffect(new DashPathEffect( new float[] { 0, distance, phase > 0 ? mMarkerLength : 0, mGlyphData[i].length }, 0)); canvas.drawPath(mGlyphData[i].path, mGlyphData[i].paint); } if (t > mFillStart) { if (mState < STATE_FILL_STARTED) { changeState(STATE_FILL_STARTED); } float phase = MathUtil.constrain(0, 1, (t - mFillStart) * 1f / mFillTime); for (int i = 0; i < mGlyphData.length; i++) { GlyphData glyphData = mGlyphData[i]; mFillPaint.setARGB((int) (phase * ((float) mFillAlphas[i] / (float) 255) * 255), mFillReds[i], mFillGreens[i], mFillBlues[i]); canvas.drawPath(glyphData.path, mFillPaint); } } if (t < mFillStart + mFillTime) { ViewCompat.postInvalidateOnAnimation(this); } else { changeState(STATE_FINISHED); } }
From source file:com.codegarden.nativenavigation.JuceActivity.java
public final int[] renderGlyph(char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds) { Path p = new Path(); paint.getTextPath(String.valueOf(glyph), 0, 1, 0.0f, 0.0f, p); RectF boundsF = new RectF(); p.computeBounds(boundsF, true);//from w ww . ja va 2 s. co m matrix.mapRect(boundsF); boundsF.roundOut(bounds); bounds.left--; bounds.right++; final int w = bounds.width(); final int h = Math.max(1, bounds.height()); Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bm); matrix.postTranslate(-bounds.left, -bounds.top); c.setMatrix(matrix); c.drawPath(p, paint); final int sizeNeeded = w * h; if (cachedRenderArray.length < sizeNeeded) cachedRenderArray = new int[sizeNeeded]; bm.getPixels(cachedRenderArray, 0, w, 0, 0, w, h); bm.recycle(); return cachedRenderArray; }
From source file:com.daitu_liang.study.mytest.svg.AnimatedSvgView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mState == STATE_NOT_STARTED || mGlyphData == null) { return;// w w w. jav a 2s . c o m } long t = System.currentTimeMillis() - mStartTime; // ? for (int i = 0; i < mGlyphData.length; i++) { float phase = MathUtil.constrain(0, 1, (t - (mTraceTime - mTraceTimePerGlyph) * i * 1f / mGlyphData.length) * 1f / mTraceTimePerGlyph); float distance = INTERPOLATOR.getInterpolation(phase) * mGlyphData[i].length; mGlyphData[i].paint.setColor(mTraceResidueColors[i]); mGlyphData[i].paint .setPathEffect(new DashPathEffect(new float[] { distance, mGlyphData[i].length }, 0)); canvas.drawPath(mGlyphData[i].path, mGlyphData[i].paint); mGlyphData[i].paint.setColor(mTraceColors[i]); mGlyphData[i].paint.setPathEffect(new DashPathEffect( new float[] { 0, distance, phase > 0 ? mMarkerLength : 0, mGlyphData[i].length }, 0)); canvas.drawPath(mGlyphData[i].path, mGlyphData[i].paint); } if (t > mFillStart) { if (mState < STATE_FILL_STARTED) { changeState(STATE_FILL_STARTED); } // ????alpha float phase = MathUtil.constrain(0, 1, (t - mFillStart) * 1f / mFillTime); for (int i = 0; i < mGlyphData.length; i++) { GlyphData glyphData = mGlyphData[i]; mFillPaint.setARGB((int) (phase * ((float) mFillAlphas[i] / (float) 255) * 255), mFillReds[i], mFillGreens[i], mFillBlues[i]); canvas.drawPath(glyphData.path, mFillPaint); } } if (t < mFillStart + mFillTime) { ViewCompat.postInvalidateOnAnimation(this); } else { changeState(STATE_FINISHED); } }
From source file:com.mukesh.OtpView.java
private void drawOtpBox(Canvas canvas, int i) { if (getText() != null && hideLineWhenFilled && i < getText().length()) { return;/* w ww . j a va 2s .c o m*/ } canvas.drawPath(path, paint); }
From source file:com.andremion.music.MusicCoverView.java
@Override protected void onDraw(Canvas canvas) { if (SHAPE_CIRCLE == mShape) { canvas.clipPath(mClipPath);/*ww w .j a v a 2 s . c o m*/ } else if (SHAPE_RECTANGLE == mShape) { canvas.clipPath(mClipPath); } else if (SHAPE_SQUARE == mShape) { if (getTransitionSquareAsCircle()) { canvas.clipPath(mClipPathAsCircle, Region.Op.REPLACE); } else { canvas.clipPath(mRectSquarePath, Region.Op.REPLACE); } } super.onDraw(canvas); canvas.drawPath(mTrackPath, mTrackPaint); canvas.drawPath(mDiscPathCenterDecor, mDiscPaintCenterDecor); canvas.drawPath(mDiscPathCenter, mDiscPaintCenter); }
From source file:org.ayo.robot.anim.svg.AnimatedSvgView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mState == STATE_NOT_STARTED || mGlyphData == null) { return;/*from w ww. ja v a 2s .c om*/ } long t = System.currentTimeMillis() - mStartTime; // for (int i = 0; i < mGlyphData.length; i++) { float phase = MathUtil.constrain(0, 1, (t - (mTraceTime - mTraceTimePerGlyph) * i * 1f / mGlyphData.length) * 1f / mTraceTimePerGlyph); float distance = INTERPOLATOR.getInterpolation(phase) * mGlyphData[i].length; mGlyphData[i].paint.setColor(mTraceResidueColors[i]); mGlyphData[i].paint .setPathEffect(new DashPathEffect(new float[] { distance, mGlyphData[i].length }, 0)); canvas.drawPath(mGlyphData[i].path, mGlyphData[i].paint); mGlyphData[i].paint.setColor(mTraceColors[i]); mGlyphData[i].paint.setPathEffect(new DashPathEffect( new float[] { 0, distance, phase > 0 ? mMarkerLength : 0, mGlyphData[i].length }, 0)); canvas.drawPath(mGlyphData[i].path, mGlyphData[i].paint); } if (t > mFillStart) { if (mState < STATE_FILL_STARTED) { changeState(STATE_FILL_STARTED); } // alpha float phase = MathUtil.constrain(0, 1, (t - mFillStart) * 1f / mFillTime); for (int i = 0; i < mGlyphData.length; i++) { GlyphData glyphData = mGlyphData[i]; mFillPaint.setARGB((int) (phase * ((float) mFillAlphas[i] / (float) 255) * 255), mFillReds[i], mFillGreens[i], mFillBlues[i]); canvas.drawPath(glyphData.path, mFillPaint); } } if (t < mFillStart + mFillTime) { ViewCompat.postInvalidateOnAnimation(this); } else { changeState(STATE_FINISHED); } }
From source file:com.kmagic.solitaire.DrawMaster.java
/** * Draw a diamond//from ww w .jav a 2 s .co m * @param canvas canvas to draw on * @param width width of the diamond * @param height height of the diamond */ public void drawDiamond(final Canvas canvas, final float width, final float height) { final Paint paint = getRedPaint(); final Path path = new Path(); path.moveTo(width / 2, 0); final float offset = height / 5; path.lineTo(offset, height / 2); path.lineTo(width / 2, height); path.lineTo(width - offset, height / 2); path.lineTo(width / 2, 0); path.close(); canvas.drawPath(path, paint); }
From source file:com.blestep.sportsbracelet.view.TimelineChartView.java
private void drawTargetLine(Canvas c) { if (mIsShowTargetDashedLine && mTargetValue > 0) { if (mTargetValue > mMaxValue) { Path path = new Path(); path.moveTo(0, mTopSpaceHeight); path.lineTo(mGraphArea.width(), mTopSpaceHeight); c.drawPath(path, mGraphTargetDashedLinePaint); } else {//from w w w. ja v a2 s .c o m float height = mGraphArea.height(); float y = (float) (height - (height * ((mTargetValue * 100) / mMaxValue)) / 100) + mTopSpaceHeight; Path path = new Path(); path.moveTo(0, y); path.lineTo(mGraphArea.width(), y); c.drawPath(path, mGraphTargetDashedLinePaint); } } }