Last active
May 3, 2018 19:20
-
-
Save mitchtabian/c9f515b5c9b27e60ccfa1f9f9e9720fb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
private IMainActivity mIMainActivity; | |
static int mAppHeight; | |
static int currentOrientation = -1; | |
public void setKeyboardVisibilityListener() { | |
final View contentView = getActivity().findViewById(android.R.id.content); | |
contentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { | |
private int mPreviousHeight; | |
@Override | |
public void onGlobalLayout() { | |
int newHeight = contentView.getHeight(); | |
if (newHeight == mPreviousHeight) | |
return; | |
mPreviousHeight = newHeight; | |
Log.d(TAG, "onGlobalLayout: new height: " + newHeight); | |
if (getActivity().getResources().getConfiguration().orientation != currentOrientation) { | |
currentOrientation = getActivity().getResources().getConfiguration().orientation; | |
mAppHeight =0; | |
Log.d(TAG, "onGlobalLayout: current Orientation: " + currentOrientation); | |
Log.d(TAG, "onGlobalLayout: app height: " + mAppHeight); | |
} | |
if (newHeight >= mAppHeight) { | |
mAppHeight = newHeight; | |
Log.d(TAG, "onGlobalLayout: app height: " + mAppHeight); | |
} | |
Log.d(TAG, "onGlobalLayout: -------------------------\n"); | |
if (newHeight != 0) { | |
MessagesFragment messagesFragment = (MessagesFragment) getActivity() | |
.getSupportFragmentManager().findFragmentByTag(getActivity().getString(R.string.tag_fragment_messages)); | |
if(messagesFragment.isVisible()){ | |
if (mAppHeight > newHeight) { | |
Log.d(TAG, "onGlobalLayout: hiding bottom nav"); | |
// Height decreased: keyboard was shown | |
mIMainActivity.setBottomNavigationVisibility(false); | |
} | |
else { | |
Log.d(TAG, "onGlobalLayout: showing bottom nav"); | |
// Height increased: keyboard was hidden | |
mIMainActivity.setBottomNavigationVisibility(true); | |
} | |
} | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment