Haptic feedback for the Dialer (bug 1940121).
It's enabled using a per-platform resource in config.xml (which for now is
"true" on all platforms.) But if enough users are annoyed by this, we
might eventually need to make it a user preference rather than a
per-platform resource.
diff --git a/res/values/config.xml b/res/values/config.xml
index 1edd007..669a9d4 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -33,4 +33,14 @@
<!-- Flag indicating whether Contacts app is allowed to export contacts to SDCard -->
<bool name="config_allow_export_to_sdcard">false</bool>
+
+ <!-- If true, enable vibration (haptic feedback) for dialer key presses.
+ TODO: If enough users are annoyed by this, we might eventually
+ need to make it a user preference rather than a per-platform
+ resource. -->
+ <bool name="config_enable_dialer_key_vibration">true</bool>
+
+ <!-- How long to vibrate (in msec), if dialer key vibration is enabled. -->
+ <integer name="config_dialer_key_vibrate_duration">40</integer>
+
</resources>
diff --git a/src/com/android/contacts/TwelveKeyDialer.java b/src/com/android/contacts/TwelveKeyDialer.java
index 152ff30..9284e05 100644
--- a/src/com/android/contacts/TwelveKeyDialer.java
+++ b/src/com/android/contacts/TwelveKeyDialer.java
@@ -34,6 +34,7 @@
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
+import android.os.Vibrator;
import android.provider.Contacts.Intents.Insert;
import android.provider.Contacts.People;
import android.provider.Contacts.Phones;
@@ -98,7 +99,12 @@
// determines if we want to playback local DTMF tones.
private boolean mDTMFToneEnabled;
-
+
+ // Vibration (haptic feedback) for dialer key presses.
+ private Vibrator mVibrator;
+ private boolean mVibrateOn;
+ private long mVibrateDuration;
+
/** Identifier for the "Add Call" intent extra. */
static final String ADD_CALL_MODE_KEY = "add_call_mode";
/** Indicates if we are opening this dialer to add a call from the InCallScreen. */
@@ -215,6 +221,13 @@
}
}
}
+
+ // Initialize vibration parameters.
+ // TODO: We might eventually need to make mVibrateOn come from a
+ // user preference rather than a per-platform resource, in which
+ // case we would need to update it in onResume() rather than here.
+ mVibrateOn = r.getBoolean(R.bool.config_enable_dialer_key_vibration);
+ mVibrateDuration = (long) r.getInteger(R.integer.config_dialer_key_vibrate_duration);
}
@Override
@@ -371,7 +384,7 @@
@Override
protected void onResume() {
super.onResume();
-
+
// retrieve the DTMF tone play back setting.
mDTMFToneEnabled = Settings.System.getInt(getContentResolver(),
Settings.System.DTMF_TONE_WHEN_DIALING, 1) == 1;
@@ -534,6 +547,7 @@
}
private void keyPressed(int keyCode) {
+ vibrate();
KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
mDigits.onKeyDown(keyCode, event);
}
@@ -617,6 +631,7 @@
return;
}
case R.id.digits: {
+ vibrate(); // Vibrate here too, just like we do for the regular keys
placeCall();
return;
}
@@ -939,4 +954,17 @@
}
return phoneInUse;
}
+
+ /**
+ * Triggers haptic feedback (if enabled) for dialer key presses.
+ */
+ private synchronized void vibrate() {
+ if (!mVibrateOn) {
+ return;
+ }
+ if (mVibrator == null) {
+ mVibrator = new Vibrator();
+ }
+ mVibrator.vibrate(mVibrateDuration);
+ }
}