3131import android .view .WindowManager ;
3232import android .view .inputmethod .InputMethodManager ;
3333import android .widget .Button ;
34- import android .widget .EditText ;
3534import android .widget .LinearLayout ;
3635
3736import androidx .annotation .Keep ;
@@ -96,21 +95,11 @@ private void showDialogUI(String hint, String current, int editType) {
9695 container .setOrientation (LinearLayout .VERTICAL );
9796 builder .setView (container );
9897 AlertDialog alertDialog = builder .create ();
99- EditText editText ;
100- // For multi-line, do not close the dialog after pressing back button
101- if (editType == 1 ) {
102- editText = new EditText (this );
103- } else {
104- editText = new CustomEditText (this );
105- }
98+ CustomEditText editText = new CustomEditText (this , editType );
10699 container .addView (editText );
107100 editText .setMaxLines (8 );
108- editText .requestFocus ();
109101 editText .setHint (hint );
110102 editText .setText (current );
111- final InputMethodManager imm = (InputMethodManager ) getSystemService (INPUT_METHOD_SERVICE );
112- Objects .requireNonNull (imm ).toggleSoftInput (InputMethodManager .SHOW_FORCED ,
113- InputMethodManager .HIDE_IMPLICIT_ONLY );
114103 if (editType == 1 )
115104 editText .setInputType (InputType .TYPE_CLASS_TEXT |
116105 InputType .TYPE_TEXT_FLAG_MULTI_LINE );
@@ -119,7 +108,8 @@ else if (editType == 3)
119108 InputType .TYPE_TEXT_VARIATION_PASSWORD );
120109 else
121110 editText .setInputType (InputType .TYPE_CLASS_TEXT );
122- editText .setSelection (editText .getText ().length ());
111+ editText .setSelection (Objects .requireNonNull (editText .getText ()).length ());
112+ final InputMethodManager imm = (InputMethodManager ) getSystemService (INPUT_METHOD_SERVICE );
123113 editText .setOnKeyListener ((view , keyCode , event ) -> {
124114 // For multi-line, do not submit the text after pressing Enter key
125115 if (keyCode == KeyEvent .KEYCODE_ENTER && editType != 1 ) {
@@ -143,12 +133,13 @@ else if (editType == 3)
143133 alertDialog .dismiss ();
144134 }));
145135 }
146- alertDialog .show ();
147136 alertDialog .setOnCancelListener (dialog -> {
148137 getWindow ().setSoftInputMode (WindowManager .LayoutParams .SOFT_INPUT_STATE_ALWAYS_HIDDEN );
149138 messageReturnValue = current ;
150139 messageReturnCode = -1 ;
151140 });
141+ alertDialog .show ();
142+ editText .requestFocusTryShow ();
152143 }
153144
154145 public int getDialogState () {
0 commit comments