List of usage examples for android.graphics Canvas drawPath
public void drawPath(@NonNull Path path, @NonNull Paint paint)
From source file:org.florescu.android.rangeseekbar.RangeSeekBar.java
/** * Draws a drop shadow beneath the slider thumb. * * @param screenCoord the x-coordinate of the slider thumb * @param canvas the canvas on which to draw the shadow */// www.j a v a 2s . co m private void drawThumbShadow(float screenCoord, Canvas canvas) { mThumbShadowMatrix.setTranslate(screenCoord + mThumbShadowXOffset, mTextOffset + mThumbHalfHeight + mThumbShadowYOffset); mTranslatedThumbShadowPath.set(mThumbShadowPath); mTranslatedThumbShadowPath.transform(mThumbShadowMatrix); canvas.drawPath(mTranslatedThumbShadowPath, shadowPaint); }
From source file:com.justwayward.reader.view.RVPIndicator.java
/** * (?view)/*from w w w .j a v a2 s . c om*/ */ @Override protected void dispatchDraw(Canvas canvas) { // ? canvas.save(); switch (mIndicatorStyle) { case STYLE_BITMAP: canvas.translate(mTranslationX, 0); canvas.drawBitmap(mBitmap, null, mRectF, mPaint); break; case STYLE_LINE: canvas.translate(mTranslationX, getHeight() - mIndicatorHeight); canvas.drawRect(mRectF, mPaint); break; case STYLE_SQUARE: canvas.translate(mTranslationX, 0); canvas.drawRect(mRectF, mPaint); break; case STYLE_TRIANGLE: canvas.translate(mTranslationX, 0); // // mPaint.setPathEffect(new CornerPathEffect(10)); mPath = new Path(); int midOfTab = getWidth() / mTabVisibleCount / 2; mPath.moveTo(midOfTab, getHeight() - mIndicatorHeight); mPath.lineTo(midOfTab - mIndicatorWidth / 2, getHeight()); mPath.lineTo(midOfTab + mIndicatorWidth / 2, getHeight()); mPath.close(); canvas.drawPath(mPath, mPaint); break; } // ?? canvas.restore(); super.dispatchDraw(canvas); }
From source file:android.example.com.visualizerpreferences.AudioVisuals.VisualizerView.java
public VisualizerView(Context context, AttributeSet attrs) { super(context, attrs); mBytes = null;//from w w w . j a v a 2 s .com TrailedShape.setMinSize(MIN_SIZE_DEFAULT); // Create each of the shapes and define how they are drawn on screen // Make bass circle mBassCircle = new TrailedShape(BASS_MULTIPLIER) { @Override protected void drawThisShape(float shapeCenterX, float shapeCenterY, float currentSize, Canvas canvas, Paint paint) { canvas.drawCircle(shapeCenterX, shapeCenterY, currentSize, paint); } }; // Make midrange square mMidSquare = new TrailedShape(MID_MULTIPLIER) { @Override protected void drawThisShape(float shapeCenterX, float shapeCenterY, float currentSize, Canvas canvas, Paint paint) { canvas.drawRect(shapeCenterX - currentSize, shapeCenterY - currentSize, shapeCenterX + currentSize, shapeCenterY + currentSize, paint); } }; // Make treble triangle mTrebleTriangle = new TrailedShape(TREBLE_MULTIPLIER) { @Override protected void drawThisShape(float shapeCenterX, float shapeCenterY, float currentSize, Canvas canvas, Paint paint) { Path trianglePath = new Path(); trianglePath.moveTo(shapeCenterX, shapeCenterY - currentSize); trianglePath.lineTo(shapeCenterX + currentSize, shapeCenterY + currentSize / 2); trianglePath.lineTo(shapeCenterX - currentSize, shapeCenterY + currentSize / 2); trianglePath.lineTo(shapeCenterX, shapeCenterY - currentSize); canvas.drawPath(trianglePath, paint); } }; }
From source file:org.goodev.material.widget.InkPageIndicator.java
private void drawUnselected(Canvas canvas) { combinedUnselectedPath.rewind();/*w w w .j ava2s . c o m*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // draw any settled, revealing or joining dots for (int page = 0; page < pageCount; page++) { int nextXIndex = page == pageCount - 1 ? page : page + 1; combinedUnselectedPath.op(getUnselectedPath(page, dotCenterX[page], dotCenterX[nextXIndex], page == pageCount - 1 ? INVALID_FRACTION : joiningFractions[page], dotRevealFractions[page]), Path.Op.UNION); } // draw any retreating joins if (retreatingJoinX1 != INVALID_FRACTION) { combinedUnselectedPath.op(getRetreatingJoinPath(), Path.Op.UNION); } } canvas.drawPath(combinedUnselectedPath, unselectedPaint); }
From source file:com.astir_trotter.atcustom.ui.iconics.core.IconicsDrawable.java
@Override public void draw(Canvas canvas) { if (mIcon != null || mPlainIcon != null) { final Rect viewBounds = getBounds(); updatePaddingBounds(viewBounds); updateTextSize(viewBounds);// w w w. ja va 2 s . c o m offsetIcon(viewBounds); if (mBackgroundPaint != null && mRoundedCornerRy > -1 && mRoundedCornerRx > -1) { canvas.drawRoundRect(new RectF(0, 0, viewBounds.width(), viewBounds.height()), mRoundedCornerRx, mRoundedCornerRy, mBackgroundPaint); } mPath.close(); if (mDrawContour) { canvas.drawPath(mPath, mContourPaint); } mIconPaint.setAlpha(mAlpha); mIconPaint.setColorFilter(mColorFilter == null ? mTintFilter : mColorFilter); canvas.drawPath(mPath, mIconPaint); } }
From source file:android.support.design.widget.ShadowDrawableWrapper.java
private void drawShadow(Canvas canvas) { final int rotateSaved = canvas.save(); canvas.rotate(mRotation, mContentBounds.centerX(), mContentBounds.centerY()); final float edgeShadowTop = -mCornerRadius - mShadowSize; final float shadowOffset = mCornerRadius; final boolean drawHorizontalEdges = mContentBounds.width() - 2 * shadowOffset > 0; final boolean drawVerticalEdges = mContentBounds.height() - 2 * shadowOffset > 0; final float shadowOffsetTop = mRawShadowSize - (mRawShadowSize * SHADOW_TOP_SCALE); final float shadowOffsetHorizontal = mRawShadowSize - (mRawShadowSize * SHADOW_HORIZ_SCALE); final float shadowOffsetBottom = mRawShadowSize - (mRawShadowSize * SHADOW_BOTTOM_SCALE); final float shadowScaleHorizontal = shadowOffset / (shadowOffset + shadowOffsetHorizontal); final float shadowScaleTop = shadowOffset / (shadowOffset + shadowOffsetTop); final float shadowScaleBottom = shadowOffset / (shadowOffset + shadowOffsetBottom); // LT//from w ww . j a v a 2 s . co m int saved = canvas.save(); canvas.translate(mContentBounds.left + shadowOffset, mContentBounds.top + shadowOffset); canvas.scale(shadowScaleHorizontal, shadowScaleTop); canvas.drawPath(mCornerShadowPath, mCornerShadowPaint); if (drawHorizontalEdges) { // TE canvas.scale(1f / shadowScaleHorizontal, 1f); canvas.drawRect(0, edgeShadowTop, mContentBounds.width() - 2 * shadowOffset, -mCornerRadius, mEdgeShadowPaint); } canvas.restoreToCount(saved); // RB saved = canvas.save(); canvas.translate(mContentBounds.right - shadowOffset, mContentBounds.bottom - shadowOffset); canvas.scale(shadowScaleHorizontal, shadowScaleBottom); canvas.rotate(180f); canvas.drawPath(mCornerShadowPath, mCornerShadowPaint); if (drawHorizontalEdges) { // BE canvas.scale(1f / shadowScaleHorizontal, 1f); canvas.drawRect(0, edgeShadowTop, mContentBounds.width() - 2 * shadowOffset, -mCornerRadius + mShadowSize, mEdgeShadowPaint); } canvas.restoreToCount(saved); // LB saved = canvas.save(); canvas.translate(mContentBounds.left + shadowOffset, mContentBounds.bottom - shadowOffset); canvas.scale(shadowScaleHorizontal, shadowScaleBottom); canvas.rotate(270f); canvas.drawPath(mCornerShadowPath, mCornerShadowPaint); if (drawVerticalEdges) { // LE canvas.scale(1f / shadowScaleBottom, 1f); canvas.drawRect(0, edgeShadowTop, mContentBounds.height() - 2 * shadowOffset, -mCornerRadius, mEdgeShadowPaint); } canvas.restoreToCount(saved); // RT saved = canvas.save(); canvas.translate(mContentBounds.right - shadowOffset, mContentBounds.top + shadowOffset); canvas.scale(shadowScaleHorizontal, shadowScaleTop); canvas.rotate(90f); canvas.drawPath(mCornerShadowPath, mCornerShadowPaint); if (drawVerticalEdges) { // RE canvas.scale(1f / shadowScaleTop, 1f); canvas.drawRect(0, edgeShadowTop, mContentBounds.height() - 2 * shadowOffset, -mCornerRadius, mEdgeShadowPaint); } canvas.restoreToCount(saved); canvas.restoreToCount(rotateSaved); }
From source file:com.dirkgassen.wator.ui.view.RangeSlider.java
/** * Draws the view//from ww w. j a v a 2 s. c om * @param canvas canvas to paint on */ @Override protected void onDraw(Canvas canvas) { int paddingLeft = getPaddingLeft(); int paddingTop = getPaddingTop(); int paddingRight = getPaddingRight(); int paddingBottom = getPaddingBottom(); int sliderY = (getHeight() - paddingTop - paddingBottom) / 2 + paddingTop; canvas.drawLine(paddingLeft + thumbSize / 2, sliderY, getWidth() - paddingRight - thumbSize / 2, sliderY, sliderPaint); String valueString = String.format(Locale.getDefault(), thumbFormat, value); final float valueWidth = (thumbTextPaint.measureText(valueString, 0, valueString.length())); float thumbTip = positionFromValue(paddingLeft, paddingRight); if (thumbPath.isEmpty()) { thumbPath.addCircle(thumbTip, sliderY, thumbSize / 2, Path.Direction.CW); } else { thumbPath.offset(thumbTip, 0); } canvas.drawPath(thumbPath, thumbBackgroundPaint); canvas.drawText(valueString, thumbTip - valueWidth / 2, sliderY + (-thumbTextPaint.ascent()) / 2, thumbTextPaint); thumbPath.offset(-thumbTip, 0); }
From source file:com.grarak.kerneladiutor.views.XYGraph.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int width = getMeasuredWidth(); int height = getMeasuredHeight(); boolean isRTL = Utils.isRTL(this); for (int i = 1; i < 10; i++) { float y = ((float) height / 10) * i; canvas.drawLine(0, y, width, y, mPaintLine); }// w w w . ja v a 2 s . c o m for (int i = 0; i < 7; i++) { float x = ((float) width / 6) * i; float offset = (float) width / 6 / 4 * state; if (isRTL) { x += offset; } else { x -= offset; } canvas.drawLine(x, 0, x, height, mPaintLine); } mPathGraph.reset(); float graphX; if (isRTL) { graphX = ((float) width / 24) * (mPercentages.size() - 1); } else { graphX = width - ((float) width / 24) * (mPercentages.size() - 1); } mPathGraph.moveTo(graphX, height); float x = 0; float y; for (int i = 0; i < mPercentages.size(); i++) { if (isRTL) { x = graphX - ((float) width / 24) * i; } else { x = graphX + ((float) width / 24) * i; } y = ((float) (100 - mPercentages.get(i)) / 100) * height; mPathGraph.lineTo(x, y); } mPathGraph.lineTo(x, height); mPathGraph.close(); canvas.drawPath(mPathGraph, mPaintGraph); canvas.drawPath(mPathGraph, mPaintGraphStroke); if (mEdgeVisible) { canvas.drawRect(0, 0, width, height, mPaintEdge); } }
From source file:com.breel.wearables.shadowclock.graphics.ShapeShadow.java
public void drawShadow(Canvas canvas, float _sunPosX, float _sunPosY) { tmpSunPositionVector.setPosition(_sunPosX, _sunPosY); shadowPath.reset();//from w w w . j av a 2s . c om for (int i = 0; i < vertexArray.size(); i++) { Path tmpPath = shadowPaths.get(i); tmpPath.reset(); AVector v1 = vertexArray.get(i); AVector v2 = vertexArray.get(i == getVertCount() - 1 ? 0 : i + 1); tmpPath.moveTo(v2.getX(), v2.getY()); tmpPath.lineTo(v1.getX(), v1.getY()); // Current shadow vertex AVector tmpShadowVector = AVector.sub(v1, tmpSunPositionVector); tmpShadowVector.normalize(); tmpShadowVector.multiply(600.0f); tmpShadowVector.add(v1); tmpPath.lineTo(tmpShadowVector.getX(), tmpShadowVector.getY()); // Current shadow vertex tmpShadowVector = AVector.sub(v2, tmpSunPositionVector); tmpShadowVector.normalize(); tmpShadowVector.multiply(600.0f); tmpShadowVector.add(v2); tmpPath.lineTo(tmpShadowVector.getX(), tmpShadowVector.getY()); tmpPath.close(); shadowPath.op(tmpPath, Path.Op.UNION); } canvas.drawPath(shadowPath, shadowPathPaint); }
From source file:com.shizhefei.view.coolrefreshview.header.JellyHeader.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int totalDistance = totalDistance(); int headerHeight; int pullHeight; int offsetToKeepHeaderWhileLoading = offsetToKeepHeaderWhileLoading(); if (status == CoolRefreshView.PULL_STATUS_REFRESHING) { headerHeight = offsetToKeepHeaderWhileLoading; pullHeight = currentDistance;/*from ww w. j a v a 2 s .c o m*/ } else { headerHeight = Math.min(currentDistance / 2, offsetToKeepHeaderWhileLoading); pullHeight = currentDistance; } if (headerHeight == 0) { return; } int saveCount = canvas.save(); canvas.translate(0, totalDistance - currentDistance); final int width = canvas.getWidth(); //??touchx ????touchx?? mPointX = width / 2; final float mDisplayX = (mPointX - width / 2f) * 0.5f + width / 2f; mPaint.setColor(mColor); mPath.rewind(); // ? mPath.moveTo(0, 0); mPath.lineTo(0, headerHeight); // ??? mPath.quadTo(mDisplayX, pullHeight, width, headerHeight); mPath.lineTo(width, 0); mPath.close(); canvas.drawPath(mPath, mPaint); canvas.restoreToCount(saveCount); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setOutlineProvider(mViewOutlineProvider); } }