Skip to content

Commit

Permalink
Update: Issue nextcloud#1259, Dismiss keyboard after changing the not…
Browse files Browse the repository at this point in the history
…e title
  • Loading branch information
ScottieKim committed Jun 17, 2021
1 parent 2a2ed18 commit 7d12408
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7d12408

Please sign in to comment.