Flutter Engine
The Flutter Engine
SpellCheckChannel.java
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package io.flutter.embedding.engine.systemchannels;
6
7import androidx.annotation.NonNull;
8import androidx.annotation.Nullable;
9import io.flutter.Log;
10import io.flutter.embedding.engine.dart.DartExecutor;
11import io.flutter.plugin.common.MethodCall;
12import io.flutter.plugin.common.MethodChannel;
13import io.flutter.plugin.common.StandardMethodCodec;
14import java.util.ArrayList;
15
16/**
17 * {@link SpellCheckChannel} is a platform channel that is used by the framework to initiate spell
18 * check in the embedding and for the embedding to send back the results.
19 *
20 * <p>When there is new text to be spell checked, the framework will send to the embedding the
21 * message {@code SpellCheck.initiateSpellCheck} with the {@code String} locale to spell check with
22 * and the {@code String} of text to spell check as arguments. In response, the {@link
23 * io.flutter.plugin.editing.SpellCheckPlugin} will make a call to Android's spell check service to
24 * fetch spell check results for the specified text.
25 *
26 * <p>Once the spell check results are received by the {@link
27 * io.flutter.plugin.editing.SpellCheckPlugin}, it will send back to the framework the {@code
28 * ArrayList<HashMap<String,Object>>} of spell check results (see {@link
29 * io.flutter.plugin.editing.SpellCheckPlugin#onGetSentenceSuggestions} for details). The {@link
30 * io.flutter.plugin.editing.SpellCheckPlugin} only handles one request to fetch spell check results
31 * at a time; see {@link io.flutter.plugin.editing.SpellCheckPlugin#initiateSpellCheck} for details.
32 *
33 * <p>{@link io.flutter.plugin.editing.SpellCheckPlugin} implements {@link SpellCheckMethodHandler}
34 * to initiate spell check. Implement {@link SpellCheckMethodHandler} to respond to spell check
35 * requests.
36 */
37public class SpellCheckChannel {
38 private static final String TAG = "SpellCheckChannel";
39
40 public final MethodChannel channel;
41 private SpellCheckMethodHandler spellCheckMethodHandler;
42
43 @NonNull
44 public final MethodChannel.MethodCallHandler parsingMethodHandler =
46 @Override
47 public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
48 if (spellCheckMethodHandler == null) {
49 Log.v(
50 TAG,
51 "No SpellCheckeMethodHandler registered, call not forwarded to spell check API.");
52 return;
53 }
54 String method = call.method;
55 Object args = call.arguments;
56 Log.v(TAG, "Received '" + method + "' message.");
57 switch (method) {
58 case "SpellCheck.initiateSpellCheck":
59 try {
60 final ArrayList<String> argumentList = (ArrayList<String>) args;
61 String locale = argumentList.get(0);
62 String text = argumentList.get(1);
63 spellCheckMethodHandler.initiateSpellCheck(locale, text, result);
64 } catch (IllegalStateException exception) {
65 result.error("error", exception.getMessage(), null);
66 }
67 break;
68 default:
69 result.notImplemented();
70 break;
71 }
72 }
73 };
74
75 public SpellCheckChannel(@NonNull DartExecutor dartExecutor) {
76 channel = new MethodChannel(dartExecutor, "flutter/spellcheck", StandardMethodCodec.INSTANCE);
78 }
79
80 /**
81 * Sets the {@link SpellCheckMethodHandler} which receives all requests to spell check the
82 * specified text sent through this channel.
83 */
85 @Nullable SpellCheckMethodHandler spellCheckMethodHandler) {
86 this.spellCheckMethodHandler = spellCheckMethodHandler;
87 }
88
89 public interface SpellCheckMethodHandler {
90 /**
91 * Requests that spell check is initiated for the specified text, which will respond to the
92 * {@code result} with either success if spell check results are received or error if the
93 * request is skipped.
94 */
96 @NonNull String locale, @NonNull String text, @NonNull MethodChannel.Result result);
97 }
98}
static void v(@NonNull String tag, @NonNull String message)
Definition: Log.java:40
void setSpellCheckMethodHandler( @Nullable SpellCheckMethodHandler spellCheckMethodHandler)
void setMethodCallHandler(final @Nullable MethodCallHandler handler)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
GAsyncResult * result
void initiateSpellCheck( @NonNull String locale, @NonNull String text, @NonNull MethodChannel.Result result)
std::u16string text
def call(args)
Definition: dom.py:159
#define TAG()