Back button closes ActionModes

Change-Id: I763782706ce7aa65a5a11129450d97a2bcb3a625
This commit is contained in:
Adam Powell
2010-08-18 11:59:11 -07:00
parent 487300abe1
commit 04253aa134

View File

@@ -1683,7 +1683,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
final int keyCode = event.getKeyCode();
final boolean isDown = event.getAction() == KeyEvent.ACTION_DOWN;
final int action = event.getAction();
final boolean isDown = action == KeyEvent.ACTION_DOWN;
/*
* If the user hits another key within the play sound delay, then
@@ -1740,6 +1741,14 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
}
}
// Back cancels action modes first.
if (mActionMode != null && keyCode == KeyEvent.KEYCODE_BACK) {
if (action == KeyEvent.ACTION_UP) {
mActionMode.finish();
}
return true;
}
final Callback cb = getCallback();
final boolean handled = cb != null && mFeatureId < 0 ? cb.dispatchKeyEvent(event)
: super.dispatchKeyEvent(event);
@@ -1976,7 +1985,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
mActionMode.finish();
}
ActionMode mode = getCallback().onStartActionMode(callback);
final ActionMode.Callback wrappedCallback = new ActionModeCallbackWrapper(callback);
ActionMode mode = getCallback().onStartActionMode(wrappedCallback);
if (mode != null) {
mActionMode = mode;
} else {
@@ -1989,13 +1999,14 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
} else {
ViewStub stub = (ViewStub) findViewById(
com.android.internal.R.id.action_mode_bar_stub);
mActionModeView = (ActionBarContextView) stub.inflate();
if (stub != null) {
mActionModeView = (ActionBarContextView) stub.inflate();
}
}
}
if (mActionModeView != null) {
mode = new StandaloneActionMode(getContext(), mActionModeView,
new ActionModeCallbackWrapper(callback));
mode = new StandaloneActionMode(getContext(), mActionModeView, wrappedCallback);
if (callback.onCreateActionMode(mode, mode.getMenu())) {
mode.invalidate();
mActionModeView.initForMode(mode);
@@ -2213,7 +2224,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
public void onDestroyActionMode(ActionMode mode) {
mWrapped.onDestroyActionMode(mode);
mActionModeView.removeAllViews();
if (mActionModeView != null) {
mActionModeView.removeAllViews();
}
mActionMode = null;
}
}