Very often I use my phone lying in bed (with phone camera facing the ceiling) and the orientation changes drive me crazy. Literally if I turn the phone a few degrees it will go from portait to landscape and vice versa.
I can disable auto-rotation, but it's not desirable in some scenarios, like when i turn on my shoulder and I want the orientation to change.
Basically, is it possible to write your own logic for screen rotation and make it run on system wide scope?
UPD: I do not want to toggle auto-rotation. I want to rewrite that logic that based on current sensor setting changes the screen orientation on system level.
This widget works well... No customer rom or root required. :0)
You could write an app that locks to portrait orientation when whatever conditions you want are met.
So you could make it always be portrait unless the phone is held perfectly vertical in landscape position.
As far as I can tell, you can't force landscape orientation, so you'll have to just enable autorotation unless you want to make your own ROM.
Your app will probably need to be a Service and use SensorManager.
You can search the Android source on Google Code.
In CyanogenMod, and you can set up to have the power widget on the notification bar, the power widget in Cyanogen is enhanced so it can control more settings, one of it is the ability to lock the orientation sensor. Whenever you want to lock, simply pull out the notification bar and tap on the lock orientation button.