コード例 #1
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();
             }
         }
     }
 }
コード例 #2
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();
        }