//Get the centered position for the joystick axis
        private float GetCenteredAxis(MotionEvent e, InputDevice device, Axis axis)
        {
            InputDevice.MotionRange range = device.GetMotionRange(axis, e.Source);
            if (range != null)
            {
                float flat  = range.Flat;
                float value = e.GetAxisValue(axis);
                if (System.Math.Abs(value) > flat)
                {
                    return(value);
                }
            }

            return(0);
        }
Пример #2
0
        private static float getCenteredAxis(MotionEvent evt, InputDevice device, Axis axis, int historyPos)
        {
            InputDevice.MotionRange range =
                device.GetMotionRange(axis, evt.Source);

            // A joystick at rest does not always report an absolute position of
            // (0,0). Use the getFlat() method to determine the range of values
            // bounding the joystick axis center.
            if (range != null)
            {
                float flat  = range.Flat;
                float value =
                    historyPos < 0 ? evt.GetAxisValue(axis):
                    evt.GetHistoricalAxisValue(axis, historyPos);

                // Ignore axis values that are within the 'flat' region of the
                // joystick axis center.
                if (Math.Abs(value) > flat)
                {
                    return(value);
                }
            }
            return(0);
        }