summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2024-02-27 00:25:34 +0100
committercyBerta <cyberta@riseup.net>2024-02-27 00:25:34 +0100
commitb8adf36cbf732da19dcd100ba89d1b01af6db694 (patch)
treeadad857dbad822e25e23e088a5a4e0b357109bf4
parentb8f3fbd25f19498e7a6a9080369ff5815c18d6d7 (diff)
scroll EditText to visible area after the keyboard appeared
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java11
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/fragments/ProviderSelectionFragment.java6
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());
}