aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java4
-rw-r--r--java/src/com/android/inputmethod/latin/CandidateView.java115
-rw-r--r--java/src/com/android/inputmethod/latin/DictionaryFactory.java14
-rw-r--r--java/src/com/android/inputmethod/latin/ExpandableDictionary.java14
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java8
-rw-r--r--java/src/com/android/inputmethod/latin/LocaleUtils.java51
-rw-r--r--java/src/com/android/inputmethod/latin/Settings.java6
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeSwitcher.java2
-rw-r--r--java/src/com/android/inputmethod/latin/SuggestedWords.java2
-rw-r--r--java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserDictionary.java41
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java34
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java8
12 files changed, 203 insertions, 96 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
index 360c944d2..5546d48c0 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
@@ -157,9 +157,9 @@ class BinaryDictionaryGetter {
private static AssetFileAddress loadFallbackResource(final Context context,
final int fallbackResId, final Locale locale) {
final Resources res = context.getResources();
- final Locale savedLocale = Utils.setSystemLocale(res, locale);
+ final Locale savedLocale = LocaleUtils.setSystemLocale(res, locale);
final AssetFileDescriptor afd = res.openRawResourceFd(fallbackResId);
- Utils.setSystemLocale(res, savedLocale);
+ LocaleUtils.setSystemLocale(res, savedLocale);
if (afd == null) {
Log.e(TAG, "Found the resource but cannot read it. Is it compressed? resId="
diff --git a/java/src/com/android/inputmethod/latin/CandidateView.java b/java/src/com/android/inputmethod/latin/CandidateView.java
index 5f20c70b4..f445abf48 100644
--- a/java/src/com/android/inputmethod/latin/CandidateView.java
+++ b/java/src/com/android/inputmethod/latin/CandidateView.java
@@ -64,6 +64,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
private static final boolean DBG = LatinImeLogger.sDBG;
+ private final ViewGroup mCandidatesPlacer;
private final ViewGroup mCandidatesStrip;
private ViewGroup mCandidatesPane;
private ViewGroup mCandidatesPaneContainer;
@@ -76,13 +77,9 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
private final PopupWindow mPreviewPopup;
private final TextView mPreviewText;
- private final View mTouchToSave;
- private final TextView mWordToSave;
-
private Listener mListener;
private SuggestedWords mSuggestions = SuggestedWords.EMPTY;
private boolean mShowingAutoCorrectionInverted;
- private boolean mShowingAddToDictionary;
private final SuggestionsStripParams mStripParams;
private final SuggestionsPaneParams mPaneParams;
@@ -94,7 +91,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
private static final int MSG_HIDE_PREVIEW = 0;
private static final int MSG_UPDATE_SUGGESTION = 1;
- private static final long DELAY_HIDE_PREVIEW = 1000;
+ private static final long DELAY_HIDE_PREVIEW = 1300;
private static final long DELAY_UPDATE_SUGGESTION = 300;
public UiHandler(CandidateView outerInstance) {
@@ -239,8 +236,8 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
lastView = info;
info.measure(WRAP_CONTENT, WRAP_CONTENT);
final int infoWidth = info.getMeasuredWidth();
- FrameLayoutCompatUtils.placeViewAt(info, x - infoWidth, y, infoWidth,
- info.getMeasuredHeight());
+ FrameLayoutCompatUtils.placeViewAt(
+ info, x - infoWidth, y, infoWidth, info.getMeasuredHeight());
}
}
if (x != 0) {
@@ -274,13 +271,16 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
private static final int AUTO_CORRECT_INVERT = 0x04;
private static final int VALID_TYPED_WORD_BOLD = 0x08;
- private final TextPaint mPaint;
private final int mSuggestionStripOption;
private final ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>();
public boolean mMoreSuggestionsAvailable;
+ public final TextView mWordToSaveView;
+ private final TextView mHintToSaveView;
+ private final CharSequence mHintToSaveText;
+
public SuggestionsStripParams(Context context, AttributeSet attrs, int defStyle,
List<TextView> words, List<View> dividers, List<TextView> infos) {
super(words, dividers, infos);
@@ -305,9 +305,10 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
mInvertedForegroundColorSpan = new ForegroundColorSpan(mColorTypedWord ^ 0x00ffffff);
mInvertedBackgroundColorSpan = new BackgroundColorSpan(mColorTypedWord);
- mPaint = new TextPaint();
- final float textSize = res.getDimension(R.dimen.candidate_text_size);
- mPaint.setTextSize(textSize);
+ final LayoutInflater inflater = LayoutInflater.from(context);
+ mWordToSaveView = (TextView)inflater.inflate(R.layout.candidate_word, null);
+ mHintToSaveView = (TextView)inflater.inflate(R.layout.candidate_word, null);
+ mHintToSaveText = context.getText(R.string.hint_add_to_dictionary);
}
public int getTextColor() {
@@ -366,7 +367,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
final SuggestedWordInfo info = (pos < suggestions.size())
? suggestions.getInfo(pos) : null;
- if (info != null && info.isPreviousSuggestedWord()) {
+ if (info != null && info.isObsoleteSuggestedWord()) {
return applyAlpha(color, 0.5f);
} else {
return color;
@@ -388,7 +389,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
return word;
}
- public int layout(SuggestedWords suggestions, ViewGroup stripView, ViewGroup paneView,
+ public int layout(SuggestedWords suggestions, ViewGroup stripView, ViewGroup placer,
int stripWidth) {
if (suggestions.isPunctuationSuggestions()) {
return layoutPunctuationSuggestions(suggestions, stripView);
@@ -405,6 +406,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
final View divider = mDividers.get(pos);
// Add divider if this isn't the left most suggestion in candidate strip.
stripView.addView(divider);
+ x += divider.getMeasuredWidth();
}
final CharSequence styled = mTexts.get(pos);
@@ -429,18 +431,19 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
word.setTextScaleX(scaleX);
stripView.addView(word);
setLayoutWeight(word, getCandidateWeight(index), MATCH_PARENT);
+ x += word.getMeasuredWidth();
if (DBG) {
final CharSequence debugInfo = getDebugInfo(suggestions, pos);
if (debugInfo != null) {
final TextView info = mInfos.get(pos);
info.setText(debugInfo);
- paneView.addView(info);
+ placer.addView(info);
info.measure(WRAP_CONTENT, WRAP_CONTENT);
final int infoWidth = info.getMeasuredWidth();
final int y = info.getMeasuredHeight();
- FrameLayoutCompatUtils.placeViewAt(info, x, 0, infoWidth, y);
- x += infoWidth * 2;
+ FrameLayoutCompatUtils.placeViewAt(
+ info, x - infoWidth, y, infoWidth, info.getMeasuredHeight());
}
}
}
@@ -498,6 +501,33 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
mMoreSuggestionsAvailable = false;
return countInStrip;
}
+
+ public void layoutAddToDictionaryHint(CharSequence word, ViewGroup stripView,
+ int stripWidth) {
+ final int width = stripWidth - mDividerWidth - mPadding * 2;
+
+ final TextView wordView = mWordToSaveView;
+ wordView.setTextColor(mColorTypedWord);
+ final int wordWidth = (int)(width * mCenterCandidateWeight);
+ final CharSequence text = getEllipsizedText(word, wordWidth, wordView.getPaint());
+ final float wordScaleX = wordView.getTextScaleX();
+ wordView.setTag(word);
+ wordView.setText(text);
+ wordView.setTextScaleX(wordScaleX);
+ stripView.addView(wordView);
+ setLayoutWeight(wordView, mCenterCandidateWeight, MATCH_PARENT);
+
+ stripView.addView(mDividers.get(0));
+
+ final TextView hintView = mHintToSaveView;
+ hintView.setTextColor(mColorAutoCorrect);
+ final int hintWidth = width - wordWidth;
+ final float hintScaleX = getTextScaleX(mHintToSaveText, hintWidth, hintView.getPaint());
+ hintView.setText(mHintToSaveText);
+ hintView.setTextScaleX(hintScaleX);
+ stripView.addView(hintView);
+ setLayoutWeight(hintView, 1.0f - mCenterCandidateWeight, MATCH_PARENT);
+ }
}
/**
@@ -517,7 +547,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
super(context, attrs);
if (defStyle != R.attr.candidateViewStyle) {
throw new IllegalArgumentException(
- "can't accept defStyle other than R.attr.candidayeViewStyle: defStyle="
+ "can't accept defStyle other than R.attr.candidateViewStyle: defStyle="
+ defStyle);
}
setBackgroundDrawable(LinearLayoutCompatUtils.getBackgroundDrawable(
@@ -532,6 +562,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
mPreviewPopup.setContentView(mPreviewText);
mPreviewPopup.setBackgroundDrawable(null);
+ mCandidatesPlacer = (ViewGroup)findViewById(R.id.candidates_placer);
mCandidatesStrip = (ViewGroup)findViewById(R.id.candidates_strip);
for (int pos = 0; pos < MAX_SUGGESTIONS; pos++) {
final TextView word = (TextView)inflater.inflate(R.layout.candidate_word, null);
@@ -546,13 +577,10 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
mInfos.add((TextView)inflater.inflate(R.layout.candidate_info, null));
}
- mTouchToSave = findViewById(R.id.touch_to_save);
- mWordToSave = (TextView)findViewById(R.id.word_to_save);
- mWordToSave.setOnClickListener(this);
-
mStripParams = new SuggestionsStripParams(context, attrs, defStyle, mWords, mDividers,
mInfos);
mPaneParams = new SuggestionsPaneParams(mWords, mDividers, mInfos);
+ mStripParams.mWordToSaveView.setOnClickListener(this);
}
/**
@@ -588,7 +616,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
final int width = getWidth();
final int countInStrip = mStripParams.layout(
- mSuggestions, mCandidatesStrip, mCandidatesPane, width);
+ mSuggestions, mCandidatesStrip, mCandidatesPlacer, width);
mPaneParams.layout(
mSuggestions, mCandidatesPane, countInStrip, mStripParams.getTextColor(), width);
}
@@ -636,6 +664,15 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
}
}
+ private static float getTextScaleX(CharSequence text, int maxWidth, TextPaint paint) {
+ paint.setTextScaleX(1.0f);
+ final int width = getTextWidth(text, paint);
+ if (width <= maxWidth) {
+ return 1.0f;
+ }
+ return maxWidth / (float)width;
+ }
+
private static CharSequence getEllipsizedText(CharSequence text, int maxWidth,
TextPaint paint) {
if (text == null) return null;
@@ -718,20 +755,21 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
}
public boolean isShowingAddToDictionaryHint() {
- return mShowingAddToDictionary;
+ return mCandidatesStrip.getChildCount() > 0
+ && mCandidatesStrip.getChildAt(0) == mStripParams.mWordToSaveView;
}
public void showAddToDictionaryHint(CharSequence word) {
- mWordToSave.setText(word);
- mShowingAddToDictionary = true;
- mCandidatesStrip.setVisibility(GONE);
- mTouchToSave.setVisibility(VISIBLE);
+ clear();
+ mStripParams.layoutAddToDictionaryHint(word, mCandidatesStrip, getWidth());
}
public boolean dismissAddToDictionaryHint() {
- if (!mShowingAddToDictionary) return false;
- clear();
- return true;
+ if (isShowingAddToDictionaryHint()) {
+ clear();
+ return true;
+ }
+ return false;
}
public SuggestedWords getSuggestions() {
@@ -739,10 +777,9 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
}
public void clear() {
- mShowingAddToDictionary = false;
mShowingAutoCorrectionInverted = false;
- mTouchToSave.setVisibility(GONE);
- mCandidatesStrip.setVisibility(VISIBLE);
+ mCandidatesPlacer.removeAllViews();
+ mCandidatesPlacer.addView(mCandidatesStrip);
mCandidatesStrip.removeAllViews();
mCandidatesPane.removeAllViews();
closeCandidatesPane();
@@ -752,7 +789,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
mPreviewPopup.dismiss();
}
- private void showPreview(int index, CharSequence word) {
+ private void showPreview(View view, CharSequence word) {
if (TextUtils.isEmpty(word))
return;
@@ -761,9 +798,8 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
previewText.setText(word);
previewText.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
- View v = mWords.get(index);
final int[] offsetInWindow = new int[2];
- v.getLocationInWindow(offsetInWindow);
+ view.getLocationInWindow(offsetInWindow);
final int posX = offsetInWindow[0];
final int posY = offsetInWindow[1] - previewText.getMeasuredHeight();
final PopupWindow previewPopup = mPreviewPopup;
@@ -778,7 +814,8 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
private void addToDictionary(CharSequence word) {
if (mListener.addWordToDictionary(word.toString())) {
- showPreview(0, getContext().getString(R.string.added_word, word));
+ final CharSequence message = getContext().getString(R.string.added_word, word);
+ showPreview(mStripParams.mWordToSaveView, message);
}
}
@@ -793,8 +830,8 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
@Override
public void onClick(View view) {
- if (view == mWordToSave) {
- addToDictionary(((TextView)view).getText());
+ if (view == mStripParams.mWordToSaveView) {
+ addToDictionary((CharSequence)view.getTag());
clear();
return;
}
diff --git a/java/src/com/android/inputmethod/latin/DictionaryFactory.java b/java/src/com/android/inputmethod/latin/DictionaryFactory.java
index 9642151d7..dfaad26bc 100644
--- a/java/src/com/android/inputmethod/latin/DictionaryFactory.java
+++ b/java/src/com/android/inputmethod/latin/DictionaryFactory.java
@@ -83,9 +83,9 @@ public class DictionaryFactory {
try {
final Resources res = context.getResources();
if (null != locale) {
- final Locale savedLocale = Utils.setSystemLocale(res, locale);
+ final Locale savedLocale = LocaleUtils.setSystemLocale(res, locale);
afd = res.openRawResourceFd(resId);
- Utils.setSystemLocale(res, savedLocale);
+ LocaleUtils.setSystemLocale(res, savedLocale);
} else {
afd = res.openRawResourceFd(resId);
}
@@ -145,7 +145,7 @@ public class DictionaryFactory {
*/
public static boolean isDictionaryAvailable(Context context, Locale locale) {
final Resources res = context.getResources();
- final Locale saveLocale = Utils.setSystemLocale(res, locale);
+ final Locale saveLocale = LocaleUtils.setSystemLocale(res, locale);
final int resourceId = Utils.getMainDictionaryResourceId(res);
final AssetFileDescriptor afd = res.openRawResourceFd(resourceId);
@@ -156,14 +156,14 @@ public class DictionaryFactory {
/* Um, what can we do here exactly? */
}
- Utils.setSystemLocale(res, saveLocale);
+ LocaleUtils.setSystemLocale(res, saveLocale);
return hasDictionary;
}
// TODO: Do not use the size of the dictionary as an unique dictionary ID.
- public static Long getDictionaryId(Context context, Locale locale) {
+ public static Long getDictionaryId(final Context context, final Locale locale) {
final Resources res = context.getResources();
- final Locale saveLocale = Utils.setSystemLocale(res, locale);
+ final Locale saveLocale = LocaleUtils.setSystemLocale(res, locale);
final int resourceId = Utils.getMainDictionaryResourceId(res);
final AssetFileDescriptor afd = res.openRawResourceFd(resourceId);
@@ -175,7 +175,7 @@ public class DictionaryFactory {
} catch (java.io.IOException e) {
}
- Utils.setSystemLocale(res, saveLocale);
+ LocaleUtils.setSystemLocale(res, saveLocale);
return size;
}
diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
index 9f4777f5a..2b78b9065 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
@@ -202,7 +202,11 @@ public class ExpandableDictionary extends Dictionary {
// Currently updating contacts, don't return any results.
if (mUpdatingDictionary) return;
}
+ getWordsInner(codes, callback, proximityInfo);
+ }
+ protected final void getWordsInner(final WordComposer codes, final WordCallback callback,
+ final ProximityInfo proximityInfo) {
mInputLength = codes.size();
if (mCodes.length < mInputLength) mCodes = new int[mInputLength][];
// Cache the codes so that we don't have to lookup an array list
@@ -223,8 +227,7 @@ public class ExpandableDictionary extends Dictionary {
if (mRequiresReload) startDictionaryLoadingTaskLocked();
if (mUpdatingDictionary) return false;
}
- final int freq = getWordFrequency(word);
- return freq > -1;
+ return getWordFrequency(word) > -1;
}
/**
@@ -464,7 +467,7 @@ public class ExpandableDictionary extends Dictionary {
}
/**
- * Used only for testing purposes
+ * Used for testing purposes and in the spell checker
* This function will wait for loading from database to be done
*/
void waitForDictionaryLoading() {
@@ -477,6 +480,11 @@ public class ExpandableDictionary extends Dictionary {
}
}
+ protected final void blockingReloadDictionaryIfRequired() {
+ reloadDictionaryIfRequired();
+ waitForDictionaryLoading();
+ }
+
// Local to reverseLookUp, but do not allocate each time.
private final char[] mLookedUpString = new char[MAX_WORD_LENGTH];
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 552517bc8..229bf0f4c 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -479,10 +479,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private void initSuggest() {
final String localeStr = mSubtypeSwitcher.getInputLocaleStr();
- final Locale keyboardLocale = Utils.constructLocaleFromString(localeStr);
+ final Locale keyboardLocale = LocaleUtils.constructLocaleFromString(localeStr);
final Resources res = mResources;
- final Locale savedLocale = Utils.setSystemLocale(res, keyboardLocale);
+ final Locale savedLocale = LocaleUtils.setSystemLocale(res, keyboardLocale);
final ContactsDictionary oldContactsDictionary;
if (mSuggest != null) {
oldContactsDictionary = mSuggest.getContactsDictionary();
@@ -514,7 +514,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
updateCorrectionMode();
- Utils.setSystemLocale(res, savedLocale);
+ LocaleUtils.setSystemLocale(res, savedLocale);
}
/**
@@ -551,7 +551,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
/* package private */ void resetSuggestMainDict() {
final String localeStr = mSubtypeSwitcher.getInputLocaleStr();
- final Locale keyboardLocale = Utils.constructLocaleFromString(localeStr);
+ final Locale keyboardLocale = LocaleUtils.constructLocaleFromString(localeStr);
int mainDicResId = Utils.getMainDictionaryResourceId(mResources);
mSuggest.resetMainDict(this, mainDicResId, keyboardLocale);
}
diff --git a/java/src/com/android/inputmethod/latin/LocaleUtils.java b/java/src/com/android/inputmethod/latin/LocaleUtils.java
index 054f1f9b8..efa9bfee3 100644
--- a/java/src/com/android/inputmethod/latin/LocaleUtils.java
+++ b/java/src/com/android/inputmethod/latin/LocaleUtils.java
@@ -16,8 +16,13 @@
package com.android.inputmethod.latin;
+import android.content.res.Configuration;
+import android.content.res.Resources;
import android.text.TextUtils;
+import java.util.HashMap;
+import java.util.Locale;
+
/**
* A class to help with handling Locales in string form.
*
@@ -30,6 +35,10 @@ public class LocaleUtils {
private final static String TAG = LocaleUtils.class.getSimpleName();
+ private LocaleUtils() {
+ // Intentional empty constructor for utility class.
+ }
+
// Locale match level constants.
// A higher level of match is guaranteed to have a higher numerical value.
// Some room is left within constants to add match cases that may arise necessary
@@ -154,4 +163,46 @@ public class LocaleUtils {
public static boolean isMatch(int level) {
return LOCALE_MATCH <= level;
}
+
+ /**
+ * Sets the system locale for this process.
+ *
+ * @param res the resources to use. Pass current resources.
+ * @param newLocale the locale to change to.
+ * @return the old locale.
+ */
+ public static Locale setSystemLocale(final Resources res, final Locale newLocale) {
+ final Configuration conf = res.getConfiguration();
+ final Locale saveLocale = conf.locale;
+ conf.locale = newLocale;
+ res.updateConfiguration(conf, res.getDisplayMetrics());
+ return saveLocale;
+ }
+
+ private static final HashMap<String, Locale> sLocaleCache = new HashMap<String, Locale>();
+
+ /**
+ * Creates a locale from a string specification.
+ */
+ public static Locale constructLocaleFromString(final String localeStr) {
+ if (localeStr == null)
+ return null;
+ synchronized (sLocaleCache) {
+ if (sLocaleCache.containsKey(localeStr))
+ return sLocaleCache.get(localeStr);
+ Locale retval = null;
+ String[] localeParams = localeStr.split("_", 3);
+ if (localeParams.length == 1) {
+ retval = new Locale(localeParams[0]);
+ } else if (localeParams.length == 2) {
+ retval = new Locale(localeParams[0], localeParams[1]);
+ } else if (localeParams.length == 3) {
+ retval = new Locale(localeParams[0], localeParams[1], localeParams[2]);
+ }
+ if (retval != null) {
+ sLocaleCache.put(localeStr, retval);
+ }
+ return retval;
+ }
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index 87a713f5c..a5eed9015 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -128,8 +128,8 @@ public class Settings extends InputMethodSettingsActivity
final Resources res = context.getResources();
final Locale savedLocale;
if (null != localeStr) {
- final Locale keyboardLocale = Utils.constructLocaleFromString(localeStr);
- savedLocale = Utils.setSystemLocale(res, keyboardLocale);
+ final Locale keyboardLocale = LocaleUtils.constructLocaleFromString(localeStr);
+ savedLocale = LocaleUtils.setSystemLocale(res, keyboardLocale);
} else {
savedLocale = null;
}
@@ -191,7 +191,7 @@ public class Settings extends InputMethodSettingsActivity
mVoiceKeyEnabled = voiceMode != null && !voiceMode.equals(voiceModeOff);
mVoiceKeyOnMain = voiceMode != null && voiceMode.equals(voiceModeMain);
- Utils.setSystemLocale(res, savedLocale);
+ LocaleUtils.setSystemLocale(res, savedLocale);
}
public boolean isSuggestedPunctuation(int code) {
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index d969e39eb..87d854940 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -267,7 +267,7 @@ public class SubtypeSwitcher {
// "en" --> language: en
// "" --> the system locale
if (!TextUtils.isEmpty(inputLocaleStr)) {
- mInputLocale = Utils.constructLocaleFromString(inputLocaleStr);
+ mInputLocale = LocaleUtils.constructLocaleFromString(inputLocaleStr);
mInputLocaleStr = inputLocaleStr;
} else {
mInputLocale = mSystemLocale;
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index c1c46fa47..b177d144a 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -199,7 +199,7 @@ public class SuggestedWords {
}
}
- public boolean isPreviousSuggestedWord () {
+ public boolean isObsoleteSuggestedWord () {
return mPreviousSuggestedWord;
}
}
diff --git a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserDictionary.java b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserDictionary.java
new file mode 100644
index 000000000..4a812b3a9
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserDictionary.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.inputmethod.latin;
+
+import android.content.Context;
+
+import com.android.inputmethod.keyboard.ProximityInfo;
+
+public class SynchronouslyLoadedUserDictionary extends UserDictionary {
+
+ public SynchronouslyLoadedUserDictionary(final Context context, final String locale) {
+ super(context, locale);
+ }
+
+ @Override
+ public void getWords(final WordComposer codes, final WordCallback callback,
+ final ProximityInfo proximityInfo) {
+ blockingReloadDictionaryIfRequired();
+ getWordsInner(codes, callback, proximityInfo);
+ }
+
+ @Override
+ public synchronized boolean isValidWord(CharSequence word) {
+ blockingReloadDictionaryIfRequired();
+ return getWordFrequency(word) > -1;
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index ff051dcbb..60a4cfb38 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -705,38 +705,6 @@ public class Utils {
return (int) (dip * scale + 0.5);
}
- public static Locale setSystemLocale(Resources res, Locale newLocale) {
- final Configuration conf = res.getConfiguration();
- final Locale saveLocale = conf.locale;
- conf.locale = newLocale;
- res.updateConfiguration(conf, res.getDisplayMetrics());
- return saveLocale;
- }
-
- private static final HashMap<String, Locale> sLocaleCache = new HashMap<String, Locale>();
-
- public static Locale constructLocaleFromString(String localeStr) {
- if (localeStr == null)
- return null;
- synchronized (sLocaleCache) {
- if (sLocaleCache.containsKey(localeStr))
- return sLocaleCache.get(localeStr);
- Locale retval = null;
- String[] localeParams = localeStr.split("_", 3);
- if (localeParams.length == 1) {
- retval = new Locale(localeParams[0]);
- } else if (localeParams.length == 2) {
- retval = new Locale(localeParams[0], localeParams[1]);
- } else if (localeParams.length == 3) {
- retval = new Locale(localeParams[0], localeParams[1], localeParams[2]);
- }
- if (retval != null) {
- sLocaleCache.put(localeStr, retval);
- }
- return retval;
- }
- }
-
/**
* Remove duplicates from an array of strings.
*
@@ -783,7 +751,7 @@ public class Utils {
}
public static String getMiddleDisplayLanguage(Locale locale) {
- return toTitleCase((constructLocaleFromString(
+ return toTitleCase((LocaleUtils.constructLocaleFromString(
locale.getLanguage()).getDisplayLanguage(locale)), locale);
}
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
index 502ebb52a..a6a5b6dd6 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -33,6 +33,8 @@ import com.android.inputmethod.latin.Dictionary.DataType;
import com.android.inputmethod.latin.Dictionary.WordCallback;
import com.android.inputmethod.latin.DictionaryCollection;
import com.android.inputmethod.latin.DictionaryFactory;
+import com.android.inputmethod.latin.LocaleUtils;
+import com.android.inputmethod.latin.SynchronouslyLoadedUserDictionary;
import com.android.inputmethod.latin.UserDictionary;
import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.WordComposer;
@@ -139,7 +141,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
private DictionaryPool getDictionaryPool(final String locale) {
DictionaryPool pool = mDictionaryPools.get(locale);
if (null == pool) {
- final Locale localeObject = Utils.constructLocaleFromString(locale);
+ final Locale localeObject = LocaleUtils.constructLocaleFromString(locale);
pool = new DictionaryPool(POOL_SIZE, this, localeObject);
mDictionaryPools.put(locale, pool);
}
@@ -155,7 +157,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
final String localeStr = locale.toString();
Dictionary userDict = mUserDictionaries.get(localeStr);
if (null == userDict) {
- userDict = new UserDictionary(this, localeStr);
+ userDict = new SynchronouslyLoadedUserDictionary(this, localeStr);
mUserDictionaries.put(localeStr, userDict);
}
dictionaryCollection.addDictionary(userDict);
@@ -172,7 +174,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
public void onCreate() {
final String localeString = getLocale();
mDictionaryPool = getDictionaryPool(localeString);
- mLocale = Utils.constructLocaleFromString(localeString);
+ mLocale = LocaleUtils.constructLocaleFromString(localeString);
}
// Note : this must be reentrant