views:

112

answers:

2

I'm looking for an android code example on how I would be able to make my phone listen for a "shake" and then have it trigger webview.reload(); to simply reload the webview on the activity. Anyone have any insight on this topic?

+1  A: 

You can try the Shaker class from this project.

CommonsWare
aohhhha thank you Mark!
Jorgesys
That was perfect! Thanks I got it!
brybam
Careful how to use is since the listener may not stop when the activity is out of focus (in case you are firing any intent with that shake)
weakwire
@weakwire: correct -- best usage is to set up the `Shaker` in `onResume()` and close it in `onPause()`. My sample is a little on the simple side.
CommonsWare
Anyone that used this Shaker class know what to modify so it has to be shaken a tad rougher? right now i barely tilt my nexus and it triggers it :/
brybam
@brybam: The `threshold` parameter expresses a ratio to Earth's gravity -- 1.25 means acceleration 25% more than gravity is considered the start of a shake. You can increase that value to require a more generous shake.
CommonsWare
A: 

I think its just as simple as read the accel, watch the x accel, look for a pos peak about 1G, (this sample is the first that is less than the previous couple of samples), increment a counter. After three 'shakes', you're golden. You have 2 params to adjust... threshold and reps.

BobG