Created
February 9, 2012 12:12
-
-
Save fpillet/1779575 to your computer and use it in GitHub Desktop.
Detect whether the Android Soft Keyboard is up
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
containerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() | |
{ | |
public void onGlobalLayout() | |
{ | |
final Activity app = getActivity(); | |
if (app == null) | |
return; | |
Rect r = new Rect(); | |
containerView.getWindowVisibleDisplayFrame(r); | |
boolean visible = (Math.abs(r.height() - containerView.getHeight()) > 128); | |
if (visible != keyboardVisible) | |
{ | |
keyboardVisible = visible; | |
NotificationCenter.postNotification( | |
Constants.KEYBOARD_VISIBILITY_CHANGED, | |
this, | |
CFDictionary.withObjectsAndKeys(visible, "visible")); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment