Code example for RectF

Methods: contains, inset, offset, set

0
    public boolean fullPhotoCropped() { 
        return cropBounds.contains(photoBounds);
    } 
 
    private int detectTouchArea(float x, float y) {
        RectF area = new RectF();
        area.set(cropBounds);
        area.inset(-TOUCH_AREA_SPAN, -TOUCH_AREA_SPAN);
        if (!area.contains(x, y)) {
            return TOUCH_AREA_OUTSIDE;
        } 
 
        // left 
        area.set(cropBounds.left - TOUCH_AREA_SPAN, cropBounds.top  + TOUCH_AREA_SPAN,
                cropBounds.left + TOUCH_AREA_SPAN, cropBounds.bottom - TOUCH_AREA_SPAN);
        if (area.contains(x, y)) {
            return TOUCH_AREA_LEFT;
        } 
        // right 
        area.offset(cropBounds.width(), 0f);
        if (area.contains(x, y)) {
            return TOUCH_AREA_RIGHT;
        } 
        // top 
        area.set(cropBounds.left + TOUCH_AREA_SPAN, cropBounds.top - TOUCH_AREA_SPAN,
                cropBounds.right - TOUCH_AREA_SPAN, cropBounds.top + TOUCH_AREA_SPAN);
        if (area.contains(x, y)) {
            return TOUCH_AREA_TOP;
        } 
        // bottom 
        area.offset(0f, cropBounds.height());
        if (area.contains(x, y)) {
            return TOUCH_AREA_BOTTOM;
        } 
        // top left 
        area.set(cropBounds.left - TOUCH_AREA_SPAN, cropBounds.top - TOUCH_AREA_SPAN,
                cropBounds.left + TOUCH_AREA_SPAN, cropBounds.top + TOUCH_AREA_SPAN);
        if (area.contains(x, y)) {
            return TOUCH_AREA_TOP_LEFT;
        } 
        // top right 
        area.offset(cropBounds.width(), 0f);
        if (area.contains(x, y)) {
            return TOUCH_AREA_TOP_RIGHT;
        } 
        // bottom right 
        area.offset(0f, cropBounds.height());
        if (area.contains(x, y)) {
            return TOUCH_AREA_BOTTOM_RIGHT;
        } 
        // bottom left 
        area.offset(-cropBounds.width(), 0f);
        if (area.contains(x, y)) {
            return TOUCH_AREA_BOTTOM_LEFT;
        } 
        return TOUCH_AREA_INSIDE;
    }