From 7d12408dceabe067762642398915ab0372f4aedb Mon Sep 17 00:00:00 2001 From: ScottieKim Date: Thu, 17 Jun 2021 21:36:10 +0900 Subject: [PATCH] Update: Issue #1259, Dismiss keyboard after changing the note title --- .../edit/title/EditTitleDialogFragment.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/title/EditTitleDialogFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/title/EditTitleDialogFragment.java index e9473399e..d0c1fae80 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/title/EditTitleDialogFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/title/EditTitleDialogFragment.java @@ -3,11 +3,14 @@ import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; +import android.content.DialogInterface; import android.os.Bundle; +import android.os.IBinder; import android.util.Log; import android.view.View; import android.view.Window; import android.view.WindowManager; +import android.view.inputmethod.InputMethodManager; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -56,12 +59,25 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { return new AlertDialog.Builder(getActivity()) .setTitle(R.string.change_note_title) .setView(dialogView) - .setCancelable(true) - .setPositiveButton(R.string.action_edit_save, (dialog, which) -> listener.onTitleEdited(binding.title.getText().toString())) - .setNegativeButton(R.string.simple_cancel, null) + .setCancelable(false) + .setPositiveButton(R.string.action_edit_save, (dialog, which) -> { + hideKeyboard(dialogView.findViewById(R.id.title).getWindowToken()); + listener.onTitleEdited(binding.title.getText().toString()); + }) + .setNegativeButton(R.string.simple_cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + hideKeyboard(dialogView.findViewById(R.id.title).getWindowToken()); + } + }) .create(); } + private void hideKeyboard(IBinder windowToken) { + InputMethodManager inputManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + inputManager.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS); + } + @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState);