public AccelerometerManager(Context context, IAccelerometerListener listener)
 {
     this.context = context;
       eventListener = new ShakeSensorEventListener(listener);
       sensorManager = (SensorManager) context.GetSystemService(Context.SensorService);
       IsSupported = sensorManager.GetSensorList(SensorType.Accelerometer).Count > 0;
 }
Exemple #2
0
 public void GetSpeed()
 {
     // Register this as a listener with the underlying service.
     sensorManager = (Android.Hardware.SensorManager)Forms.Context.GetSystemService(Context.SensorService);
     sensor        = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.Accelerometer);
     sensorManager.RegisterListener(this, sensor, Android.Hardware.SensorDelay.Game);
 }
Exemple #3
0
 protected override void OnCreate(Bundle bundle)
 {
     base.OnCreate(bundle);
     SetContentView(Resource.Layout.Main);
     _sensorManager = (SensorManager) GetSystemService(SensorService);
     _sensorTextView = FindViewById<TextView>(Resource.Id.accelerometer_text);
 }
Exemple #4
0
 public GradientChanger(SensorManager sensorManager, SensorType sensorType, AbsoluteLayout layout)
 {
     this._sensorManager = sensorManager;
     this._sensorType = sensorType;
     _layout = layout;
     this.StartListening();
 }
Exemple #5
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            illuminationView = FindViewById <TextView> (Resource.Id.Illumination);
            historyView      = FindViewById <TextView> (Resource.Id.History);
            manager          = (SensorManager)GetSystemService(SensorService);
            lightSensor      = manager.GetDefaultSensor(SensorType.Light);

            var executeButton = FindViewById <Button> (Resource.Id.Execute);

            executeButton.Click += (sender, e) => {
                detectable         = !detectable;
                executeButton.Text = detectable ? "停止" : "開始";

                if (detectable)
                {
                    RegisterLightListener();
                }
                else
                {
                    UnRegisterLightListener();
                }
            };

            var clearButton = FindViewById <Button> (Resource.Id.Clear);

            clearButton.Click += (sender, e) => historyView.Text = "";
        }
		public SimulationView (Context context, SensorManager sensorManager, IWindowManager window)
			: base (context)
		{
			Bounds = new PointF ();

			// Get an accelorometer sensor
			sensor_manager = sensorManager;
			accel_sensor = sensor_manager.GetDefaultSensor (SensorType.Accelerometer);

			// Calculate screen size and dpi
			var metrics = new DisplayMetrics ();
			window.DefaultDisplay.GetMetrics (metrics);

			meters_to_pixels_x = metrics.Xdpi / 0.0254f;
			meters_to_pixels_y = metrics.Ydpi / 0.0254f;

			// Rescale the ball so it's about 0.5 cm on screen
			var ball = BitmapFactory.DecodeResource (Resources, Resource.Drawable.Ball);
			var dest_w = (int)(BALL_DIAMETER * meters_to_pixels_x + 0.5f);
			var dest_h = (int)(BALL_DIAMETER * meters_to_pixels_y + 0.5f);
			ball_bitmap = Bitmap.CreateScaledBitmap (ball, dest_w, dest_h, true);

			// Load the wood background texture
			var opts = new BitmapFactory.Options ();
			opts.InDither = true;
			opts.InPreferredConfig = Bitmap.Config.Rgb565;
			wood_bitmap = BitmapFactory.DecodeResource (Resources, Resource.Drawable.Wood, opts);
			wood_bitmap2 = BitmapFactory.DecodeResource (Resources, Resource.Drawable.Wood, opts);

			display = window.DefaultDisplay;
			particles = new ParticleSystem (this);
		}
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate (savedInstanceState);

            // Get a reference to the sensor manager
            sensor_manager = (SensorManager) GetSystemService (Context.SensorService);

            // Create our view
            var map_view = new MapView (this, "MapViewCompassDemo_DummyAPIKey");

            rotate_view = new RotateView (this);
            rotate_view.AddView (map_view);

            SetContentView (rotate_view);

            // Create the location overlay
            location_overlay = new MyLocationOverlay (this, map_view);
            location_overlay.RunOnFirstFix (delegate {
                map_view.Controller.AnimateTo (location_overlay.MyLocation);
            });
            map_view.Overlays.Add (location_overlay);

            map_view.Controller.SetZoom(18);
            map_view.Clickable = true;
            map_view.Enabled = true;
        }
