Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b1703f43 authored by Adam Powell's avatar Adam Powell Committed by Android (Google) Code Review
Browse files

Merge "Back button closes ActionModes"

parents 71f72c37 04253aa1
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -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);
                        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);
                if (mActionModeView != null) {
                    mActionModeView.removeAllViews();
                }
                mActionMode = null;
            }
        }