Levels of smartphone addiction being what they are, locking and unlocking your mobile can take up a lot of precious time in the day: If only your phone knew when you were looking at it and when you'd set it down or put it in a pocket. That's exactly that Gravity Screen offers, a free download from the Google Play Store.
Gravity Screen can turn the screen off when you put the phone in your pocket or when you set it down on a table (face up or face down). What's more, you can keep the screen on with a small shake when it begins to dim, and it can automatically wake up when motion is detected (when you pull it up from your desk, for example).
The sensitivity for these settings can be easily adjusted through the options screen, where you can also temporarily disable the app's features -- if you want more control over the settings and access to the Gravity Screen widget then a paid-for Pro upgrade is available, but the app functions fine in free mode too.
Some of the supported options may vary depending on your device, and on some phones the app can cause alarms to disable themselves when the handset is face down, so test this first -- if you do run into problems, there's an extensive FAQ online that deals with most common issues.
Essentially, Gravity Screen replaces the power button on your phone, taking care of the locking and unlocking process for you (it might be worth trying if your phone's power button is unreliable). Because of the advanced permissions the app requires, you can't uninstall it in the usual way -- use the option at the bottom of the settings screen instead.