Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
io.flutter.plugin.text.ProcessTextPlugin Class Reference
Inheritance diagram for io.flutter.plugin.text.ProcessTextPlugin:
io.flutter.embedding.engine.plugins.FlutterPlugin io.flutter.embedding.engine.plugins.activity.ActivityAware io.flutter.plugin.common.PluginRegistry.ActivityResultListener io.flutter.embedding.engine.systemchannels.ProcessTextChannel.ProcessTextMethodHandler

Public Member Functions

 ProcessTextPlugin (@NonNull ProcessTextChannel processTextChannel)
 
Map< String, String > queryTextActions ()
 
void processTextAction ( @NonNull String id, @NonNull String text, @NonNull boolean readOnly, @NonNull MethodChannel.Result result)
 
boolean onActivityResult (int requestCode, int resultCode, @Nullable Intent intent)
 
void destroy ()
 
void onAttachedToEngine (@NonNull FlutterPluginBinding binding)
 
void onDetachedFromEngine (@NonNull FlutterPluginBinding binding)
 
void onAttachedToActivity (@NonNull ActivityPluginBinding binding)
 
void onDetachedFromActivityForConfigChanges ()
 
void onReattachedToActivityForConfigChanges (@NonNull ActivityPluginBinding binding)
 
void onDetachedFromActivity ()
 
void onAttachedToEngine (@NonNull FlutterPluginBinding binding)
 
void onDetachedFromEngine (@NonNull FlutterPluginBinding binding)
 
void onAttachedToActivity (@NonNull ActivityPluginBinding binding)
 
void onDetachedFromActivityForConfigChanges ()
 
void onReattachedToActivityForConfigChanges (@NonNull ActivityPluginBinding binding)
 
void onDetachedFromActivity ()
 
boolean onActivityResult (int requestCode, int resultCode, @Nullable Intent data)
 
Map< String, String > queryTextActions ()
 
void processTextAction ( @NonNull String id, @NonNull String input, @NonNull boolean readOnly, @NonNull MethodChannel.Result result)
 

Detailed Description

Definition at line 28 of file ProcessTextPlugin.java.

Constructor & Destructor Documentation

◆ ProcessTextPlugin()

io.flutter.plugin.text.ProcessTextPlugin.ProcessTextPlugin ( @NonNull ProcessTextChannel  processTextChannel)
inline

Definition at line 44 of file ProcessTextPlugin.java.

44 {
45 this.processTextChannel = processTextChannel;
46 this.packageManager = processTextChannel.packageManager;
47
48 processTextChannel.setMethodHandler(this);
49 }
void setMethodHandler(@Nullable ProcessTextMethodHandler processTextMethodHandler)

Member Function Documentation

◆ destroy()

void io.flutter.plugin.text.ProcessTextPlugin.destroy ( )
inline

Unregisters this ProcessTextPlugin as the
ProcessTextChannel.ProcessTextMethodHandler
, for the io.flutter.embedding.engine.systemchannels.ProcessTextChannel.

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

Definition at line 162 of file ProcessTextPlugin.java.

162 {
163 processTextChannel.setMethodHandler(null);
164 }

◆ onActivityResult()

boolean io.flutter.plugin.text.ProcessTextPlugin.onActivityResult ( int  requestCode,
int  resultCode,
@Nullable Intent  intent 
)
inline

Executed when a text processing activity terminates.

When an activity returns a value, the request is completed successfully and returns the processed text.

When an activity does not return a value. the request is completed successfully and returns null.

Implements io.flutter.plugin.common.PluginRegistry.ActivityResultListener.

Definition at line 141 of file ProcessTextPlugin.java.

141 {
142 // Return early if the result is not related to a request sent by this plugin.
143 if (!requestsByCode.containsKey(requestCode)) {
144 return false;
145 }
146
147 String result = null;
148 if (resultCode == Activity.RESULT_OK) {
149 result = intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT);
150 }
151 requestsByCode.remove(requestCode).success(result);
152 return true;
153 }
GAsyncResult * result

◆ onAttachedToActivity()

void io.flutter.plugin.text.ProcessTextPlugin.onAttachedToActivity ( @NonNull ActivityPluginBinding  binding)
inline

