Merge "Move suggestion strip visibility to SettingsValues"

This commit is contained in:
Jean Chalard 2012-06-11 18:18:50 -07:00 committed by Android (Google) Code Review
commit 64913d72bc
2 changed files with 33 additions and 29 deletions

View File

@ -102,21 +102,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
*/
private static final String SCHEME_PACKAGE = "package";
// TODO: migrate this to SettingsValues
private int mSuggestionVisibility;
private static final int SUGGESTION_VISIBILITY_SHOW_VALUE
= R.string.prefs_suggestion_visibility_show_value;
private static final int SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE
= R.string.prefs_suggestion_visibility_show_only_portrait_value;
private static final int SUGGESTION_VISIBILITY_HIDE_VALUE
= R.string.prefs_suggestion_visibility_hide_value;
private static final int[] SUGGESTION_VISIBILITY_VALUE_ARRAY = new int[] {
SUGGESTION_VISIBILITY_SHOW_VALUE,
SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE,
SUGGESTION_VISIBILITY_HIDE_VALUE
};
private static final int SPACE_STATE_NONE = 0;
// Double space: the state where the user pressed space twice quickly, which LatinIME
// resolved as period-space. Undoing this converts the period to a space.
@ -694,7 +679,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mSpaceState = SPACE_STATE_NONE;
loadSettings();
updateSuggestionVisibility(mResources);
if (mSuggest != null && mSettingsValues.mAutoCorrectEnabled) {
mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold);
@ -1650,9 +1634,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
public boolean isShowingSuggestionsStrip() {
return (mSuggestionVisibility == SUGGESTION_VISIBILITY_SHOW_VALUE)
|| (mSuggestionVisibility == SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE
&& mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT);
return mSettingsValues.isSuggestionStripVisibleInOrientation(mDisplayOrientation);
}
public boolean isSuggestionsStripVisible() {
@ -2257,16 +2239,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
};
private void updateSuggestionVisibility(final Resources res) {
final String suggestionVisiblityStr = mSettingsValues.mShowSuggestionsSetting;
for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) {
if (suggestionVisiblityStr.equals(res.getString(visibility))) {
mSuggestionVisibility = visibility;
break;
}
}
}
private void launchSettings() {
launchSettingsClass(SettingsActivity.class);
}

View File

@ -18,6 +18,7 @@ package com.android.inputmethod.latin;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.util.Log;
import android.view.inputmethod.EditorInfo;
@ -37,6 +38,19 @@ import java.util.HashMap;
public class SettingsValues {
private static final String TAG = SettingsValues.class.getSimpleName();
private static final int SUGGESTION_VISIBILITY_SHOW_VALUE
= R.string.prefs_suggestion_visibility_show_value;
private static final int SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE
= R.string.prefs_suggestion_visibility_show_only_portrait_value;
private static final int SUGGESTION_VISIBILITY_HIDE_VALUE
= R.string.prefs_suggestion_visibility_hide_value;
private static final int[] SUGGESTION_VISIBILITY_VALUE_ARRAY = new int[] {
SUGGESTION_VISIBILITY_SHOW_VALUE,
SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE,
SUGGESTION_VISIBILITY_HIDE_VALUE
};
// From resources:
public final int mDelayUpdateOldSuggestions;
public final String mWeakSpaceStrippers;
@ -80,6 +94,7 @@ public class SettingsValues {
public final boolean mAutoCorrectEnabled;
public final float mAutoCorrectionThreshold;
public final int mCorrectionMode;
public final int mSuggestionVisibility;
private final boolean mVoiceKeyEnabled;
private final boolean mVoiceKeyOnMain;
@ -153,6 +168,7 @@ public class SettingsValues {
mAdditionalSubtypes = AdditionalSubtype.createAdditionalSubtypesArray(
getPrefAdditionalSubtypes(prefs, res));
mCorrectionMode = createCorrectionMode(inputAttributes);
mSuggestionVisibility = createSuggestionVisibility(res);
}
// Helper functions to create member values.
@ -193,6 +209,16 @@ public class SettingsValues {
return shouldAutoCorrect ? Suggest.CORRECTION_FULL : Suggest.CORRECTION_NONE;
}
private int createSuggestionVisibility(final Resources res) {
final String suggestionVisiblityStr = mShowSuggestionsSetting;
for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) {
if (suggestionVisiblityStr.equals(res.getString(visibility))) {
return visibility;
}
}
throw new RuntimeException("Bug: visibility string is not configured correctly");
}
private static boolean isVibrateOn(final Context context, final SharedPreferences prefs,
final Resources res) {
final boolean hasVibrator = VibratorUtils.getInstance(context).hasVibrator();
@ -200,6 +226,12 @@ public class SettingsValues {
res.getBoolean(R.bool.config_default_vibration_enabled));
}
public boolean isSuggestionStripVisibleInOrientation(final int orientation) {
return (mSuggestionVisibility == SUGGESTION_VISIBILITY_SHOW_VALUE)
|| (mSuggestionVisibility == SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE
&& orientation == Configuration.ORIENTATION_PORTRAIT);
}
public boolean isWordSeparator(int code) {
return mWordSeparators.contains(String.valueOf((char)code));
}