30
30
import android .view .View ;
31
31
import android .view .WindowManager ;
32
32
import android .view .inputmethod .InputMethodManager ;
33
+ import android .widget .Button ;
33
34
import android .widget .EditText ;
35
+ import android .widget .LinearLayout ;
34
36
35
37
import androidx .appcompat .app .AlertDialog ;
36
38
@@ -85,9 +87,19 @@ public void showDialog(String acceptButton, String hint, String current, int edi
85
87
86
88
private void showDialogUI (String hint , String current , int editType ) {
87
89
final AlertDialog .Builder builder = new AlertDialog .Builder (this );
88
- EditText editText = new CustomEditText (this );
89
- builder .setView (editText );
90
+ LinearLayout container = new LinearLayout (this );
91
+ container .setOrientation (LinearLayout .VERTICAL );
92
+ builder .setView (container );
90
93
AlertDialog alertDialog = builder .create ();
94
+ EditText editText ;
95
+ // For multi-line, do not close the dialog after pressing back button
96
+ if (editType == 1 ) {
97
+ editText = new EditText (this );
98
+ } else {
99
+ editText = new CustomEditText (this );
100
+ }
101
+ container .addView (editText );
102
+ editText .setMaxLines (8 );
91
103
editText .requestFocus ();
92
104
editText .setHint (hint );
93
105
editText .setText (current );
@@ -103,8 +115,9 @@ else if (editType == 3)
103
115
else
104
116
editText .setInputType (InputType .TYPE_CLASS_TEXT );
105
117
editText .setSelection (editText .getText ().length ());
106
- editText .setOnKeyListener ((view , KeyCode , event ) -> {
107
- if (KeyCode == KeyEvent .KEYCODE_ENTER ) {
118
+ editText .setOnKeyListener ((view , keyCode , event ) -> {
119
+ // For multi-line, do not submit the text after pressing Enter key
120
+ if (keyCode == KeyEvent .KEYCODE_ENTER && editType != 1 ) {
108
121
imm .hideSoftInputFromWindow (editText .getWindowToken (), 0 );
109
122
messageReturnCode = 0 ;
110
123
messageReturnValue = editText .getText ().toString ();
@@ -113,6 +126,18 @@ else if (editType == 3)
113
126
}
114
127
return false ;
115
128
});
129
+ // For multi-line, add Done button since Enter key does not submit text
130
+ if (editType == 1 ) {
131
+ Button doneButton = new Button (this );
132
+ container .addView (doneButton );
133
+ doneButton .setText (R .string .ime_dialog_done );
134
+ doneButton .setOnClickListener ((view -> {
135
+ imm .hideSoftInputFromWindow (editText .getWindowToken (), 0 );
136
+ messageReturnCode = 0 ;
137
+ messageReturnValue = editText .getText ().toString ();
138
+ alertDialog .dismiss ();
139
+ }));
140
+ }
116
141
alertDialog .show ();
117
142
alertDialog .setOnCancelListener (dialog -> {
118
143
getWindow ().setSoftInputMode (WindowManager .LayoutParams .SOFT_INPUT_STATE_ALWAYS_HIDDEN );
0 commit comments