-
-
Save Zoha131/db3ebec883db08906682206b837bf587 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
This is a comment for api trial