1
1
package vocabletrainer .heinecke .aron .vocabletrainer .dialog ;
2
2
3
3
import android .app .Dialog ;
4
+ import android .content .Context ;
4
5
import android .content .DialogInterface ;
5
6
import android .os .Bundle ;
6
- import androidx .annotation .NonNull ;
7
- import androidx .annotation .Nullable ;
8
- import com .google .android .material .textfield .TextInputEditText ;
9
- import com .google .android .material .textfield .TextInputLayout ;
10
- import androidx .fragment .app .DialogFragment ;
11
- import androidx .appcompat .app .AlertDialog ;
12
7
import android .util .Log ;
13
- import android .view .KeyEvent ;
14
8
import android .view .View ;
15
9
import android .view .ViewGroup ;
10
+ import android .view .WindowManager ;
16
11
import android .view .inputmethod .EditorInfo ;
12
+ import android .view .inputmethod .InputMethodManager ;
13
+ import android .widget .EditText ;
17
14
import android .widget .ImageButton ;
18
15
import android .widget .LinearLayout ;
19
16
import android .widget .RelativeLayout ;
20
- import android .widget .TextView ;
17
+
18
+ import androidx .annotation .NonNull ;
19
+ import androidx .annotation .Nullable ;
20
+ import androidx .appcompat .app .AlertDialog ;
21
+ import androidx .fragment .app .DialogFragment ;
22
+
23
+ import com .google .android .material .textfield .TextInputEditText ;
24
+ import com .google .android .material .textfield .TextInputLayout ;
21
25
22
26
import java .util .ArrayList ;
23
27
import java .util .List ;
28
+ import java .util .Objects ;
24
29
25
30
import vocabletrainer .heinecke .aron .vocabletrainer .R ;
26
31
import vocabletrainer .heinecke .aron .vocabletrainer .lib .Function ;
@@ -40,6 +45,7 @@ public class VEntryEditorDialog extends DialogFragment {
40
45
private final static String KEY_INPUT_B_COUNT = "inputBCount" ;
41
46
private final static String KEY_INPUT_HINT = "inputH" ;
42
47
private final static String KEY_INPUT_ADDITION = "inputAd" ;
48
+ private EditText focusableEditText = null ;
43
49
private Function <Void ,VEntry > okAction ;
44
50
private Function <Void ,VEntry > cancelAction ;
45
51
private VEntry entry ;
@@ -74,6 +80,18 @@ public void setCancelAction(Function<Void,VEntry> cancelAction) {
74
80
this .cancelAction = cancelAction ;
75
81
}
76
82
83
+ @ Override
84
+ public void onResume () {
85
+ super .onResume ();
86
+ if (focusableEditText != null ) {
87
+ focusableEditText .requestFocus ();
88
+ InputMethodManager imm = (InputMethodManager ) requireActivity ().getSystemService (Context .INPUT_METHOD_SERVICE );
89
+ imm .showSoftInput (focusableEditText , InputMethodManager .SHOW_FORCED );
90
+ InputMethodManager inputMethodManager = (InputMethodManager ) requireActivity ().getSystemService (Context .INPUT_METHOD_SERVICE );
91
+ inputMethodManager .toggleSoftInput (InputMethodManager .SHOW_FORCED , 0 );
92
+ }
93
+ }
94
+
77
95
@ Override
78
96
public void onCreate (@ Nullable Bundle savedInstanceState ) {
79
97
super .onCreate (savedInstanceState );
@@ -154,6 +172,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
154
172
okAction ();
155
173
});
156
174
builder .setNegativeButton (R .string .Editor_Diag_edit_btn_CANCEL , (dialog , which ) -> callCancelAction ());
175
+
157
176
return builder .create ();
158
177
}
159
178
@@ -274,8 +293,14 @@ private View generateMeaning(final String meaning, final String hint,int image,
274
293
ImageButton btn = container .findViewById (R .id .btnMeaning );
275
294
text .setSingleLine ();
276
295
277
- if (focus )
296
+ if (focus ) {
297
+ Log .d (TAG ,"requesting focus" );
278
298
layout .requestFocus ();
299
+ InputMethodManager imm = (InputMethodManager ) requireActivity ().getSystemService (Context .INPUT_METHOD_SERVICE );
300
+ imm .showSoftInput (text , InputMethodManager .SHOW_FORCED );
301
+ InputMethodManager inputMethodManager = (InputMethodManager ) requireActivity ().getSystemService (Context .INPUT_METHOD_SERVICE );
302
+ inputMethodManager .toggleSoftInput (InputMethodManager .SHOW_FORCED , 0 );
303
+ }
279
304
280
305
layout .setHint (hint );
281
306
text .setText (meaning );
0 commit comments