public BasicWorldWindowController() { this.panRecognizer.addListener(this); this.pinchRecognizer.addListener(this); this.rotationRecognizer.addListener(this); this.tiltRecognizer.addListener(this); ((PanRecognizer) this.panRecognizer).setMaxNumberOfPointers(2); ((PanRecognizer) this.tiltRecognizer).setMinNumberOfPointers(3); // TODO support for two-finger tilt gestures }
@Override protected void reset() { super.reset(); this.scale = 1; this.scaleOffset = 1; this.referenceDistance = 0; this.pointerIdCount = 0; }
@Override protected void prepareToRecognize(MotionEvent event) { // set translation to zero when the pan begins this.setTranslationX(0); this.setTranslationY(0); }
protected void handleActionUp(MotionEvent event) { this.actionUp(event); int state = this.getState(); if (state == WorldWind.POSSIBLE) { this.transitionToState(event, WorldWind.FAILED); } else if (state == WorldWind.BEGAN || state == WorldWind.CHANGED) { this.transitionToState(event, WorldWind.ENDED); } this.reset(); }
protected void handleActionCancel(MotionEvent event) { this.actionCancel(event); int state = this.getState(); if (state == WorldWind.POSSIBLE) { this.transitionToState(event, WorldWind.FAILED); } else if (state == WorldWind.BEGAN || state == WorldWind.CHANGED) { this.transitionToState(event, WorldWind.CANCELLED); } this.reset(); }
protected void actionMove(MotionEvent event) { if (this.pointerIdCount == 2) { int state = this.getState(); if (state == WorldWind.POSSIBLE) { if (this.shouldRecognize(event)) { this.transitionToState(event, WorldWind.BEGAN); } } else if (state == WorldWind.BEGAN || state == WorldWind.CHANGED) { float angle = this.currentTouchAngle(event); float newRotation = (float) WWMath.normalizeAngle180(angle - this.referenceAngle); this.rotation = this.lowPassFilter(this.rotation, newRotation); this.transitionToState(event, WorldWind.CHANGED); } } }
@Override protected void actionMove(MotionEvent event) { int state = this.getState(); if (state == WorldWind.POSSIBLE) { if (this.shouldInterpret(event)) { if (this.shouldRecognize(event)) { this.transitionToState(event, WorldWind.BEGAN); } else { this.transitionToState(event, WorldWind.FAILED); } } } else if (state == WorldWind.BEGAN || state == WorldWind.CHANGED) { this.transitionToState(event, WorldWind.CHANGED); } }
protected void handleActionMove(MotionEvent event) { this.eventCentroid(event, this.centroidArray); float dx = this.centroidArray[0] - this.startX + this.centroidShiftX; float dy = this.centroidArray[1] - this.startY + this.centroidShiftY; this.x = this.centroidArray[0]; this.y = this.centroidArray[1]; this.translationX = this.lowPassFilter(this.translationX, dx); this.translationY = this.lowPassFilter(this.translationY, dy); this.actionMove(event); }
protected void handleActionPointerUp(MotionEvent event) { this.centroidChanged(event); this.actionUp(event); }
protected void handleActionPointerDown(MotionEvent event) { this.centroidChanged(event); this.actionDown(event); }
protected boolean shouldInterpret(MotionEvent event) { float dx = this.getTranslationX(); float dy = this.getTranslationY(); float distance = (float) Math.sqrt(dx * dx + dy * dy); return distance > this.interpretDistance; // interpret touches when the touch centroid moves far enough }
protected void prepareToRecognize(MotionEvent event) { this.referenceAngle = this.currentTouchAngle(event); this.rotation = 0; }
protected void prepareToRecognize(MotionEvent event) { this.referenceDistance = this.currentPinchDistance(event); this.scale = 1; }
protected void notifyListeners(MotionEvent event) { for (GestureListener listener : this.listenerList) { listener.gestureStateChanged(event, this); } }
protected void centroidChanged(MotionEvent event) { this.centroidShiftX += this.x; this.centroidShiftY += this.y; this.eventCentroid(event, this.centroidArray); this.x = this.centroidArray[0]; this.y = this.centroidArray[1]; this.centroidShiftX -= this.centroidArray[0]; this.centroidShiftY -= this.centroidArray[1]; }
@Override public boolean onTouchEvent(MotionEvent event) { boolean handled = false; for (int idx = 0, len = this.allRecognizers.size(); idx < len; idx++) { handled |= this.allRecognizers.get(idx).onTouchEvent(event); // use or-assignment to indicate if any recognizer handled the event } return handled; }
protected void handleActionDown(MotionEvent event) { int index = event.getActionIndex(); this.x = event.getX(index); this.y = event.getY(index); this.startX = this.x; this.startY = this.y; this.translationX = 0; this.translationY = 0; this.centroidShiftX = 0; this.centroidShiftY = 0; this.actionDown(event); }
protected void reset() { super.reset(); this.rotation = 0; this.rotationOffset = 0; this.referenceAngle = 0; this.pointerIdCount = 0; }
protected void actionDown(MotionEvent event) { int pointerIndex = event.getActionIndex(); int pointerId = event.getPointerId(pointerIndex); if (this.pointerIdCount < 2) { this.pointerIds[this.pointerIdCount++] = pointerId; // add it to the pointer ID array if (this.pointerIdCount == 2) { this.referenceAngle = this.currentTouchAngle(event); this.rotationOffset += this.rotation; this.rotation = 0; } } }
protected void actionDown(MotionEvent event) { int pointerId = event.getPointerId(event.getActionIndex()); if (this.pointerIdCount < 2) { this.pointerIds[this.pointerIdCount++] = pointerId; // add it to the pointer ID array if (this.pointerIdCount == 2) { this.referenceDistance = this.currentPinchDistance(event); this.scaleOffset *= this.scale; this.scale = 1; } } }