If you want a button to provide haptic feedback (ie, the phone vibrates very briefly so you can feel that you really pushed the button), what's the standard way to do that? It seems you can either explicitly set an onClick() event and call the vibrate() function, giving a number of milliseconds to vibrate, or you can set hapticFeedbackEnabled in the view.
The documentation seems to indicate that the latter only works for long-presses or virtual on-screen keys: http://developer.android.com/reference/android/view/View.html#performHapticFeedback(int)
If that's right, then I need to either make my button a virtual on-screen key or manually set the onClick() event.
What do you recommend?
Also, if I want the vibrating to happen immediately when the user's finger touches the button, as opposed to when their finger "releases" the button, what's the best way to accomplish that?
Related question: How to enable haptic feedback on button view
There is a longer description in the Android Cookbook - Chapter Haptic Feedback
Abstract: there are several step needed:
performHapticFeedback()
on Touch downYou can have both a onTouchLister for the haptic feedback and a onClickHandler for your action, just make sure the the onTouchHandler returns false, otherwise the event is marked as consumed and not given to the onClickHandler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With