Skip to content

Commit f70ff8a

Browse files
ScottieKimAndyScherzinger
authored andcommitted
Update: Issue #1259, Dismiss keyboard after changing the note title
1 parent b0248e6 commit f70ff8a

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

app/src/main/java/it/niedermann/owncloud/notes/edit/title/EditTitleDialogFragment.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import android.app.Dialog;
44
import android.content.Context;
5+
import android.content.DialogInterface;
56
import android.os.Bundle;
7+
import android.os.IBinder;
68
import android.util.Log;
79
import android.view.View;
810
import android.view.Window;
911
import android.view.WindowManager;
12+
import android.view.inputmethod.InputMethodManager;
1013

1114
import androidx.annotation.NonNull;
1215
import androidx.annotation.Nullable;
@@ -60,12 +63,25 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
6063
return new MaterialAlertDialogBuilder(requireContext())
6164
.setTitle(R.string.change_note_title)
6265
.setView(dialogView)
63-
.setCancelable(true)
64-
.setPositiveButton(R.string.action_edit_save, (dialog, which) -> listener.onTitleEdited(binding.title.getText().toString()))
65-
.setNegativeButton(R.string.simple_cancel, null)
66+
.setCancelable(false)
67+
.setPositiveButton(R.string.action_edit_save, (dialog, which) -> {
68+
hideKeyboard(dialogView.findViewById(R.id.title).getWindowToken());
69+
listener.onTitleEdited(binding.title.getText().toString());
70+
})
71+
.setNegativeButton(R.string.simple_cancel, new DialogInterface.OnClickListener() {
72+
@Override
73+
public void onClick(DialogInterface dialogInterface, int i) {
74+
hideKeyboard(dialogView.findViewById(R.id.title).getWindowToken());
75+
}
76+
})
6677
.create();
6778
}
6879

80+
private void hideKeyboard(IBinder windowToken) {
81+
InputMethodManager inputManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
82+
inputManager.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS);
83+
}
84+
6985
@Override
7086
public void onActivityCreated(Bundle savedInstanceState) {
7187
super.onActivityCreated(savedInstanceState);

0 commit comments

Comments
 (0)