Methods Summary |
---|
private static boolean | checkGlobalSetting(android.content.Context context)
return Settings.System.getInt(context.getContentResolver(),
Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) == 1;
|
public void | start()Call to setup the controller.
mVibrator = (Vibrator) mContext.getSystemService(Service.VIBRATOR_SERVICE);
// Setup a listener for changes in haptic feedback settings
mIsGloballyEnabled = checkGlobalSetting(mContext);
Uri uri = Settings.System.getUriFor(Settings.System.HAPTIC_FEEDBACK_ENABLED);
mContext.getContentResolver().registerContentObserver(uri, false, mContentObserver);
|
public void | stop()Call this when you don't need the controller anymore.
mVibrator = null;
mContext.getContentResolver().unregisterContentObserver(mContentObserver);
|
public void | tryVibrate()Try to vibrate. To prevent this becoming a single continuous vibration, nothing will
happen if we have vibrated very recently.
if (mVibrator != null && mIsGloballyEnabled) {
long now = SystemClock.uptimeMillis();
// We want to try to vibrate each individual tick discretely.
if (now - mLastVibrate >= VIBRATE_DELAY_MS) {
mVibrator.vibrate(VIBRATE_LENGTH_MS);
mLastVibrate = now;
}
}
|