diff options
author | cyBerta <cyberta@riseup.net> | 2024-02-27 00:25:34 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2024-02-27 00:25:34 +0100 |
commit | b8adf36cbf732da19dcd100ba89d1b01af6db694 (patch) | |
tree | adad857dbad822e25e23e088a5a4e0b357109bf4 | |
parent | b8f3fbd25f19498e7a6a9080369ff5815c18d6d7 (diff) |
scroll EditText to visible area after the keyboard appeared
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java | 11 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/providersetup/fragments/ProviderSelectionFragment.java | 6 |
2 files changed, 17 insertions, 0 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java index ed7bd9f2..e04ba70d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java @@ -229,8 +229,19 @@ public class ViewHelper { } public static void hideKeyboardFrom(Context context, View view) { + if (context == null) { + return; + } InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } + public static boolean isKeyboardShown(Context context) { + if (context == null) { + return false; + } + InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); + return imm.isActive(); + } + } diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/fragments/ProviderSelectionFragment.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/fragments/ProviderSelectionFragment.java index 8ccfee22..0b0c5034 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/fragments/ProviderSelectionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/fragments/ProviderSelectionFragment.java @@ -121,6 +121,12 @@ public class ProviderSelectionFragment extends BaseSetupFragment implements Canc ViewHelper.hideKeyboardFrom(getContext(), v); } }); + + binding.getRoot().getViewTreeObserver().addOnGlobalLayoutListener(() -> { + if(ViewHelper.isKeyboardShown(getContext())) { + binding.getRoot().smoothScrollTo(binding.editCustomProvider.getLeft(), binding.getRoot().getBottom()); + } + }); binding.providerRadioGroup.check(viewModel.getSelected()); } |