Haptic Feedback ?
Haptic feedback, often referred to as simply "haptics", is the use of the sense of touch in a user interface design to provide information to an end user. The resistive force that some "force feedback" joysticks and video game steering wheels provide is another form of haptic feedback.
Haptic Feedback in Android???
Haptic feedback (commonly referred to as haptics) is the use of touchfeedback to the end user. You know how your Android phone vibrates a tiny bit when you tap one of the navigation buttons? That's haptics at work.
How it works ?
By default haptic feedback setter works only for long press.
Here we are implementing this haptic feedback in simple onClick
You need to add the "android.permission.VIBRATE" permission to the program's manifest.
You can do so by adding the following to the "AndroidManifest.xml" file,
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
Add this line in your onCreate
Vibrator myVib = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
and add this line in your onClick
myVib.vibrate(50);
The class looks like,
public class Main extends Activity implements OnClickListener
{
private View myView;
private Vibrator myVib;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
myVib = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
//myView can be any type of view, button, etc.
myView = (View) this.findViewById(R.id.myView);
myView.setOnClickListener(this);
}
@Override
public void onClick(View v)
{
myVib.vibrate(50);
//add whatever you want after this
}
}
____________________________________________________________________
Happy Coding...
Comments
Post a Comment