File tree Expand file tree Collapse file tree 3 files changed +27
-13
lines changed
app/src/main/java/it/niedermann/owncloud/notes Expand file tree Collapse file tree 3 files changed +27
-13
lines changed Original file line number Diff line number Diff line change 25
25
import it .niedermann .owncloud .notes .branding .BrandingUtil ;
26
26
import it .niedermann .owncloud .notes .databinding .DialogChangeCategoryBinding ;
27
27
import it .niedermann .owncloud .notes .main .navigation .NavigationItem ;
28
+ import it .niedermann .owncloud .notes .shared .util .KeyboardUtils ;
28
29
29
30
/**
30
31
* This {@link DialogFragment} allows for the selection of a category.
@@ -170,12 +171,7 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
170
171
public void onActivityCreated (Bundle savedInstanceState ) {
171
172
super .onActivityCreated (savedInstanceState );
172
173
if (editCategory .getText () == null || editCategory .getText ().length () == 0 ) {
173
- editCategory .requestFocus ();
174
- if (getDialog () != null && getDialog ().getWindow () != null ) {
175
- getDialog ().getWindow ().setSoftInputMode (WindowManager .LayoutParams .SOFT_INPUT_STATE_ALWAYS_VISIBLE );
176
- } else {
177
- Log .w (TAG , "can not set SOFT_INPUT_STATE_ALWAYAS_VISIBLE because getWindow() == null" );
178
- }
174
+ KeyboardUtils .showKeyboardForEditText (editCategory );
179
175
}
180
176
}
181
177
Original file line number Diff line number Diff line change 18
18
import it .niedermann .owncloud .notes .branding .BrandedDialogFragment ;
19
19
import it .niedermann .owncloud .notes .branding .BrandingUtil ;
20
20
import it .niedermann .owncloud .notes .databinding .DialogEditTitleBinding ;
21
+ import it .niedermann .owncloud .notes .shared .util .KeyboardUtils ;
21
22
22
23
public class EditTitleDialogFragment extends BrandedDialogFragment {
23
24
@@ -68,13 +69,7 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
68
69
@ Override
69
70
public void onActivityCreated (Bundle savedInstanceState ) {
70
71
super .onActivityCreated (savedInstanceState );
71
- binding .title .requestFocus ();
72
- final var window = requireDialog ().getWindow ();
73
- if (window != null ) {
74
- window .setSoftInputMode (WindowManager .LayoutParams .SOFT_INPUT_STATE_ALWAYS_VISIBLE );
75
- } else {
76
- Log .w (TAG , "can not enable soft keyboard because " + Window .class .getSimpleName () + " is null." );
77
- }
72
+ KeyboardUtils .showKeyboardForEditText (binding .title );
78
73
}
79
74
80
75
public static DialogFragment newInstance (String title ) {
Original file line number Diff line number Diff line change
1
+ package it.niedermann.owncloud.notes.shared.util
2
+
3
+ import android.content.Context
4
+ import android.view.inputmethod.InputMethodManager
5
+ import android.widget.EditText
6
+
7
+ object KeyboardUtils {
8
+ private const val SHOW_INPUT_DELAY_MILLIS = 100L
9
+
10
+ @JvmStatic
11
+ fun showKeyboardForEditText (editText : EditText ) {
12
+ editText.requestFocus()
13
+ // needs 100ms delay to account for focus animations
14
+ editText.postDelayed({
15
+ val context = editText.context
16
+ if (context != null ) {
17
+ val inputMethodManager =
18
+ context.getSystemService(Context .INPUT_METHOD_SERVICE ) as InputMethodManager
19
+ inputMethodManager.showSoftInput(editText, InputMethodManager .SHOW_IMPLICIT )
20
+ }
21
+ }, SHOW_INPUT_DELAY_MILLIS )
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments