Commit e0bc4389 authored by miguelg@chromium.org's avatar miguelg@chromium.org

Upstream isKeyboardShowing

BUG=268339

Review URL: https://chromiumcodereview.appspot.com/22200002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215972 0039d316-1c4b-4281-b951-d872f2087c98
parent 9c5df567
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package org.chromium.ui; package org.chromium.ui;
import android.content.Context; import android.content.Context;
import android.graphics.Rect;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
...@@ -20,6 +21,9 @@ public class UiUtils { ...@@ -20,6 +21,9 @@ public class UiUtils {
private 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. * Shows the software keyboard if necessary.
* @param view The currently focused {@link View}, which would receive soft keyboard input. * @param view The currently focused {@link View}, which would receive soft keyboard input.
...@@ -44,6 +48,17 @@ public class UiUtils { ...@@ -44,6 +48,17 @@ public class UiUtils {
return imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 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}. * Inserts a {@link View} into a {@link ViewGroup} after directly before a given {@View}.
* @param container The {@link View} to add newView to. * @param container The {@link View} to add newView to.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment