SpecialCyCi / AndroidResideMenu

The idea of ResideMenu is from Dribbble 1 and 2. It has come true and run in iOS devices. iOS ResideMenu This project is the RefsideMenu Android version. The visual effect is partly referred to iOS version of ResideMenu. And thanks to the authors for the above idea and contribution.
MIT License
2.85k stars 1.1k forks source link

Activity behind hardware controls #112

Open gchristov opened 7 years ago

gchristov commented 7 years ago

Hi,

I'm seeing an issue where after adding the RESideMenu control to the Activity, it is placed behind the hardware controls of the device. If I remove the side menu, everything is aligned properly. Is this a known issue and is there a workaround?

screen shot 2016-11-14 at 11 15 52

gchristov commented 7 years ago

For anyone looking for a workaround, here's something..

After you initialize your RESideMenu, run this, which will automatically add any missing padding based on the navigation type.

// Fix RESideMenu bottom layout bug.
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);
if (hasBackKey || hasHomeKey) { // There's a navigation bar.
    resideMenu.postDelayed(new Runnable() {
        @Override
        public void run() {
            Resources resources = getResources();
            int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
            int paddingBottom = resideMenu.getPaddingBottom();
            paddingBottom += resources.getDimensionPixelSize(resourceId);;
            resideMenu.setPadding(resideMenu.getPaddingLeft(), resideMenu.getPaddingTop(), resideMenu.getPaddingRight(), paddingBottom);
        }
    }, 300);
}
hubdestro commented 7 years ago

Most stable solution after hard work

public Point getNavigationBarSize(Context context) { Point appUsableSize = getAppUsableScreenSize(context); Point realScreenSize = getRealScreenSize(context);

    // navigation bar on the right
    if (appUsableSize.x < realScreenSize.x) {
        return new Point(realScreenSize.x - appUsableSize.x, appUsableSize.y);
    }

    // navigation bar at the bottom
    if (appUsableSize.y < realScreenSize.y) {
        return new Point(appUsableSize.x, realScreenSize.y - appUsableSize.y);
    }

    // navigation bar is not present
    return new Point();
}

public Point getAppUsableScreenSize(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size;
}

public Point getRealScreenSize(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();

    if (Build.VERSION.SDK_INT >= 17) {
        display.getRealSize(size);
    } else if (Build.VERSION.SDK_INT >= 14) {
        try {
            size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
            size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
        } catch (IllegalAccessException e) {} catch (InvocationTargetException e) {} catch (NoSuchMethodException e) {}
    }

    return size;
}

And set padding of main layout

setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), getNavigationBarSize(getContext()).y);

wondersoftwares671 commented 7 years ago

The Simple solution that is working for me for now is, Get Navigation bar height and set padding to root layout of activity in OnCreate() after setContentView.


.....
     int navHeight = getNavHeight();
     if (navHeight > 0) {
         (findViewById(R.id.rlMain)).setPadding(0, 0, 0, navHeight);
     }
.....

private int getNavHeight() {
     if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
         return 0;
     try {
         Resources resources = getResources();
         int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
         if (resourceId > 0) {
             return resources.getDimensionPixelSize(resourceId);
         }
     } catch (Exception ex) {
         return 0;
     }
     return 0;
 }