Skip to content

Commit 7d12408

Browse files
committed
Update: Issue #1259, Dismiss keyboard after changing the note title
1 parent 2a2ed18 commit 7d12408

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
@@ -3,11 +3,14 @@
33
import android.app.AlertDialog;
44
import android.app.Dialog;
55
import android.content.Context;
6+
import android.content.DialogInterface;
67
import android.os.Bundle;
8+
import android.os.IBinder;
79
import android.util.Log;
810
import android.view.View;
911
import android.view.Window;
1012
import android.view.WindowManager;
13+
import android.view.inputmethod.InputMethodManager;
1114

1215
import androidx.annotation.NonNull;
1316
import androidx.annotation.Nullable;
@@ -56,12 +59,25 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
5659
return new AlertDialog.Builder(getActivity())
5760
.setTitle(R.string.change_note_title)
5861
.setView(dialogView)
59-
.setCancelable(true)
60-
.setPositiveButton(R.string.action_edit_save, (dialog, which) -> listener.onTitleEdited(binding.title.getText().toString()))
61-
.setNegativeButton(R.string.simple_cancel, null)
62+
.setCancelable(false)
63+
.setPositiveButton(R.string.action_edit_save, (dialog, which) -> {
64+
hideKeyboard(dialogView.findViewById(R.id.title).getWindowToken());
65+
listener.onTitleEdited(binding.title.getText().toString());
66+
})
67+
.setNegativeButton(R.string.simple_cancel, new DialogInterface.OnClickListener() {
68+
@Override
69+
public void onClick(DialogInterface dialogInterface, int i) {
70+
hideKeyboard(dialogView.findViewById(R.id.title).getWindowToken());
71+
}
72+
})
6273
.create();
6374
}
6475

76+
private void hideKeyboard(IBinder windowToken) {
77+
InputMethodManager inputManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
78+
inputManager.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS);
79+
}
80+
6581
@Override
6682
public void onActivityCreated(Bundle savedInstanceState) {
6783
super.onActivityCreated(savedInstanceState);

0 commit comments

Comments
 (0)