本文整理汇总了C#中Android.Hardware.Sensor类的典型用法代码示例。如果您正苦于以下问题:C# Sensor类的具体用法?C# Sensor怎么用?C# Sensor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Sensor类属于Android.Hardware命名空间,在下文中一共展示了Sensor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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 };
}
示例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 };
}
示例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);
}
示例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}
};
}
示例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}
};
}
示例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();
}
};
}
示例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 }
};
}
示例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;
}
示例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);
}