AndroidResideMenu icon indicating copy to clipboard operation
AndroidResideMenu copied to clipboard

Activity behind hardware controls

Open gchristov opened this issue 9 years ago • 3 comments

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 avatar Nov 14 '16 11:11 gchristov

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);
}

gchristov avatar Nov 14 '16 13:11 gchristov

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);

hubdestro avatar Jan 27 '17 11:01 hubdestro

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;
 }

wondersoftwares671 avatar Sep 02 '17 05:09 wondersoftwares671