1010import android .view .InputDevice ;
1111import android .view .KeyEvent ;
1212import android .view .View ;
13+ import android .view .inputmethod .EditorInfo ;
1314import android .view .inputmethod .ExtractedTextRequest ;
1415import android .view .inputmethod .InputConnection ;
1516
@@ -21,6 +22,11 @@ public class AdbIME extends InputMethodService {
2122 private String IME_EDITORCODE = "ADB_EDITOR_CODE" ;
2223 private String IME_MESSAGE_B64 = "ADB_INPUT_B64" ;
2324 private String IME_CLEAR_TEXT = "ADB_CLEAR_TEXT" ;
25+ private String IME_ACTION_SEARCH = "ADB_ACTION_SEARCH" ;
26+ private String IME_ACTION_GO = "ADB_ACTION_GO" ;
27+ private String IME_ACTION_DONE = "ADB_ACTION_DONE" ;
28+ private String IME_ACTION_NEXT = "ADB_ACTION_NEXT" ;
29+ private String IME_ACTION_SEND = "ADB_ACTION_SEND" ;
2430 private BroadcastReceiver mReceiver = null ;
2531
2632 @ Override
@@ -35,6 +41,11 @@ public View onCreateInputView() {
3541 filter .addAction (IME_EDITORCODE );
3642 filter .addAction (IME_MESSAGE_B64 );
3743 filter .addAction (IME_CLEAR_TEXT );
44+ filter .addAction (IME_ACTION_SEARCH );
45+ filter .addAction (IME_ACTION_GO );
46+ filter .addAction (IME_ACTION_DONE );
47+ filter .addAction (IME_ACTION_NEXT );
48+ filter .addAction (IME_ACTION_SEND );
3849 mReceiver = new AdbReceiver ();
3950 registerReceiver (mReceiver , filter );
4051 }
@@ -153,11 +164,58 @@ public void onReceive(Context context, Intent intent) {
153164 if (intent .getAction ().equals (IME_CLEAR_TEXT )) {
154165 InputConnection ic = getCurrentInputConnection ();
155166 if (ic != null ) {
156- //REF: stackoverflow/33082004 author: Maxime Epain
157- CharSequence curPos = ic .getExtractedText (new ExtractedTextRequest (), 0 ).text ;
158- CharSequence beforePos = ic .getTextBeforeCursor (curPos .length (), 0 );
159- CharSequence afterPos = ic .getTextAfterCursor (curPos .length (), 0 );
160- ic .deleteSurroundingText (beforePos .length (), afterPos .length ());
167+ // Try to get extracted text first
168+ ExtractedTextRequest req = new ExtractedTextRequest ();
169+ req .hintMaxChars = 100000 ;
170+ req .hintMaxLines = 10000 ;
171+ android .view .inputmethod .ExtractedText et = ic .getExtractedText (req , 0 );
172+ if (et != null && et .text != null ) {
173+ CharSequence beforePos = ic .getTextBeforeCursor (et .text .length (), 0 );
174+ CharSequence afterPos = ic .getTextAfterCursor (et .text .length (), 0 );
175+ if (beforePos != null && afterPos != null ) {
176+ ic .deleteSurroundingText (beforePos .length (), afterPos .length ());
177+ }
178+ } else {
179+ // Fallback: select all and delete
180+ ic .performContextMenuAction (android .R .id .selectAll );
181+ ic .commitText ("" , 1 );
182+ }
183+ }
184+ }
185+
186+ // IME Actions - convenient shortcuts
187+ if (intent .getAction ().equals (IME_ACTION_SEARCH )) {
188+ InputConnection ic = getCurrentInputConnection ();
189+ if (ic != null ) {
190+ ic .performEditorAction (EditorInfo .IME_ACTION_SEARCH );
191+ }
192+ }
193+
194+ if (intent .getAction ().equals (IME_ACTION_GO )) {
195+ InputConnection ic = getCurrentInputConnection ();
196+ if (ic != null ) {
197+ ic .performEditorAction (EditorInfo .IME_ACTION_GO );
198+ }
199+ }
200+
201+ if (intent .getAction ().equals (IME_ACTION_DONE )) {
202+ InputConnection ic = getCurrentInputConnection ();
203+ if (ic != null ) {
204+ ic .performEditorAction (EditorInfo .IME_ACTION_DONE );
205+ }
206+ }
207+
208+ if (intent .getAction ().equals (IME_ACTION_NEXT )) {
209+ InputConnection ic = getCurrentInputConnection ();
210+ if (ic != null ) {
211+ ic .performEditorAction (EditorInfo .IME_ACTION_NEXT );
212+ }
213+ }
214+
215+ if (intent .getAction ().equals (IME_ACTION_SEND )) {
216+ InputConnection ic = getCurrentInputConnection ();
217+ if (ic != null ) {
218+ ic .performEditorAction (EditorInfo .IME_ACTION_SEND );
161219 }
162220 }
163221 }
0 commit comments