Deal with canceled keys.

This commit is contained in:
Dianne Hackborn
2009-07-24 17:14:15 -07:00
parent ed0b01a717
commit 676902e287

View File

@@ -110,6 +110,9 @@ public class Home extends Activity {
private boolean mBlockAnimation; private boolean mBlockAnimation;
private boolean mHomeDown;
private boolean mBackDown;
private View mShowApplications; private View mShowApplications;
private CheckBox mShowApplicationsCheck; private CheckBox mShowApplicationsCheck;
@@ -395,20 +398,45 @@ public class Home extends Activity {
return info; return info;
} }
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (!hasFocus) {
mBackDown = mHomeDown = false;
}
}
@Override @Override
public boolean dispatchKeyEvent(KeyEvent event) { public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (event.getKeyCode()) { switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_BACK: case KeyEvent.KEYCODE_BACK:
mBackDown = true;
return true; return true;
case KeyEvent.KEYCODE_HOME: case KeyEvent.KEYCODE_HOME:
mHomeDown = true;
return true;
}
} else if (event.getAction() == KeyEvent.ACTION_UP) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_BACK:
if (!event.isCanceled()) {
// Do BACK behavior.
}
mBackDown = true;
return true;
case KeyEvent.KEYCODE_HOME:
if (!event.isCanceled()) {
// Do HOME behavior.
}
mHomeDown = true;
return true; return true;
} }
} }
return super.dispatchKeyEvent(event); return super.dispatchKeyEvent(event);
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);