file cosmetics
This commit is contained in:
parent
3674025076
commit
c1ff1a4c4f
1 changed files with 63 additions and 65 deletions
|
@ -16,26 +16,26 @@ public class MultiTouchSupport {
|
||||||
|
|
||||||
private static final Log log = PlatformUtil.getLog(MultiTouchSupport.class);
|
private static final Log log = PlatformUtil.getLog(MultiTouchSupport.class);
|
||||||
|
|
||||||
public static final int ACTION_MASK = 255;
|
public static final int ACTION_MASK = 255;
|
||||||
public static final int ACTION_POINTER_ID_SHIFT = 8;
|
public static final int ACTION_POINTER_ID_SHIFT = 8;
|
||||||
public static final int ACTION_POINTER_DOWN = 5;
|
public static final int ACTION_POINTER_DOWN = 5;
|
||||||
public static final int ACTION_POINTER_UP = 6;
|
public static final int ACTION_POINTER_UP = 6;
|
||||||
private float angleStarted;
|
private float angleStarted;
|
||||||
private float angleRelative;
|
private float angleRelative;
|
||||||
|
|
||||||
public interface MultiTouchZoomListener {
|
public interface MultiTouchZoomListener {
|
||||||
|
|
||||||
public void onZoomStarted(PointF centerPoint);
|
public void onZoomStarted(PointF centerPoint);
|
||||||
|
|
||||||
public void onZoomingOrRotating(double relativeToStart, float angle);
|
public void onZoomingOrRotating(double relativeToStart, float angle);
|
||||||
|
|
||||||
public void onZoomOrRotationEnded(double relativeToStart, float angleRelative);
|
public void onZoomOrRotationEnded(double relativeToStart, float angleRelative);
|
||||||
|
|
||||||
public void onGestureInit(float x1, float y1, float x2, float y2);
|
public void onGestureInit(float x1, float y1, float x2, float y2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean multiTouchAPISupported = false;
|
private boolean multiTouchAPISupported = false;
|
||||||
private final MultiTouchZoomListener listener;
|
private final MultiTouchZoomListener listener;
|
||||||
protected final Context ctx;
|
protected final Context ctx;
|
||||||
|
|
||||||
|
@ -45,45 +45,44 @@ public class MultiTouchSupport {
|
||||||
protected Method getPointerId;
|
protected Method getPointerId;
|
||||||
|
|
||||||
|
|
||||||
|
public MultiTouchSupport(Context ctx, MultiTouchZoomListener listener){
|
||||||
public MultiTouchSupport(Context ctx, MultiTouchZoomListener listener){
|
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
initMethods();
|
initMethods();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMultiTouchSupported(){
|
public boolean isMultiTouchSupported(){
|
||||||
return multiTouchAPISupported;
|
return multiTouchAPISupported;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInZoomMode(){
|
public boolean isInZoomMode(){
|
||||||
return inZoomMode;
|
return inZoomMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initMethods(){
|
private void initMethods(){
|
||||||
try {
|
try {
|
||||||
getPointerCount = MotionEvent.class.getMethod("getPointerCount"); //$NON-NLS-1$
|
getPointerCount = MotionEvent.class.getMethod("getPointerCount"); //$NON-NLS-1$
|
||||||
getPointerId = MotionEvent.class.getMethod("getPointerId", Integer.TYPE); //$NON-NLS-1$
|
getPointerId = MotionEvent.class.getMethod("getPointerId", Integer.TYPE); //$NON-NLS-1$
|
||||||
getX = MotionEvent.class.getMethod("getX", Integer.TYPE); //$NON-NLS-1$
|
getX = MotionEvent.class.getMethod("getX", Integer.TYPE); //$NON-NLS-1$
|
||||||
getY = MotionEvent.class.getMethod("getY", Integer.TYPE); //$NON-NLS-1$
|
getY = MotionEvent.class.getMethod("getY", Integer.TYPE); //$NON-NLS-1$
|
||||||
multiTouchAPISupported = true;
|
multiTouchAPISupported = true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
multiTouchAPISupported = false;
|
multiTouchAPISupported = false;
|
||||||
log.info("Multi touch not supported", e); //$NON-NLS-1$
|
log.info("Multi touch not supported", e); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean inZoomMode = false;
|
private boolean inZoomMode = false;
|
||||||
private double zoomStartedDistance = 100;
|
private double zoomStartedDistance = 100;
|
||||||
private double zoomRelative = 1;
|
private double zoomRelative = 1;
|
||||||
private PointF centerPoint = new PointF();
|
private PointF centerPoint = new PointF();
|
||||||
|
|
||||||
public boolean onTouchEvent(MotionEvent event){
|
public boolean onTouchEvent(MotionEvent event){
|
||||||
if(!isMultiTouchSupported()){
|
if(!isMultiTouchSupported()){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int actionCode = event.getAction() & ACTION_MASK;
|
int actionCode = event.getAction() & ACTION_MASK;
|
||||||
try {
|
try {
|
||||||
Integer pointCount = (Integer) getPointerCount.invoke(event);
|
Integer pointCount = (Integer) getPointerCount.invoke(event);
|
||||||
if(pointCount < 2){
|
if(pointCount < 2){
|
||||||
if(inZoomMode){
|
if(inZoomMode){
|
||||||
|
@ -97,12 +96,12 @@ public class MultiTouchSupport {
|
||||||
Float y1 = (Float) getY.invoke(event, 0);
|
Float y1 = (Float) getY.invoke(event, 0);
|
||||||
Float y2 = (Float) getY.invoke(event, 1);
|
Float y2 = (Float) getY.invoke(event, 1);
|
||||||
float distance = (float) Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
|
float distance = (float) Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
|
||||||
float angle = 0;
|
float angle = 0;
|
||||||
boolean angleDefined = false;
|
boolean angleDefined = false;
|
||||||
if(x1 != x2 || y1 != y2) {
|
if(x1 != x2 || y1 != y2) {
|
||||||
angleDefined = true;
|
angleDefined = true;
|
||||||
angle = (float) (Math.atan2(y2 - y1, x2 -x1) * 180 / Math.PI);
|
angle = (float) (Math.atan2(y2 - y1, x2 -x1) * 180 / Math.PI);
|
||||||
}
|
}
|
||||||
if (actionCode == ACTION_POINTER_DOWN) {
|
if (actionCode == ACTION_POINTER_DOWN) {
|
||||||
centerPoint = new PointF((x1 + x2) / 2, (y1 + y2) / 2);
|
centerPoint = new PointF((x1 + x2) / 2, (y1 + y2) / 2);
|
||||||
listener.onGestureInit(x1, y1, x2, y2);
|
listener.onGestureInit(x1, y1, x2, y2);
|
||||||
|
@ -128,14 +127,13 @@ public class MultiTouchSupport {
|
||||||
} else if (pointCount >= 2) {
|
} else if (pointCount >= 2) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug("Multi touch exception" , e); //$NON-NLS-1$
|
log.debug("Multi touch exception" , e); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PointF getCenterPoint() {
|
||||||
public PointF getCenterPoint() {
|
|
||||||
return centerPoint;
|
return centerPoint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue