• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Hardware.Sensor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Android.Hardware.Sensor的典型用法代码示例。如果您正苦于以下问题:C# Sensor类的具体用法?C# Sensor怎么用?C# Sensor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Sensor类属于Android.Hardware命名空间,在下文中一共展示了Sensor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Initialize

        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;
        }
开发者ID:joewan,项目名称:xenko,代码行数:28,代码来源:InputManager.Android.cs


示例2: SimulationView

		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);
		}
开发者ID:CHANDAN145,项目名称:monodroid-samples,代码行数:32,代码来源:SimulationView.cs


示例3: Initialize

        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);
        }
开发者ID:trishalaneeraj,项目名称:sensus,代码行数:8,代码来源:AndroidSensorListener.cs


示例4: Start

        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);
        }
开发者ID:Gunner92,项目名称:Xamarin-Forms-Labs,代码行数:8,代码来源:Accelerometer.cs


示例5: Start

        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);
        }
开发者ID:GGHG72,项目名称:Xamarin-Forms-Labs,代码行数:8,代码来源:Gyroscope.cs


示例6: StartListening

 public void StartListening()
 {
     var sensors = sensorManager.GetSensorList(SensorType.Accelerometer);
       if (sensors.Count > 0)
       {
     sensor = sensors[0];
     IsListening = sensorManager.RegisterListener(eventListener, sensor, SensorDelay.Game);
       }
 }
开发者ID:phaufe,项目名称:PuppyKittyOverflow,代码行数:9,代码来源:AccelerometerManager.cs


示例7: SetupAccelerometer

		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 };
        }
开发者ID:valsavva,项目名称:dynacat,代码行数:11,代码来源:Accelerometer.cs


示例8: SetupAccelerometer

        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 };
        }
开发者ID:JesterScribble,项目名称:MonoGame,代码行数:11,代码来源:Accelerometer.cs


示例9: StartUpdatingHeading

		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);
		}
开发者ID:aspyct,项目名称:Traq,代码行数:12,代码来源:Geolocator_Android.cs


示例10: SensorReadingTest

 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}
     };
 }
开发者ID:ZENG-Yuhao,项目名称:Xamarin-CrossPlatform,代码行数:15,代码来源:SensorReadingTest.cs


示例11: DeviceMotionImplementation

      /// <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}
			};
      }
开发者ID:lampshade9909,项目名称:xamarin-plugins,代码行数:18,代码来源:DeviceMotionImplementation.cs


示例12: OnCreate

		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();
				}
			};

		}
开发者ID:CHANDAN145,项目名称:monodroid-samples,代码行数:47,代码来源:SensorsActivity.cs


示例13: Implementation

        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 }

            };
        }
开发者ID:ZENG-Yuhao,项目名称:Xamarin-CrossPlatform,代码行数:19,代码来源:Implementation.cs


示例14: Implementation

        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;
        }
开发者ID:ZENG-Yuhao,项目名称:Xamarin-CrossPlatform,代码行数:22,代码来源:Implementation.cs


示例15: Start

        public void Start()
        {
            if (_accelerometer != null)
            {
                throw new MvxException("Accelerometer already started");
            }

            var globals = Mvx.Resolve<IMvxAndroidGlobals>();
            _sensorManager = (SensorManager) globals.ApplicationContext.GetSystemService(Context.SensorService);
            if (_sensorManager == null)
                throw new MvxException("Failed to find SensorManager");

            _accelerometer = _sensorManager.GetDefaultSensor(SensorType.Accelerometer);
            if (_accelerometer == null)
                throw new MvxException("Failed to find Accelerometer");

            // It is not necessary to get accelerometer events at a very high
            // rate, by using a slower rate (SENSOR_DELAY_UI), we get an
            // automatic low-pass filter, which "extracts" the gravity component
            // of the acceleration. As an added benefit, we use less power and
            // CPU resources.
            _sensorManager.RegisterListener(this, _accelerometer, SensorDelay.Ui);
        }
开发者ID:jokvist,项目名称:MvvmCross-Plugins,代码行数:23,代码来源:MvxAccelerometer.cs


示例16: OnAccuracyChanged

 public void OnAccuracyChanged(Sensor Sensor, SensorStatus accuracy)
 {
     accelStrength = (TextView)FindViewById(Resource.Id.accelStrength);
     //Correlate to ENUMS later... for now just display strong...
 }
开发者ID:leef3,项目名称:LatLongLog_Xamarin,代码行数:5,代码来源:AccelerometerTest.cs


示例17: OnAccuracyChanged

 public void OnAccuracyChanged(Sensor sensor, SensorStatus accuracy)
 {
     // ignored
 }
开发者ID:jokvist,项目名称:MvvmCross-Plugins,代码行数:4,代码来源:MvxAccelerometer.cs


示例18: OnAccuracyChanged

 public void OnAccuracyChanged(Sensor sensor, int accuracy)
 {
     // TODO Auto-generated method stub
 }
开发者ID:4ndr01d,项目名称:monodroid-samples,代码行数:4,代码来源:RotateView.cs


示例19: OnAccuracyChanged

 public void OnAccuracyChanged(Sensor sensor, [GeneratedEnum] SensorStatus accuracy)
 {
 }
开发者ID:ZENG-Yuhao,项目名称:Xamarin-CrossPlatform,代码行数:3,代码来源:SensorReadingTest.cs


示例20: OnCreate

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.AccelerometerMain);

            //Normal Accelerometer (Pure Hardware)
            accelStatus = (TextView)FindViewById(Resource.Id.accelStatus);
            accelStrength = (TextView)FindViewById(Resource.Id.accelStrength);
            accelX = (TextView)FindViewById(Resource.Id.accelX);
            accelY = (TextView)FindViewById(Resource.Id.accelY);
            accelZ = (TextView)FindViewById(Resource.Id.accelZ);

            //Linear Accelerometer (Software Adjusted)
            linearStatus = (TextView)FindViewById(Resource.Id.linearStatus);
            linearStrength = (TextView)FindViewById(Resource.Id.linearStrength);
            linearX = (TextView)FindViewById(Resource.Id.linearX);
            linearY = (TextView)FindViewById(Resource.Id.linearY);
            linearZ = (TextView)FindViewById(Resource.Id.linearZ);

            //GPS
            gpsStatus = (TextView)FindViewById(Resource.Id.gpsStatus);
            gpsProvider = (TextView)FindViewById(Resource.Id.gpsProvider);
            gpsLatitude = (TextView)FindViewById(Resource.Id.gpsLatitude);
            gpsLongitude = (TextView)FindViewById(Resource.Id.gpsLongitude);
            gpsSpeed = (TextView)FindViewById(Resource.Id.gpsSpeed);
            InitalizeLocationManager();

            //List<Sensor> deviceSensors = new List<Sensor>(mSensorManager.GetSensorList(SensorType.All));

            //Sensor Initializations
            mSensorManager = (SensorManager)GetSystemService(Context.SensorService);
            if(mSensorManager.GetDefaultSensor(SensorType.Accelerometer) != null)
            {
                accelStatus.Text = "EXISTS";
                mSensor = mSensorManager.GetDefaultSensor(SensorType.Accelerometer);
            }
            else
            {
                accelStatus.Text = "NOT AVAILABLE";
            }

            if (mSensorManager.GetDefaultSensor(SensorType.LinearAcceleration) != null)
            {
                linearStatus.Text = "EXISTS";
                mLinearSensor = mSensorManager.GetDefaultSensor(SensorType.LinearAcceleration);
            }
            else
            {
                linearStatus.Text = "NOT AVAILABLE";
            }
        }
开发者ID:leef3,项目名称:LatLongLog_Xamarin,代码行数:52,代码来源:AccelerometerTest.cs



注:本文中的Android.Hardware.Sensor类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Locations.Location类代码示例发布时间:2022-05-24
下一篇:
C# Hardware.Camera类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap