Last time I described how I would be rewriting some of the Plyer facades. I had some confusion about the how to go about this after listening to varying opinions from different Kivy community members. I even had a plan to study the sl4a style of doing things. But finally after a discussion with tito  and the rest of the group, we decided to drop that approach altogether and stick with using Pyjnius on Android.
In my introductory post to Kivy, I had described the motivation behind the Pyjnius project:
… a Python module to access Java classes as Python classes using JNI. The idea behind Pyjnius is completely different from other frameworks offering similar functionality of providing device independent access to hardware features. Instead of having to write specific “interface” code using Android SDK to make calls to the device APIs.
Pyjnius let’s you autoclass any of the Java classes and even implement abstract classes that act as API interfaces. To illustrate this with an example, I’ll consider the accelerometer facade in Plyer that I re-worked upon:
Yes, it’s actually as simple as that! You can access any of the Android APIs just by specifying the corresponding Java classes.
Implementing an abstract class takes slightly more effort as you have to declare an interface with the methods that need to be implemented:
Except hashCode, the rest of the portions are quite self-explanatory. Wikipedia has the following to say about the hash code function in Java:
In the Java programming language, every class implicitly or explicitly provides a hashCode() method, which digests the data stored in an instance of the class into a single hash value (a 32-bit signed integer). This hash is used by other code when storing or manipulating the instance …
You would probably want to refer to http://pyjnius.readthedocs.org/, if you are interested in using Pyjnius yourself.
I think after this first accelerometer facade, implementation other similar features (other sensors) would a be a trivial task. I hope to make some good progress on them in the coming week.
- I must acknowledge that a most of the content in this post has been derived from this discussion. ^