diff options
| author | 2010-08-18 14:01:33 -0700 | |
|---|---|---|
| committer | 2010-08-18 14:01:33 -0700 | |
| commit | b1703f439cd92c036b940c4219d7e79e5aab3ffb (patch) | |
| tree | 7b8c2e5d205eb0dec90f43f0e170ae6d937b11b5 | |
| parent | 71f72c37e97021520de1ca07271287c01b481cff (diff) | |
| parent | 04253aa134c4795d98cdb219b952393be1914f8b (diff) | |
Merge "Back button closes ActionModes"
| -rw-r--r-- | policy/src/com/android/internal/policy/impl/PhoneWindow.java | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java index f59f32cb8f57..2bb445614ccd 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java @@ -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; } } |