If you think the Android project AndroIUT listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (c) 2010, Sony Ericsson Mobile Communication AB. All rights reserved.
*//fromwww.java2s.com
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the Sony Ericsson Mobile Communication AB nor the names
* of its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/package com.iutdijon.androiut2.util.zoom;
import android.view.MotionEvent;
import android.view.View;
/**
* Simple on touch listener for zoom view
*/publicclass SimpleZoomListener implements View.OnTouchListener {
/**
* Which type of control is used
*/publicenum ControlType {
PAN, ZOOM
}
/** State being controlled by touch events */private ZoomState mState;
/** Current control type being used */private ControlType mControlType = ControlType.ZOOM;
/** X-coordinate of previously handled touch event */privatefloat mX;
/** Y-coordinate of previously handled touch event */privatefloat mY;
/**
* Sets the zoom state that should be controlled
*
* @param state Zoom state
*/publicvoid setZoomState(ZoomState state) {
mState = state;
}
/**
* Sets the control type to use
*
* @param controlType Control type
*/publicvoid setControlType(ControlType controlType) {
mControlType = controlType;
}
// implements View.OnTouchListener
@Override
publicboolean onTouch(View v, MotionEvent event) {
finalint action = event.getAction();
finalfloat x = event.getX();
finalfloat y = event.getY();
switch (action) {
case MotionEvent.ACTION_DOWN:
mX = x;
mY = y;
break;
case MotionEvent.ACTION_MOVE: {
finalfloat dx = (x - mX) / v.getWidth();
finalfloat dy = (y - mY) / v.getHeight();
if (mControlType == ControlType.ZOOM) {
mState.setZoom(mState.getZoom() * (float)Math.pow(20, -dy));
mState.notifyObservers();
} else {
mState.setPanX(mState.getPanX() - dx);
mState.setPanY(mState.getPanY() - dy);
mState.notifyObservers();
}
mX = x;
mY = y;
break;
}
}
return true;
}
}