Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Attributes | Package Attributes | List of all members
io.flutter.plugin.editing.SpellCheckPlugin Class Reference
Inheritance diagram for io.flutter.plugin.editing.SpellCheckPlugin:
io.flutter.embedding.engine.systemchannels.SpellCheckChannel.SpellCheckMethodHandler

Public Member Functions

 SpellCheckPlugin ( @NonNull TextServicesManager textServicesManager, @NonNull SpellCheckChannel spellCheckChannel)
 
void destroy ()
 
void initiateSpellCheck ( @NonNull String locale, @NonNull String text, @NonNull MethodChannel.Result result)
 
void performSpellCheck (@NonNull String locale, @NonNull String text)
 
void onGetSentenceSuggestions (SentenceSuggestionsInfo[] results)
 
void onGetSuggestions (SuggestionsInfo[] results)
 
void initiateSpellCheck ( @NonNull String locale, @NonNull String text, @NonNull MethodChannel.Result result)
 

Static Public Attributes

static final String START_INDEX_KEY = "startIndex"
 
static final String END_INDEX_KEY = "endIndex"
 
static final String SUGGESTIONS_KEY = "suggestions"
 

Package Attributes

MethodChannel.Result pendingResult
 

Detailed Description

SpellCheckPlugin is the implementation of all functionality needed for spell check for text input.

The plugin handles requests for spell check sent by the io.flutter.embedding.engine.systemchannels.SpellCheckChannel via sending requests to the Android spell checker. It also receives the spell check results from the service and sends them back to the framework through the io.flutter.embedding.engine.systemchannels.SpellCheckChannel.

Definition at line 30 of file SpellCheckPlugin.java.

Constructor & Destructor Documentation

◆ SpellCheckPlugin()

io.flutter.plugin.editing.SpellCheckPlugin.SpellCheckPlugin ( @NonNull TextServicesManager  textServicesManager,
@NonNull SpellCheckChannel  spellCheckChannel 
)
inline

Definition at line 48 of file SpellCheckPlugin.java.

50 {
51 mTextServicesManager = textServicesManager;
52 mSpellCheckChannel = spellCheckChannel;
53
54 mSpellCheckChannel.setSpellCheckMethodHandler(this);
55 }
void setSpellCheckMethodHandler( @Nullable SpellCheckMethodHandler spellCheckMethodHandler)

Member Function Documentation

◆ destroy()

void io.flutter.plugin.editing.SpellCheckPlugin.destroy ( )
inline

Unregisters this SpellCheckPlugin as the
SpellCheckChannel.SpellCheckMethodHandler
, for the io.flutter.embedding.engine.systemchannels.SpellCheckChannel, and closes the most recently opened SpellCheckerSession.

Do not invoke any methods on a SpellCheckPlugin after invoking this method.

Definition at line 65 of file SpellCheckPlugin.java.

65 {
66 mSpellCheckChannel.setSpellCheckMethodHandler(null);
67
68 if (mSpellCheckerSession != null) {
69 mSpellCheckerSession.close();
70 }
71 }

◆ initiateSpellCheck()

void io.flutter.plugin.editing.SpellCheckPlugin.initiateSpellCheck ( @NonNull String  locale,
@NonNull String  text,
@NonNull MethodChannel.Result  result 
)
inline

Initiates call to native spell checker to spell check specified text if there is no result awaiting a response.

Implements io.flutter.embedding.engine.systemchannels.SpellCheckChannel.SpellCheckMethodHandler.

Definition at line 78 of file SpellCheckPlugin.java.

79 {
80 if (pendingResult != null) {
81 result.error("error", "Previous spell check request still pending.", null);
82 return;
83 }
84
86
87 performSpellCheck(locale, text);
88 }
void performSpellCheck(@NonNull String locale, @NonNull String text)
GAsyncResult * result
std::u16string text

◆ onGetSentenceSuggestions()

void io.flutter.plugin.editing.SpellCheckPlugin.onGetSentenceSuggestions ( SentenceSuggestionsInfo[]  results)
inline

Callback for Android spell check API that decomposes results and send results through the SpellCheckChannel.

Spell check results are encoded as dictionaries with a format that looks like


{
startIndex: 0,
endIndex: 5,
suggestions: [hello, ...]
}

where there may be up to 5 suggestions.

Definition at line 125 of file SpellCheckPlugin.java.

125 {
126 if (results.length == 0) {
127 pendingResult.success(new ArrayList<HashMap<String, Object>>());
128 pendingResult = null;
129 return;
130 }
131
132 ArrayList<HashMap<String, Object>> spellCheckerSuggestionSpans =
133 new ArrayList<HashMap<String, Object>>();
134 SentenceSuggestionsInfo spellCheckResults = results[0];
135 if (spellCheckResults == null) {
136 pendingResult.success(new ArrayList<HashMap<String, Object>>());
137 pendingResult = null;
138 return;
139 }
140
141 for (int i = 0; i < spellCheckResults.getSuggestionsCount(); i++) {
142 SuggestionsInfo suggestionsInfo = spellCheckResults.getSuggestionsInfoAt(i);
143 int suggestionsCount = suggestionsInfo.getSuggestionsCount();
144
145 if (suggestionsCount <= 0) {
146 continue;
147 }
148
149 HashMap<String, Object> spellCheckerSuggestionSpan = new HashMap<String, Object>();
150 int start = spellCheckResults.getOffsetAt(i);
151 int end = start + spellCheckResults.getLengthAt(i);
152
153 spellCheckerSuggestionSpan.put(START_INDEX_KEY, start);
154 spellCheckerSuggestionSpan.put(END_INDEX_KEY, end);
155
156 ArrayList<String> suggestions = new ArrayList<String>();
157 boolean validSuggestionsFound = false;
158 for (int j = 0; j < suggestionsCount; j++) {
159 String suggestion = suggestionsInfo.getSuggestionAt(j);
160 // TODO(camsim99): Support spell check on Samsung by retrieving accurate spell check
161 // results, then remove this check: https://github.com/flutter/flutter/issues/120608.
162 if (!suggestion.equals("")) {
163 validSuggestionsFound = true;
164 suggestions.add(suggestion);
165 }
166 }
167
168 if (!validSuggestionsFound) {
169 continue;
170 }
171 spellCheckerSuggestionSpan.put(SUGGESTIONS_KEY, suggestions);
172 spellCheckerSuggestionSpans.add(spellCheckerSuggestionSpan);
173 }
174
175 pendingResult.success(spellCheckerSuggestionSpans);
176 pendingResult = null;
177 }
glong glong end

◆ onGetSuggestions()

void io.flutter.plugin.editing.SpellCheckPlugin.onGetSuggestions ( SuggestionsInfo[]  results)
inline

Definition at line 180 of file SpellCheckPlugin.java.

180 {
181 // Deprecated callback for Android spell check API; will not use.
182 }

◆ performSpellCheck()

void io.flutter.plugin.editing.SpellCheckPlugin.performSpellCheck ( @NonNull String  locale,
@NonNull String  text 
)
inline

Calls on the Android spell check API to spell check specified text.

referToSpellCheckerLanguageSettings=

Definition at line 91 of file SpellCheckPlugin.java.

91 {
92 Locale localeFromString = LocalizationPlugin.localeFromString(locale);
93
94 if (mSpellCheckerSession == null) {
95 mSpellCheckerSession =
96 mTextServicesManager.newSpellCheckerSession(
97 null,
98 localeFromString,
99 this,
100 /** referToSpellCheckerLanguageSettings= */
101 true);
102 }
103
104 TextInfo[] textInfos = new TextInfo[] {new TextInfo(text)};
105 mSpellCheckerSession.getSentenceSuggestions(textInfos, MAX_SPELL_CHECK_SUGGESTIONS);
106 }

Member Data Documentation

◆ END_INDEX_KEY

final String io.flutter.plugin.editing.SpellCheckPlugin.END_INDEX_KEY = "endIndex"
static

Definition at line 39 of file SpellCheckPlugin.java.

◆ pendingResult

MethodChannel.Result io.flutter.plugin.editing.SpellCheckPlugin.pendingResult
package

Definition at line 42 of file SpellCheckPlugin.java.

◆ START_INDEX_KEY

final String io.flutter.plugin.editing.SpellCheckPlugin.START_INDEX_KEY = "startIndex"
static

Definition at line 38 of file SpellCheckPlugin.java.

◆ SUGGESTIONS_KEY

final String io.flutter.plugin.editing.SpellCheckPlugin.SUGGESTIONS_KEY = "suggestions"
static

Definition at line 40 of file SpellCheckPlugin.java.


The documentation for this class was generated from the following file: