From c1ff52d21154ad1589616fe89a14c3d58ee00f4d Mon Sep 17 00:00:00 2001 From: Matt Casey Date: Mon, 22 Feb 2021 21:46:51 -0500 Subject: [PATCH] Add a tab to grab to CropView handles. Not codifying the handle size in an attribute since the mock is expected to be replaced so that param may not make sense soon. Also call getWidth/getHeight where we were calling getMeasuredWidth/Height before. Bug: 180967468 Test: Visual verification of half-circle tabs drawn on crop handles Change-Id: I4716fa2d19c40ce1f825c71f3a135544532bc927 --- .../android/systemui/screenshot/CropView.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/CropView.java b/packages/SystemUI/src/com/android/systemui/screenshot/CropView.java index 1386ddfa7692a..53d9f1c08e6f0 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/CropView.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/CropView.java @@ -97,8 +97,8 @@ public class CropView extends View { float bottom = mBottomCrop + mBottomDelta; drawShade(canvas, 0, top); drawShade(canvas, bottom, 1f); - drawHandle(canvas, top); - drawHandle(canvas, bottom); + drawHandle(canvas, top, /* draw the handle tab down */ false); + drawHandle(canvas, bottom, /* draw the handle tab up */ true); } @Override @@ -122,7 +122,7 @@ public class CropView extends View { } else { // Bottom mBottomDelta = pixelsToFraction((int) MathUtils.constrain(delta, topPx + 2 * mCropTouchMargin - bottomPx, - getMeasuredHeight() - bottomPx)); + getHeight() - bottomPx)); } updateListener(event); invalidate(); @@ -212,21 +212,25 @@ public class CropView extends View { } private void drawShade(Canvas canvas, float fracStart, float fracEnd) { - canvas.drawRect(0, fractionToPixels(fracStart), getMeasuredWidth(), + canvas.drawRect(0, fractionToPixels(fracStart), getWidth(), fractionToPixels(fracEnd), mShadePaint); } - private void drawHandle(Canvas canvas, float frac) { + private void drawHandle(Canvas canvas, float frac, boolean handleTabUp) { int y = fractionToPixels(frac); - canvas.drawLine(0, y, getMeasuredWidth(), y, mHandlePaint); + canvas.drawLine(0, y, getWidth(), y, mHandlePaint); + float radius = 15 * getResources().getDisplayMetrics().density; + float x = getWidth() * .9f; + canvas.drawArc(x - radius, y - radius, x + radius, y + radius, handleTabUp ? 180 : 0, 180, + true, mHandlePaint); } private int fractionToPixels(float frac) { - return (int) (frac * getMeasuredHeight()); + return (int) (frac * getHeight()); } private float pixelsToFraction(int px) { - return px / (float) getMeasuredHeight(); + return px / (float) getHeight(); } private CropBoundary nearestBoundary(MotionEvent event, int topPx, int bottomPx) {