List of usage examples for android.view.inputmethod InputConnectionWrapper InputConnectionWrapper
public InputConnectionWrapper(InputConnection target, boolean mutable)
From source file:org.mozilla.focus.widget.InlineAutocompleteEditText.java
/** * Code to handle deleting autocomplete first when backspacing. * If there is no autocomplete text, both removeAutocomplete() and commitAutocomplete() * are no-ops and return false. Therefore we can use them here without checking explicitly * if we have autocomplete text or not./*from w ww. j a v a2 s .c o m*/ * * Also turns off text prediction for private mode tabs. */ @Override public InputConnection onCreateInputConnection(final EditorInfo outAttrs) { final InputConnection ic = super.onCreateInputConnection(outAttrs); if (ic == null) { return null; } return new InputConnectionWrapper(ic, false) { @Override public boolean deleteSurroundingText(final int beforeLength, final int afterLength) { if (removeAutocomplete(getText())) { // If we have autocomplete text, the cursor is at the boundary between // regular and autocomplete text. So regardless of which direction we // are deleting, we should delete the autocomplete text first. // Make the IME aware that we interrupted the deleteSurroundingText call, // by restarting the IME. final InputMethodManager imm = (InputMethodManager) mContext .getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.restartInput(InlineAutocompleteEditText.this); } return false; } return super.deleteSurroundingText(beforeLength, afterLength); } private boolean removeAutocompleteOnComposing(final CharSequence text) { final Editable editable = getText(); final int composingStart = BaseInputConnection.getComposingSpanStart(editable); final int composingEnd = BaseInputConnection.getComposingSpanEnd(editable); // We only delete the autocomplete text when the user is backspacing, // i.e. when the composing text is getting shorter. if (composingStart >= 0 && composingEnd >= 0 && (composingEnd - composingStart) > text.length() && removeAutocomplete(editable)) { // Make the IME aware that we interrupted the setComposingText call, // by having finishComposingText() send change notifications to the IME. finishComposingText(); setComposingRegion(composingStart, composingEnd); return true; } return false; } @Override public boolean commitText(CharSequence text, int newCursorPosition) { if (removeAutocompleteOnComposing(text)) { return false; } return super.commitText(text, newCursorPosition); } @Override public boolean setComposingText(final CharSequence text, final int newCursorPosition) { if (removeAutocompleteOnComposing(text)) { return false; } return super.setComposingText(text, newCursorPosition); } }; }
From source file:com.example.libwidgettv.bak.AbsListView.java
/** * Return an InputConnection for editing of the filter text. *//* w ww .j ava 2 s .c o m*/ @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { if (isTextFilterEnabled()) { // XXX we need to have the text filter created, so we can get an // InputConnection to proxy to. Unfortunately this means we pretty // much need to make it as soon as a list view gets focus. createTextFilter(false); if (mPublicInputConnection == null) { mDefInputConnection = new BaseInputConnection(this, false); mPublicInputConnection = new InputConnectionWrapper(mTextFilter.onCreateInputConnection(outAttrs), true) { @Override public boolean reportFullscreenMode(boolean enabled) { // Use our own input connection, since it is // the "real" one the IME is talking with. return mDefInputConnection.reportFullscreenMode(enabled); } @Override public boolean performEditorAction(int editorAction) { // The editor is off in its own window; we need to be // the one that does this. if (editorAction == EditorInfo.IME_ACTION_DONE) { InputMethodManager imm = (InputMethodManager) getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.hideSoftInputFromWindow(getWindowToken(), 0); } return true; } return false; } @Override public boolean sendKeyEvent(KeyEvent event) { // Use our own input connection, since the filter // text view may not be shown in a window so has // no ViewAncestor to dispatch events with. return mDefInputConnection.sendKeyEvent(event); } }; } outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_FILTER; outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE; return mPublicInputConnection; } return null; }
From source file:com.appunite.list.AbsHorizontalListView.java
/** * Return an InputConnection for editing of the filter text. *///from w w w . j av a2s.c o m @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { if (isTextFilterEnabled()) { // XXX we need to have the text filter created, so we can get an // InputConnection to proxy to. Unfortunately this means we pretty // much need to make it as soon as a list view gets focus. createTextFilter(false); if (mPublicInputConnection == null) { mDefInputConnection = new BaseInputConnection(this, false); mPublicInputConnection = new InputConnectionWrapper(mTextFilter.onCreateInputConnection(outAttrs), true) { @Override public boolean reportFullscreenMode(boolean enabled) { // Use our own input connection, since it is // the "real" one the IME is talking with. return mDefInputConnection.reportFullscreenMode(enabled); } @Override public boolean performEditorAction(int editorAction) { // The editor is off in its own window; we need to be // the one that does this. if (editorAction == EditorInfo.IME_ACTION_DONE) { InputMethodManager imm = (InputMethodManager) getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.hideSoftInputFromWindow(getWindowToken(), 0); } return true; } return false; } @Override public boolean sendKeyEvent(KeyEvent event) { // Use our own input connection, since the filter // text view may not be shown in a window so has // no ViewAncestor to dispatch events with. return mDefInputConnection.sendKeyEvent(event); } }; } outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_FILTER; outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE; return mPublicInputConnection; } return null; }