This ActivityAware io.flutter.embedding.engine.plugins.FlutterPlugin is now associated with an android.app.Activity.

This method can be invoked in 1 of 2 situations:

The given ActivityPluginBinding contains android.app.Activity-related references that an ActivityAware io.flutter.embedding.engine.plugins.FlutterPlugin may require, such as a reference to the actual android.app.Activity in question. The ActivityPluginBinding may be referenced until either onDetachedFromActivityForConfigChanges() or onDetachedFromActivity() is invoked. At the conclusion of either of those methods, the binding is no longer valid. Clear any references to the binding or its resources, and do not invoke any further methods on the binding or its resources.

Implements io.flutter.embedding.engine.plugins.activity.ActivityAware.

Definition at line 180 of file ProcessTextPlugin.java.

180 {
181 this.activityBinding = binding;
182 this.activityBinding.addActivityResultListener(this);
183 };
void addActivityResultListener(@NonNull PluginRegistry.ActivityResultListener listener)

◆ onAttachedToEngine()

void io.flutter.plugin.text.ProcessTextPlugin.onAttachedToEngine ( @NonNull FlutterPluginBinding  binding)
inline

This FlutterPlugin has been associated with a io.flutter.embedding.engine.FlutterEngine instance.

Relevant resources that this FlutterPlugin may need are provided via the
binding
. The binding may be cached and referenced until onDetachedFromEngine(FlutterPluginBinding) is invoked and returns.

Implements io.flutter.embedding.engine.plugins.FlutterPlugin.

Definition at line 168 of file ProcessTextPlugin.java.

168 {
169 // Nothing to do because this plugin is instantiated by the engine.
170 }

◆ onDetachedFromActivity()

void io.flutter.plugin.text.ProcessTextPlugin.onDetachedFromActivity ( )
inline

This plugin has been detached from an android.app.Activity.

Detachment can occur for a number of reasons.

By the end of this method, the android.app.Activity that was made available in onAttachedToActivity(ActivityPluginBinding) is no longer valid. Any references to the associated android.app.Activity or ActivityPluginBinding should be cleared.

Any Lifecycle listeners that were registered in onAttachedToActivity(ActivityPluginBinding) or onReattachedToActivityForConfigChanges(ActivityPluginBinding) should be deregistered here to avoid a possible memory leak and other side effects.

Implements io.flutter.embedding.engine.plugins.activity.ActivityAware.

Definition at line 195 of file ProcessTextPlugin.java.

195 {
196 this.activityBinding.removeActivityResultListener(this);
197 this.activityBinding = null;
198 }
void removeActivityResultListener(@NonNull PluginRegistry.ActivityResultListener listener)

◆ onDetachedFromActivityForConfigChanges()

void io.flutter.plugin.text.ProcessTextPlugin.onDetachedFromActivityForConfigChanges ( )
inline

The android.app.Activity that was attached and made available in onAttachedToActivity(ActivityPluginBinding) has been detached from this
ActivityAware
's io.flutter.embedding.engine.FlutterEngine for the purpose of processing a configuration change.

By the end of this method, the android.app.Activity that was made available in onAttachedToActivity(ActivityPluginBinding) is no longer valid. Any references to the associated android.app.Activity or ActivityPluginBinding should be cleared.

This method should be quickly followed by onReattachedToActivityForConfigChanges(ActivityPluginBinding), which signifies that a new android.app.Activity has been created with the new configuration options. That method provides a new ActivityPluginBinding, which references the newly created and associated android.app.Activity.

Any Lifecycle listeners that were registered in onAttachedToActivity(ActivityPluginBinding) should be deregistered here to avoid a possible memory leak and other side effects.

Implements io.flutter.embedding.engine.plugins.activity.ActivityAware.

Definition at line 185 of file ProcessTextPlugin.java.

185 {
186 this.activityBinding.removeActivityResultListener(this);
187 this.activityBinding = null;
188 }

◆ onDetachedFromEngine()

void io.flutter.plugin.text.ProcessTextPlugin.onDetachedFromEngine ( @NonNull FlutterPluginBinding  binding)
inline

This FlutterPlugin has been removed from a io.flutter.embedding.engine.FlutterEngine instance.

