Index: ui/android/java/src/org/chromium/ui/UiUtils.java |
diff --git a/ui/android/java/src/org/chromium/ui/UiUtils.java b/ui/android/java/src/org/chromium/ui/UiUtils.java |
index 21e304e3dae3002d88966183ad9721c8e53af4f8..4a9fe15e79f5c86994c30d18b17688c3eea59921 100644 |
--- a/ui/android/java/src/org/chromium/ui/UiUtils.java |
+++ b/ui/android/java/src/org/chromium/ui/UiUtils.java |
@@ -5,6 +5,7 @@ |
package org.chromium.ui; |
import android.content.Context; |
+import android.graphics.Rect; |
import android.view.View; |
import android.view.ViewGroup; |
import android.view.inputmethod.InputMethodManager; |
@@ -20,6 +21,9 @@ public class UiUtils { |
private UiUtils() { |
} |
+ /** The minimum size of the bottom margin below the app to detect a keyboard. */ |
+ private static float KEYBOARD_DETECT_BOTTOM_THRESHOLD_DP = 100; |
+ |
/** |
* Shows the software keyboard if necessary. |
* @param view The currently focused {@link View}, which would receive soft keyboard input. |
@@ -44,6 +48,17 @@ public class UiUtils { |
return imm.hideSoftInputFromWindow(view.getWindowToken(), 0); |
} |
+ public static boolean isKeyboardShowing(Context context, View view) { |
+ View rootView = view.getRootView(); |
+ if (rootView == null) return false; |
+ Rect appRect = new Rect(); |
+ rootView.getWindowVisibleDisplayFrame(appRect); |
+ final float screenHeight = context.getResources().getDisplayMetrics().heightPixels; |
+ final float bottomMargin = Math.abs(appRect.bottom - screenHeight); |
+ final float density = context.getResources().getDisplayMetrics().density; |
+ return bottomMargin > KEYBOARD_DETECT_BOTTOM_THRESHOLD_DP * density; |
+ } |
+ |
/** |
* Inserts a {@link View} into a {@link ViewGroup} after directly before a given {@View}. |
* @param container The {@link View} to add newView to. |