xamarin/Xamarin.Mobile — pull request #25 by joelmartinez (2014-01-13 20:20:55+00:00)
Title: Accelerometer Support

Moving to pull request from email thread:

I started with the iOS implementation, as I wanted to get something up and running to flesh out the API before moving to the other platforms. You can find it here:
https://github.com/joelmartinez/Xamarin.Mobile/tree/master/MonoTouch/Xamarin.Mobile/Motion

I thought it would be interesting to expose an IObservable, so you can use Rx style event handling:

var accelerometer = new MotionManager ();
accelerometer.Subscribe(v => DoSomething (v.X, v.Y, v.Z));

Was considering adding a plain old event as well in case the user doesn’t want to use Rx, or isn’t familiar with it. Also, I’m starting the event polling as soon as you instantiate the class … will probably make it the user’s choice by moving that to a start/stop motif.

Anyways, would love to hear your thoughts on what this simple API looks like, what you’d like to see in it … and also, maybe a bit of history (in case someone already tried to add this before and had difficulties). I’m gonna start testing it more in earnest as soon as I get a better handle on the ideal API and features, and then move to implement the other platforms.

@ermau responded:
I can also tell you that I'm opposed to basing on IObservable. I realize that it's a better solution from an architecture standpoint, but when I wrote the geolocator originally I had the same idea.. turns out its near impossible to sanely consume it without getting Rx, and I do not want to force people into that.

I responded:
Yeah I can fully understand what you’re referring to; I chafed a bit at having to implement my own IObservable since I wasn’t going to make Rx a dependency.