Exemple #8
0
        public override void Initialize()
        {
            base.Initialize();

            var viewListener = new ViewListener(this);
            gameView = Game.Context.Control;
            gameView.SetOnTouchListener(viewListener);
            gameView.SetOnKeyListener(viewListener);
            gameView.Resize += GameViewOnResize;

            GameViewOnResize(null, EventArgs.Empty);

            // Get the android sensors
            sensorManager = (SensorManager)PlatformAndroid.Context.GetSystemService(Context.SensorService);
            androidAccelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer);
            androidGyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope);
            androidUserAcceleration = sensorManager.GetDefaultSensor(SensorType.LinearAcceleration);
            androidGravity = sensorManager.GetDefaultSensor(SensorType.Gravity);
            androidRotationVector = sensorManager.GetDefaultSensor(SensorType.RotationVector);

            // Determine which sensor is available on the device
            Accelerometer.IsSupported = androidAccelerometer != null;
            Compass.IsSupported = androidRotationVector != null;
            Gyroscope.IsSupported = androidGyroscope != null;
            UserAcceleration.IsSupported = androidUserAcceleration != null;
            Gravity.IsSupported = androidGravity != null;
            Orientation.IsSupported = androidRotationVector != null;
        }
        public void Initialize()
        {
            _sensorManager = (SensusServiceHelper.Get() as AndroidSensusServiceHelper).Service.GetSystemService(global::Android.Content.Context.SensorService) as SensorManager;

            _sensor = _sensorManager.GetDefaultSensor(_sensorType);
            if (_sensor == null)
                throw new Exception("No sensors present for sensor type " + _sensorType);
        }
        partial void Start()
        {
            this.sensorManager = Application.Context.GetSystemService(Context.SensorService) as SensorManager;

            this.accelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer);

            this.sensorManager.RegisterListener(this, accelerometer, this.delay);
        }
        partial void Start()
        {
            this.sensorManager = Application.Context.GetSystemService(Context.SensorService) as SensorManager;

            this.gyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope);

            this.sensorManager.RegisterListener(this, this.gyroscope, this.delay);
        }
Exemple #12
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            sensorManager = (SensorManager)GetSystemService(Context.SensorService);
            sensorListener = new SensorListener(this);
        }
 public void Stop()
 {
     if (_accelerometer == null)
     {
         throw new MvxException("Accelerometer not started");
     }
     _sensorManager.UnregisterListener(this);
     _sensorManager = null;
     _accelerometer = null;
 }
Exemple #14
0
        public void Stop()
        {
            if (_sensorManager == null)
            {
                return;
            }

            _sensorManager.UnregisterListener(this);
            _sensorManager = null;
        }
Exemple #15
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            // Create your application here
            mSensorManager = (SensorManager)GetSystemService (Context.SensorService);
            mView = new SampleView (this);

            SetContentView (mView);
        }
Exemple #16
0
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);
			//Window.AddFlags(WindowManagerFlags.Fullscreen);
			//Window.ClearFlags(WindowManagerFlags.ForceNotFullscreen);
			_sensorManager = (SensorManager) GetSystemService(Context.SensorService);
			var g = new Game1 ();
			SetContentView (g.Services.GetService<View> ());
			g.Run ();
		}
Exemple #17
0
		public static void SetupAccelerometer()
		{
            _sensorManger = (SensorManager)Game.Activity.GetSystemService(Context.SensorService);
            _sensor = _sensorManger.GetDefaultSensor(SensorType.Accelerometer);

            if (_sensor != null) 
            {
                _state = new AccelerometerState { IsConnected = true };                
            }
            else _state = new AccelerometerState { IsConnected = false };
        }
