Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a0a66638 authored by Dan Zivkovic's avatar Dan Zivkovic Committed by Android (Google) Code Review
Browse files

Merge "Add shortcut support to UserDictionaryLookup."

parents f3392aca 87eb7ac2
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import com.android.inputmethod.annotations.UsedForTesting;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -60,7 +61,17 @@ public final class CollectionUtils {
     * @return Whether c contains no elements.
     */
    @UsedForTesting
    public static boolean isNullOrEmpty(@Nullable final Collection<?> c) {
    public static boolean isNullOrEmpty(@Nullable final Collection c) {
        return c == null || c.isEmpty();
    }

    /**
     * Tests whether map contains no elements, true if map is null or map is empty.
     * @param map Map to test.
     * @return Whether map contains no elements.
     */
    @UsedForTesting
    public static boolean isNullOrEmpty(@Nullable final Map map) {
        return map == null || map.isEmpty();
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -39,6 +39,10 @@ public abstract class Dictionary {
    public static final String TYPE_USER_TYPED = "user_typed";
    public static final PhonyDictionary DICTIONARY_USER_TYPED = new PhonyDictionary(TYPE_USER_TYPED);

    public static final String TYPE_USER_SHORTCUT = "user_shortcut";
    public static final PhonyDictionary DICTIONARY_USER_SHORTCUT =
            new PhonyDictionary(TYPE_USER_SHORTCUT);

    public static final String TYPE_APPLICATION_DEFINED = "application_defined";
    public static final PhonyDictionary DICTIONARY_APPLICATION_DEFINED =
            new PhonyDictionary(TYPE_APPLICATION_DEFINED);
+154 −56

File changed and moved.

Preview size limit exceeded, changes collapsed.

+2 −33
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.text.InputType;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;
import android.view.textservice.SuggestionsInfo;
import android.util.Log;

import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId;
@@ -83,7 +82,6 @@ public final class AndroidSpellCheckerService extends SpellCheckerService

    public static final String SINGLE_QUOTE = "\u0027";
    public static final String APOSTROPHE = "\u2019";
    private UserDictionaryLookup mUserDictionaryLookup;

    public AndroidSpellCheckerService() {
        super();
@@ -95,30 +93,11 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
    @Override
    public void onCreate() {
        super.onCreate();
        mRecommendedThreshold =
                Float.parseFloat(getString(R.string.spellchecker_recommended_threshold_value));
        mRecommendedThreshold = Float.parseFloat(
                getString(R.string.spellchecker_recommended_threshold_value));
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        prefs.registerOnSharedPreferenceChangeListener(this);
        onSharedPreferenceChanged(prefs, PREF_USE_CONTACTS_KEY);
        // Create a UserDictionaryLookup.  It needs to be close()d and set to null in onDestroy.
        if (mUserDictionaryLookup == null) {
            if (DEBUG) {
                Log.d(TAG, "Creating mUserDictionaryLookup in onCreate");
            }
            mUserDictionaryLookup = new UserDictionaryLookup(this);
        } else if (DEBUG) {
            Log.d(TAG, "mUserDictionaryLookup already created before onCreate");
        }
    }

    @Override
    public void onDestroy() {
        if (DEBUG) {
            Log.d(TAG, "Closing and dereferencing mUserDictionaryLookup in onDestroy");
        }
        mUserDictionaryLookup.close();
        mUserDictionaryLookup = null;
        super.onDestroy();
    }

    public float getRecommendedThreshold() {
@@ -181,16 +160,6 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
    public boolean isValidWord(final Locale locale, final String word) {
        mSemaphore.acquireUninterruptibly();
        try {
            if (mUserDictionaryLookup.isValidWord(word, locale)) {
                if (DEBUG) {
                    Log.d(TAG, "mUserDictionaryLookup.isValidWord(" + word + ")=true");
                }
                return true;
            } else {
                if (DEBUG) {
                    Log.d(TAG, "mUserDictionaryLookup.isValidWord(" + word + ")=false");
                }
            }
            DictionaryFacilitator dictionaryFacilitatorForLocale =
                    mDictionaryFacilitatorCache.get(locale);
            return dictionaryFacilitatorForLocale.isValidSpellingWord(word);
+96 −23

File changed and moved.

Preview size limit exceeded, changes collapsed.

Loading