Move settings variables to the settings class

Change-Id: Ifa7033a84b08ea626eb44cf6d04ba8e28c250bea
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 985793e..de273b5 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -221,11 +221,9 @@
     private long mLastKeyTime;
 
     private AudioManager mAudioManager;
-    private float mFxVolume = -1.0f; // default volume
     private boolean mSilentModeOn; // System-wide current configuration
 
     private VibratorCompatWrapper mVibrator;
-    private long mKeypressVibrationDuration = -1;
 
     // TODO: Move this flag to VoiceProxy
     private boolean mConfigurationChanging;
@@ -550,8 +548,6 @@
         if (null == mSubtypeSwitcher) mSubtypeSwitcher = SubtypeSwitcher.getInstance();
         mSettingsValues = new SettingsValues(mPrefs, this, mSubtypeSwitcher.getInputLocaleStr());
         resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
-        updateSoundEffectVolume();
-        updateKeypressVibrationDuration();
     }
 
     private void initSuggest() {
@@ -2321,11 +2317,6 @@
         }
     };
 
-    // update keypress sound volume
-    private void updateSoundEffectVolume() {
-        mFxVolume = SettingsValues.getCurrentKeypressSoundVolume(mPrefs, mResources);
-    }
-
     // update flags for silent mode
     private void updateRingerMode() {
         if (mAudioManager == null) {
@@ -2335,10 +2326,6 @@
         mSilentModeOn = (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL);
     }
 
-    private void updateKeypressVibrationDuration() {
-        mKeypressVibrationDuration = SettingsValues.getCurrentVibrationDuration(mPrefs, mResources);
-    }
-
     private void playKeyClick(int primaryCode) {
         // if mAudioManager is null, we don't have the ringer state yet
         // mAudioManager will be set by updateRingerMode
@@ -2363,7 +2350,7 @@
                 sound = AudioManager.FX_KEYPRESS_STANDARD;
                 break;
             }
-            mAudioManager.playSoundEffect(sound, mFxVolume);
+            mAudioManager.playSoundEffect(sound, mSettingsValues.mFxVolume);
         }
     }
 
@@ -2371,7 +2358,7 @@
         if (!mSettingsValues.mVibrateOn) {
             return;
         }
-        if (mKeypressVibrationDuration < 0) {
+        if (mSettingsValues.mKeypressVibrationDuration < 0) {
             // Go ahead with the system default
             LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
             if (inputView != null) {
@@ -2380,7 +2367,7 @@
                         HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
             }
         } else if (mVibrator != null) {
-            mVibrator.vibrate(mKeypressVibrationDuration);
+            mVibrator.vibrate(mSettingsValues.mKeypressVibrationDuration);
         }
     }
 
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index 6558c3c..4166e62 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -543,8 +543,8 @@
         });
         final View v = context.getLayoutInflater().inflate(
                 R.layout.sound_effect_volume_dialog, null);
-        final int currentVolumeInt = (int)(SettingsValues.getCurrentKeypressSoundVolume(
-                getPreferenceManager().getSharedPreferences(), getResources()) * 100);
+        final int currentVolumeInt =
+                (int)(SettingsValues.getCurrentKeypressSoundVolume(sp, res) * 100);
         mKeypressSoundVolumeSettingsTextView =
                 (TextView)v.findViewById(R.id.sound_effect_volume_value);
         final SeekBar sb = (SeekBar)v.findViewById(R.id.sound_effect_volume_bar);
diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java
index 50fa694..62cf4a3 100644
--- a/java/src/com/android/inputmethod/latin/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/SettingsValues.java
@@ -25,7 +25,6 @@
 
 import com.android.inputmethod.compat.InputTypeCompatUtils;
 import com.android.inputmethod.compat.VibratorCompatWrapper;
-import com.android.inputmethod.latin.R.array;
 
 import java.util.Arrays;
 import java.util.Locale;
@@ -62,6 +61,10 @@
     private final boolean mVoiceKeyEnabled;
     private final boolean mVoiceKeyOnMain;
 
+    // Deduced settings
+    public final int mKeypressVibrationDuration;
+    public final float mFxVolume;
+
     public SettingsValues(final SharedPreferences prefs, final Context context,
             final String localeStr) {
         final Resources res = context.getResources();
@@ -122,6 +125,9 @@
         mVoiceKeyEnabled = voiceMode != null && !voiceMode.equals(voiceModeOff);
         mVoiceKeyOnMain = voiceMode != null && voiceMode.equals(voiceModeMain);
 
+        mFxVolume = getCurrentKeypressSoundVolume(prefs, res);
+        mKeypressVibrationDuration = getCurrentVibrationDuration(prefs, res);
+
         LocaleUtils.setSystemLocale(res, savedLocale);
     }
 
@@ -244,7 +250,9 @@
         return mVoiceKeyOnMain;
     }
 
-    public static float getCurrentKeypressSoundVolume(SharedPreferences sp, Resources res) {
+    // Accessed from the settings interface, hence public
+    public static float getCurrentKeypressSoundVolume(final SharedPreferences sp,
+                final Resources res) {
         final float volume = sp.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, -1.0f);
         if (volume >= 0) {
             return volume;
@@ -260,7 +268,9 @@
         return -1.0f;
     }
 
-    public static int getCurrentVibrationDuration(SharedPreferences sp, Resources res) {
+    // Likewise
+    public static int getCurrentVibrationDuration(final SharedPreferences sp,
+                final Resources res) {
         final int ms = sp.getInt(Settings.PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS, -1);
         if (ms >= 0) {
             return ms;