Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1ff52d2 authored by Matt Casey's avatar Matt Casey
Browse files

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
parent d2191dba
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -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) {