If you think the Android project iosched2011 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 2011 Google Inc./*fromwww.java2s.com*/
*
* 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 com.google.android.apps.iosched.util;
import android.view.MotionEvent;
/**
* A utility class that emulates multitouch APIs available in Android 2.0+.
*/publicclass MotionEventUtils {
publicstaticfinalint ACTION_MASK = 0xff;
publicstaticfinalint ACTION_POINTER_UP = 0x6;
publicstaticfinalint ACTION_POINTER_INDEX_MASK = 0x0000ff00;
publicstaticfinalint ACTION_POINTER_INDEX_SHIFT = 8;
publicstaticboolean sMultiTouchApiAvailable;
static {
try {
MotionEvent.class.getMethod("getPointerId", new Class[]{int.class});
sMultiTouchApiAvailable = true;
} catch (NoSuchMethodException nsme) {
sMultiTouchApiAvailable = false;
}
}
publicstaticfloat getX(MotionEvent ev, int pointerIndex) {
if (sMultiTouchApiAvailable) {
return WrappedStaticMotionEvent.getX(ev, pointerIndex);
} else {
return ev.getX();
}
}
publicstaticfloat getY(MotionEvent ev, int pointerIndex) {
if (sMultiTouchApiAvailable) {
return WrappedStaticMotionEvent.getY(ev, pointerIndex);
} else {
return ev.getY();
}
}
publicstaticint getPointerId(MotionEvent ev, int pointerIndex) {
if (sMultiTouchApiAvailable) {
return WrappedStaticMotionEvent.getPointerId(ev, pointerIndex);
} else {
return 0;
}
}
publicstaticint findPointerIndex(MotionEvent ev, int pointerId) {
if (sMultiTouchApiAvailable) {
return WrappedStaticMotionEvent.findPointerIndex(ev, pointerId);
} else {
return (pointerId == 0) ? 0 : -1;
}
}
/**
* A wrapper around newer (SDK level 5) MotionEvent APIs. This class only gets loaded
* if it is determined that these new APIs exist on the device.
*/privatestaticclass WrappedStaticMotionEvent {
publicstaticfloat getX(MotionEvent ev, int pointerIndex) {
return ev.getX(pointerIndex);
}
publicstaticfloat getY(MotionEvent ev, int pointerIndex) {
return ev.getY(pointerIndex);
}
publicstaticint getPointerId(MotionEvent ev, int pointerIndex) {
return ev.getPointerId(pointerIndex);
}
publicstaticint findPointerIndex(MotionEvent ev, int pointerId) {
return ev.findPointerIndex(pointerId);
}
}
}