SearchAutoCompleteTextViewpublic class SearchAutoCompleteTextView extends android.widget.AutoCompleteTextView This class is not for the faint of heart. Home works in the pan & scan
soft input mode. However, this mode gets rid of the soft keyboard on rotation,
which is a probelm when the Search widget has focus. This special class
changes Home's soft input method temporarily as long as the Search widget holds
the focus. This way, the soft keyboard remains after rotation. |
Fields Summary |
---|
private boolean | mShowKeyboard | private android.os.Handler | mLoseFocusHandler |
Methods Summary |
---|
protected void | onFocusChanged(boolean gainFocus, int direction, android.graphics.Rect previouslyFocusedRect)
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
final WindowManager.LayoutParams lp = ((Activity) getContext()).getWindow().getAttributes();
if (gainFocus) {
lp.softInputMode =
(lp.softInputMode & ~WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) |
WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED;
} else {
//noinspection PointlessBitwiseExpression
lp.softInputMode =
(lp.softInputMode & ~WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) |
WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED;
// If we don't immediately gain focus, we want to hide the IME.
mLoseFocusHandler.sendEmptyMessage(1);
}
if (getWindowToken() != null) {
final WindowManager manager = (WindowManager)
getContext().getSystemService(Context.WINDOW_SERVICE);
manager.updateViewLayout(getRootView(), lp);
if (mShowKeyboard) {
if (getContext().getResources().getConfiguration().hardKeyboardHidden ==
Configuration.HARDKEYBOARDHIDDEN_YES) {
InputMethodManager inputManager = (InputMethodManager)
getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(this, 0);
}
mShowKeyboard = false;
}
}
| public void | onWindowFocusChanged(boolean hasWindowFocus)
super.onWindowFocusChanged(hasWindowFocus);
// See Workspace#focusOnSearch()
setFocusableInTouchMode(false);
| void | showKeyboardOnNextFocus()
mShowKeyboard = true;
|
|