示例#1
0
        /// <summary>
        /// Tries to create a sensor listener if it is supported
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public AndroidSensorListener TryGetSensorListener(SensorType type)
        {
            var listener = new AndroidSensorListener(type);

            if (!listener.Enable())
            {
                listener.Dispose();
                return(null);
            }

            listener.Disable();
            return(listener);
        }
示例#2
0
        public override void Initialize(InputManager inputManager)
        {
            var context = inputManager.Game.Context as GameContextAndroid;

            uiControl = context.Control;

            // Create android pointer and keyboard
            keyboard = new KeyboardAndroid(this, uiControl);
            pointer  = new PointerAndroid(this, uiControl);
            RegisterDevice(keyboard);
            RegisterDevice(pointer);

            // Create android sensors
            if ((accelerometerListener = TryGetSensorListener(SensorType.Accelerometer)) != null)
            {
                accelerometerSensor = new AccelerometerSensor(this, "Android");
                RegisterDevice(accelerometerSensor);
            }

            if ((linearAccelerationListener = TryGetSensorListener(SensorType.LinearAcceleration)) != null)
            {
                userAccelerationSensor = new UserAccelerationSensor(this, "Android");
                RegisterDevice(userAccelerationSensor);
            }

            if ((gyroscopeListener = TryGetSensorListener(SensorType.Gyroscope)) != null)
            {
                gyroscopeSensor = new GyroscopeSensor(this, "Android");
                RegisterDevice(gyroscopeSensor);
            }

            if ((gravityListener = TryGetSensorListener(SensorType.Gravity)) != null)
            {
                gravitySensor = new GravitySensor(this, "Android");
                RegisterDevice(gravitySensor);
            }

            if ((orientationListener = TryGetSensorListener(SensorType.RotationVector)) != null)
            {
                orientationSensor = new OrientationSensor(this, "Android");
                compassSensor     = new CompassSensor(this, "Android");
                RegisterDevice(orientationSensor);
                RegisterDevice(compassSensor);
            }
        }
示例#3
0
        public void UpdateSensorPair <TSensor>(AndroidSensorListener listener, TSensor sensor, Action <TSensor, AndroidSensorListener> updater) where TSensor : Sensor
        {
            if (listener != null)
            {
                bool enable = sensor.IsEnabled;
                if (enable != listener.Enabled)
                {
                    if (enable)
                    {
                        listener.Enable();
                    }
                    else
                    {
                        listener.Disable();
                    }
                }

                if (enable)
                {
                    updater.Invoke(sensor, listener);
                }
            }
        }