The binding passed to this method is the same instance that was passed in onAttachedToEngine(FlutterPluginBinding). It is provided again in this method as a convenience. The binding may be referenced during the execution of this method, but it must not be cached or referenced after this method returns.

FlutterPlugins should release all resources in this method.

Implements io.flutter.embedding.engine.plugins.FlutterPlugin.

Definition at line 172 of file ProcessTextPlugin.java.

172 {
173 // Nothing to do because this plugin is instantiated by the engine.
174 }

◆ onReattachedToActivityForConfigChanges()

void io.flutter.plugin.text.ProcessTextPlugin.onReattachedToActivityForConfigChanges ( @NonNull ActivityPluginBinding  binding)
inline

This plugin and its io.flutter.embedding.engine.FlutterEngine have been re-attached to an android.app.Activity after the android.app.Activity was recreated to handle configuration changes.

binding includes a reference to the new instance of the android.app.Activity. binding and its references may be cached and used from now until either onDetachedFromActivityForConfigChanges() or onDetachedFromActivity() is invoked. At the conclusion of either of those methods, the binding is no longer valid. Clear any references to the binding or its resources, and do not invoke any further methods on the binding or its resources.

Implements io.flutter.embedding.engine.plugins.activity.ActivityAware.

Definition at line 190 of file ProcessTextPlugin.java.

190 {
191 this.activityBinding = binding;
192 this.activityBinding.addActivityResultListener(this);
193 }

◆ processTextAction()

void io.flutter.plugin.text.ProcessTextPlugin.processTextAction ( @NonNull String  id,
@NonNull String  input,
@NonNull boolean  readOnly,
@NonNull MethodChannel.Result  result 
)
inline

Requests to run a text action on a given input text.

Parameters
idThe ID of the text action returned by ProcessText.queryTextActions.
inputThe text to be processed.
readOnlyIndicates to the activity if the processed text will be used as read-only. see https://developer.android.com/reference/android/content/Intent#EXTRA_PROCESS_TEXT_READONLY
resultThe method channel result instance used to reply.

Implements io.flutter.embedding.engine.systemchannels.ProcessTextChannel.ProcessTextMethodHandler.

Definition at line 65 of file ProcessTextPlugin.java.

69 {
70 if (activityBinding == null) {
71 result.error("error", "Plugin not bound to an Activity", null);
72 return;
73 }
74
75 if (Build.VERSION.SDK_INT < API_LEVELS.API_23) {
76 result.error("error", "Android version not supported", null);
77 return;
78 }
79
80 if (resolveInfosById == null) {
81 result.error("error", "Can not process text actions before calling queryTextActions", null);
82 return;
83 }
84
85 final ResolveInfo info = resolveInfosById.get(id);
86 if (info == null) {
87 result.error("error", "Text processing activity not found", null);
88 return;
89 }
90
91 Integer requestCode = result.hashCode();
92 requestsByCode.put(requestCode, result);
93
94 Intent intent = new Intent();
95 intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
96 intent.setAction(Intent.ACTION_PROCESS_TEXT);
97 intent.setType("text/plain");
98 intent.putExtra(Intent.EXTRA_PROCESS_TEXT, text);
99 intent.putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, readOnly);
100
101 // Start the text processing activity. When the activity completes, the onActivityResult
102 // callback
103 // is called.
104 activityBinding.getActivity().startActivityForResult(intent, requestCode);
105 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
std::u16string text
def Build(configs, env, options)
Definition: build.py:232

◆ queryTextActions()

Map< String, String > io.flutter.plugin.text.ProcessTextPlugin.queryTextActions ( )
inline

Requests the map of text actions. Each text action has a unique id and a localized label.

Implements io.flutter.embedding.engine.systemchannels.ProcessTextChannel.ProcessTextMethodHandler.

Definition at line 52 of file ProcessTextPlugin.java.

52 {
53 if (resolveInfosById == null) {
54 cacheResolveInfos();
55 }
56 Map<String, String> result = new HashMap<String, String>();
57 for (String id : resolveInfosById.keySet()) {
58 final ResolveInfo info = resolveInfosById.get(id);
59 result.put(id, info.loadLabel(packageManager).toString());
60 }
61 return result;
62 }

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