protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); SetContentView(Resource.Layout.activity_main); Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); var sensorManager = SensorManager.FromContext(this); ShakeDetector shakeDetector = new ShakeDetector(() => Toast.MakeText(this, "Don't shake me, bro!", ToastLength.Short).Show()); shakeDetector.Start(sensorManager); var textView = new TextView(this); textView.Gravity = GravityFlags.Center; textView.Text = "Shake me, bro!"; SetContentView( textView, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent)); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // set up the sensor var sensorManager = SensorManager.FromContext(this); var shakeDetector = new ShakeDetector(() => { Toast.MakeText(this, "Don't shake me, bro!", ToastLength.Short).Show(); }); shakeDetector.Start(sensorManager); // create the UI var textView = new TextView(this); textView.Gravity = GravityFlags.Center; textView.Text = "Shake me, bro!"; // set the UI SetContentView( textView, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent)); }
public HingeSensor(Context context) { sensorManager = SensorManager.FromContext(context); var sensors = sensorManager.GetSensorList(SensorType.All); hingeSensor = sensors.FirstOrDefault(s => s.StringType.Equals(HINGE_SENSOR_TYPE, StringComparison.OrdinalIgnoreCase)); }
public ShakePageViewModel(Alarm alarm) { CurrentAlarm = alarm; manager = SensorManager.FromContext(Forms.Context); var accelerometer = manager.GetDefaultSensor(SensorType.Accelerometer); ss.OnShake += AddShake; manager.RegisterListener(ss, accelerometer, SensorDelay.Fastest); DependencyService.Get <IAudio>().PlayMp3File("sanicRape.mp3", CurrentAlarm.Volume); Device.StartTimer(TimeSpan.FromMilliseconds(16), OnTimerTick); }
public FoldableHingeAngleSensor(object owner) { if (!(ContextHelper.Current is Activity currentActivity)) { throw new InvalidOperationException("FoldableHingeAngleSensor must be initialized on the UI Thread"); } _sensorManager = SensorManager.FromContext(currentActivity); var sensors = _sensorManager.GetSensorList(Android.Hardware.SensorType.All); _hingeSensor = sensors.FirstOrDefault(s => s.Name.Contains(HINGE_SENSOR_NAME, StringComparison.OrdinalIgnoreCase)); // NAME - generic foldable device/s }
public HingeSensor(Context context) { sensorManager = SensorManager.FromContext(context); var sensors = sensorManager.GetSensorList(SensorType.All); foreach (var sensor in sensors) { // Use generic "hinge" sensor name, to match on a variety of folding device types if (sensor.Name.Contains(HINGE_SENSOR_NAME, StringComparison.InvariantCultureIgnoreCase)) { hingeSensor = sensor; break; } } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); var plotView = FindViewById <PlotView>(Resource.Id.plotView); var sm = SensorManager.FromContext(this); var sensor = sm.GetDefaultSensor(SensorType.LinearAcceleration); var listener = new ObservableSensorListener(sm); sm.RegisterListener(listener, sensor, SensorDelay.Normal); // Here, we're going to take our raw data and make a version that // is a bit less erratic, by averaging the last eight points. Trends // are easier to see in smoothed graphs than in raw data. var smoothedPoints = listener .Buffer(8, 1) .Select(xs => xs.Average()); var normalPointsSeries = new LineSeries(); var smoothedPointsSeries = new LineSeries(); // We're going to plot data relative to the time the graph was started // (i.e. a point on the X-axis might be, '+3 seconds'), so we need to // remember the current time, and reset it every time we reset the graph. var currentTime = DateTimeOffset.Now; smoothedPoints .Select(x => new DataPoint((DateTimeOffset.Now - currentTime).TotalMilliseconds, x)) .Subscribe(x => smoothedPointsSeries.Points.Add(x)); listener .Select(x => new DataPoint((DateTimeOffset.Now - currentTime).TotalMilliseconds, x)) .Subscribe(x => normalPointsSeries.Points.Add(x)); var maxPlotLength = 10; // seconds // Since LineSeries' backing field is just a List, we need to manually // tell OxyPlot to update the graph (we wouldn't want it updating for every // point anyways!). // // We also need to clear the graph from time to time, similar to how // an Oscilloscope works. We'll do that here too Observable.Interval(TimeSpan.FromMilliseconds(250)) .Subscribe(x => { // Observable.Interval schedules to background threads. We // need to move to the UI thread to make changes this.RunOnUiThread(() => { // Clear the plot every maxPlotLength seconds if (x % (maxPlotLength * 4) == 0) { normalPointsSeries.Points.Clear(); smoothedPointsSeries.Points.Clear(); currentTime = DateTimeOffset.Now; } // Cause the Plot to redraw plotView.InvalidatePlot(true); }); }); // Set up our graph plotView.Model = new PlotModel(); plotView.Model.Series.Add(normalPointsSeries); plotView.Model.Series.Add(smoothedPointsSeries); }
private RTCProximitySensor(Context context, Runnable sensorStateListener) { _onSensorStateListener = sensorStateListener; _sensorManager = SensorManager.FromContext(context); }