Пример #1
0
 private void refresh(Canvas canvas, Paint p) {
   String s = sharedPrefs.getString("list", "-1");
   if ((s.equals("2")) && (ColorTheme.isLightTheme)) {
     ColorTheme.setDarkTheme();
   } else if ((s.equals("1") && (ColorTheme.isDarkTheme))) {
     ColorTheme.setLightTheme();
   }
   if (!coordinateSystemCreated) {
     setSystemInformation();
     coordinateSystem = new CoordinateSystem();
     coordinateSystemCreated = true;
   }
   canvas.drawColor(ColorTheme.DARK_COLOR);
   paint.setStrokeWidth(4);
   for (ShapeList shape : shapes) {
     shape.draw(canvas, p);
     if (paint.getStrokeWidth() == 4) {
       paint.setStrokeWidth(1);
     }
   }
   if (shapes.size() != 0) {
     paint.setStrokeWidth(4);
     shapes.get(FIRST_SHAPE_IN_LIST).draw(canvas, paint);
   }
   if (shapes.size() > 0) {
     canvas.drawText(shapes.get(FIRST_SHAPE_IN_LIST).toString(), 30, 15, p);
   }
   if (sharedPrefs.getBoolean("checkBox", false)) {
     coordinateSystem.draw(canvas);
   }
 }
Пример #2
0
 private Shape getClickedShapeFromShapeList() {
   for (ShapeList shape : shapes) {
     if (shape.isTouched(touchCoordinates)) {
       return shape.getTouchedFigureInList(touchCoordinates);
     }
   }
   return null;
 }
Пример #3
0
 private boolean isClickOnShape() {
   for (ShapeList shape : shapes) {
     if (shape.isTouched(touchCoordinates)) {
       return true;
     }
   }
   return false;
 }
Пример #4
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;
  }
Пример #5
0
 private void moveTouchedFigureToFirstPosition() {
   isTouchedShape = false;
   int touchedShapePosition = 0;
   for (ShapeList s : shapes) {
     if (s.isTouched(touchCoordinates)) {
       isTouchedShape = true;
       shapes.set(
           touchedShapePosition,
           shapes.set(FIRST_SHAPE_IN_LIST, shapes.get(touchedShapePosition)));
       break;
     }
     touchedShapePosition++;
   }
 }
Пример #6
0
 public void unMergeAllFigures(ShapeList shapeList) {
   for (Shape shape : shapeList.getShapeArray()) {
     ShapeList listOfShapes = new ShapeList(shape);
     addShape(listOfShapes);
   }
   shapes.remove(shapeList);
 }
Пример #7
0
 public void disconnectFigure(ShapeList shapeList, Shape touchedShape) {
   ShapeList listOfShapes = new ShapeList(touchedShape);
   addShape(listOfShapes);
   shapeList.getShapeArray().remove(touchedShape);
 }