diff --git a/app/src/main/java/com/nmc/android/utils/KeyboardUtils.java b/app/src/main/java/com/nmc/android/utils/KeyboardUtils.java new file mode 100644 index 000000000000..ec43ac2dd3a8 --- /dev/null +++ b/app/src/main/java/com/nmc/android/utils/KeyboardUtils.java @@ -0,0 +1,21 @@ +package com.nmc.android.utils; + +import android.app.Activity; +import android.content.Context; +import android.view.View; +import android.view.inputmethod.InputMethodManager; + +public class KeyboardUtils { + + public static void showSoftKeyboard(Context context, View view) { + view.requestFocus(); + InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); + } + + public static void hideKeyboardFrom(Context context, View view) { + view.clearFocus(); + InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index b7066e8a458d..69314d58c97a 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -134,6 +134,7 @@ import com.owncloud.android.utils.MimeTypeUtil; import com.owncloud.android.utils.PermissionUtil; import com.owncloud.android.utils.PushUtils; +import com.nmc.android.utils.KeyboardUtils; import com.owncloud.android.utils.StringUtils; import com.owncloud.android.utils.theme.CapabilityUtils; @@ -1056,6 +1057,8 @@ public void onBackPressed() { // pop back resetScrolling(true); hideSearchView(getCurrentDir()); + //hide the keyboard on back press if showing + KeyboardUtils.hideKeyboardFrom(this, binding.getRoot()); showSortListGroup(true); super.onBackPressed(); } diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/UnifiedSearchFragment.kt b/app/src/main/java/com/owncloud/android/ui/fragment/UnifiedSearchFragment.kt index d14e37204f08..f558a9a00668 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/UnifiedSearchFragment.kt +++ b/app/src/main/java/com/owncloud/android/ui/fragment/UnifiedSearchFragment.kt @@ -38,6 +38,7 @@ import com.nextcloud.client.account.CurrentAccountProvider import com.nextcloud.client.core.AsyncRunner import com.nextcloud.client.di.Injectable import com.nextcloud.client.di.ViewModelFactory +import com.nmc.android.utils.KeyboardUtils import com.nextcloud.client.network.ClientFactory import com.owncloud.android.R import com.owncloud.android.databinding.ListFragmentBinding @@ -192,6 +193,8 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface private fun showFile(file: OCFile) { activity.let { if (activity is FileDisplayActivity) { + //NMC: hide keyboard when user taps on any file to view + KeyboardUtils.hideKeyboardFrom(requireContext(), binding.root) val fda = activity as FileDisplayActivity fda.file = file fda.showFile("") @@ -255,6 +258,7 @@ class UnifiedSearchFragment : Fragment(), Injectable, UnifiedSearchListInterface } override fun onQueryTextSubmit(query: String): Boolean { + KeyboardUtils.hideKeyboardFrom(requireContext(), binding.root) vm.setQuery(query) vm.initialQuery() return true