Exemplo n.º 1
0
 public boolean equals(Object obj) {
   if (this == obj) {
     return true;
   }
   if (!(obj instanceof Point)) {
     return false;
   } else {
     obj = (Point) obj;
     return point.equals(((Point) (obj)).point);
   }
 }
Exemplo n.º 2
0
  @SuppressLint("DrawAllocation")
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (leftTop.equals(0, 0) && getDrawable() != null)
      mHandler.postDelayed(
          new Runnable() {

            @Override
            public void run() {
              resetPoints();
            }
          },
          100);

    canvas.drawRect(leftTop.x, leftTop.y, rightBottom.x, rightBottom.y, cornerOfRectPaint);
    drawShadowOverlay(canvas);
    draw4circle(canvas, affectedSide);

    if (DEBUG) {
      Log.i(TAG, "LeftTop(" + leftTop.x + "," + leftTop.y + ")");
      Log.i(TAG, "RightBottom(" + rightBottom.x + "," + rightBottom.y + ")");
    }
  }
Exemplo n.º 3
0
  @Override
  public boolean onAreaTouched(
      final TouchEvent pSceneTouchEvent,
      final float pTouchAreaLocalX,
      final float pTouchAreaLocalY) {
    if (pSceneTouchEvent.getMotionEvent().getPointerCount() > 1) {
      this.lastMultiTouched = System.currentTimeMillis();
    }

    int moutiTouchTolleranceMs = 200;
    int touchDeltaTollerancePx = 20;

    // ignore all multi-touch-inputs
    if ((System.currentTimeMillis() - this.lastMultiTouched) < moutiTouchTolleranceMs) {
      return false;
    }

    Point currentTouchedCell = this.positionToCell(pTouchAreaLocalX, pTouchAreaLocalY);
    Log.d(
        this.getClass().getName(),
        "Touched game-field at "
            + currentTouchedCell.toString()
            + " - "
            + new PointF(pTouchAreaLocalX, pTouchAreaLocalY)
            + " with action "
            + pSceneTouchEvent.getAction());

    if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_DOWN) {
      this.firstTouchedCell = this.positionToCell(pTouchAreaLocalX, pTouchAreaLocalY);
      this.firstMovePos = new PointF(pTouchAreaLocalX, pTouchAreaLocalY);
      this.wasMoved = false;
    }

    if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_MOVE) {
      Point oldDragCell = this.lastDragPoint;

      if ((this.firstTouchedCell != null) && this.isLampAt(this.firstTouchedCell)) {
        if ((oldDragCell == null) || !oldDragCell.equals(currentTouchedCell)) {
          if (oldDragCell == null) {
            oldDragCell = currentTouchedCell;
          }
          this.fireGameFieldDragged(currentTouchedCell, oldDragCell);
          this.lastDragPoint = currentTouchedCell;
        }
        return true;
      } else {
        if (this.firstMovePos != null) {
          // check if was moved
          if (pTouchAreaLocalX > (this.firstMovePos.x + touchDeltaTollerancePx)) {
            this.wasMoved = true;
          }
          if (pTouchAreaLocalX < (this.firstMovePos.x - touchDeltaTollerancePx)) {
            this.wasMoved = true;
          }
          if (pTouchAreaLocalY > (this.firstMovePos.y + touchDeltaTollerancePx)) {
            this.wasMoved = true;
          }
          if (pTouchAreaLocalY < (this.firstMovePos.y - touchDeltaTollerancePx)) {
            this.wasMoved = true;
          }
          return !this.wasMoved;
        }
        return false;
      }
    }

    if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP) {
      Log.d(
          this.getClass().getName(),
          "HistorySize=" + pSceneTouchEvent.getMotionEvent().getHistorySize());

      this.lastDragPoint = null;
      if ((this.firstTouchedCell != null)
          && this.firstTouchedCell.equals(currentTouchedCell)
          && (this.wasMoved == false)) {
        this.fireGameFieldTouched(currentTouchedCell);
      }
      this.firstTouchedCell = null;
      this.firstMovePos = null;
    }

    return false;
  }