Exemple #18
0
        public SensorManager() : base()
        {
            sensorManager = (Android.Hardware.SensorManager)Android.App.Application.Context.GetSystemService(Context.SensorService);

            sensorAccelerometer      = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.Accelerometer);
            sensorGyroscope          = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.Gyroscope);
            sensorMagnetometer       = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.MagneticField);
            sensorCompass            = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.Orientation);
            sensorLight              = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.Light);
            sensorPressure           = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.Pressure);
            sensorProximity          = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.Proximity);
            sensorLinearAcceleration = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.LinearAcceleration);
            sensorRotation           = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.RotationVector);
            sensorGameRotation       = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.GameRotationVector);
            sensorHumidity           = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.RelativeHumidity);
            sensorAmbientTemperature = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.AmbientTemperature);
            sensorSignificantMotion  = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.SignificantMotion);
            sensorStepDetector       = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.StepDetector);
            sensorStepCounter        = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.StepCounter);
            sensorHeartRate          = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.HeartRate);
            sensorPose       = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.Pose6dof);
            sensorStationary = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.StationaryDetect);
            sensorMotion     = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.MotionDetect);
            sensorHeartBeat  = sensorManager.GetDefaultSensor(Android.Hardware.SensorType.HeartBeat);


            sensorStatus = new Dictionary <InteractClient.Sensors.SensorType, bool>
            {
                { InteractClient.Sensors.SensorType.AcceleroMeter, false },
                { InteractClient.Sensors.SensorType.Gyroscope, false },
                { InteractClient.Sensors.SensorType.MagnetoMeter, false },
                { InteractClient.Sensors.SensorType.Compass, false },
                { InteractClient.Sensors.SensorType.Light, false },
                { InteractClient.Sensors.SensorType.Pressure, false },
                { InteractClient.Sensors.SensorType.Proximity, false },
                { InteractClient.Sensors.SensorType.LinearAcceleration, false },
                { InteractClient.Sensors.SensorType.Rotation, false },
                { InteractClient.Sensors.SensorType.GameRotation, false },
                { InteractClient.Sensors.SensorType.Humidity, false },
                { InteractClient.Sensors.SensorType.AmbientTemperature, false },
                { InteractClient.Sensors.SensorType.SignificantMotion, false },
                { InteractClient.Sensors.SensorType.StepDetector, false },
                { InteractClient.Sensors.SensorType.StepCounter, false },
                { InteractClient.Sensors.SensorType.HeartRate, false },
                { InteractClient.Sensors.SensorType.Pose, false },
                { InteractClient.Sensors.SensorType.Stationary, false },
                { InteractClient.Sensors.SensorType.Motion, false },
                { InteractClient.Sensors.SensorType.HeartBeat, false },
                { InteractClient.Sensors.SensorType.Tilt, false },
            };

            TriggerEventListener          = new SensorTriggerEventListener();
            TriggerEventListener.Callback = OnSensorTrigger;
        }
        public static void SetupAccelerometer()
        {
            _sensorManger = (SensorManager)Game.contextInstance.GetSystemService(Context.SensorService);
            _sensor = _sensorManger.GetDefaultSensor(SensorType.Accelerometer);

            if (_sensor != null) {
                _state = new AccelerometerState { IsConnected = true };
                _sensorManger.RegisterListener(new SensorListener(), _sensor, SensorDelay.Game);
            }
            else _state = new AccelerometerState { IsConnected = false };
        }
Exemple #20
0
		public void StartUpdatingHeading ()
		{
			if (_manager == null) {
				_manager = (SensorManager) Forms.Context.GetSystemService (Context.SensorService);
			}

			if (_compass == null) {
				_compass = _manager.GetDefaultSensor (SensorType.Orientation);
			}

			_manager.RegisterListener (this, _compass, SensorDelay.Normal);
		}
Exemple #21
0
 public void SetSensorListener(ISensorListener l)
 {
     listener = l;
     if (listener != null) {
         sensorManager = (SensorManager) context.GetSystemService(Context.SensorService);
         sensorManager.RegisterListener(this, sensorManager.GetDefaultSensor(SensorType.Accelerometer), SensorDelay.Game);
     } else {
         if (sensorManager != null) {
             sensorManager.UnregisterListener(this);
             sensorManager = null;
         }
     }
 }
Exemple #22
0
        // Initialization of the Activity after it is first created.  Must at least
        // call {@link android.app.Activity#setContentView setContentView()} to
        // describe what is to be displayed in the screen.
        protected override void OnCreate(Bundle savedInstanceState)
        {
            // Be sure to call the base class.
            base.OnCreate (savedInstanceState);

            sensor_manager = (SensorManager)GetSystemService (SensorService);
            graph_view = new GraphView (this.BaseContext);
            SetContentView (graph_view);

            sensor_manager.RegisterListener (graph_view,
                SensorManager.SensorAccelerometer |
                SensorManager.SensorMagneticField |
                SensorManager.SensorOrientation,
                SensorDelay.Fastest);
        }
 public SensorReadingTest()
 {
     sensorManager = (SensorManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.SensorService);
     sensorAccelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer);
     sensorMagnetometer = sensorManager.GetDefaultSensor(SensorType.MagneticField);
     sensorGravity = sensorManager.GetDefaultSensor(SensorType.Gravity);
     sensorGyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope);
     sensorStatus = new Dictionary<SensorType, bool>()
     {
         { SensorType.Accelerometer, false},
         { SensorType.MagneticField, false},
         { SensorType.Gravity, false},
         { SensorType.Gyroscope, false}
     };
 }
      /// <summary>
      /// Initializes a new instance of the DeviceMotionImplementation class.
      /// </summary>
      public DeviceMotionImplementation() : base()
      {

          sensorManager = (SensorManager)Application.Context.GetSystemService(Context.SensorService);
          sensorAccelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer);
          sensorGyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope);
          sensorMagnetometer = sensorManager.GetDefaultSensor(SensorType.MagneticField);
          sensorCompass = sensorManager.GetDefaultSensor(SensorType.Orientation);
          sensorStatus = new Dictionary<MotionSensorType, bool>(){
				{ MotionSensorType.Accelerometer, false},
				{ MotionSensorType.Gyroscope, false},
				{ MotionSensorType.Magnetometer, false},
                { MotionSensorType.Compass,false}
			};
      }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Initilize system sensor service
            sensorManager = (SensorManager)GetSystemService(SensorService);

            // Get elemnt from the layout resource,
            outerDialImage = FindViewById<ImageView>(Resource.Id.imageViewCompass);
            headingDirection = FindViewById<TextView>(Resource.Id.headingDirection);
            headingDegree = FindViewById<TextView>(Resource.Id.headingDegree);
            dialImage = FindViewById<ImageView>(Resource.Id.imageViewDial);
        }
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			SetContentView (Resource.Layout.Sensors);

			trackButton = FindViewById<Button> (Resource.Id.trackButton);
			stepCount = FindViewById<TextView> (Resource.Id.stepCount);

			// create a sensor manager to schedule batches of sensor data
			senMgr = (SensorManager) GetSystemService (SensorService);

			// update state from orientation change
			if (bundle != null)
			{
				count = bundle.GetFloat ("step_count", 0);
				if (bundle.GetBoolean ("visible", false)) {
					visible = true;
					stepCount.Text = count.ToString ();
				}
				Log.Debug(GetType().FullName, "Recovered instance state");
			}


			// This button gets the user's step count since the last time the device was rebooted
			trackButton.Click += (o, e) => {
				// get the step counter sensor via the SensorManager
				counter = senMgr.GetDefaultSensor (SensorType.StepCounter);

				// button's been clicked, so counter visibility gets set to true
				visible = true;

				// This sensor is only available on Nexus 5 and Moto X at time of writing
				// The following line will check if the sensor is available explicitly:
				bool counterAvailabe = PackageManager.HasSystemFeature(PackageManager.FeatureSensorStepCounter);
				Log.Info("SensorManager", "Counter available");

				if (counterAvailabe && counter != null) {
					// Set sensor delay to normal, the default rate for batching sensor data
					senMgr.RegisterListener(this, counter, SensorDelay.Normal);
					Toast.MakeText(this,"Count sensor started",ToastLength.Long).Show();
				} else {
					Toast.MakeText(this, "Count sensor unavailable", ToastLength.Long).Show();
				}
			};

		}
