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 2525import it .niedermann .owncloud .notes .branding .BrandingUtil ;
2626import it .niedermann .owncloud .notes .databinding .DialogChangeCategoryBinding ;
2727import it .niedermann .owncloud .notes .main .navigation .NavigationItem ;
28+ import it .niedermann .owncloud .notes .shared .util .KeyboardUtils ;
2829
2930/**
3031 * This {@link DialogFragment} allows for the selection of a category.
@@ -170,12 +171,7 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
170171 public void onActivityCreated (Bundle savedInstanceState ) {
171172 super .onActivityCreated (savedInstanceState );
172173 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 );
179175 }
180176 }
181177
Original file line number Diff line number Diff line change 1818import it .niedermann .owncloud .notes .branding .BrandedDialogFragment ;
1919import it .niedermann .owncloud .notes .branding .BrandingUtil ;
2020import it .niedermann .owncloud .notes .databinding .DialogEditTitleBinding ;
21+ import it .niedermann .owncloud .notes .shared .util .KeyboardUtils ;
2122
2223public class EditTitleDialogFragment extends BrandedDialogFragment {
2324
@@ -68,13 +69,7 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
6869 @ Override
6970 public void onActivityCreated (Bundle savedInstanceState ) {
7071 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 );
7873 }
7974
8075 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