public class

HapticFeedback

extends Object
java.lang.Object
   ↳ com.android.phone.HapticFeedback

Class Overview

Handles the haptic feedback: a light buzz happening when the user presses a soft key (UI button or capacitive key). The haptic feedback is controlled by: - a system resource for the pattern The pattern used is tuned per device and stored in an internal resource (config_virtualKeyVibePattern.) - a system setting HAPTIC_FEEDBACK_ENABLED. HAPTIC_FEEDBACK_ENABLED can be changed by the user using the system Settings activity. It must be rechecked each time the activity comes in the foreground (onResume). This class is not thread safe. It assumes it'll be called from the UI thead. Typical usage: -------------- static private final boolean HAPTIC_ENABLED = true; private HapticFeedback mHaptic = new HapticFeedback(); protected void onCreate(Bundle icicle) { mHaptic.init((Context)this, HAPTIC_ENABLED); } protected void onResume() { // Refresh the system setting. mHaptic.checkSystemSetting(); } public void foo() { mHaptic.vibrate(); }

Summary

Public Constructors
HapticFeedback()
Public Methods
void checkSystemSetting()
Reload the system settings to check if the user enabled the haptic feedback.
void init(Context context, boolean enabled)
Initialize this instance using the app and system configs.
void vibrate()
Generate the haptic feedback vibration.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public HapticFeedback ()

Public Methods

public void checkSystemSetting ()

Reload the system settings to check if the user enabled the haptic feedback.

public void init (Context context, boolean enabled)

Initialize this instance using the app and system configs. Since these don't change, init is typically called once in 'onCreate'. checkSettings is not called during init.

Parameters
context To look up the resources and system settings.
enabled If false, vibrate will be a no-op regardless of the system settings.

public void vibrate ()

Generate the haptic feedback vibration. Only one thread can request it. If the phone is already in a middle of an haptic feedback sequence, the request is ignored.