this.fingerIdToCursorId = new HashMap<Integer, Long>();
}
public void update(Observable obj, Object arg) {
Finger finger = (Finger) arg;
int fingerID = finger.getID();
ActiveCursorPool cursorPool = ActiveCursorPool.getInstance();
int inputID;
Long cursorID = fingerIdToCursorId.get(fingerID);
InputCursor cursor = (cursorID != null)? cursorPool.getActiveCursorByID(cursorID) : null;
if (finger.getState() == FingerState.PRESSED) {
if (cursor == null) { //new finger
cursor = new InputCursor();
fingerIdToCursorId.put(fingerID, cursor.getId());
cursorPool.putActiveCursor(cursor.getId(), cursor);
inputID = MTFingerInputEvt.INPUT_DETECTED;
} else { //updated finger
inputID = MTFingerInputEvt.INPUT_UPDATED;
}
} else { //removed finger
if (cursorID != null){
cursorPool.removeCursor(cursorID);
}
fingerIdToCursorId.remove(fingerID);
inputID = MTFingerInputEvt.INPUT_ENDED;
}
int absoluteX = Math.round(finger.getX()*this.windowWidth);
int absoluteY = Math.round((1-finger.getY())*this.windowHeight);
this.enqueueInputEvent(new MTFingerInputEvt(this, absoluteX, absoluteY, inputID, cursor));
}