diff options
Diffstat (limited to 'src/com/android/launcher3/ExtendedEditText.java')
-rw-r--r-- | src/com/android/launcher3/ExtendedEditText.java | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/com/android/launcher3/ExtendedEditText.java b/src/com/android/launcher3/ExtendedEditText.java index bf4551b26..f7737f423 100644 --- a/src/com/android/launcher3/ExtendedEditText.java +++ b/src/com/android/launcher3/ExtendedEditText.java @@ -19,6 +19,7 @@ import android.content.Context; import android.util.AttributeSet; import android.view.DragEvent; import android.view.KeyEvent; +import android.view.inputmethod.InputMethodManager; import android.widget.EditText; @@ -27,6 +28,8 @@ import android.widget.EditText; */ public class ExtendedEditText extends EditText { + private boolean mShowImeAfterFirstLayout; + /** * Implemented by listeners of the back key. */ @@ -37,11 +40,11 @@ public class ExtendedEditText extends EditText { private OnBackKeyListener mBackKeyListener; public ExtendedEditText(Context context) { - super(context); + this(context, null, 0); } public ExtendedEditText(Context context, AttributeSet attrs) { - super(context, attrs); + this(context, attrs, 0); } public ExtendedEditText(Context context, AttributeSet attrs, int defStyleAttr) { @@ -69,4 +72,29 @@ public class ExtendedEditText extends EditText { // We don't want this view to interfere with Launcher own drag and drop. return false; } + + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + super.onLayout(changed, left, top, right, bottom); + if (mShowImeAfterFirstLayout) { + // soft input only shows one frame after the layout of the EditText happens, + post(new Runnable() { + @Override + public void run() { + showSoftInput(); + mShowImeAfterFirstLayout = false; + } + }); + } + } + + public void showKeyboard() { + mShowImeAfterFirstLayout = !showSoftInput(); + } + + private boolean showSoftInput() { + return requestFocus() && + ((InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE)) + .showSoftInput(this, InputMethodManager.SHOW_FORCED); + } } |