From 4174655e23734563775acb9e1e644b31b9e72fa5 Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Thu, 11 Nov 2010 18:15:41 +0900 Subject: [PATCH] Check the system vibrator availability for the "Vibrate on keypress" preference. bug: 3021001 Change-Id: I7843a3e4765333c720fd8f258c1fffdf6f090d3a --- java/src/com/android/inputmethod/latin/LatinIME.java | 6 ++++-- .../com/android/inputmethod/latin/LatinIMESettings.java | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 60828c372..e2b85c525 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -39,6 +39,7 @@ import android.os.Debug; import android.os.Handler; import android.os.Message; import android.os.SystemClock; +import android.os.Vibrator; import android.preference.PreferenceActivity; import android.preference.PreferenceManager; import android.speech.SpeechRecognizer; @@ -89,7 +90,6 @@ public class LatinIME extends InputMethodService static final boolean VOICE_INSTALLED = true; static final boolean ENABLE_VOICE_BUTTON = true; - private static final String PREF_VIBRATE_ON = "vibrate_on"; private static final String PREF_SOUND_ON = "sound_on"; private static final String PREF_POPUP_ON = "popup_on"; private static final String PREF_AUTO_CAP = "auto_cap"; @@ -2533,7 +2533,9 @@ public class LatinIME extends InputMethodService private void loadSettings(EditorInfo attribute) { // Get the settings preferences SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); - mVibrateOn = sp.getBoolean(PREF_VIBRATE_ON, false); + Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); + mVibrateOn = vibrator != null && vibrator.hasVibrator() + && sp.getBoolean(LatinIMESettings.PREF_VIBRATE_ON, false); mSoundOn = sp.getBoolean(PREF_SOUND_ON, false); mPopupOn = sp.getBoolean(PREF_POPUP_ON, mResources.getBoolean(R.bool.default_popup_preview)); diff --git a/java/src/com/android/inputmethod/latin/LatinIMESettings.java b/java/src/com/android/inputmethod/latin/LatinIMESettings.java index 4f20e9b10..d8f3ebc51 100644 --- a/java/src/com/android/inputmethod/latin/LatinIMESettings.java +++ b/java/src/com/android/inputmethod/latin/LatinIMESettings.java @@ -25,6 +25,7 @@ import android.app.backup.BackupManager; import android.content.DialogInterface; import android.content.SharedPreferences; import android.os.Bundle; +import android.os.Vibrator; import android.preference.CheckBoxPreference; import android.preference.ListPreference; import android.preference.PreferenceActivity; @@ -47,6 +48,7 @@ public class LatinIMESettings extends PreferenceActivity private static final String PREF_AUTO_COMPLETION_THRESHOLD = "auto_completion_threshold"; private static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion"; /* package */ static final String PREF_SETTINGS_KEY = "settings_key"; + /* package */ static final String PREF_VIBRATE_ON = "vibrate_on"; private static final String TAG = "LatinIMESettings"; @@ -101,6 +103,12 @@ public class LatinIMESettings extends PreferenceActivity R.bool.config_enable_show_settings_key_option); if (!showSettingsKeyOption) getPreferenceScreen().removePreference(mSettingsKeyPreference); + + Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); + if (vibrator == null || !vibrator.hasVibrator()) { + getPreferenceScreen().removePreference( + getPreferenceScreen().findPreference(PREF_VIBRATE_ON)); + } } @Override