If you think the Android project Hungry-Mouse 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
//Name: AndroidInput.java
//Purpose: get input of user
//www.java2s.compackage com.hungry.mouse.framework.implementation;
import com.hungry.mouse.framework.Input;
//java libraries
import java.util.List;//a collection which maintain an ordering for its elements
//android libraries stored in SDK platform
import android.content.Context;//interface to global information for app environment
import android.os.Build.VERSION;//various version strings
import android.view.View;//represents basic building block for user interface components
publicclass AndroidInput implements Input {
AccelerometerHandler accelHandler;
TouchHandler touchHandler;
//constructor
public AndroidInput(Context context, View view, float scaleX, float scaleY) {
accelHandler = new AccelerometerHandler(context);//for accelerometer
//in android 2.0 (API 5), multi-touch was introduced
//check the api and implement the appropriate touch handler
if(Integer.parseInt(VERSION.SDK) < 5)
touchHandler = new SingleTouchHandler(view, scaleX, scaleY);
else
touchHandler = new MultiTouchHandler(view, scaleX, scaleY);
}
@Override
publicboolean isTouchDown(int pointer) {
return touchHandler.isTouchDown(pointer);
}
@Override
publicint getTouchX(int pointer) {
return touchHandler.getTouchX(pointer);
}
@Override
publicint getTouchY(int pointer) {
return touchHandler.getTouchY(pointer);
}
//accelerometer
@Override
publicfloat getAccelX() {
return accelHandler.getAccelX();
}
@Override
publicfloat getAccelY() {
return accelHandler.getAccelY();
}
@Override
publicfloat getAccelZ() {
return accelHandler.getAccelZ();
}
@Override
public List<TouchEvent> getTouchEvents() {
return touchHandler.getTouchEvents();
}
}