Example #1
0
  @Override
  public boolean onTouch(View view, MotionEvent motionEvent) {

    switch (motionEvent.getAction()) {
      case MotionEvent.ACTION_DOWN:
        downCoordinates.setX(motionEvent.getX());
        downCoordinates.setY(motionEvent.getY());

        touchCoordinates.setX(motionEvent.getX());
        touchCoordinates.setY(motionEvent.getY());

        if (createFigureMode) {
          CreateNewFigureInCreateFigureMode(motionEvent);
        }

        isLongClick = true;
        moveTouchedFigureToFirstPosition();

        break;
      case MotionEvent.ACTION_MOVE:
        touchCoordinates.setX(motionEvent.getX());
        touchCoordinates.setY(motionEvent.getY());
        if ((!downCoordinates.nearlyEquals(touchCoordinates)) && isLongClick) {
          isLongClick = false;
        }

        if (isTouchedShape) {
          shapes.get(FIRST_SHAPE_IN_LIST).move(touchCoordinates);
          getFigureTouchedWithFirstFigure();
          for (ShapeList shape : shapes) {
            shape.setFigureThatItWillNotBeOutsideTheScreen(getWidth(), getHeight());
          }
        }
        break;
      case MotionEvent.ACTION_UP:
        for (ShapeList s : shapes) {
          s.refreshCoordinates();
        }
        ShapeList figureTouchedWithFirstFigure = getFigureTouchedWithFirstFigure();
        if (figureTouchedWithFirstFigure != null) {
          mergeShapeLists(shapes.get(FIRST_SHAPE_IN_LIST), figureTouchedWithFirstFigure);
          thereAreTouchedFigures = false;
        }
        break;

      default:
        break;
    }
    invalidate();
    return false;
  }
Example #2
0
 @Override
 public void changeCoordinatesToDelta(Point delta) {
   point.setX(point.getX() - delta.getX());
   point.setY(point.getY() - delta.getY());
 }