Exemple #27
0
        // Initialization of the Activity after it is first created.  Must at least
        // call {@link android.app.Activity#setContentView setContentView()} to
        // describe what is to be displayed in the screen.
        protected override void OnCreate(Bundle savedInstanceState)
        {
            // Be sure to call the base class.
            base.OnCreate (savedInstanceState);

            sensor_manager = (SensorManager)GetSystemService (SensorService);
            graph_view = new GraphView (this.BaseContext);
            SetContentView (graph_view);

            var accel = sensor_manager.GetDefaultSensor (SensorType.Accelerometer);
            var mag = sensor_manager.GetDefaultSensor (SensorType.MagneticField);
            var ori = sensor_manager.GetDefaultSensor (SensorType.Orientation);

            sensor_manager.RegisterListener (graph_view, accel, SensorDelay.Fastest);
            sensor_manager.RegisterListener (graph_view, mag, SensorDelay.Fastest);
            sensor_manager.RegisterListener (graph_view, ori, SensorDelay.Fastest);
        }
		public GPSListener(LocationManager lm, SensorManager sm, IWindowManager wm) : base()
		{
			// Get LocationManager
			_locManager = lm;
			_windowManager = wm;

			var locationCriteria = new Criteria ()
			{
				Accuracy = global::Android.Locations.Accuracy.Fine,
				AltitudeRequired = true,
				PowerRequirement = Power.Low
			};

//			locationProvider = _locManager.GetBestProvider(locationCriteria, true);
			locationProvider = LocationManager.GpsProvider;

			if (locationProvider == null)
				throw new Exception("No location provider found");

			List<String> providers = _locManager.GetProviders(true) as List<String>;

			// Loop over the array backwards, and if you get an accurate location, then break out the loop
			GPSLocation loc = null;

			if (providers != null) {
				for (int i = providers.Count - 1; i >= 0; i--) {
					loc = new GPSLocation(_locManager.GetLastKnownLocation(providers[i]));
					if (loc != null) 
						break;
				}
			}

			// If we have an old location, than use this as first location
			if (loc != null)
			{
				_location = new GPSLocation(loc);
			} else {
				_location = new GPSLocation();
			}

			_sensorManager = sm;

			_orientationSensor = _sensorManager.GetDefaultSensor(SensorType.Orientation);
			_accelerometerSensor = _sensorManager.GetDefaultSensor(SensorType.Accelerometer);
		}
        public Implementation()
        {
            sensorManager = (SensorManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.SensorService);
            sensorAccelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer);
            sensorGravimeter = sensorManager.GetDefaultSensor(SensorType.Gravity);
            sensorGyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope);
            sensorMagnetometer = sensorManager.GetDefaultSensor(SensorType.MagneticField);
            sensorOrientation = sensorManager.GetDefaultSensor(SensorType.Orientation);

            sensorStatus = new Dictionary<DeviceSensorType, bool>()
            {
                { DeviceSensorType.Accelerometer, false},
                { DeviceSensorType.Gravimeter, false},
                { DeviceSensorType.Gyroscope, false},
                { DeviceSensorType.Magnetometer, false},
                { DeviceSensorType.Orientation, false }

            };
        }
		public LocListener(LocationManager lm, SensorManager sm) : base()
		{
			// Get LocationManager
			locManager = lm;

			var locationCriteria = new Criteria ()
			{
				Accuracy = global::Android.Locations.Accuracy.Fine,
				AltitudeRequired = true,
				PowerRequirement = Power.Low
			};

			locationProvider = locManager.GetBestProvider(locationCriteria, true);

			if (locationProvider == null)
				throw new Exception("No location provider found");

			List<String> providers = locManager.GetProviders(true) as List<String>;

			// Loop over the array backwards, and if you get an accurate location, then break out the loop
			Location loc = null;

			if (providers != null) {
				for (int i = providers.Count - 1; i >= 0; i--) {
					loc = locManager.GetLastKnownLocation(providers[i]);
					if (loc != null) 
						break;
				}
			}

			if (loc != null)
			{
				lat = loc.Latitude;
				lon = loc.Longitude;
				alt = loc.Altitude;
				accuracy = loc.Accuracy;
			}

			sensorManager = sm;
			accelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer);
			magnetometer = sensorManager.GetDefaultSensor(SensorType.MagneticField);
		}
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Remove the title bar
			RequestWindowFeature (WindowFeatures.NoTitle);

			// Keep the screen from turning off while we're running
			Window.AddFlags (WindowManagerFlags.KeepScreenOn);

			// Get an instance of the SensorManager
			sensor_manager = (SensorManager)GetSystemService (Activity.SensorService);

			// Get an instance of the WindowManager
			window_manager = GetSystemService (Activity.WindowService).JavaCast<IWindowManager> ();

			// Instantiate our simulation view and set it as the activity's content
			sim_view = new SimulationView (this, sensor_manager, window_manager);
			SetContentView (sim_view);
		}
        /// <summary>
        /// Called when the activity is first created. </summary>
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Get an instance of the SensorManager
            mSensorManager = (SensorManager)GetSystemService(SENSOR_SERVICE);

            // Get an instance of the PowerManager
            mPowerManager = (PowerManager)GetSystemService(POWER_SERVICE);

            // Get an instance of the WindowManager
            mWindowManager = (IWindowManager)GetSystemService(WINDOW_SERVICE);
            mDisplay = mWindowManager.GetDefaultDisplay();

            // Create a bright wake lock
            mWakeLock = mPowerManager.NewWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, this.GetType().Name);

            // instantiate our simulation view and set it as the activity's content
            mSimulationView = new SimulationView(this);
            SetContentView(mSimulationView);
        }
        public Implementation()
        {
            sensorManager = (SensorManager)Android.App.Application.Context.GetSystemService(Context.SensorService);
            sensorAccelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer);
            sensorGravimeter = sensorManager.GetDefaultSensor(SensorType.Gravity);
            sensorGyroscope = sensorManager.GetDefaultSensor(SensorType.Gyroscope);
            sensorMagnetometer = sensorManager.GetDefaultSensor(SensorType.MagneticField);
            sensorOrientation = sensorManager.GetDefaultSensor(SensorType.Orientation);

            //Instead of using raw data from the orientation sensor, we recommend that you use the getRotationMatrix() method in conjunction with the getOrientation() method to compute orientation values.You can also use the remapCoordinateSystem() method to translate the orientation values to your application's frame of reference.
            sensorStatus = new Dictionary<DeviceSensorType, bool>()
            {
                { DeviceSensorType.Accelerometer, false},
                { DeviceSensorType.Gravimeter, false},
                { DeviceSensorType.Gyroscope, false},
                { DeviceSensorType.Magnetometer, false},
                { DeviceSensorType.Orientation, false },
                { DeviceSensorType.OrientationRaw, false}
            };

            isOrientationRawActivated = false;
        }
Exemple #34
0
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App());



            mSensorManager                   = GetSystemService(Android.Content.Context.SensorService) as Android.Hardware.SensorManager;
            mRotationVectorSensor            = mSensorManager.GetDefaultSensor(Android.Hardware.SensorType.RotationVector);
            mGeomagneticRotationVectorSensor = mSensorManager.GetDefaultSensor(SensorType.GeomagneticRotationVector);
            mAccelerometerSensor             = mSensorManager.GetDefaultSensor(SensorType.Accelerometer);
            mMagneticFieldSensor             = mSensorManager.GetDefaultSensor(SensorType.MagneticField);

            mSensorManager.RegisterListener(this, mRotationVectorSensor, SensorDelay.Normal);
            mSensorManager.RegisterListener(this, mGeomagneticRotationVectorSensor, SensorDelay.Normal);
            mSensorManager.RegisterListener(this, mAccelerometerSensor, SensorDelay.Normal);
            mSensorManager.RegisterListener(this, mMagneticFieldSensor, SensorDelay.Normal);
        }