public int centerX(){ return drawBounds.centerX(); }
private float getMaxRadius(float x, float y, Rect bounds){ float x1 = x < bounds.centerX() ? bounds.right : bounds.left; float y1 = y < bounds.centerY() ? bounds.bottom : bounds.top; return (float)Math.sqrt(Math.pow(x1 - x, 2) + Math.pow(y1 - y, 2)); }
public Rect clipSquare(Rect rect) { int w = rect.width(); int h = rect.height(); int min = Math.min(w, h); int cx = rect.centerX(); int cy = rect.centerY(); int r = min / 2; return new Rect( cx - r, cy - r, cx + r, cy + r ); }
private void drawChecked(@NonNull Canvas canvas, float radius) { Rect bounds = getBounds(); paint.setShader(null); canvas.drawBitmap(uncheckedBitmap, bounds.left, bounds.top, paint); maskCanvas.drawColor(0xffffffff); maskPaint.setXfermode(porterDuffClear); maskCanvas.drawCircle(maskBitmap.getWidth() / 2 + bounds.width() * offset.x, maskBitmap.getHeight() / 2 + bounds.height() * offset.y, radius, maskPaint); maskPaint.setXfermode(porterDuffSrcIn); maskCanvas.drawBitmap(filledBitmap, 0, 0, maskPaint); canvas.drawBitmap(maskBitmap, bounds.left, bounds.top, paint); paint.setShader(checkedShader); canvas.drawCircle(bounds.centerX() + bounds.width() * offset.x, bounds.centerY() + bounds.height() * offset.y, radius, paint); }
/** * Set the icon offset */ private void offsetIcon(@NonNull Rect viewBounds) { float startX = viewBounds.centerX() - (mPathBounds.width() / 2); float offsetX = startX - mPathBounds.left; float startY = viewBounds.centerY() - (mPathBounds.height() / 2); float offsetY = startY - (mPathBounds.top); mPath.offset(offsetX + mIconOffsetX, offsetY + mIconOffsetY); }
public RectAssert hasCenterX(int center) { isNotNull(); int actualCenter = actual.centerX(); assertThat(actualCenter) // .overridingErrorMessage("Expected X center <%s> but was <%s>.", center, actualCenter) // .isEqualTo(center); return this; }
@Override public void drawShape(Canvas canvas, Paint paint) { if (getDrawBounds() != null) { paint.setStyle(Paint.Style.STROKE); int radius = Math.min(getDrawBounds().width(), getDrawBounds().height()) / 2; paint.setStrokeWidth(radius / 12); canvas.drawCircle(getDrawBounds().centerX(), getDrawBounds().centerY(), radius, paint); } }
@Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); if (bounds.left == 0 && bounds.top == 0 && bounds.right == 0 && bounds.bottom == 0) { return; } final int centerX = bounds.centerX(); final int centerY = bounds.centerY(); final int radius = Math.min(bounds.height(), bounds.width()) >> 1; final int maxStrokeRadius = ((int) Math.max(getForegroundLineSize(), getBackgroundLineSize()) >> 1) + 1; final int areRadius = radius - maxStrokeRadius; mOval.set(centerX - areRadius, centerY - areRadius, centerX + areRadius, centerY + areRadius); }
@Override public void draw(Canvas canvas) { Rect bounds = getBounds(); float canvasRotate; if (mVerticalMirror) { canvasRotate = MathUtils.lerp(270, 135f, mProgress); } else { canvasRotate = MathUtils.lerp(0f, 135f, mProgress); } canvas.save(); canvas.translate(bounds.centerX(), bounds.centerY()); canvas.rotate(canvasRotate); canvas.drawPath(mPath, mPaint); canvas.restore(); }
int getOuterCircleRadius(int centerX, int centerY, Rect textBounds, Rect targetBounds) { final int targetCenterX = targetBounds.centerX(); final int targetCenterY = targetBounds.centerY(); final int expandedRadius = (int) (1.1f * TARGET_RADIUS); final Rect expandedBounds = new Rect(targetCenterX, targetCenterY, targetCenterX, targetCenterY); expandedBounds.inset(-expandedRadius, -expandedRadius); final int textRadius = maxDistanceToPoints(centerX, centerY, textBounds); final int targetRadius = maxDistanceToPoints(centerX, centerY, expandedBounds); return Math.max(textRadius, targetRadius) + CIRCLE_PADDING; }
@Override public void drawShape(Canvas canvas, Paint paint) { if (getDrawBounds() != null) { int radius = Math.min(getDrawBounds().width(), getDrawBounds().height()) / 2; canvas.drawCircle(getDrawBounds().centerX(), getDrawBounds().centerY(), radius, paint); } } }
@Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); bounds = clipSquare(bounds); int radius = (int) (bounds.width() * Math.PI / 3.6f / getChildCount()); int left = bounds.centerX() - radius; int right = bounds.centerX() + radius; for (int i = 0; i < getChildCount(); i++) { Sprite sprite = getChildAt(i); sprite.setDrawBounds(left, bounds.top, right, bounds.top + radius * 2); } } }
Rect getTextBounds() { final int totalTextHeight = getTotalTextHeight(); final int totalTextWidth = getTotalTextWidth(); final int possibleTop = targetBounds.centerY() - TARGET_RADIUS - TARGET_PADDING - totalTextHeight; final int top; if (possibleTop > topBoundary) { top = possibleTop; } else { top = targetBounds.centerY() + TARGET_RADIUS + TARGET_PADDING; } final int relativeCenterDistance = (getWidth() / 2) - targetBounds.centerX(); final int bias = relativeCenterDistance < 0 ? -TEXT_POSITIONING_BIAS : TEXT_POSITIONING_BIAS; final int left = Math.max(TEXT_PADDING, targetBounds.centerX() - bias - totalTextWidth); final int right = Math.min(getWidth() - TEXT_PADDING, left + totalTextWidth); return new Rect(left, top, right, top + totalTextHeight); }
@Override public void drawChild(Canvas canvas) { Rect bounds = clipSquare(getBounds()); for (int i = 0; i < getChildCount(); i++) { int count = canvas.save(); canvas.rotate(45 + i * 90, bounds.centerX(), bounds.centerY()); Sprite sprite = getChildAt(i); sprite.draw(canvas); canvas.restoreToCount(count); } }
public static void clickBottom(LithoView lithoView, String testKey) { final TestItem testItem = LithoViewTestHelper.findTestItem(lithoView, testKey); final Rect testItemBounds = testItem.getBounds(); final int[] locationOnScreen = new int[2]; lithoView.getLocationOnScreen(locationOnScreen); click(new Point( locationOnScreen[0] + testItemBounds.centerX(), locationOnScreen[1] + testItemBounds.bottom - 1)); }
@Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); final int cx = bounds.centerX(); final int cy = bounds.centerY(); // Setup points mP1.set(cx - mWidth, cy - mHeight); mP2.set(cx + mWidth, cy - mHeight); mP3.set(cx, cy + mHeight); // Setup triangle mTrianglePath.reset(); mTrianglePath.setFillType(Path.FillType.EVEN_ODD); mTrianglePath.moveTo(mP1.x, mP1.y); mTrianglePath.lineTo(mP2.x, mP2.y); mTrianglePath.lineTo(mP3.x, mP3.y); mTrianglePath.close(); }
@Override public void drawChild(Canvas canvas) { for (int i = 0; i < getChildCount(); i++) { Sprite sprite = getChildAt(i); int count = canvas.save(); canvas.rotate(i * 360 / getChildCount(), getBounds().centerX(), getBounds().centerY()); sprite.draw(canvas); canvas.restoreToCount(count); } }
int[] getOuterCircleCenterPoint() { if (inGutter(targetBounds.centerY())) { return new int[]{targetBounds.centerX(), targetBounds.centerY()}; } final int targetRadius = Math.max(targetBounds.width(), targetBounds.height()) / 2 + TARGET_PADDING; final int totalTextHeight = getTotalTextHeight(); final boolean onTop = targetBounds.centerY() - TARGET_RADIUS - TARGET_PADDING - totalTextHeight > 0; final int left = Math.min(textBounds.left, targetBounds.left - targetRadius); final int right = Math.max(textBounds.right, targetBounds.right + targetRadius); final int titleHeight = titleLayout == null ? 0 : titleLayout.getHeight(); final int centerY = onTop ? targetBounds.centerY() - TARGET_RADIUS - TARGET_PADDING - totalTextHeight + titleHeight : targetBounds.centerY() + TARGET_RADIUS + TARGET_PADDING + titleHeight; return new int[] { (left + right) / 2, centerY }; }
public void setDrawBounds(int left, int top, int right, int bottom) { this.drawBounds = new Rect(left, top, right, bottom); setPivotX(getDrawBounds().centerX()); setPivotY(getDrawBounds().centerY()); }
public static void click(LithoView lithoView, String testKey) { final TestItem testItem = LithoViewTestHelper.findTestItem(lithoView, testKey); if (testItem == null) { throw new ViewForTestKeyNotFoundException(testKey); } final Rect testItemBounds = testItem.getBounds(); final int[] locationOnScreen = new int[2]; lithoView.getLocationOnScreen(locationOnScreen); click(new Point( locationOnScreen[0] + testItemBounds.centerX(), locationOnScreen[1] + testItemBounds.centerY())); }