Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ce0413b7 authored by Wenyi Wang's avatar Wenyi Wang
Browse files

Hide keyboard on touching type spinner and show it after selection changed

Bug: 25322155
Change-Id: I33eecbcaad15828a417921b893d6eb495395a15c
parent 5a83ad90
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -29,10 +29,12 @@ import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
@@ -137,6 +139,18 @@ public abstract class LabeledEditorView extends LinearLayout implements Editor,
        // Turn off the Spinner's own state management. We do this ourselves on rotation
        mLabel.setId(View.NO_ID);
        mLabel.setOnItemSelectedListener(mSpinnerListener);
        mLabel.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (v == mLabel) {
                    final InputMethodManager inputMethodManager = (InputMethodManager)
                            getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                    inputMethodManager.hideSoftInputFromWindow(
                            mLabel.getWindowToken(), /* flags */ 0);
                }
                return false;
            }
        });

        mDelete = (ImageView) findViewById(R.id.delete_button);
        mDeleteContainer = findViewById(R.id.delete_button_container);
+15 −7
Original line number Diff line number Diff line
@@ -123,13 +123,7 @@ public class TextFieldsEditorView extends LabeledEditorView {
        final View editor = mFields.getChildAt(0);

        // Show the soft-keyboard.
        InputMethodManager imm =
                (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            if (!imm.showSoftInput(editor, InputMethodManager.SHOW_IMPLICIT)) {
                Log.w(TAG, "Failed to show soft input method.");
            }
        }
        showSoftKeyboard(editor);
    }

    @Override
@@ -178,12 +172,26 @@ public class TextFieldsEditorView extends LabeledEditorView {
                }
                if (editText.hasFocus()) {
                    anyFieldHasFocus = true;
                    showSoftKeyboard(editText);
                    break;
                }
            }
            if (!anyFieldHasFocus && firstField != null) {
                firstField.requestFocus();
                showSoftKeyboard(firstField);
            }
        }
    }

    /**
     * Show soft keyboard for the currently focused view.
     */
    private void showSoftKeyboard(View v) {
        final InputMethodManager inputMethodManager = (InputMethodManager)
                getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (inputMethodManager != null &&
                !inputMethodManager.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT)) {
            Log.w(TAG, "Failed to show soft input method.");
        }
    }