OSDN Git Service

Add setComposingRegion() and getSelectedText() to our InputConnection
authorJack Palevich <jack.palevich@gmail.com>
Sat, 23 Apr 2011 18:29:57 +0000 (11:29 -0700)
committerJack Palevich <jack.palevich@gmail.com>
Sat, 23 Apr 2011 18:29:57 +0000 (11:29 -0700)
The definition of the InputConnection interface for SDK version >= 9
includes new functions setComposingRegion() and getSelectedText().  If
we don't include them in our implementation, the build fails with

   [javac] /home/steven/devel/android-terminal-emulator/src/jackpal/androidterm/Term.java:2955: <anonymous jackpal.androidterm.EmulatorView$4> is not abstract and does not override abstract method setComposingRegion(int,int) in android.view.inputmethod.InputConnection

(at least when building with SDK 10).

src/jackpal/androidterm/Term.java

index 9cfc17b..ea8d2e9 100644 (file)
@@ -2960,6 +2960,8 @@ class EmulatorView extends View implements GestureDetector.OnGestureListener {
             private int mCursor;
             private int mComposingTextStart;
             private int mComposingTextEnd;
+            private int mSelectedTextStart;
+            private int mSelectedTextEnd;
 
             private void sendChar(int c) {
                 try {
@@ -3173,12 +3175,41 @@ class EmulatorView extends View implements GestureDetector.OnGestureListener {
                 return true;
             }
 
-            public boolean setSelection(int arg0, int arg1) {
+            public boolean setSelection(int start, int end) {
                 if (Term.LOG_IME) {
-                    Log.w(TAG, "setSelection" + arg0 + "," + arg1);
+                    Log.w(TAG, "setSelection" + start + "," + end);
+                }
+                int length = mImeBuffer.length();
+                if (start == end && start > 0 && start < length) {
+                    mSelectedTextStart = mSelectedTextEnd = 0;
+                    mCursor = start;
+                } else if (start < end && start > 0 && end < length) {
+                    mSelectedTextStart = start;
+                    mSelectedTextEnd = end;
+                    mCursor = start;
                 }
                 return true;
             }
+
+            public boolean setComposingRegion(int start, int end) {
+                if (Term.LOG_IME) {
+                    Log.w(TAG, "setComposingRegion " + start + "," + end);
+                }
+                if (start < end && start > 0 && end < mImeBuffer.length()) {
+                    clearComposingText();
+                    mComposingTextStart = start;
+                    mComposingTextEnd = end;
+                }
+                return true;
+            }
+
+            public CharSequence getSelectedText(int flags) {
+                if (Term.LOG_IME) {
+                    Log.w(TAG, "getSelectedText " + flags);
+                }
+                return mImeBuffer.substring(mSelectedTextStart, mSelectedTextEnd+1);
+            }
+            
         };
     }