public void zoomView(float factor) { float newScaling; if (scalingInterpolator.isActive()) { newScaling = scalingInterpolator.getEndValue() * factor; } else { newScaling = currentScaling * factor; } scalingInterpolator.setStartEndValues(currentScaling, newScaling); scalingInterpolator.startInterpolating(); }
@Override public void onDraw(Canvas canvas) { // zooming animation if (scalingInterpolator.isActive()) { setCurrentScaling(scalingInterpolator.getCurrentValue()); } // translation animation if (translationXInterpolator.isActive() || translationYInterpolator.isActive()) { float transX = currentTranslation[0]; float transY = currentTranslation[1]; if (translationXInterpolator.isActive()) { transX = translationXInterpolator.getCurrentValue(); } if (translationYInterpolator.isActive()) { transY = translationYInterpolator.getCurrentValue(); } setCurrentTranslation(transX, transY); } // center rotation animation if (centerRotationInterpolator.isActive()) { setCurrentCenterRotation(centerRotationInterpolator.getCurrentValue()); } // calculate current viewport matrix if necessary if (getAndClearViewportFlag()) { recalculateViewportTransformation(); recalculateSizeScale(); } // clear background canvas.drawColor(0xFF000000); // draw audio scene canvas.setMatrix(viewportTransformation); synchronized (GlobalData.audioScene) { GlobalData.audioScene.draw(canvas, currentInverseScaling); } // reset matrix canvas.setMatrix(null); // draw size scale sizeScalePicture.draw(canvas); }
public void setOrientation(int newOrientation) { if (currentOrientation == newOrientation) return; if (newOrientation == Configuration.ORIENTATION_LANDSCAPE) { // portrait -> landscape centerRotationInterpolator.setStartEndValues(0.0f, -90.0f); } else if (newOrientation == Configuration.ORIENTATION_PORTRAIT) { // landscape -> portrait centerRotationInterpolator.setStartEndValues(-90.0f, 0.0f); } else { // unsupported orientation, this should never happen return; } // save current orientation currentOrientation = newOrientation; setOrientationFlag(true); // start interpolating centerRotationInterpolator.startInterpolating(); }
public void translateView(float transX, float transY) { float newTransX; float newTransY; if (transX != 0.0f) { if (translationXInterpolator.isActive()) { newTransX = translationXInterpolator.getEndValue() + transX; } else { newTransX = currentTranslation[0] + transX; } translationXInterpolator.setStartEndValues(currentTranslation[0], newTransX); translationXInterpolator.startInterpolating(); } if (transY != 0.0f) { if (translationYInterpolator.isActive()) { newTransY = translationYInterpolator.getEndValue() + transY; } else { newTransY = currentTranslation[1] + transY; } translationYInterpolator.setStartEndValues(currentTranslation[1], newTransY); translationYInterpolator.startInterpolating(); } }
private void init() { // make this view focusable setFocusable(true); // init fields viewportTransformation = new Matrix(); newViewportTransformation = new Matrix(); inverseViewportTransformation = new Matrix(); selectionOffset = new float[2]; touchPoint = new float[2]; buffer = ByteBuffer.allocate(1024); scalingInterpolator = new TimedInterpolator(); scalingInterpolator.setDuration(800); translationXInterpolator = new TimedInterpolator(); translationXInterpolator.setDuration(800); translationYInterpolator = new TimedInterpolator(); translationYInterpolator.setDuration(800); rotationInterpolator = new TimedInterpolator(); rotationInterpolator.setDuration(800); centerRotationInterpolator = new TimedInterpolator(); centerRotationInterpolator.setDuration(800); currentOrientation = getContext().getResources().getConfiguration().orientation; setOrientationFlag(true); if (SourcesView.paint == null) { SourcesView.paint = new Paint(); SourcesView.paint.setAntiAlias(false); SourcesView.paint.setStrokeWidth(0); SourcesView.paint.setTextAlign(Paint.Align.CENTER); SourcesView.paint.setTextSize(9.0f); } // set up orientation event listener orientationEventListener = new OrientationEventListener(getContext(), SensorManager.SENSOR_DELAY_NORMAL) { @Override public void onOrientationChanged(int orientation) { if ((orientation >= 80 && orientation <= 100) || (orientation >= 260 && orientation <= 280)) { // landscape setOrientation(Configuration.ORIENTATION_LANDSCAPE); } else if ((orientation >= 350 || orientation <= 10) || (orientation >= 170 && orientation <= 190)) { // portrait setOrientation(Configuration.ORIENTATION_PORTRAIT); } } }; if (!GlobalData .orientationTrackingEnabled) // orientation tracking and screen rotation tracking don't go // together orientationEventListener.enable(); // set up gesture detector gestureDetector = new GestureDetector(getContext(), this); gestureDetector.setIsLongpressEnabled(false); gestureDetector.setOnDoubleTapListener(this); // init viewport transformation matrix recalculateViewportTransformation(); }