在Android层实现触摸屏校验
2010-05-31 14:35:00 来源:WEB开发网import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnTouchListener;
import android.widget.Toast;
import android.os.SystemProperties;
public class AndroidCalibrate extends Activity {
final String TAG = "ScreenCalibration";
final int UI_SCREEN_WIDTH = 800;
final int UI_SCREEN_HEIGHT = 480;
CrossView myview;
int direction;
private Calibrate cal;
int xList[] = {
50, UI_SCREEN_WIDTH - 50, UI_SCREEN_WIDTH - 50, 50, UI_SCREEN_WIDTH / 2
};
int yList[] = {
50, UI_SCREEN_HEIGHT - 50, UI_SCREEN_HEIGHT - 50, 50, UI_SCREEN_HEIGHT / 2
};
static void setNotTitle(Activity act) {
act.requestWindowFeature(Window.FEATURE_NO_TITLE);
}
static void setFullScreen(Activity act) {
setNotTitle(act);
act.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setFullScreen(this);
myview = new CrossView(this);
setContentView(myview);
SystemProperties.set("ts.config.calibrate", "start");
cal = new Calibrate();
direction = 0;
myview.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i("OnTouch", event.getX() + "," + event.getY());
v.invalidate();
if (direction < 4) {
Log.i("XXW time onTouchListener", " " + direction);
cal.get_sample(direction, (int)event.getX(), (int)event.getY(),
xList[direction], yList[direction]);
}
if (direction == 4) {
更多精彩
赞助商链接