Handle action modes in the IME extract mode view.

This presents action modes (such as the one for text editing) in a
less screen-consuming way in the IME extract mode layout. The submit
button is replaced by an "Edit..." button that shows the action mode
menu when clicked.

Still needs UX design and tweaking.

Change-Id: Ia7b3f3446edced0ee5a9abc5e2f0ff16f4fa3ab1
diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java
index 6cfeb87..dda3be6 100644
--- a/core/java/com/android/internal/app/ActionBarImpl.java
+++ b/core/java/com/android/internal/app/ActionBarImpl.java
@@ -362,8 +362,8 @@
         }
 
         mContextView.killMode();
-        ActionMode mode = new ActionModeImpl(callback);
-        if (callback.onCreateActionMode(mode, mode.getMenu())) {
+        ActionModeImpl mode = new ActionModeImpl(callback);
+        if (mode.dispatchOnCreate()) {
             mWasHiddenBeforeMode = !isShowing();
             mode.invalidate();
             mContextView.initForMode(mode);
@@ -633,8 +633,20 @@
 
         @Override
         public void invalidate() {
-            if (mCallback.onPrepareActionMode(this, mMenu)) {
-                // Refresh content in both context views
+            mMenu.stopDispatchingItemsChanged();
+            try {
+                mCallback.onPrepareActionMode(this, mMenu);
+            } finally {
+                mMenu.startDispatchingItemsChanged();
+            }
+        }
+
+        public boolean dispatchOnCreate() {
+            mMenu.stopDispatchingItemsChanged();
+            try {
+                return mCallback.onCreateActionMode(this, mMenu);
+            } finally {
+                mMenu.startDispatchingItemsChanged();
             }
         }