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

Commit 34386e69 authored by Amith Yamasani's avatar Amith Yamasani Committed by Jean-Baptiste Queru
Browse files

Auto add new words to the user dictionary.

First pass at automatically adding new words that the user types and deliberately
accepts.
After typing the word 4 times, the word gets promoted to being valid.
After typing the word 7 times, the word gets added into the UserDictionary and can
be removed from the UserDictionary Settings UI.

Also add a second row of symbols to the period popup.
parent 322dc3d3
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -25,7 +25,16 @@
    android:keyHeight="@dimen/key_height"
    >

    <Row android:rowEdgeFlags="top|bottom">
    <Row android:rowEdgeFlags="top">
        <Key android:keyLabel=";" android:keyEdgeFlags="left" />
        <Key android:keyLabel="\\" />
        <Key android:keyLabel="&amp;" />
        <Key android:keyLabel="(" />
        <Key android:keyLabel=")" />
        <Key android:keyLabel="-" />
        <Key android:keyLabel="+" android:keyEdgeFlags="right" />
    </Row>
    <Row android:rowEdgeFlags="bottom">
        <Key android:codes="58" android:keyLabel=":" android:keyEdgeFlags="left" />
        <Key android:codes="47" android:keyLabel="/" />
        <Key android:codes="64" android:keyLabel="\@" />
+423 −0

File added.

Preview size limit exceeded, changes collapsed.

+37 −2
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ public class LatinIME extends InputMethodService
    KeyboardSwitcher mKeyboardSwitcher;
    
    private UserDictionary mUserDictionary;
    private ExpandableDictionary mAutoDictionary;
    
    private String mLocale;

@@ -172,7 +173,9 @@ public class LatinIME extends InputMethodService
        mSuggest = new Suggest(this, R.raw.main);
        mSuggest.setCorrectionMode(mCorrectionMode);
        mUserDictionary = new UserDictionary(this);
        mAutoDictionary = new AutoDictionary(this);
        mSuggest.setUserDictionary(mUserDictionary);
        mSuggest.setAutoDictionary(mAutoDictionary);
        mWordSeparators = getResources().getString(R.string.word_separators);
        mSentenceSeparators = getResources().getString(R.string.sentence_separators);
    }
@@ -465,6 +468,7 @@ public class LatinIME extends InputMethodService
                }
                mCommittedLength = mComposing.length();
                TextEntryState.acceptedTyped(mComposing);
                mAutoDictionary.addWord(mComposing.toString(), 1);
            }
            updateSuggestions();
        }
@@ -820,6 +824,10 @@ public class LatinIME extends InputMethodService
        if (ic != null) {
            ic.commitText(suggestion, 1);
        }
        // Add the word to the auto dictionary if it's not a known word
        if (mAutoDictionary.isValidWord(suggestion) || !mSuggest.isValidWord(suggestion)) {
            mAutoDictionary.addWord(suggestion.toString(), 1);
        }
        mPredicting = false;
        mCommittedLength = suggestion.length();
        if (mCandidateView != null) {
@@ -999,6 +1007,11 @@ public class LatinIME extends InputMethodService
        mTutorial = null;
    }

    void promoteToUserDictionary(String word, int frequency) {
        if (mUserDictionary.isValidWord(word)) return;
        mUserDictionary.addWord(word, frequency);
    }

    private void launchSettings() {
        handleClose();
        Intent intent = new Intent();
@@ -1108,6 +1121,28 @@ public class LatinIME extends InputMethodService
        System.out.println("CPS = " + ((CPS_BUFFER_SIZE * 1000f) / total));
    }

    class AutoDictionary extends ExpandableDictionary {
        private static final int VALIDITY_THRESHOLD = 3;
        private static final int PROMOTION_THRESHOLD = 6;

        public AutoDictionary(Context context) {
            super(context);
        }

        @Override
        public boolean isValidWord(CharSequence word) {
            final int frequency = getWordFrequency(word);
            return frequency > VALIDITY_THRESHOLD;
        }

        @Override
        public void addWord(String word, int frequency) {
            super.addWord(word, 1);
            if (getWordFrequency(word) > PROMOTION_THRESHOLD) {
                LatinIME.this.promoteToUserDictionary(word, frequency);
            }
        }
    }
}


+14 −7

File changed.

Preview size limit exceeded, changes collapsed.

+17 −364

File changed.

Preview size limit exceeded, changes collapsed.