Merge "Update the setting of re-correction when user changed"

main
satok 2011-05-13 03:19:18 -07:00 committed by Android (Google) Code Review
commit 950def1df3
1 changed files with 32 additions and 12 deletions

View File

@ -42,7 +42,8 @@ import java.util.ArrayList;
/** /**
* Manager of re-correction functionalities * Manager of re-correction functionalities
*/ */
public class Recorrection { public class Recorrection implements SharedPreferences.OnSharedPreferenceChangeListener {
public static final boolean USE_LEGACY_RECORRECTION = true;
private static final Recorrection sInstance = new Recorrection(); private static final Recorrection sInstance = new Recorrection();
private LatinIME mService; private LatinIME mService;
@ -69,20 +70,17 @@ public class Recorrection {
} }
private void initInternal(LatinIME context, SharedPreferences prefs) { private void initInternal(LatinIME context, SharedPreferences prefs) {
final Resources res = context.getResources(); if (!USE_LEGACY_RECORRECTION) {
// If the option should not be shown, do not read the re-correction preference mRecorrectionEnabled = false;
// but always use the default setting defined in the resources. return;
if (res.getBoolean(R.bool.config_enable_show_recorrection_option)) {
mRecorrectionEnabled = prefs.getBoolean(Settings.PREF_RECORRECTION_ENABLED,
res.getBoolean(R.bool.config_default_recorrection_enabled));
} else {
mRecorrectionEnabled = res.getBoolean(R.bool.config_default_recorrection_enabled);
} }
updateRecorrectionEnabled(context.getResources(), prefs);
mService = context; mService = context;
prefs.registerOnSharedPreferenceChangeListener(this);
} }
public void checkRecorrectionOnStart() { public void checkRecorrectionOnStart() {
if (!mRecorrectionEnabled) return; if (!USE_LEGACY_RECORRECTION || !mRecorrectionEnabled) return;
final InputConnection ic = mService.getCurrentInputConnection(); final InputConnection ic = mService.getCurrentInputConnection();
if (ic == null) return; if (ic == null) return;
@ -112,7 +110,7 @@ public class Recorrection {
CandidateView candidateView, int candidatesStart, int candidatesEnd, CandidateView candidateView, int candidatesStart, int candidatesEnd,
int newSelStart, int newSelEnd, int oldSelStart, int lastSelectionStart, int newSelStart, int newSelEnd, int oldSelStart, int lastSelectionStart,
int lastSelectionEnd, boolean hasUncommittedTypedChars) { int lastSelectionEnd, boolean hasUncommittedTypedChars) {
if (!mRecorrectionEnabled) return; if (!USE_LEGACY_RECORRECTION || !mRecorrectionEnabled) return;
if (!mService.isShowingSuggestionsStrip()) return; if (!mService.isShowingSuggestionsStrip()) return;
if (!keyboardSwitcher.isInputViewShown()) return; if (!keyboardSwitcher.isInputViewShown()) return;
if (!mService.isSuggestionsRequested()) return; if (!mService.isSuggestionsRequested()) return;
@ -144,7 +142,7 @@ public class Recorrection {
} }
public void saveRecorrectionSuggestion(WordComposer word, CharSequence result) { public void saveRecorrectionSuggestion(WordComposer word, CharSequence result) {
if (!mRecorrectionEnabled) return; if (!USE_LEGACY_RECORRECTION || !mRecorrectionEnabled) return;
if (word.size() <= 1) { if (word.size() <= 1) {
return; return;
} }
@ -172,6 +170,7 @@ public class Recorrection {
*/ */
public boolean applyTypedAlternatives(WordComposer word, Suggest suggest, public boolean applyTypedAlternatives(WordComposer word, Suggest suggest,
KeyboardSwitcher keyboardSwitcher, EditingUtils.SelectedWord touching) { KeyboardSwitcher keyboardSwitcher, EditingUtils.SelectedWord touching) {
if (!USE_LEGACY_RECORRECTION || !mRecorrectionEnabled) return false;
// If we didn't find a match, search for result in typed word history // If we didn't find a match, search for result in typed word history
WordComposer foundWord = null; WordComposer foundWord = null;
RecorrectionSuggestionEntries alternatives = null; RecorrectionSuggestionEntries alternatives = null;
@ -224,6 +223,7 @@ public class Recorrection {
boolean hasUncommittedTypedChars, int lastSelectionStart, int lastSelectionEnd, boolean hasUncommittedTypedChars, int lastSelectionStart, int lastSelectionEnd,
String wordSeparators) { String wordSeparators) {
if (!InputConnectionCompatUtils.RECORRECTION_SUPPORTED) return; if (!InputConnectionCompatUtils.RECORRECTION_SUPPORTED) return;
if (!USE_LEGACY_RECORRECTION || !mRecorrectionEnabled) return;
voiceProxy.setShowingVoiceSuggestions(false); voiceProxy.setShowingVoiceSuggestions(false);
if (candidateView != null && candidateView.isShowingAddToDictionaryHint()) { if (candidateView != null && candidateView.isShowingAddToDictionaryHint()) {
return; return;
@ -257,6 +257,7 @@ public class Recorrection {
} }
public void abortRecorrection(boolean force) { public void abortRecorrection(boolean force) {
if (!USE_LEGACY_RECORRECTION) return;
if (force || TextEntryState.isRecorrecting()) { if (force || TextEntryState.isRecorrecting()) {
TextEntryState.onAbortRecorrection(); TextEntryState.onAbortRecorrection();
mService.setCandidatesViewShown(mService.isCandidateStripVisible()); mService.setCandidatesViewShown(mService.isCandidateStripVisible());
@ -264,4 +265,23 @@ public class Recorrection {
mService.clearSuggestions(); mService.clearSuggestions();
} }
} }
public void updateRecorrectionEnabled(Resources res, SharedPreferences prefs) {
// If the option should not be shown, do not read the re-correction preference
// but always use the default setting defined in the resources.
if (res.getBoolean(R.bool.config_enable_show_recorrection_option)) {
mRecorrectionEnabled = prefs.getBoolean(Settings.PREF_RECORRECTION_ENABLED,
res.getBoolean(R.bool.config_default_recorrection_enabled));
} else {
mRecorrectionEnabled = res.getBoolean(R.bool.config_default_recorrection_enabled);
}
}
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (!USE_LEGACY_RECORRECTION) return;
if (key.equals(Settings.PREF_RECORRECTION_ENABLED)) {
updateRecorrectionEnabled(mService.getResources(), prefs);
}
}
} }