am c207e0a7: Move settings variables to the settings class

* commit 'c207e0a7dad0bdae054be47cafe878698f9401fc':
  Move settings variables to the settings class
main
Jean Chalard 2011-12-09 11:00:47 -08:00 committed by Android Git Automerger
commit e092f8145f
3 changed files with 18 additions and 21 deletions

View File

@ -221,11 +221,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
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 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
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 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
};
// 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 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
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 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
sound = AudioManager.FX_KEYPRESS_STANDARD;
break;
}
mAudioManager.playSoundEffect(sound, mFxVolume);
mAudioManager.playSoundEffect(sound, mSettingsValues.mFxVolume);
}
}
@ -2371,7 +2358,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
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 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}
} else if (mVibrator != null) {
mVibrator.vibrate(mKeypressVibrationDuration);
mVibrator.vibrate(mSettingsValues.mKeypressVibrationDuration);
}
}

View File

@ -543,8 +543,8 @@ public class Settings extends InputMethodSettingsActivity
});
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);

View File

@ -25,7 +25,6 @@ import android.view.inputmethod.EditorInfo;
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 @@ public class SettingsValues {
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 @@ public class SettingsValues {
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 @@ public class SettingsValues {
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 @@ public class SettingsValues {
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;