Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(374)

Unified Diff: ui/android/java/src/org/chromium/ui/UiUtils.java

Issue 22200002: Upstream isKeyboardShowing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698