diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
9 files changed, 96 insertions, 48 deletions
diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java index ae2ee577f..fd81d13ca 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java @@ -18,6 +18,7 @@ package com.android.inputmethod.latin; import android.content.Context; import android.text.TextUtils; +import android.util.Log; import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; @@ -31,6 +32,7 @@ import java.util.LinkedList; * be searched for suggestions and valid words. */ public class ExpandableDictionary extends Dictionary { + private static final String TAG = ExpandableDictionary.class.getSimpleName(); /** * The weight to give to a word if it's length is the same as the number of typed characters. */ @@ -551,8 +553,13 @@ public class ExpandableDictionary extends Dictionary { // word. We do want however to return the correct case for the right hand side. // So we want to squash the case of the left hand side, and preserve that of the right // hand side word. - Node firstWord = searchWord(mRoots, word1.toLowerCase(), 0, null); - Node secondWord = searchWord(mRoots, word2, 0, null); + final String word1Lower = word1.toLowerCase(); + if (TextUtils.isEmpty(word1Lower) || TextUtils.isEmpty(word2)) { + Log.e(TAG, "Invalid bigram pair: " + word1 + ", " + word1Lower + ", " + word2); + return frequency; + } + final Node firstWord = searchWord(mRoots, word1Lower, 0, null); + final Node secondWord = searchWord(mRoots, word2, 0, null); LinkedList<NextWord> bigrams = firstWord.mNGrams; if (bigrams == null || bigrams.size() == 0) { firstWord.mNGrams = CollectionUtils.newLinkedList(); diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index e3650d9cc..92b68dcd7 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -156,7 +156,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction private PositionalInfoForUserDictPendingAddition mPositionalInfoForUserDictPendingAddition = null; private final WordComposer mWordComposer = new WordComposer(); - private RichInputConnection mConnection = new RichInputConnection(this); + private final RichInputConnection mConnection = new RichInputConnection(this); // 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; @@ -803,10 +803,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction @Override public void onWindowHidden() { - if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { - ResearchLogger.latinIME_onWindowHidden(mLastSelectionStart, mLastSelectionEnd, - getCurrentInputConnection()); - } super.onWindowHidden(); final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView(); if (mainKeyboardView != null) { @@ -834,8 +830,10 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // Remove pending messages related to update suggestions mHandler.cancelUpdateSuggestionStrip(); resetComposingState(true /* alsoResetLastComposedWord */); + // Notify ResearchLogger if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { - ResearchLogger.getInstance().latinIME_onFinishInputViewInternal(); + ResearchLogger.latinIME_onFinishInputViewInternal(finishingInput, mLastSelectionStart, + mLastSelectionEnd, getCurrentInputConnection()); } } @@ -2297,25 +2295,27 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // expect to receive non-words. if (!mSettings.getCurrent().mCorrectionEnabled) return null; + final Suggest suggest = mSuggest; final UserHistoryDictionary userHistoryDictionary = mUserHistoryDictionary; - if (userHistoryDictionary != null) { - final String prevWord - = mConnection.getNthPreviousWord(mSettings.getCurrent().mWordSeparators, 2); - final String secondWord; - if (mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps()) { - secondWord = suggestion.toLowerCase(mSubtypeSwitcher.getCurrentSubtypeLocale()); - } else { - secondWord = suggestion; - } - // We demote unrecognized words (frequency < 0, below) by specifying them as "invalid". - // We don't add words with 0-frequency (assuming they would be profanity etc.). - final int maxFreq = AutoCorrection.getMaxFrequency( - mSuggest.getUnigramDictionaries(), suggestion); - if (maxFreq == 0) return null; - userHistoryDictionary.addToUserHistory(prevWord, secondWord, maxFreq > 0); - return prevWord; + if (suggest == null || userHistoryDictionary == null) { + // Avoid concurrent issue + return null; + } + final String prevWord + = mConnection.getNthPreviousWord(mSettings.getCurrent().mWordSeparators, 2); + final String secondWord; + if (mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps()) { + secondWord = suggestion.toLowerCase(mSubtypeSwitcher.getCurrentSubtypeLocale()); + } else { + secondWord = suggestion; } - return null; + // We demote unrecognized words (frequency < 0, below) by specifying them as "invalid". + // We don't add words with 0-frequency (assuming they would be profanity etc.). + final int maxFreq = AutoCorrection.getMaxFrequency( + suggest.getUnigramDictionaries(), suggestion); + if (maxFreq == 0) return null; + userHistoryDictionary.addToUserHistory(prevWord, secondWord, maxFreq > 0); + return prevWord; } /** @@ -2526,7 +2526,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction final CharSequence[] items = new CharSequence[] { // TODO: Should use new string "Select active input modes". getString(R.string.language_selection_title), - getString(R.string.english_ime_settings), + getString(Utils.getAcitivityTitleResId(this, SettingsActivity.class)), }; final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { @Override diff --git a/java/src/com/android/inputmethod/latin/SettingsFragment.java b/java/src/com/android/inputmethod/latin/SettingsFragment.java index 4fdd83911..928141c32 100644 --- a/java/src/com/android/inputmethod/latin/SettingsFragment.java +++ b/java/src/com/android/inputmethod/latin/SettingsFragment.java @@ -69,6 +69,11 @@ public final class SettingsFragment extends InputMethodSettingsFragment setInputMethodSettingsCategoryTitle(R.string.language_selection_title); setSubtypeEnablerTitle(R.string.select_language); addPreferencesFromResource(R.xml.prefs); + final PreferenceScreen preferenceScreen = getPreferenceScreen(); + if (preferenceScreen != null) { + preferenceScreen.setTitle( + Utils.getAcitivityTitleResId(getActivity(), SettingsActivity.class)); + } final Resources res = getResources(); final Context context = getActivity(); diff --git a/java/src/com/android/inputmethod/latin/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java index 9cbfe6698..5e28cc2d0 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeLocale.java +++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java @@ -114,7 +114,7 @@ public final class SubtypeLocale { final String[] keyboardLayoutSetMap = res.getStringArray( R.array.locale_and_extra_value_to_keyboard_layout_set_map); - for (int i = 0; i < keyboardLayoutSetMap.length; i += 2) { + for (int i = 0; i + 1 < keyboardLayoutSetMap.length; i += 2) { final String key = keyboardLayoutSetMap[i]; final String keyboardLayoutSet = keyboardLayoutSetMap[i + 1]; sLocaleAndExtraValueToKeyboardLayoutSetMap.put(key, keyboardLayoutSet); diff --git a/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java b/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java index 62f2a9750..10931555e 100644 --- a/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java +++ b/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java @@ -207,7 +207,12 @@ public final class UserHistoryDictIOUtils { final ArrayList<PendingAttribute> attrList = bigrams.get(entry.getKey()); if (attrList != null) { for (final PendingAttribute attr : attrList) { - to.setBigram(word1, unigrams.get(attr.mAddress), + final String word2 = unigrams.get(attr.mAddress); + if (word1 == null || word2 == null) { + Log.e(TAG, "Invalid bigram pair detected: " + word1 + ", " + word2); + continue; + } + to.setBigram(word1, word2, BinaryDictInputOutput.reconstructBigramFrequency(unigramFrequency, attr.mFrequency)); } diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 7a604dc6a..aff5d17d7 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -16,8 +16,13 @@ package com.android.inputmethod.latin; +import android.app.Activity; +import android.content.ComponentName; +import android.content.Context; import android.content.Intent; +import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.inputmethodservice.InputMethodService; import android.net.Uri; import android.os.AsyncTask; @@ -45,6 +50,8 @@ import java.util.Date; import java.util.Locale; public final class Utils { + private static final String TAG = Utils.class.getSimpleName(); + private Utils() { // This utility class is not publicly instantiable. } @@ -453,4 +460,17 @@ public final class Utils { if (TextUtils.isEmpty(info)) return null; return info; } + + public static int getAcitivityTitleResId(Context context, Class<? extends Activity> cls) { + final ComponentName cn = new ComponentName(context, cls); + try { + final ActivityInfo ai = context.getPackageManager().getActivityInfo(cn, 0); + if (ai != null) { + return ai.labelRes; + } + } catch (NameNotFoundException e) { + Log.e(TAG, "Failed to get settings activity title res id.", e); + } + return 0; + } } diff --git a/java/src/com/android/inputmethod/latin/XmlParseUtils.java b/java/src/com/android/inputmethod/latin/XmlParseUtils.java index f01d4c5e6..48e5ed30a 100644 --- a/java/src/com/android/inputmethod/latin/XmlParseUtils.java +++ b/java/src/com/android/inputmethod/latin/XmlParseUtils.java @@ -30,50 +30,53 @@ public final class XmlParseUtils { @SuppressWarnings("serial") public static class ParseException extends XmlPullParserException { - public ParseException(String msg, XmlPullParser parser) { + public ParseException(final String msg, final XmlPullParser parser) { super(msg + " at " + parser.getPositionDescription()); } } @SuppressWarnings("serial") public static final class IllegalStartTag extends ParseException { - public IllegalStartTag(XmlPullParser parser, String parent) { - super("Illegal start tag " + parser.getName() + " in " + parent, parser); + public IllegalStartTag(final XmlPullParser parser, final String tag, final String parent) { + super("Illegal start tag " + tag + " in " + parent, parser); } } @SuppressWarnings("serial") public static final class IllegalEndTag extends ParseException { - public IllegalEndTag(XmlPullParser parser, String parent) { - super("Illegal end tag " + parser.getName() + " in " + parent, parser); + public IllegalEndTag(final XmlPullParser parser, final String tag, final String parent) { + super("Illegal end tag " + tag + " in " + parent, parser); } } @SuppressWarnings("serial") public static final class IllegalAttribute extends ParseException { - public IllegalAttribute(XmlPullParser parser, String attribute) { - super("Tag " + parser.getName() + " has illegal attribute " + attribute, parser); + public IllegalAttribute(final XmlPullParser parser, final String tag, + final String attribute) { + super("Tag " + tag + " has illegal attribute " + attribute, parser); } } @SuppressWarnings("serial") public static final class NonEmptyTag extends ParseException{ - public NonEmptyTag(String tag, XmlPullParser parser) { + public NonEmptyTag(final XmlPullParser parser, final String tag) { super(tag + " must be empty tag", parser); } } - public static void checkEndTag(String tag, XmlPullParser parser) + public static void checkEndTag(final String tag, final XmlPullParser parser) throws XmlPullParserException, IOException { if (parser.next() == XmlPullParser.END_TAG && tag.equals(parser.getName())) return; - throw new NonEmptyTag(tag, parser); + throw new NonEmptyTag(parser, tag); } - public static void checkAttributeExists(TypedArray attr, int attrId, String attrName, - String tag, XmlPullParser parser) throws XmlPullParserException { - if (attr.hasValue(attrId)) + public static void checkAttributeExists(final TypedArray attr, final int attrId, + final String attrName, final String tag, final XmlPullParser parser) + throws XmlPullParserException { + if (attr.hasValue(attrId)) { return; + } throw new ParseException( "No " + attrName + " attribute found in <" + tag + "/>", parser); } diff --git a/java/src/com/android/inputmethod/latin/setup/SetupActivity.java b/java/src/com/android/inputmethod/latin/setup/SetupActivity.java index 7f66c6d3e..15d0bac37 100644 --- a/java/src/com/android/inputmethod/latin/setup/SetupActivity.java +++ b/java/src/com/android/inputmethod/latin/setup/SetupActivity.java @@ -112,12 +112,13 @@ public final class SetupActivity extends Activity { // TODO: Use sans-serif-thin font family depending on the system locale white list and // the SDK version. final TextView titleView = (TextView)findViewById(R.id.setup_title); - titleView.setText(getString(R.string.setup_title, getString(R.string.english_ime_name))); + final int appName = getApplicationInfo().labelRes; + titleView.setText(getString(R.string.setup_title, getString(appName))); mStepIndicatorView = (SetupStepIndicatorView)findViewById(R.id.setup_step_indicator); final SetupStep step1 = new SetupStep(findViewById(R.id.setup_step1), - R.string.setup_step1_title, R.string.setup_step1_instruction, + appName, R.string.setup_step1_title, R.string.setup_step1_instruction, R.drawable.ic_settings_language, R.string.language_settings); step1.setAction(new Runnable() { @Override @@ -129,7 +130,7 @@ public final class SetupActivity extends Activity { mSetupSteps.addStep(STEP_1, step1); final SetupStep step2 = new SetupStep(findViewById(R.id.setup_step2), - R.string.setup_step2_title, R.string.setup_step2_instruction, + appName, R.string.setup_step2_title, R.string.setup_step2_instruction, 0 /* actionIcon */, R.string.select_input_method); step2.setAction(new Runnable() { @Override @@ -142,7 +143,7 @@ public final class SetupActivity extends Activity { mSetupSteps.addStep(STEP_2, step2); final SetupStep step3 = new SetupStep(findViewById(R.id.setup_step3), - R.string.setup_step3_title, 0 /* instruction */, + appName, R.string.setup_step3_title, 0 /* instruction */, R.drawable.sym_keyboard_language_switch, R.string.setup_step3_instruction); step3.setAction(new Runnable() { @Override @@ -290,11 +291,11 @@ public final class SetupActivity extends Activity { private final TextView mActionLabel; private Runnable mAction; - public SetupStep(final View rootView, final int title, final int instruction, - final int actionIcon, final int actionLabel) { + public SetupStep(final View rootView, final int appName, final int title, + final int instruction, final int actionIcon, final int actionLabel) { mRootView = rootView; final Resources res = rootView.getResources(); - final String applicationName = res.getString(R.string.english_ime_name); + final String applicationName = res.getString(appName); final TextView titleView = (TextView)rootView.findViewById(R.id.setup_step_title); titleView.setText(res.getString(title, applicationName)); diff --git a/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerSettingsFragment.java b/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerSettingsFragment.java index 9606b0352..5ce9d8e47 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerSettingsFragment.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerSettingsFragment.java @@ -18,8 +18,10 @@ package com.android.inputmethod.latin.spellcheck; import android.os.Bundle; import android.preference.PreferenceFragment; +import android.preference.PreferenceScreen; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.Utils; /** * Preference screen. @@ -35,5 +37,10 @@ public final class SpellCheckerSettingsFragment extends PreferenceFragment { public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); addPreferencesFromResource(R.xml.spell_checker_settings); + final PreferenceScreen preferenceScreen = getPreferenceScreen(); + if (preferenceScreen != null) { + preferenceScreen.setTitle(Utils.getAcitivityTitleResId( + getActivity(), SpellCheckerSettingsActivity.class)); + } } } |