Move the correction mode to SettingsValue and make it final
At last this guy is final, at last Change-Id: I76911f8d47493f8a1719f75fc7e949be5d7da1a2
This commit is contained in:
parent
3791183076
commit
4b9e6ee6fb
2 changed files with 21 additions and 21 deletions
|
@ -163,8 +163,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
private WordComposer mWordComposer = new WordComposer();
|
private WordComposer mWordComposer = new WordComposer();
|
||||||
private RichInputConnection mConnection = new RichInputConnection();
|
private RichInputConnection mConnection = new RichInputConnection();
|
||||||
|
|
||||||
private int mCorrectionMode;
|
|
||||||
|
|
||||||
// Keep track of the last selection range to decide if we need to show word alternatives
|
// Keep track of the last selection range to decide if we need to show word alternatives
|
||||||
private static final int NOT_A_CURSOR_POSITION = -1;
|
private static final int NOT_A_CURSOR_POSITION = -1;
|
||||||
private int mLastSelectionStart = NOT_A_CURSOR_POSITION;
|
private int mLastSelectionStart = NOT_A_CURSOR_POSITION;
|
||||||
|
@ -448,11 +446,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
final RunInLocale<SettingsValues> job = new RunInLocale<SettingsValues>() {
|
final RunInLocale<SettingsValues> job = new RunInLocale<SettingsValues>() {
|
||||||
@Override
|
@Override
|
||||||
protected SettingsValues job(Resources res) {
|
protected SettingsValues job(Resources res) {
|
||||||
return new SettingsValues(mPrefs, LatinIME.this);
|
return new SettingsValues(mPrefs, mInputAttributes, LatinIME.this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mSettingsValues = job.runInLocale(mResources, mSubtypeSwitcher.getCurrentSubtypeLocale());
|
mSettingsValues = job.runInLocale(mResources, mSubtypeSwitcher.getCurrentSubtypeLocale());
|
||||||
updateCorrectionMode();
|
|
||||||
mFeedbackManager = new AudioAndHapticFeedbackManager(this, mSettingsValues);
|
mFeedbackManager = new AudioAndHapticFeedbackManager(this, mSettingsValues);
|
||||||
resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
|
resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
|
||||||
}
|
}
|
||||||
|
@ -1092,7 +1089,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean maybeDoubleSpace() {
|
private boolean maybeDoubleSpace() {
|
||||||
if (mCorrectionMode == Suggest.CORRECTION_NONE) return false;
|
if (mSettingsValues.mCorrectionMode == Suggest.CORRECTION_NONE) return false;
|
||||||
final CharSequence lastThree = mConnection.getTextBeforeCursor(3, 0);
|
final CharSequence lastThree = mConnection.getTextBeforeCursor(3, 0);
|
||||||
if (lastThree != null && lastThree.length() == 3
|
if (lastThree != null && lastThree.length() == 3
|
||||||
&& canBeFollowedByPeriod(lastThree.charAt(0))
|
&& canBeFollowedByPeriod(lastThree.charAt(0))
|
||||||
|
@ -1644,8 +1641,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSuggestionsRequested() {
|
public boolean isSuggestionsRequested() {
|
||||||
|
// TODO: move this method to mSettingsValues
|
||||||
return mInputAttributes.mIsSettingsSuggestionStripOn
|
return mInputAttributes.mIsSettingsSuggestionStripOn
|
||||||
&& (mCorrectionMode > 0 || isShowingSuggestionsStrip());
|
&& (mSettingsValues.mCorrectionMode > 0 || isShowingSuggestionsStrip());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShowingPunctuationList() {
|
public boolean isShowingPunctuationList() {
|
||||||
|
@ -1738,7 +1736,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
final CharSequence typedWord = mWordComposer.getTypedWord();
|
final CharSequence typedWord = mWordComposer.getTypedWord();
|
||||||
// getSuggestedWords handles gracefully a null value of prevWord
|
// getSuggestedWords handles gracefully a null value of prevWord
|
||||||
final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer,
|
final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer,
|
||||||
prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), mCorrectionMode);
|
prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(),
|
||||||
|
mSettingsValues.mCorrectionMode);
|
||||||
|
|
||||||
// Basically, we update the suggestion strip only when suggestion count > 1. However,
|
// Basically, we update the suggestion strip only when suggestion count > 1. However,
|
||||||
// there is an exception: We update the suggestion strip whenever typed word's length
|
// there is an exception: We update the suggestion strip whenever typed word's length
|
||||||
|
@ -1962,7 +1961,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
}
|
}
|
||||||
|
|
||||||
final SuggestedWords suggestedWords;
|
final SuggestedWords suggestedWords;
|
||||||
if (mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM) {
|
if (mSettingsValues.mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM) {
|
||||||
final CharSequence prevWord = mConnection.getThisWord(mSettingsValues.mWordSeparators);
|
final CharSequence prevWord = mConnection.getThisWord(mSettingsValues.mWordSeparators);
|
||||||
if (!TextUtils.isEmpty(prevWord)) {
|
if (!TextUtils.isEmpty(prevWord)) {
|
||||||
suggestedWords = mSuggest.getBigramPredictions(prevWord);
|
suggestedWords = mSuggest.getBigramPredictions(prevWord);
|
||||||
|
@ -1994,8 +1993,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
// Only auto-add to dictionary if auto-correct is ON. Otherwise we'll be
|
// Only auto-add to dictionary if auto-correct is ON. Otherwise we'll be
|
||||||
// adding words in situations where the user or application really didn't
|
// adding words in situations where the user or application really didn't
|
||||||
// want corrections enabled or learned.
|
// want corrections enabled or learned.
|
||||||
if (!(mCorrectionMode == Suggest.CORRECTION_FULL
|
if (!(mSettingsValues.mCorrectionMode == Suggest.CORRECTION_FULL
|
||||||
|| mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM)) {
|
|| mSettingsValues.mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2260,15 +2259,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void updateCorrectionMode() {
|
|
||||||
// TODO: cleanup messy flags
|
|
||||||
final boolean shouldAutoCorrect = mSettingsValues.mAutoCorrectEnabled
|
|
||||||
&& !mInputAttributes.mInputTypeNoAutoCorrect;
|
|
||||||
mCorrectionMode = shouldAutoCorrect ? Suggest.CORRECTION_FULL : Suggest.CORRECTION_NONE;
|
|
||||||
mCorrectionMode = (mSettingsValues.mBigramSuggestionEnabled && shouldAutoCorrect)
|
|
||||||
? Suggest.CORRECTION_FULL_BIGRAM : mCorrectionMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateSuggestionVisibility(final Resources res) {
|
private void updateSuggestionVisibility(final Resources res) {
|
||||||
final String suggestionVisiblityStr = mSettingsValues.mShowSuggestionsSetting;
|
final String suggestionVisiblityStr = mSettingsValues.mShowSuggestionsSetting;
|
||||||
for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) {
|
for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) {
|
||||||
|
@ -2356,7 +2346,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
|
final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
|
||||||
p.println(" Keyboard mode = " + keyboardMode);
|
p.println(" Keyboard mode = " + keyboardMode);
|
||||||
p.println(" mIsSuggestionsRequested=" + mInputAttributes.mIsSettingsSuggestionStripOn);
|
p.println(" mIsSuggestionsRequested=" + mInputAttributes.mIsSettingsSuggestionStripOn);
|
||||||
p.println(" mCorrectionMode=" + mCorrectionMode);
|
p.println(" mCorrectionMode=" + mSettingsValues.mCorrectionMode);
|
||||||
p.println(" isComposingWord=" + mWordComposer.isComposingWord());
|
p.println(" isComposingWord=" + mWordComposer.isComposingWord());
|
||||||
p.println(" mAutoCorrectEnabled=" + mSettingsValues.mAutoCorrectEnabled);
|
p.println(" mAutoCorrectEnabled=" + mSettingsValues.mAutoCorrectEnabled);
|
||||||
p.println(" mSoundOn=" + mSettingsValues.mSoundOn);
|
p.println(" mSoundOn=" + mSettingsValues.mSoundOn);
|
||||||
|
|
|
@ -79,10 +79,12 @@ public class SettingsValues {
|
||||||
public final int mKeyPreviewPopupDismissDelay;
|
public final int mKeyPreviewPopupDismissDelay;
|
||||||
public final boolean mAutoCorrectEnabled;
|
public final boolean mAutoCorrectEnabled;
|
||||||
public final float mAutoCorrectionThreshold;
|
public final float mAutoCorrectionThreshold;
|
||||||
|
public final int mCorrectionMode;
|
||||||
private final boolean mVoiceKeyEnabled;
|
private final boolean mVoiceKeyEnabled;
|
||||||
private final boolean mVoiceKeyOnMain;
|
private final boolean mVoiceKeyOnMain;
|
||||||
|
|
||||||
public SettingsValues(final SharedPreferences prefs, final Context context) {
|
public SettingsValues(final SharedPreferences prefs, final InputAttributes inputAttributes,
|
||||||
|
final Context context) {
|
||||||
final Resources res = context.getResources();
|
final Resources res = context.getResources();
|
||||||
|
|
||||||
// Get the resources
|
// Get the resources
|
||||||
|
@ -150,6 +152,7 @@ public class SettingsValues {
|
||||||
mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain);
|
mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain);
|
||||||
mAdditionalSubtypes = AdditionalSubtype.createAdditionalSubtypesArray(
|
mAdditionalSubtypes = AdditionalSubtype.createAdditionalSubtypesArray(
|
||||||
getPrefAdditionalSubtypes(prefs, res));
|
getPrefAdditionalSubtypes(prefs, res));
|
||||||
|
mCorrectionMode = createCorrectionMode(inputAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper functions to create member values.
|
// Helper functions to create member values.
|
||||||
|
@ -183,6 +186,13 @@ public class SettingsValues {
|
||||||
return wordSeparators;
|
return wordSeparators;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int createCorrectionMode(final InputAttributes inputAttributes) {
|
||||||
|
final boolean shouldAutoCorrect = mAutoCorrectEnabled
|
||||||
|
&& !inputAttributes.mInputTypeNoAutoCorrect;
|
||||||
|
if (mBigramSuggestionEnabled && shouldAutoCorrect) return Suggest.CORRECTION_FULL_BIGRAM;
|
||||||
|
return shouldAutoCorrect ? Suggest.CORRECTION_FULL : Suggest.CORRECTION_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isVibrateOn(final Context context, final SharedPreferences prefs,
|
private static boolean isVibrateOn(final Context context, final SharedPreferences prefs,
|
||||||
final Resources res) {
|
final Resources res) {
|
||||||
final boolean hasVibrator = VibratorUtils.getInstance(context).hasVibrator();
|
final boolean hasVibrator = VibratorUtils.getInstance(context).hasVibrator();
|
||||||
|
|
Loading…
Reference in a new issue