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

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

Merge "Personal dictionary feeds a personal LM."

parents 3952078a 541ef56e
Loading
Loading
Loading
Loading
+12 −12
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ import android.provider.ContactsContract.Contacts;
import android.util.Log;
import android.util.Log;


import com.android.inputmethod.latin.ContactsManager.ContactsChangedListener;
import com.android.inputmethod.latin.ContactsManager.ContactsChangedListener;
import com.android.inputmethod.latin.define.DebugFlags;
import com.android.inputmethod.latin.utils.ExecutorUtils;
import com.android.inputmethod.latin.utils.ExecutorUtils;


import java.util.ArrayList;
import java.util.ArrayList;
@@ -33,8 +34,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 * A content observer that listens to updates to content provider {@link Contacts#CONTENT_URI}.
 * A content observer that listens to updates to content provider {@link Contacts#CONTENT_URI}.
 */
 */
public class ContactsContentObserver implements Runnable {
public class ContactsContentObserver implements Runnable {
    private static final String TAG = ContactsContentObserver.class.getSimpleName();
    private static final String TAG = "ContactsContentObserver";
    private static final boolean DEBUG = false;
    private static AtomicBoolean sRunning = new AtomicBoolean(false);
    private static AtomicBoolean sRunning = new AtomicBoolean(false);


    private final Context mContext;
    private final Context mContext;
@@ -49,8 +49,8 @@ public class ContactsContentObserver implements Runnable {
    }
    }


    public void registerObserver(final ContactsChangedListener listener) {
    public void registerObserver(final ContactsChangedListener listener) {
        if (DEBUG) {
        if (DebugFlags.DEBUG_ENABLED) {
            Log.d(TAG, "Registered Contacts Content Observer");
            Log.d(TAG, "registerObserver()");
        }
        }
        mContactsChangedListener = listener;
        mContactsChangedListener = listener;
        mContentObserver = new ContentObserver(null /* handler */) {
        mContentObserver = new ContentObserver(null /* handler */) {
@@ -67,13 +67,13 @@ public class ContactsContentObserver implements Runnable {
    @Override
    @Override
    public void run() {
    public void run() {
        if (!sRunning.compareAndSet(false /* expect */, true /* update */)) {
        if (!sRunning.compareAndSet(false /* expect */, true /* update */)) {
            if (DEBUG) {
            if (DebugFlags.DEBUG_ENABLED) {
                Log.d(TAG, "run() : Already running. Don't waste time checking again.");
                Log.d(TAG, "run() : Already running. Don't waste time checking again.");
            }
            }
            return;
            return;
        }
        }
        if (haveContentsChanged()) {
        if (haveContentsChanged()) {
            if (DEBUG) {
            if (DebugFlags.DEBUG_ENABLED) {
                Log.d(TAG, "run() : Contacts have changed. Notifying listeners.");
                Log.d(TAG, "run() : Contacts have changed. Notifying listeners.");
            }
            }
            mContactsChangedListener.onContactsChange();
            mContactsChangedListener.onContactsChange();
@@ -91,9 +91,9 @@ public class ContactsContentObserver implements Runnable {
            return false;
            return false;
        }
        }
        if (contactCount != mManager.getContactCountAtLastRebuild()) {
        if (contactCount != mManager.getContactCountAtLastRebuild()) {
            if (DEBUG) {
            if (DebugFlags.DEBUG_ENABLED) {
                Log.d(TAG, "Contact count changed: " + mManager.getContactCountAtLastRebuild()
                Log.d(TAG, "haveContentsChanged() : Count changed from "
                        + " to " + contactCount);
                        + mManager.getContactCountAtLastRebuild() + " to " + contactCount);
            }
            }
            return true;
            return true;
        }
        }
@@ -101,9 +101,9 @@ public class ContactsContentObserver implements Runnable {
        if (names.hashCode() != mManager.getHashCodeAtLastRebuild()) {
        if (names.hashCode() != mManager.getHashCodeAtLastRebuild()) {
            return true;
            return true;
        }
        }
        if (DEBUG) {
        if (DebugFlags.DEBUG_ENABLED) {
            Log.d(TAG, "No contacts changed. (runtime = " + (SystemClock.uptimeMillis() - startTime)
            Log.d(TAG, "haveContentsChanged() : No change detected in "
                    + " ms)");
                    + (SystemClock.uptimeMillis() - startTime) + " ms)");
        }
        }
        return false;
        return false;
    }
    }
+1 −2
Original line number Original line Diff line number Diff line
@@ -35,8 +35,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 * measure of the current state of the content provider.
 * measure of the current state of the content provider.
 */
 */
public class ContactsManager {
public class ContactsManager {
    private static final String TAG = ContactsManager.class.getSimpleName();
    private static final String TAG = "ContactsManager";
    private static final boolean DEBUG = false;


    /**
    /**
     * Interface to implement for classes interested in getting notified for updates
     * Interface to implement for classes interested in getting notified for updates
+4 −21
Original line number Original line Diff line number Diff line
@@ -45,31 +45,14 @@ public interface DictionaryFacilitator {


    public static final String[] ALL_DICTIONARY_TYPES = new String[] {
    public static final String[] ALL_DICTIONARY_TYPES = new String[] {
            Dictionary.TYPE_MAIN,
            Dictionary.TYPE_MAIN,
            Dictionary.TYPE_CONTACTS,
            Dictionary.TYPE_USER_HISTORY,
            Dictionary.TYPE_USER_HISTORY,
            Dictionary.TYPE_USER,
            Dictionary.TYPE_USER};
            Dictionary.TYPE_CONTACTS};


    public static final String[] DYNAMIC_DICTIONARY_TYPES = new String[] {
    public static final String[] DYNAMIC_DICTIONARY_TYPES = new String[] {
            Dictionary.TYPE_CONTACTS,
            Dictionary.TYPE_USER_HISTORY,
            Dictionary.TYPE_USER_HISTORY,
            Dictionary.TYPE_USER,
            Dictionary.TYPE_USER};
            Dictionary.TYPE_CONTACTS};

    /**
     * {@link Dictionary#TYPE_USER} is deprecated, except for the spelling service.
     */
    public static final String[] DICTIONARY_TYPES_FOR_SPELLING = new String[] {
            Dictionary.TYPE_MAIN,
            Dictionary.TYPE_USER_HISTORY,
            Dictionary.TYPE_USER,
            Dictionary.TYPE_CONTACTS};

    /**
     * {@link Dictionary#TYPE_USER} is deprecated, except for the spelling service.
     */
    public static final String[] DICTIONARY_TYPES_FOR_SUGGESTIONS = new String[] {
            Dictionary.TYPE_MAIN,
            Dictionary.TYPE_USER_HISTORY,
            Dictionary.TYPE_CONTACTS};


    /**
    /**
     * Returns whether this facilitator is exactly for this locale.
     * Returns whether this facilitator is exactly for this locale.
+3 −3
Original line number Original line Diff line number Diff line
@@ -557,7 +557,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
                false /* firstSuggestionExceedsConfidenceThreshold */);
                false /* firstSuggestionExceedsConfidenceThreshold */);
        final float[] weightOfLangModelVsSpatialModel =
        final float[] weightOfLangModelVsSpatialModel =
                new float[] { Dictionary.NOT_A_WEIGHT_OF_LANG_MODEL_VS_SPATIAL_MODEL };
                new float[] { Dictionary.NOT_A_WEIGHT_OF_LANG_MODEL_VS_SPATIAL_MODEL };
        for (final String dictType : DICTIONARY_TYPES_FOR_SUGGESTIONS) {
        for (final String dictType : ALL_DICTIONARY_TYPES) {
            final Dictionary dictionary = mDictionaryGroup.getDict(dictType);
            final Dictionary dictionary = mDictionaryGroup.getDict(dictType);
            if (null == dictionary) continue;
            if (null == dictionary) continue;
            final float weightForLocale = composedData.mIsBatchMode
            final float weightForLocale = composedData.mIsBatchMode
@@ -577,11 +577,11 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
    }
    }


    public boolean isValidSpellingWord(final String word) {
    public boolean isValidSpellingWord(final String word) {
        return isValidWord(word, DICTIONARY_TYPES_FOR_SPELLING);
        return isValidWord(word, ALL_DICTIONARY_TYPES);
    }
    }


    public boolean isValidSuggestionWord(final String word) {
    public boolean isValidSuggestionWord(final String word) {
        return isValidWord(word, DICTIONARY_TYPES_FOR_SUGGESTIONS);
        return isValidWord(word, ALL_DICTIONARY_TYPES);
    }
    }


    private boolean isValidWord(final String word, final String[] dictionariesToCheck) {
    private boolean isValidWord(final String word, final String[] dictionariesToCheck) {
+225 −114

File changed and moved.

Preview size limit exceeded, changes collapsed.

Loading