示例#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);
        }
示例#2
0
        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);
        }
示例#3
0
        public bool ProcessKeyUp(Keycode keyCode, KeyEvent e)
        {
            Key iKey = TranslateKeyCode(keyCode);

            if (iKey == Key.Invalid)
            {
                int ch = e.UnicodeChar;
                if (ch != 0)
                {
                    if ((ch & KeyCharacterMap.CombiningAccent) != 0)
                    {
                        m_DeadKey = ch & KeyCharacterMap.CombiningAccentMask;
                    }
                    else
                    {
                        if (m_DeadKey != 0)
                        {
                            ch        = KeyCharacterMap.GetDeadChar(m_DeadKey, ch);
                            m_DeadKey = 0;
                        }

                        m_Canvas.Input_Character((char)ch);
                    }
                }
            }

            return(m_Canvas.Input_Key(iKey, false));
        }
        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);
            }
        }
示例#5
0
        private static GamePadCapabilities CapabilitiesOfDevice(InputDevice device)
        {
            var capabilities = new GamePadCapabilities();

            capabilities.IsConnected           = true;
            capabilities.GamePadType           = GamePadType.GamePad;
            capabilities.HasLeftVibrationMotor = capabilities.HasRightVibrationMotor = device.Vibrator.HasVibrator;

            // build out supported inputs from what the gamepad exposes
            int[] keyMap = new int[16];
            keyMap[0] = (int)Keycode.ButtonA;
            keyMap[1] = (int)Keycode.ButtonB;
            keyMap[2] = (int)Keycode.ButtonX;
            keyMap[3] = (int)Keycode.ButtonY;

            keyMap[4] = (int)Keycode.ButtonThumbl;
            keyMap[5] = (int)Keycode.ButtonThumbr;

            keyMap[6] = (int)Keycode.ButtonL1;
            keyMap[7] = (int)Keycode.ButtonR1;
            keyMap[8] = (int)Keycode.ButtonL2;
            keyMap[9] = (int)Keycode.ButtonR2;

            keyMap[10] = (int)Keycode.DpadDown;
            keyMap[11] = (int)Keycode.DpadLeft;
            keyMap[12] = (int)Keycode.DpadRight;
            keyMap[13] = (int)Keycode.DpadUp;

            keyMap[14] = (int)Keycode.ButtonStart;
            keyMap[15] = (int)Keycode.Back;

            // get a bool[] with indices matching the keyMap
            bool[] hasMap = new bool[16];
            // HasKeys() was defined in Kitkat / API19 / Android 4.4
            if (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.Kitkat)
            {
                var keyMap2 = new Keycode[keyMap.Length];
                for (int i = 0; i < keyMap.Length; i++)
                {
                    keyMap2[i] = (Keycode)keyMap[i];
                }
                hasMap = KeyCharacterMap.DeviceHasKeys(keyMap2);
            }
            else
            {
                hasMap = device.HasKeys(keyMap);
            }

            capabilities.HasAButton = hasMap[0];
            capabilities.HasBButton = hasMap[1];
            capabilities.HasXButton = hasMap[2];
            capabilities.HasYButton = hasMap[3];

            // we only check for the thumb button to see if we have 2 thumbsticks
            // if ever a controller doesn't support buttons on the thumbsticks,
            // this will need fixing
            capabilities.HasLeftXThumbStick  = hasMap[4];
            capabilities.HasLeftYThumbStick  = hasMap[4];
            capabilities.HasRightXThumbStick = hasMap[5];
            capabilities.HasRightYThumbStick = hasMap[5];

            capabilities.HasLeftShoulderButton  = hasMap[6];
            capabilities.HasRightShoulderButton = hasMap[7];
            capabilities.HasLeftTrigger         = hasMap[8];
            capabilities.HasRightTrigger        = hasMap[9];

            capabilities.HasDPadDownButton  = hasMap[10];
            capabilities.HasDPadLeftButton  = hasMap[11];
            capabilities.HasDPadRightButton = hasMap[12];
            capabilities.HasDPadUpButton    = hasMap[13];

            capabilities.HasStartButton = hasMap[14];
            capabilities.HasBackButton  = hasMap[15];

            return(capabilities);
        }
        private static GamePadCapabilities CapabilitiesOfDevice(InputDevice device)
        {
            // build out supported inputs from what the gamepad exposes
            var keyMap = new int[16];

            keyMap[0] = (int)Keycode.ButtonA;
            keyMap[1] = (int)Keycode.ButtonB;
            keyMap[2] = (int)Keycode.ButtonX;
            keyMap[3] = (int)Keycode.ButtonY;

            keyMap[4] = (int)Keycode.ButtonThumbl;
            keyMap[5] = (int)Keycode.ButtonThumbr;

            keyMap[6] = (int)Keycode.ButtonL1;
            keyMap[7] = (int)Keycode.ButtonR1;
            keyMap[8] = (int)Keycode.ButtonL2;
            keyMap[9] = (int)Keycode.ButtonR2;

            keyMap[10] = (int)Keycode.DpadDown;
            keyMap[11] = (int)Keycode.DpadLeft;
            keyMap[12] = (int)Keycode.DpadRight;
            keyMap[13] = (int)Keycode.DpadUp;

            keyMap[14] = (int)Keycode.ButtonStart;
            keyMap[15] = (int)Keycode.Back;

            bool[] hasMap;
            // HasKeys() was defined in Kitkat / API19 / Android 4.4
            if (Build.VERSION.SdkInt < BuildVersionCodes.Kitkat)
            {
                var keyMap2 = new Keycode[keyMap.Length];
                for (int i = 0; i < keyMap.Length; i++)
                {
                    keyMap2[i] = (Keycode)keyMap[i];
                }

                hasMap = KeyCharacterMap.DeviceHasKeys(keyMap2);
            }
            else
            {
                hasMap = device.HasKeys(keyMap);
            }

            bool hasVibrationMotor = device.Vibrator.HasVibrator;

            return(new GamePadCapabilities(
                       isConnected: true,
                       displayName: device.Name,
                       identifier: device.Descriptor,

                       hasAButton: hasMap[0],
                       hasBButton: hasMap[1],
                       hasBackButton: hasMap[15],

                       hasDPadDownButton: hasMap[10],
                       hasDPadLeftButton: hasMap[11],
                       hasDPadRightButton: hasMap[12],
                       hasDPadUpButton: hasMap[13],

                       hasLeftShoulderButton: hasMap[6],
                       hasLeftStickButton: false,
                       hasRightShoulderButton: hasMap[7],
                       hasRightStickButton: false,

                       hasStartButton: hasMap[14],
                       hasXButton: hasMap[2],
                       hasYButton: hasMap[3],
                       hasBigButton: false,

                       // we only check for the thumb button to see if we have 2 thumbsticks
                       // if ever a controller doesn't support buttons on the thumbsticks,
                       // this will need fixing
                       hasLeftXThumbStick: hasMap[4],
                       hasLeftYThumbStick: hasMap[4],
                       hasRightXThumbStick: hasMap[5],
                       hasRightYThumbStick: hasMap[5],

                       hasLeftTrigger: hasMap[8],
                       hasRightTrigger: hasMap[9],

                       hasLeftVibrationMotor: hasVibrationMotor,
                       hasRightVibrationMotor: hasVibrationMotor,

                       hasVoiceSupport: false,
                       gamePadType: GamePadType.GamePad));
        }