Exemplo n.º 1
0
 private int nextSpellCheckSpanIndex()
 {
     {
         for (int i = 0; i < mLength; i++)
         {
             if (mIds[i] < 0)
             {
                 return(i);
             }
         }
     }
     if (mLength == mSpellCheckSpans.Length)
     {
         int   newSize = mLength * 2;
         int[] newIds  = new int[newSize];
         android.text.style.SpellCheckSpan[] newSpellCheckSpans = new android.text.style.SpellCheckSpan
                                                                  [newSize];
         System.Array.Copy(mIds, 0, newIds, 0, mLength);
         System.Array.Copy(mSpellCheckSpans, 0, newSpellCheckSpans, 0, mLength);
         mIds             = newIds;
         mSpellCheckSpans = newSpellCheckSpans;
     }
     mSpellCheckSpans[mLength] = new android.text.style.SpellCheckSpan();
     mLength++;
     return(mLength - 1);
 }
Exemplo n.º 2
0
 public virtual void removeSpellCheckSpan(android.text.style.SpellCheckSpan spellCheckSpan
                                          )
 {
     {
         for (int i = 0; i < mLength; i++)
         {
             if (mSpellCheckSpans[i] == spellCheckSpan)
             {
                 mSpellCheckSpans[i].setSpellCheckInProgress(false);
                 mIds[i] = -1;
                 return;
             }
         }
     }
 }
Exemplo n.º 3
0
 public virtual void onGetSuggestions(android.view.textservice.SuggestionsInfo[] results
                                      )
 {
     android.text.Editable editable = (android.text.Editable)mTextView.getText();
     {
         for (int i = 0; i < results.Length; i++)
         {
             android.view.textservice.SuggestionsInfo suggestionsInfo = results[i];
             if (suggestionsInfo.getCookie() != mCookie)
             {
                 continue;
             }
             int sequenceNumber = suggestionsInfo.getSequence();
             {
                 for (int j = 0; j < mLength; j++)
                 {
                     if (sequenceNumber == mIds[j])
                     {
                         int  attributes     = suggestionsInfo.getSuggestionsAttributes();
                         bool isInDictionary = ((attributes & android.view.textservice.SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY
                                                 ) > 0);
                         bool looksLikeTypo = ((attributes & android.view.textservice.SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO
                                                ) > 0);
                         android.text.style.SpellCheckSpan spellCheckSpan = mSpellCheckSpans[j];
                         if (!isInDictionary && looksLikeTypo)
                         {
                             createMisspelledSuggestionSpan(editable, suggestionsInfo, spellCheckSpan);
                         }
                         editable.removeSpan(spellCheckSpan);
                         break;
                     }
                 }
             }
         }
     }
     int length = mSpellParsers.Length;
     {
         for (int i_1 = 0; i_1 < length; i_1++)
         {
             android.widget.SpellChecker.SpellParser spellParser = mSpellParsers[i_1];
             if (!spellParser.isDone())
             {
                 spellParser.parse();
             }
         }
     }
 }
Exemplo n.º 4
0
        private void spellCheck()
        {
            if (mSpellCheckerSession == null)
            {
                return;
            }
            android.text.Editable editable = (android.text.Editable)mTextView.getText();
            int selectionStart             = android.text.Selection.getSelectionStart(editable);
            int selectionEnd = android.text.Selection.getSelectionEnd(editable);

            android.view.textservice.TextInfo[] textInfos = new android.view.textservice.TextInfo
                                                            [mLength];
            int textInfosCount = 0;

            {
                for (int i = 0; i < mLength; i++)
                {
                    android.text.style.SpellCheckSpan spellCheckSpan = mSpellCheckSpans[i];
                    if (spellCheckSpan.isSpellCheckInProgress())
                    {
                        continue;
                    }
                    int start = editable.getSpanStart(spellCheckSpan);
                    int end   = editable.getSpanEnd(spellCheckSpan);
                    // Do not check this word if the user is currently editing it
                    if (start >= 0 && end > start && (selectionEnd < start || selectionStart > end))
                    {
                        string word = editable.SubSequence(start, end).ToString();
                        spellCheckSpan.setSpellCheckInProgress(true);
                        textInfos[textInfosCount++] = new android.view.textservice.TextInfo(word, mCookie
                                                                                            , mIds[i]);
                    }
                }
            }
            if (textInfosCount > 0)
            {
                if (textInfosCount < textInfos.Length)
                {
                    android.view.textservice.TextInfo[] textInfosCopy = new android.view.textservice.TextInfo
                                                                        [textInfosCount];
                    System.Array.Copy(textInfos, 0, textInfosCopy, 0, textInfosCount);
                    textInfos = textInfosCopy;
                }
                mSpellCheckerSession.getSuggestions(textInfos, android.text.style.SuggestionSpan.
                                                    SUGGESTIONS_MAX_SIZE, false);
            }
        }
