Check the system vibrator availability for the "Vibrate on keypress" preference.

bug: 3021001
Change-Id: I7843a3e4765333c720fd8f258c1fffdf6f090d3a
main
Ken Wakasa 2010-11-11 18:15:41 +09:00
parent ca26f20fa4
commit 4174655e23
2 changed files with 12 additions and 2 deletions

View File

@ -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));

View File

@ -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