@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; }
public String toString() { return point.toString(); }