Exemple #1
0
        public int GetNavBarHeight(Context c)
        {
            int result = 0;

            if (Build.VERSION.SdkInt >= BuildVersionCodes.IceCreamSandwich)
            {
                bool hasMenuKey = ViewConfiguration.Get(c).HasPermanentMenuKey;
                bool hasBackKey = KeyCharacterMap.DeviceHasKey(Keycode.Back);

                if (!hasMenuKey && !hasBackKey)
                {
                    //The device has a navigation bar
                    Resources resources   = c.Resources;
                    var       orientation = Resources.Configuration.Orientation;
                    int       resourceId;
                    if (IsTablet(c))
                    {
                        resourceId = resources.GetIdentifier(orientation == AContRes_O.Portrait ? "navigation_bar_height" : "navigation_bar_height_landscape", "dimen", "android");
                    }
                    else
                    {
                        resourceId = resources.GetIdentifier(orientation == AContRes_O.Portrait ? "navigation_bar_height" : "navigation_bar_width", "dimen", "android");
                    }

                    if (resourceId > 0)
                    {
                        return(Resources.GetDimensionPixelSize(resourceId));
                    }
                }
            }
            return(result);
        }
        public bool HasSoftKeys()
        {
            bool hasSoftwareKeys;
            var  c = Android.App.Application.Context;

            if (Build.VERSION.SdkInt >= Build.VERSION_CODES.JellyBeanMr1)
            {
                Display d = c.GetSystemService(Context.WindowService).JavaCast <IWindowManager>().DefaultDisplay;

                DisplayMetrics realDisplayMetrics = new DisplayMetrics();
                d.GetRealMetrics(realDisplayMetrics);

                int realHeight = realDisplayMetrics.HeightPixels;
                int realWidth  = realDisplayMetrics.WidthPixels;

                DisplayMetrics displayMetrics = new DisplayMetrics();
                d.GetMetrics(displayMetrics);

                int displayHeight = displayMetrics.HeightPixels;
                int displayWidth  = displayMetrics.WidthPixels;

                BottomBarHeight = (realHeight - displayHeight);

                hasSoftwareKeys = (realWidth - displayWidth) > 0 ||
                                  (realHeight - displayHeight) > 0;
            }
            else
            {
                bool hasMenuKey = ViewConfiguration.Get(c).HasPermanentMenuKey;
                bool hasBackKey = KeyCharacterMap.DeviceHasKey(Keycode.Back);
                hasSoftwareKeys = !hasMenuKey && !hasBackKey;
            }
            return(hasSoftwareKeys);
        }
        public bool IsNavigationBarAvailable()
        {
            bool hasBackKey = KeyCharacterMap.DeviceHasKey(KeyEvent.KeyCodeFromString("KEYCODE_BACK"));
            bool hasHomeKey = KeyCharacterMap.DeviceHasKey(KeyEvent.KeyCodeFromString("KEYCODE_HOME"));

            if (hasBackKey && hasHomeKey)
            {
                // no navigation bar, unless it is enabled in the settings
                return(false);
            }
            else
            {
                // 99% sure there's a navigation bar
                return(true);
            }
        }