From 5b054dcb5229819e8578a600a6720e59e0a17d21 Mon Sep 17 00:00:00 2001 From: dankito Date: Sun, 13 Sep 2020 02:19:53 +0200 Subject: [PATCH] Hiding keyboard when showing instant payment info PopupWindow --- .../ui/android/dialogs/TransferMoneyDialog.kt | 4 +++- .../dialogs/settings/BankSettingsDialog.kt | 1 - .../ui/android/extensions/ContextExtensions.kt | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/extensions/ContextExtensions.kt diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/TransferMoneyDialog.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/TransferMoneyDialog.kt index dbc5b546..656b3435 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/TransferMoneyDialog.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/TransferMoneyDialog.kt @@ -196,7 +196,9 @@ open class TransferMoneyDialog : DialogFragment() { } protected open fun showInstantPaymentInfo(btnShowInstantPaymentInfo: ImageButton, rootView: View) { - context?.asActivity()?.layoutInflater?.inflate(R.layout.view_instant_payment_info, null)?.let { contentView -> + requireActivity().layoutInflater.inflate(R.layout.view_instant_payment_info, null)?.let { contentView -> + requireContext().hideKeyboard(lytInstantPayment) + val popupWindow = PopupWindow(contentView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) popupWindow.isFocusable = true diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/BankSettingsDialog.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/BankSettingsDialog.kt index 9480da08..5fd72574 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/BankSettingsDialog.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/settings/BankSettingsDialog.kt @@ -15,7 +15,6 @@ import net.dankito.banking.ui.android.di.BankingComponent import net.dankito.banking.ui.android.views.FormEditText import net.dankito.banking.ui.model.TypedCustomer import net.dankito.banking.ui.presenter.BankingPresenter -import net.dankito.utils.android.extensions.hideKeyboardDelayed import javax.inject.Inject diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/extensions/ContextExtensions.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/extensions/ContextExtensions.kt new file mode 100644 index 00000000..b562f6b6 --- /dev/null +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/extensions/ContextExtensions.kt @@ -0,0 +1,16 @@ +package net.dankito.banking.ui.android.extensions + +import android.content.Context +import android.os.IBinder +import android.view.View +import android.view.inputmethod.InputMethodManager + + +fun Context.hideKeyboard(anyViewInHierarchy: View, flags: Int = 0) { + hideKeyboard(anyViewInHierarchy.windowToken, flags) +} + +fun Context.hideKeyboard(windowToken: IBinder, flags: Int = 0) { + val keyboard = this.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + keyboard.hideSoftInputFromWindow(windowToken, flags) +} \ No newline at end of file