开发者

How to implement a 'calibratable' orientation listener in android?

Please look at the code from here.

To summarize the code in the above link, the code declares an interface ‘OrientationListener’ and ‘a class ‘OrientationManager’. ‘OrientationManager’ listens to ‘SensorEvent’(s) and calls one of the foure decalred methods in ‘OrientationListenor’, ‘onTopUp()’, ‘onRightUp()’, ‘onBottomUp()’, and ‘onLeftUp()’, if the device’s top, right, bottom, or left side is facing up.

This works great if you assume that the users only use their devices such that the xy coordinates of the device are parallel to the ground. The reality is, users usually use their device a开发者_如何转开发t angel will sitting down, or laying down while holding their phone upside down.

How can I modify this code to allow users to ‘calibrate’ their phone?

Help is very appreciated, this is my second day looking into this with no results.


@Gallal, I assume you already got an answer for this question in the previous question?

However, for this problem you described here (that is, determining which side is "up", no matter by how much), you may consider using the accelerometer readings rather than the rotation matrix. Again, read your accels at Calibrate and store the 3 gravity components you read as Axi, Ayi, Azi. Now, assuming the device always "faces up", then you can compare the current accel readings to the initial ones to determine which side went "up" (the one where the gravity component got smaller) and which side "down" (the one where the gravity component got bigger).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