Exemplo n.º 5
0
        private void createMisspelledSuggestionSpan(android.text.Editable editable, android.view.textservice.SuggestionsInfo
                                                    suggestionsInfo, android.text.style.SpellCheckSpan spellCheckSpan)
        {
            int start = editable.getSpanStart(spellCheckSpan);
            int end   = editable.getSpanEnd(spellCheckSpan);

            // Other suggestion spans may exist on that region, with identical suggestions, filter
            // them out to avoid duplicates. First, filter suggestion spans on that exact region.
            android.text.style.SuggestionSpan[] suggestionSpans = editable.getSpans <android.text.style.SuggestionSpan
                                                                                     >(start, end);
            int length = suggestionSpans.Length;
            {
                for (int i = 0; i < length; i++)
                {
                    int spanStart = editable.getSpanStart(suggestionSpans[i]);
                    int spanEnd   = editable.getSpanEnd(suggestionSpans[i]);
                    if (spanStart != start || spanEnd != end)
                    {
                        suggestionSpans[i] = null;
                        break;
                    }
                }
            }
            int suggestionsCount = suggestionsInfo.getSuggestionsCount();

            string[] suggestions;
            if (suggestionsCount <= 0)
            {
                // A negative suggestion count is possible
                suggestions = new string[0];
            }
            else
            {
                int numberOfSuggestions = 0;
                suggestions = new string[suggestionsCount];
                {
                    for (int i_1 = 0; i_1 < suggestionsCount; i_1++)
                    {
                        string spellSuggestion = suggestionsInfo.getSuggestionAt(i_1);
                        if (spellSuggestion == null)
                        {
                            break;
                        }
                        bool suggestionFound = false;
                        {
                            for (int j = 0; j < length && !suggestionFound; j++)
                            {
                                if (suggestionSpans[j] == null)
                                {
                                    break;
                                }
                                string[] suggests = suggestionSpans[j].getSuggestions();
                                {
                                    for (int k = 0; k < suggests.Length; k++)
                                    {
                                        if (spellSuggestion.Equals(suggests[k]))
                                        {
                                            // The suggestion is already provided by an other SuggestionSpan
                                            suggestionFound = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        if (!suggestionFound)
                        {
                            suggestions[numberOfSuggestions++] = spellSuggestion;
                        }
                    }
                }
                if (numberOfSuggestions != suggestionsCount)
                {
                    string[] newSuggestions = new string[numberOfSuggestions];
                    System.Array.Copy(suggestions, 0, newSuggestions, 0, numberOfSuggestions);
                    suggestions = newSuggestions;
                }
            }
            android.text.style.SuggestionSpan suggestionSpan = new android.text.style.SuggestionSpan
                                                                   (mTextView.getContext(), suggestions, android.text.style.SuggestionSpan.FLAG_EASY_CORRECT
                                                                   | android.text.style.SuggestionSpan.FLAG_MISSPELLED);
            editable.setSpan(suggestionSpan, start, end, android.text.SpannedClass.SPAN_EXCLUSIVE_EXCLUSIVE
                             );
            // TODO limit to the word rectangle region
            mTextView.invalidate();
        }