public float exactCenterX(){ return drawBounds.exactCenterX(); }
/** * Calculate the duration for the transition depending upon how far the text has to move. */ private long calculateDuration(@NonNull Rect startPosition, @NonNull Rect endPosition) { float distance = (float) Math.hypot( startPosition.exactCenterX() - endPosition.exactCenterX(), startPosition.exactCenterY() - endPosition.exactCenterY()); long duration = (long) (1000 * (distance / velocity)); return Math.max(minDuration, Math.min(maxDuration, duration)); }
@Override protected void onBoundsChange(Rect bounds) { float x = bounds.exactCenterX(); float y = bounds.exactCenterY(); mPath.reset(); mPath.moveTo(x, y + mSize / 2f); mPath.lineTo(x - mSize, y - mSize / 2f); mPath.lineTo(x + mSize, y - mSize / 2f); mPath.close(); }
private final Rect textBounds = new Rect(); //don't new this up in a draw method public void drawTextCentred(Canvas canvas, Paint paint, String text, float cx, float cy){ paint.getTextBounds(text, 0, text.length(), textBounds); canvas.drawText(text, cx - textBounds.exactCenterX(), cy - textBounds.exactCenterY(), paint); }
@Override protected void onBoundsChange(Rect bounds) { mX = bounds.exactCenterX(); mY = bounds.exactCenterY(); mRadius = Math.min(bounds.width(), bounds.height()) / 2f; }
@Override protected void onBoundsChange(Rect bounds) { mBoxRect.set(bounds.exactCenterX() - mBoxSize / 2, bounds.exactCenterY() - mBoxSize / 2, bounds.exactCenterX() + mBoxSize / 2, bounds.exactCenterY() + mBoxSize / 2); }
@Override public void draw(@NonNull Canvas c) { final Drawable thisDrawable = this; final Rect bounds = thisDrawable.getBounds(); final int saveCount = c.save(); c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY()); mRing.draw(c, bounds); c.restoreToCount(saveCount); }
/** * Compute target values that are dependent on bounding. */ private void computeBoundedTargetValues() { mTargetX = (mClampedStartingX - mBounds.exactCenterX()) * .7f; mTargetY = (mClampedStartingY - mBounds.exactCenterY()) * .7f; mTargetRadius = mBoundedRadius; }
private void updateMatrix(){ if(mBitmap == null) return; Rect bounds = getBounds(); if(bounds.width() == 0 || bounds.height() == 0) return; mMatrix.reset(); float scale = bounds.height() / (float)Math.min(mBitmap.getWidth(), mBitmap.getHeight()); mMatrix.setScale(scale, scale, 0, 0); mMatrix.postTranslate(bounds.exactCenterX() - mBitmap.getWidth() * scale / 2, bounds.exactCenterY() - mBitmap.getHeight() * scale / 2); mBitmapShader.setLocalMatrix(mMatrix); }
@Override public void draw(Canvas canvas) { if(mBitmap != null){ Rect bounds = getBounds(); float x = bounds.exactCenterX(); float y = bounds.exactCenterY(); float radius = bounds.height() / 2f; mPaint.setShader(mBitmapShader); canvas.drawCircle(x, y, radius, mPaint); } }
private float getCurrentX() { return MathUtils.lerp(mClampedStartingX - mBounds.exactCenterX(), mTargetX, mTweenX); }
public void draw(Canvas c, Rect bounds) { final RectF arcBounds = mTempBounds; arcBounds.set(bounds); arcBounds.inset(mStrokeInset, mStrokeInset); final float startAngle = (mStartTrim + mRotation) * 360; final float endAngle = (mEndTrim + mRotation) * 360; float sweepAngle = endAngle - startAngle; if (sweepAngle != 0) { mPaint.setColor(mCurrentColor); c.drawArc(arcBounds, startAngle, sweepAngle, false, mPaint); } drawTriangle(c, startAngle, sweepAngle, bounds); if (mAlpha < 255) { mCirclePaint.setColor(mBackgroundColor); mCirclePaint.setAlpha(255 - mAlpha); c.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), bounds.width() / 2, mCirclePaint); } }
private void drawTriangle(Canvas c, float startAngle, float sweepAngle, Rect bounds) { if (mShowArrow) { if (mArrow == null) { mArrow = new Path(); mArrow.setFillType(Path.FillType.EVEN_ODD); } else { mArrow.reset(); } // Adjust the position of the triangle so that it is inset as // much as the arc, but also centered on the arc. float inset = (int) mStrokeInset / 2 * mArrowScale; float x = (float) (mRingCenterRadius * Math.cos(0) + bounds.exactCenterX()); float y = (float) (mRingCenterRadius * Math.sin(0) + bounds.exactCenterY()); // Update the path each time. This works around an issue in SKIA // where concatenating a rotation matrix to a scale matrix // ignored a starting negative rotation. This appears to have // been fixed as of API 21. mArrow.moveTo(0, 0); mArrow.lineTo(mArrowWidth * mArrowScale, 0); mArrow.lineTo((mArrowWidth * mArrowScale / 2), (mArrowHeight * mArrowScale)); mArrow.offset(x - inset, y); mArrow.close(); // draw a triangle mArrowPaint.setColor(mCurrentColor); c.rotate(startAngle + sweepAngle - ARROW_OFFSET_ANGLE, bounds.exactCenterX(), bounds.exactCenterY()); c.drawPath(mArrow, mArrowPaint); } }
@Override protected void onDraw(Canvas canvas) { if (!mIsAnimatorCancel) { final Rect bounds = getBounds(); final int saveCount = canvas.save(); canvas.rotate(mRotation * 360, bounds.exactCenterX(), bounds.exactCenterY()); drawRing(canvas, bounds); canvas.restoreToCount(saveCount); } else { canvas.restore(); } }
/** * Clamps the starting position to fit within the ripple bounds. */ private void clampStartingPosition() { final float cX = mBounds.exactCenterX(); final float cY = mBounds.exactCenterY(); final float dX = mStartingX - cX; final float dY = mStartingY - cY; final float r = mTargetRadius; if (dX * dX + dY * dY > r * r) { // Point is outside the circle, clamp to the perimeter. final double angle = Math.atan2(dY, dX); mClampedStartingX = cX + (float) (Math.cos(angle) * r); mClampedStartingY = cY + (float) (Math.sin(angle) * r); } else { mClampedStartingX = mStartingX; mClampedStartingY = mStartingY; } }
@Override public void draw(Canvas c) { final Rect bounds = getBounds(); final int saveCount = c.save(); c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY()); mRing.draw(c, bounds); c.restoreToCount(saveCount); }
@Override public void draw(Canvas c) { final Rect bounds = getBounds(); final int saveCount = c.save(); c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY()); mRing.draw(c, bounds); c.restoreToCount(saveCount); }
/** * Draw the progress spinner */ public void draw(Canvas c, Rect bounds) { final RectF arcBounds = mTempBounds; arcBounds.set(bounds); arcBounds.inset(mStrokeInset, mStrokeInset); final float startAngle = (mStartTrim + mRotation) * 360; final float endAngle = (mEndTrim + mRotation) * 360; float sweepAngle = endAngle - startAngle; mPaint.setColor(mCurrentColor); c.drawArc(arcBounds, startAngle, sweepAngle, false, mPaint); drawTriangle(c, startAngle, sweepAngle, bounds); if (mAlpha < 255) { mCirclePaint.setColor(mBackgroundColor); mCirclePaint.setAlpha(255 - mAlpha); c.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), bounds.width() / 2, mCirclePaint); } }
public RectAssert hasExactCenterX(float center) { isNotNull(); float actualCenter = actual.exactCenterX(); assertThat(actualCenter) // .overridingErrorMessage("Expected exact X center <%s> but was <%s>.", center, actualCenter) // .isEqualTo(center); return this; }
protected void positionSelectorLikeFocusCompat(int position, View sel) { // If we're changing position, update the visibility since the selector // is technically being detached from the previous selection. final Drawable selector = getSelector(); final boolean manageState = selector != null && position != INVALID_POSITION; if (manageState) { selector.setVisible(false, false); } positionSelectorCompat(position, sel); if (manageState) { final Rect bounds = mSelectorRect; final float x = bounds.exactCenterX(); final float y = bounds.exactCenterY(); selector.setVisible(getVisibility() == VISIBLE, false); DrawableCompat.setHotspot(selector, x, y); } } protected void positionSelectorCompat(int position, View sel) {