aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorsatok <satok@google.com>2011-05-13 18:15:39 +0900
committersatok <satok@google.com>2011-05-13 18:35:09 +0900
commit9467a7a523126ab09a6b1894dab38e4bc4159d4f (patch)
tree0a3c64770c6afd6363556f5ee82deb1be1e089c8 /java/src
parentce1902bb0e87d8da5f96ca87b748fd2c7f60ac1e (diff)
downloadlatinime-9467a7a523126ab09a6b1894dab38e4bc4159d4f.tar.gz
latinime-9467a7a523126ab09a6b1894dab38e4bc4159d4f.tar.xz
latinime-9467a7a523126ab09a6b1894dab38e4bc4159d4f.zip
Update the setting of re-correction when user changed
Bug: 4401929 Change-Id: I5929e44f27ba057201110d814e9ec767d09c0ee7
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/deprecated/recorrection/Recorrection.java44
1 files changed, 32 insertions, 12 deletions
diff --git a/java/src/com/android/inputmethod/deprecated/recorrection/Recorrection.java b/java/src/com/android/inputmethod/deprecated/recorrection/Recorrection.java
index adf4204f8..bf69d5ced 100644
--- a/java/src/com/android/inputmethod/deprecated/recorrection/Recorrection.java
+++ b/java/src/com/android/inputmethod/deprecated/recorrection/Recorrection.java
@@ -42,7 +42,8 @@ import java.util.ArrayList;
/**
* 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 LatinIME mService;
@@ -69,20 +70,17 @@ public class Recorrection {
}
private void initInternal(LatinIME context, SharedPreferences prefs) {
- final Resources res = context.getResources();
- // 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);
+ if (!USE_LEGACY_RECORRECTION) {
+ mRecorrectionEnabled = false;
+ return;
}
+ updateRecorrectionEnabled(context.getResources(), prefs);
mService = context;
+ prefs.registerOnSharedPreferenceChangeListener(this);
}
public void checkRecorrectionOnStart() {
- if (!mRecorrectionEnabled) return;
+ if (!USE_LEGACY_RECORRECTION || !mRecorrectionEnabled) return;
final InputConnection ic = mService.getCurrentInputConnection();
if (ic == null) return;
@@ -112,7 +110,7 @@ public class Recorrection {
CandidateView candidateView, int candidatesStart, int candidatesEnd,
int newSelStart, int newSelEnd, int oldSelStart, int lastSelectionStart,
int lastSelectionEnd, boolean hasUncommittedTypedChars) {
- if (!mRecorrectionEnabled) return;
+ if (!USE_LEGACY_RECORRECTION || !mRecorrectionEnabled) return;
if (!mService.isShowingSuggestionsStrip()) return;
if (!keyboardSwitcher.isInputViewShown()) return;
if (!mService.isSuggestionsRequested()) return;
@@ -144,7 +142,7 @@ public class Recorrection {
}
public void saveRecorrectionSuggestion(WordComposer word, CharSequence result) {
- if (!mRecorrectionEnabled) return;
+ if (!USE_LEGACY_RECORRECTION || !mRecorrectionEnabled) return;
if (word.size() <= 1) {
return;
}
@@ -172,6 +170,7 @@ public class Recorrection {
*/
public boolean applyTypedAlternatives(WordComposer word, Suggest suggest,
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
WordComposer foundWord = null;
RecorrectionSuggestionEntries alternatives = null;
@@ -224,6 +223,7 @@ public class Recorrection {
boolean hasUncommittedTypedChars, int lastSelectionStart, int lastSelectionEnd,
String wordSeparators) {
if (!InputConnectionCompatUtils.RECORRECTION_SUPPORTED) return;
+ if (!USE_LEGACY_RECORRECTION || !mRecorrectionEnabled) return;
voiceProxy.setShowingVoiceSuggestions(false);
if (candidateView != null && candidateView.isShowingAddToDictionaryHint()) {
return;
@@ -257,6 +257,7 @@ public class Recorrection {
}
public void abortRecorrection(boolean force) {
+ if (!USE_LEGACY_RECORRECTION) return;
if (force || TextEntryState.isRecorrecting()) {
TextEntryState.onAbortRecorrection();
mService.setCandidatesViewShown(mService.isCandidateStripVisible());
@@ -264,4 +265,23 @@ public class Recorrection {
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);
+ }
+ }
}