AndroidResideMenu
AndroidResideMenu copied to clipboard
Samsung Galaxy S4 - Version 5.0.1 unwanted black container
I changed fitSystemWindows() code with the latest update. It works fine with other devices. However, it creates a black container at the bottom of the device. How can I prevent this to happen?
The updated part in ResideMenu.java:
@Override
protected boolean fitSystemWindows(Rect insets) {
// Applies the content insets to the view's padding, consuming that
// content (modifying the insets to be 0),
// and returning true. This behavior is off by default and can be
// enabled through setFitsSystemWindows(boolean)
// in api14+ devices.
// This is added to fix soft navigationBar's overlapping to content above LOLLIPOP
int bottomPadding = viewActivity.getPaddingBottom() + insets.bottom;
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);
if (!hasBackKey || !hasHomeKey) {//there's a navigation bar
bottomPadding += getNavigationBarHeight();
}
this.setPadding(viewActivity.getPaddingLeft() + insets.left,
viewActivity.getPaddingTop() + insets.top,
viewActivity.getPaddingRight() + insets.right,
bottomPadding);
insets.left = insets.top = insets.right = insets.bottom = 0;
return true;
}
private int getNavigationBarHeight() {
Resources resources = getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
return resources.getDimensionPixelSize(resourceId);
}
return 0;
}
Replace your fitSystemWindow with (Kishanjvaghela's decision): `@Override protected boolean fitSystemWindows(Rect insets) { setMyPadding(insets); return true; }
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Rect rect = new Rect(
insets.getSystemWindowInsetLeft(),
insets.getSystemWindowInsetTop(),
insets.getSystemWindowInsetRight(),
insets.getSystemWindowInsetBottom()
);
setMyPadding(rect);
return insets.consumeSystemWindowInsets();
}
private void setMyPadding(Rect rect) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (hasNavBar(getContext())) {
WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
switch (manager.getDefaultDisplay().getRotation()) {
case Surface.ROTATION_90:
rect.right += getNavBarWidth();
break;
case Surface.ROTATION_180:
rect.top += getNavBarHeight();
break;
case Surface.ROTATION_270:
rect.left += getNavBarWidth();
break;
default:
rect.bottom += getNavBarHeight();
}
}
}
setPadding(
rect.left, rect.top, rect.right, rect.bottom
);
}
/**
* check is system has navigation bar or not
* http://stackoverflow.com/a/29120269/3758898
*
* @param context context
* @return true if navigation bar is present or false
*/
boolean hasNavBar(Context context) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// navigation bar was introduced in Android 4.0 (API level 14)
Resources resources = context.getResources();
int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
if (id > 0) {
return resources.getBoolean(id);
} else { // Check for keys
boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
return !hasMenuKey && !hasBackKey;
}
} else {
return false;
}
}
private int getNavBarWidth() {
return getNavBarDimen("navigation_bar_width");
}
private int getNavBarHeight() {
return getNavBarDimen("navigation_bar_height");
}
private int getNavBarDimen(String resourceString) {
Resources r = getResources();
int id = r.getIdentifier(resourceString, "dimen", "android");
if (id > 0) {
return r.getDimensionPixelSize(id);
} else {
return 0;
}
}`
You can refer my solution here. It works with gesture navigations also https://github.com/SpecialCyCi/AndroidResideMenu/issues/121#issuecomment-460137552