private void init(Context context) {

    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();

    mHandleRadius = HandleUtil.getTargetRadius(context);

    mSnapRadius =
        TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, SNAP_RADIUS_DP, displayMetrics);

    mBorderPaint = PaintUtil.newBorderPaint(context);
    mGuidelinePaint = PaintUtil.newGuidelinePaint();
    mBackgroundPaint = PaintUtil.newBackgroundPaint(context);
    mCornerPaint = PaintUtil.newCornerPaint(context);

    // Sets the values for the corner sizes
    mCornerOffset =
        TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, DEFAULT_CORNER_OFFSET_DP, displayMetrics);
    mCornerExtension =
        TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, DEFAULT_CORNER_EXTENSION_DP, displayMetrics);
    mCornerLength =
        TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, DEFAULT_CORNER_LENGTH_DP, displayMetrics);

    // Sets guidelines to default until specified otherwise
    mGuidelines = CropImageView.DEFAULT_GUIDELINES;
  }
  /**
   * Handles a {@link MotionEvent#ACTION_DOWN} event.
   *
   * @param x the x-coordinate of the down action
   * @param y the y-coordinate of the down action
   */
  private void onActionDown(float x, float y) {

    final float left = Edge.LEFT.getCoordinate();
    final float top = Edge.TOP.getCoordinate();
    final float right = Edge.RIGHT.getCoordinate();
    final float bottom = Edge.BOTTOM.getCoordinate();

    mPressedHandle = HandleUtil.getPressedHandle(x, y, left, top, right, bottom, mHandleRadius);

    if (mPressedHandle == null) return;

    // Calculate the offset of the touch point from the precise location
    // of the handle. Save these values in a member variable since we want
    // to maintain this offset as we drag the handle.
    mTouchOffset = HandleUtil.getOffset(mPressedHandle, x, y, left, top, right, bottom);

    invalidate();
  }