List of usage examples for android.view.inputmethod InputMethodManager restartInput
public void restartInput(View view)
From source file:org.mozilla.gecko.AwesomeBar.java
private void updateGoButton(String text) { if (text.length() == 0) { mGoButton.setVisibility(View.GONE); return;/*from w w w. j ava 2s . c o m*/ } mGoButton.setVisibility(View.VISIBLE); int imageResource = R.drawable.ic_awesomebar_go; int imeAction = EditorInfo.IME_ACTION_GO; if (isSearchUrl(text)) { imageResource = R.drawable.ic_awesomebar_search; imeAction = EditorInfo.IME_ACTION_SEARCH; } mGoButton.setImageResource(imageResource); if ((mText.getImeOptions() & EditorInfo.IME_MASK_ACTION) != imeAction) { InputMethodManager imm = (InputMethodManager) mText.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); mText.setImeOptions(imeAction); imm.restartInput(mText); } }
From source file:org.mozilla.focus.widget.InlineAutocompleteEditText.java
@Override public void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); // Make search icon inactive when edit toolbar search term isn't a user entered // search term final boolean isActive = !TextUtils.isEmpty(getText()); if (mSearchStateChangeListener != null) { mSearchStateChangeListener.onSearchStateChange(isActive); }//from www. ja v a 2s.c o m if (gainFocus) { resetAutocompleteState(); return; } removeAutocomplete(getText()); final InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE); try { imm.restartInput(this); imm.hideSoftInputFromWindow(getWindowToken(), 0); } catch (NullPointerException e) { Log.e(LOGTAG, "InputMethodManagerService, why are you throwing" + " a NullPointerException? See bug 782096", e); } }
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./* ww w .j a va 2s .c om*/ * * 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:de.azapps.mirakel.main_activity.tasks_fragment.TasksFragment.java
public void focusNew(final boolean request_focus) { if (this.newTask == null) { return;//from w ww . ja v a2 s.c o m } this.newTask.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(final View v, final boolean hasFocus) { if (TasksFragment.this.main.getCurrentPosition() != MainActivity.getTasksFragmentPosition()) { return; } TasksFragment.this.newTask.post(new Runnable() { @Override public void run() { if (getActivity() == null) { // What the fuck?? This should not happen but it happens for some users return; } final InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); if (imm == null) { Log.w(TasksFragment.TAG, "Inputmanager==null"); return; } imm.restartInput(TasksFragment.this.newTask); if (request_focus && hasFocus) { getActivity().getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); imm.showSoftInput(TasksFragment.this.newTask, InputMethodManager.SHOW_IMPLICIT); getActivity().getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } else if (!hasFocus) { TasksFragment.this.newTask.requestFocus(); imm.showSoftInput(TasksFragment.this.newTask, InputMethodManager.SHOW_IMPLICIT); } else { clearFocus(); } } }); } }); this.newTask.requestFocus(); if (!this.newTask.hasFocus()) { this.newTask.postDelayed(new Runnable() { @Override public void run() { TasksFragment.this.newTask.requestFocus(); Log.wtf(TAG, "second try"); } }, 10); } }
From source file:org.akop.ararat.view.CrosswordView.java
private void resetInputMode() { setFocusableInTouchMode(mIsEditable && mInputMode != INPUT_MODE_NONE); InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { if (imm.isActive(this)) { imm.hideSoftInputFromWindow(getWindowToken(), 0); }//from w ww . ja va2 s . co m imm.restartInput(this); } }