Close keyboard after 3s

This commit is contained in:
woheller69 2023-09-27 13:48:46 +02:00
parent 117adab1c6
commit 5039510970

View file

@ -62,6 +62,8 @@ public class AddLocationDialogOmGeocodingAPI extends DialogFragment {
private static final int TRIGGER_AUTO_COMPLETE = 100;
private static final long AUTO_COMPLETE_DELAY = 300;
private static final int TRIGGER_HIDE_KEYBOARD = 200;
private static final long HIDE_KEYBOARD_DELAY = 3000;
private Handler handler;
private AutoSuggestAdapter autoSuggestAdapter;
String urlSuffix="v1/search?name=";
@ -145,8 +147,9 @@ public class AddLocationDialogOmGeocodingAPI extends DialogFragment {
public void onTextChanged(CharSequence s, int start, int before,
int count) {
handler.removeMessages(TRIGGER_AUTO_COMPLETE);
handler.sendEmptyMessageDelayed(TRIGGER_AUTO_COMPLETE,
AUTO_COMPLETE_DELAY);
handler.sendEmptyMessageDelayed(TRIGGER_AUTO_COMPLETE, AUTO_COMPLETE_DELAY);
handler.removeMessages(TRIGGER_HIDE_KEYBOARD);
handler.sendEmptyMessageDelayed(TRIGGER_HIDE_KEYBOARD, HIDE_KEYBOARD_DELAY);
}
@Override
@ -155,9 +158,7 @@ public class AddLocationDialogOmGeocodingAPI extends DialogFragment {
}
});
handler = new Handler(Looper.getMainLooper(), new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
handler = new Handler(Looper.getMainLooper(), msg -> {
if (msg.what == TRIGGER_AUTO_COMPLETE) {
if (!TextUtils.isEmpty(autoCompleteTextView.getText())) {
try {
@ -166,9 +167,12 @@ public class AddLocationDialogOmGeocodingAPI extends DialogFragment {
e.printStackTrace();
}
}
} else if (msg.what == TRIGGER_HIDE_KEYBOARD) {
//Hide keyboard to show entries behind the keyboard
final InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(rootView.getWindowToken(), 0);
}
return false;
}
});
builder.setPositiveButton(activity.getString(R.string.dialog_add_add_button), new DialogInterface.OnClickListener() {