Extracted text problems

Bug 5557258: recent text editing changed in ExtractedText mode is
broken. The modifications of the text performed by:
- drag and drop
- text suggestions, deletion
- voice IME's delete button

all change the ExtractEditText itself, while they should affect the underlying
EditText (and the change will be forwarded to the ExtractEditText). As a results,
changes are not actually modifying the underlying text.

Created new protected methods in TextView, overloaded in ExtractTextView to
affect the underlying text instead.

Changes to spans should also be forwarded to the original TV (see the 2 TODOs),
this is tracked in bug 5589158.

Change-Id: Ibfec272469e8db191b3875e7576e32481a9dc1bd
diff --git a/core/java/android/inputmethodservice/ExtractEditText.java b/core/java/android/inputmethodservice/ExtractEditText.java
index 4fc63ed..72431f3 100644
--- a/core/java/android/inputmethodservice/ExtractEditText.java
+++ b/core/java/android/inputmethodservice/ExtractEditText.java
@@ -156,4 +156,27 @@
             mIME.onViewClicked(false);
         }
     }
+
+    /**
+     * Delete the range of text, supposedly valid
+     * @hide
+     */
+    @Override
+    protected void deleteText_internal(int start, int end) {
+        // Do not call the super method. This will change the source TextView instead, which
+        // will update the ExtractTextView.
+        mIME.onExtractedDeleteText(start, end);
+    }
+
+    /**
+     * Replaces the range of text [start, end[ by replacement text
+     * @hide
+     */
+    @Override
+    protected void replaceText_internal(int start, int end, CharSequence text) {
+        // Do not call the super method. This will change the source TextView instead, which
+        // will update the ExtractTextView.
+        mIME.onExtractedReplaceText(start, end, text);
+    }
+
 }