Android 事件
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
switch (keyCode) {
case KeyEvent.KEYCODE_MENU:
Log.d(TAG, "KeyEvent.KEYCODE_MENU");
Toast.makeText(this, "KeyEvent.KEYCODE_MENU", Toast.LENGTH_LONG);
break;
case KeyEvent.KEYCODE_HOME:
Log.d(TAG, "KeyEvent.KEYCODE_HOME");
// finish();
android.os.Process.killProcess(android.os.Process.myPid());
Toast.makeText(this, "KeyEvent.KEYCODE_HOME", Toast.LENGTH_LONG);
break;
case KeyEvent.KEYCODE_BACK:
Log.d(TAG, "KeyEvent.KEYCODE_BACK");
// finish();
Toast.makeText(this, "KeyEvent.KEYCODE_BACK", Toast.LENGTH_LONG);
break;
case KeyEvent.KEYCODE_VOLUME_DOWN:
Log.d(TAG, "KeyEvent.KEYCODE_VOLUME_DOWN");
break;
case KeyEvent.KEYCODE_VOLUME_UP:
Log.d(TAG, "KeyEvent.KEYCODE_VOLUME_UP");
break;
case KeyEvent.KEYCODE_POWER:
Log.d(TAG, "KeyEvent.KEYCODE_POWER");
break;
default:
Log.d(TAG, "没有匹配的");
break;
}
return super.onKeyDown(keyCode, event);
}
// test for combination key
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int keyCode = event.getKeyCode();
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN &&
keyCode == KeyEvent.KEYCODE_POWER) {
Log.d(TAG, "VOLUME_DOWN + POWER is pressed");
// finish();
// return true;
}
//else
// return false;
return super.dispatchKeyEvent(event);
}
//当按键弹起时发生的事件
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_ALT_LEFT:
break;
default:
break;
}
return super.onKeyUp(keyCode, event);
}
//触摸屏事件,当用手或者用笔在触摸屏上做动作是发生
@Override
public boolean onTouchEvent(MotionEvent event) {
int iAction = event.getAction();
if (iAction == MotionEvent.ACTION_MOVE) {
Log.d(TAG, "你在触摸屏上进行了滑动");
}
return super.onTouchEvent(event);
}
//连续点击按键时发生的事件
@Override
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
// TODO Auto-generated method stub
return super.onKeyMultiple(keyCode, repeatCount, event);
}
// 长按某键
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
//TODO
}
return super.onKeyLongPress(keyCode, event);
}