5package io.flutter.embedding.engine.plugins.shim;
9import androidx.annotation.NonNull;
10import io.flutter.FlutterInjector;
12import io.flutter.embedding.engine.plugins.FlutterPlugin;
13import io.flutter.embedding.engine.plugins.activity.ActivityAware;
14import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
15import io.flutter.plugin.common.BinaryMessenger;
16import io.flutter.plugin.common.PluginRegistry;
17import io.flutter.plugin.platform.PlatformViewRegistry;
18import io.flutter.view.FlutterView;
19import io.flutter.view.TextureRegistry;
20import java.util.HashSet;
31 private static final String TAG =
"ShimRegistrar";
33 private final Map<String, Object> globalRegistrarMap;
34 private final String pluginId;
35 private final Set<
PluginRegistry.ViewDestroyListener> viewDestroyListeners =
new HashSet<>();
37 requestPermissionsResultListeners =
new HashSet<>();
38 private final Set<
PluginRegistry.ActivityResultListener> activityResultListeners =
40 private final Set<
PluginRegistry.NewIntentListener> newIntentListeners =
new HashSet<>();
41 private final Set<
PluginRegistry.UserLeaveHintListener> userLeaveHintListeners =
new HashSet<>();
42 private final Set<
PluginRegistry.WindowFocusChangedListener> WindowFocusChangedListeners =
44 private FlutterPlugin.FlutterPluginBinding pluginBinding;
47 public ShimRegistrar(@NonNull String pluginId, @NonNull Map<String, Object> globalRegistrarMap) {
48 this.pluginId = pluginId;
49 this.globalRegistrarMap = globalRegistrarMap;
54 return activityPluginBinding !=
null ? activityPluginBinding.
getActivity() :
null;
59 return pluginBinding !=
null ? pluginBinding.getApplicationContext() :
null;
69 return pluginBinding !=
null ? pluginBinding.getBinaryMessenger() :
null;
74 return pluginBinding !=
null ? pluginBinding.getTextureRegistry() :
null;
79 return pluginBinding !=
null ? pluginBinding.getPlatformViewRegistry() :
null;
84 throw new UnsupportedOperationException(
85 "The new embedding does not support the old FlutterView.");
100 globalRegistrarMap.put(pluginId,
value);
107 requestPermissionsResultListeners.add(listener);
109 if (activityPluginBinding !=
null) {
119 activityResultListeners.add(listener);
121 if (activityPluginBinding !=
null) {
130 newIntentListeners.add(listener);
132 if (activityPluginBinding !=
null) {
142 userLeaveHintListeners.add(listener);
144 if (activityPluginBinding !=
null) {
154 WindowFocusChangedListeners.add(listener);
156 if (activityPluginBinding !=
null) {
167 viewDestroyListeners.add(listener);
173 Log.
v(
TAG,
"Attached to FlutterEngine.");
174 pluginBinding = binding;
179 Log.
v(
TAG,
"Detached from FlutterEngine.");
180 for (
PluginRegistry.ViewDestroyListener listener : viewDestroyListeners) {
183 listener.onViewDestroy(
null);
186 pluginBinding =
null;
187 activityPluginBinding =
null;
192 Log.
v(
TAG,
"Attached to an Activity.");
193 activityPluginBinding = binding;
194 addExistingListenersToActivityPluginBinding();
199 Log.
v(
TAG,
"Detached from an Activity for config changes.");
200 activityPluginBinding =
null;
205 Log.
v(
TAG,
"Reconnected to an Activity after config changes.");
206 activityPluginBinding = binding;
207 addExistingListenersToActivityPluginBinding();
212 Log.
v(
TAG,
"Detached from an Activity.");
213 activityPluginBinding =
null;
216 private void addExistingListenersToActivityPluginBinding() {
218 requestPermissionsResultListeners) {
221 for (
PluginRegistry.ActivityResultListener listener : activityResultListeners) {
224 for (
PluginRegistry.NewIntentListener listener : newIntentListeners) {
227 for (PluginRegistry.UserLeaveHintListener listener : userLeaveHintListeners) {
230 for (PluginRegistry.WindowFocusChangedListener listener : WindowFocusChangedListeners) {
static void v(@NonNull String tag, @NonNull String message)
String getLookupKeyForAsset(@NonNull String asset)
void onAttachedToActivity(@NonNull ActivityPluginBinding binding)
PluginRegistry.Registrar addRequestPermissionsResultListener(PluginRegistry.RequestPermissionsResultListener listener)
void onDetachedFromActivity()
TextureRegistry textures()
PluginRegistry.Registrar publish(Object value)
void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding)
PlatformViewRegistry platformViewRegistry()
PluginRegistry.Registrar addWindowFocusChangedListener(PluginRegistry.WindowFocusChangedListener listener)
String lookupKeyForAsset(String asset)
PluginRegistry.Registrar addUserLeaveHintListener(PluginRegistry.UserLeaveHintListener listener)
PluginRegistry.Registrar addActivityResultListener(PluginRegistry.ActivityResultListener listener)
void onAttachedToEngine(@NonNull FlutterPluginBinding binding)
ShimRegistrar(@NonNull String pluginId, @NonNull Map< String, Object > globalRegistrarMap)
void onDetachedFromEngine(@NonNull FlutterPluginBinding binding)
String lookupKeyForAsset(String asset, String packageName)
PluginRegistry.Registrar addViewDestroyListener( @NonNull PluginRegistry.ViewDestroyListener listener)
void onDetachedFromActivityForConfigChanges()
BinaryMessenger messenger()
PluginRegistry.Registrar addNewIntentListener(PluginRegistry.NewIntentListener listener)
void addActivityResultListener(@NonNull PluginRegistry.ActivityResultListener listener)
void addOnWindowFocusChangedListener(@NonNull PluginRegistry.WindowFocusChangedListener listener)
void addOnNewIntentListener(@NonNull PluginRegistry.NewIntentListener listener)
void addOnUserLeaveHintListener(@NonNull PluginRegistry.UserLeaveHintListener listener)
void addRequestPermissionsResultListener( @NonNull PluginRegistry.RequestPermissionsResultListener listener)