android.graphics.Rect.exactCenterY()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中android.graphics.Rect.exactCenterY方法的一些代码示例,展示了Rect.exactCenterY的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Rect.exactCenterY方法的具体详情如下:
包路径:android.graphics.Rect
类名称:Rect
方法名:exactCenterY

Rect.exactCenterY介绍

暂无

代码示例

代码示例来源:origin: jdsjlzx/LRecyclerView

public float exactCenterY(){
  return drawBounds.exactCenterY();
}

代码示例来源:origin: nickbutcher/plaid

/**
 * 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));
}

代码示例来源:origin: stackoverflow.com

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);
}

代码示例来源:origin: rey5137/material

@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();
}

代码示例来源:origin: rey5137/material

@Override
protected void onBoundsChange(Rect bounds) {
  mX = bounds.exactCenterX();
  mY = bounds.exactCenterY();
  mRadius = Math.min(bounds.width(), bounds.height()) / 2f;
}

代码示例来源:origin: rey5137/material

@Override
protected void onBoundsChange(Rect bounds) {
  mBoxRect.set(bounds.exactCenterX() - mBoxSize / 2, bounds.exactCenterY() - mBoxSize / 2, bounds.exactCenterX() + mBoxSize / 2, bounds.exactCenterY() + mBoxSize / 2);
}

代码示例来源:origin: scwang90/SmartRefreshLayout

@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);
}

代码示例来源:origin: ZieIony/Carbon

/**
 * Compute target values that are dependent on bounding.
 */
private void computeBoundedTargetValues() {
  mTargetX = (mClampedStartingX - mBounds.exactCenterX()) * .7f;
  mTargetY = (mClampedStartingY - mBounds.exactCenterY()) * .7f;
  mTargetRadius = mBoundedRadius;
}

代码示例来源:origin: rey5137/material

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);
}

代码示例来源:origin: rey5137/material

@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);
  }
}

代码示例来源:origin: ZieIony/Carbon

private float getCurrentY() {
  return MathUtils.lerp(mClampedStartingY - mBounds.exactCenterY(), mTargetY, mTweenY);
}

代码示例来源:origin: scwang90/SmartRefreshLayout

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);
  }
}

代码示例来源:origin: scwang90/SmartRefreshLayout

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);
  }
}

代码示例来源:origin: smuyyh/BookReader

@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();
  }
}

代码示例来源:origin: ZieIony/Carbon

/**
 * 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;
  }
}

代码示例来源:origin: smuyyh/BookReader

@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);
}

代码示例来源:origin: android-cjj/Android-MaterialRefreshLayout

@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);
}

代码示例来源:origin: smuyyh/BookReader

/**
 * 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);
  }
}

代码示例来源:origin: square/assertj-android

public RectAssert hasExactCenterY(float center) {
 isNotNull();
 float actualCenter = actual.exactCenterY();
 assertThat(actualCenter) //
   .overridingErrorMessage("Expected exact Y center <%s> but was <%s>.", center,
     actualCenter) //
   .isEqualTo(center);
 return this;
}

代码示例来源:origin: rey5137/material

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) {

相关文章