summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordtrainor@chromium.org <dtrainor@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-18 05:00:24 +0000
committerdtrainor@chromium.org <dtrainor@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-18 05:00:24 +0000
commit5e09494c74fbadcd1bf83aedae31b0db86525e46 (patch)
treeec9101b508b8ff5a8192669d08738d904aea17f9
parent7c3ddf929bda3c87567a126a77e2cd54fe7f89ab (diff)
downloadchromium_src-5e09494c74fbadcd1bf83aedae31b0db86525e46.zip
chromium_src-5e09494c74fbadcd1bf83aedae31b0db86525e46.tar.gz
chromium_src-5e09494c74fbadcd1bf83aedae31b0db86525e46.tar.bz2
Add keyboard showing delegate
Add a way to override the keyboard visibility detection BUG=251343 Review URL: https://codereview.chromium.org/241263002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@264730 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/android/java/src/org/chromium/ui/UiUtils.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/ui/android/java/src/org/chromium/ui/UiUtils.java b/ui/android/java/src/org/chromium/ui/UiUtils.java
index 6e6bf54..e46e6fe 100644
--- a/ui/android/java/src/org/chromium/ui/UiUtils.java
+++ b/ui/android/java/src/org/chromium/ui/UiUtils.java
@@ -30,6 +30,31 @@ public class UiUtils {
/** The minimum size of the bottom margin below the app to detect a keyboard. */
private static final float KEYBOARD_DETECT_BOTTOM_THRESHOLD_DP = 100;
+ /** A delegate that allows disabling keyboard visibility detection. */
+ private static KeyboardShowingDelegate sKeyboardShowingDelegate;
+
+ /**
+ * A delegate that can be implemented to override whether or not keyboard detection will be
+ * used.
+ */
+ public interface KeyboardShowingDelegate {
+ /**
+ * Will be called to determine whether or not to detect if the keyboard is visible.
+ * @param context A {@link Context} instance.
+ * @param view A {@link View}.
+ * @return Whether or not the keyboard check should be disabled.
+ */
+ boolean disableKeyboardCheck(Context context, View view);
+ }
+
+ /**
+ * Allows setting a delegate to override the default software keyboard visibility detection.
+ * @param delegate A {@link KeyboardShowingDelegate} instance.
+ */
+ public static void setKeyboardShowingDelegate(KeyboardShowingDelegate delegate) {
+ sKeyboardShowingDelegate = delegate;
+ }
+
/**
* Shows the software keyboard if necessary.
* @param view The currently focused {@link View}, which would receive soft keyboard input.
@@ -54,7 +79,19 @@ public class UiUtils {
return imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
+ /**
+ * Detects whether or not the keyboard is showing. This is a best guess as there is no
+ * standardized/foolproof way to do this.
+ * @param context A {@link Context} instance.
+ * @param view A {@link View}.
+ * @return Whether or not the software keyboard is visible and taking up screen space.
+ */
public static boolean isKeyboardShowing(Context context, View view) {
+ if (sKeyboardShowingDelegate != null
+ && sKeyboardShowingDelegate.disableKeyboardCheck(context, view)) {
+ return false;
+ }
+
View rootView = view.getRootView();
if (rootView == null) return false;
Rect appRect = new Rect();