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?
aohhhha thank you Mark!
Jorgesys
2010-07-16 00:53:08
That was perfect! Thanks I got it!
brybam
2010-07-16 01:20:44
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
2010-07-16 03:33:45
@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
2010-07-16 10:45:28
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
2010-07-16 23:43:58
@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
2010-07-17 01:17:45
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
2010-07-17 13:20:21