X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=android-libraries%2Fachartengine%2Fsrc%2Forg%2Fachartengine%2FTouchHandlerOld.java;fp=android-libraries%2Fachartengine%2Fsrc%2Forg%2Fachartengine%2FTouchHandlerOld.java;h=38b4f227b4701b5ea1b62ffc9f02146be12b44ae;hb=dfe153139b917cc91dddc1efa0298d4204616462;hp=0000000000000000000000000000000000000000;hpb=a2fe0ba2c348102bb0c6486b201be097523c2c9a;p=debian%2Fopenrocket diff --git a/android-libraries/achartengine/src/org/achartengine/TouchHandlerOld.java b/android-libraries/achartengine/src/org/achartengine/TouchHandlerOld.java new file mode 100644 index 00000000..38b4f227 --- /dev/null +++ b/android-libraries/achartengine/src/org/achartengine/TouchHandlerOld.java @@ -0,0 +1,137 @@ +/** + * Copyright (C) 2009 - 2012 SC 4ViewSoft SRL + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.achartengine; + +import org.achartengine.chart.AbstractChart; +import org.achartengine.chart.RoundChart; +import org.achartengine.chart.XYChart; +import org.achartengine.renderer.DefaultRenderer; +import org.achartengine.tools.Pan; +import org.achartengine.tools.PanListener; +import org.achartengine.tools.ZoomListener; + +import android.graphics.RectF; +import android.view.MotionEvent; + +/** + * A handler implementation for touch events for older platforms. + */ +public class TouchHandlerOld implements ITouchHandler { + /** The chart renderer. */ + private DefaultRenderer mRenderer; + /** The old x coordinate. */ + private float oldX; + /** The old y coordinate. */ + private float oldY; + /** The zoom buttons rectangle. */ + private RectF zoomR = new RectF(); + /** The pan tool. */ + private Pan mPan; + /** The graphical view. */ + private GraphicalView graphicalView; + + /** + * Creates an implementation of the old version of the touch handler. + * + * @param view the graphical view + * @param chart the chart to be drawn + */ + public TouchHandlerOld(GraphicalView view, AbstractChart chart) { + graphicalView = view; + zoomR = graphicalView.getZoomRectangle(); + if (chart instanceof XYChart) { + mRenderer = ((XYChart) chart).getRenderer(); + } else { + mRenderer = ((RoundChart) chart).getRenderer(); + } + if (mRenderer.isPanEnabled()) { + mPan = new Pan(chart); + } + } + + public boolean handleTouch(MotionEvent event) { + int action = event.getAction(); + if (mRenderer != null && action == MotionEvent.ACTION_MOVE) { + if (oldX >= 0 || oldY >= 0) { + float newX = event.getX(); + float newY = event.getY(); + if (mRenderer.isPanEnabled()) { + mPan.apply(oldX, oldY, newX, newY); + } + oldX = newX; + oldY = newY; + graphicalView.repaint(); + return true; + } + } else if (action == MotionEvent.ACTION_DOWN) { + oldX = event.getX(); + oldY = event.getY(); + if (mRenderer != null && mRenderer.isZoomEnabled() && zoomR.contains(oldX, oldY)) { + if (oldX < zoomR.left + zoomR.width() / 3) { + graphicalView.zoomIn(); + } else if (oldX < zoomR.left + zoomR.width() * 2 / 3) { + graphicalView.zoomOut(); + } else { + graphicalView.zoomReset(); + } + return true; + } + } else if (action == MotionEvent.ACTION_UP) { + oldX = 0; + oldY = 0; + } + return !mRenderer.isClickEnabled(); + } + + /** + * Adds a new zoom listener. + * + * @param listener zoom listener + */ + public void addZoomListener(ZoomListener listener) { + } + + /** + * Removes a zoom listener. + * + * @param listener zoom listener + */ + public void removeZoomListener(ZoomListener listener) { + } + + /** + * Adds a new pan listener. + * + * @param listener pan listener + */ + public void addPanListener(PanListener listener) { + if (mPan != null) { + mPan.addPanListener(listener); + } + } + + /** + * Removes a pan listener. + * + * @param listener pan listener + */ + public void removePanListener(PanListener listener) { + if (mPan != null) { + mPan.removePanListener(listener); + } + } + +} \ No newline at end of file