aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/RichInputConnection.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/RichInputConnection.java')
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputConnection.java34
1 files changed, 27 insertions, 7 deletions
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index db68b0b96..8ed7ab264 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -17,6 +17,7 @@
package com.android.inputmethod.latin;
import android.inputmethodservice.InputMethodService;
+import android.text.SpannableString;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
@@ -181,6 +182,11 @@ public final class RichInputConnection {
}
}
+ public CharSequence getSelectedText(final int flags) {
+ if (null == mIC) return null;
+ return mIC.getSelectedText(flags);
+ }
+
/**
* Gets the caps modes we should be in after this specific string.
*
@@ -444,9 +450,9 @@ public final class RichInputConnection {
public final int mCharsAfter;
/** The actual characters that make up a word */
- public final String mWord;
+ public final CharSequence mWord;
- public Range(int charsBefore, int charsAfter, String word) {
+ public Range(int charsBefore, int charsAfter, CharSequence word) {
if (charsBefore < 0 || charsAfter < 0) {
throw new IndexOutOfBoundsException();
}
@@ -500,7 +506,7 @@ public final class RichInputConnection {
* separator. For example, if the field contains "he|llo world", where |
* represents the cursor, then "hello " will be returned.
*/
- public String getWordAtCursor(String separators) {
+ public CharSequence getWordAtCursor(String separators) {
// getWordRangeAtCursor returns null if the connection is null
Range r = getWordRangeAtCursor(separators, 0);
return (r == null) ? null : r.mWord;
@@ -519,8 +525,10 @@ public final class RichInputConnection {
if (mIC == null || sep == null) {
return null;
}
- final CharSequence before = mIC.getTextBeforeCursor(1000, 0);
- final CharSequence after = mIC.getTextAfterCursor(1000, 0);
+ final CharSequence before = mIC.getTextBeforeCursor(1000,
+ InputConnection.GET_TEXT_WITH_STYLES);
+ final CharSequence after = mIC.getTextAfterCursor(1000,
+ InputConnection.GET_TEXT_WITH_STYLES);
if (before == null || after == null) {
return null;
}
@@ -562,8 +570,9 @@ public final class RichInputConnection {
}
}
- final String word = before.toString().substring(startIndexInBefore, before.length())
- + after.toString().substring(0, endIndexInAfter);
+ final SpannableString word = new SpannableString(TextUtils.concat(
+ before.subSequence(startIndexInBefore, before.length()),
+ after.subSequence(0, endIndexInAfter)));
return new Range(before.length() - startIndexInBefore, endIndexInAfter, word);
}
@@ -711,4 +720,15 @@ public final class RichInputConnection {
// position and the expected position, then it must be a belated update.
return (newSelStart - oldSelStart) * (mCurrentCursorPosition - newSelStart) >= 0;
}
+
+ /**
+ * Looks at the text just before the cursor to find out if it looks like a URL.
+ *
+ * The weakest point here is, if we don't have enough text bufferized, we may fail to realize
+ * we are in URL situation, but other places in this class have the same limitation and it
+ * does not matter too much in the practice.
+ */
+ public boolean textBeforeCursorLooksLikeURL() {
+ return StringUtils.lastPartLooksLikeURL(mCommittedTextBeforeComposingText);
+ }
}