Skip to content

Instantly share code, notes, and snippets.

@alexoro
Created January 16, 2014 12:53
Show Gist options
  • Save alexoro/8454545 to your computer and use it in GitHub Desktop.
Save alexoro/8454545 to your computer and use it in GitHub Desktop.
private ViewTreeObserver.OnGlobalLayoutListener mOnGlobalLayoutListener;
class OnGlobalLayoutListenerImpl implements ViewTreeObserver.OnGlobalLayoutListener {
@Override
public void onGlobalLayout() {
int heightDiff = mViewHolder.activityRootView.getRootView().getHeight() - mViewHolder.activityRootView.getHeight();
if ((heightDiff > getMinKeyboardHeight()) != mIsKeyboardDisplayed) {
mIsKeyboardDisplayed = heightDiff > getMinKeyboardHeight();
setElementVisibilityForSearch(mIsKeyboardDisplayed);
}
}
}
protected int getMinKeyboardHeight() {
return (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
MIN_KEYBOARD_HEIGHT_IN_DP,
getResources().getDisplayMetrics()
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment