Flutter Engine
The Flutter Engine
FlutterPluginRegistry.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.app;
6
7import android.app.Activity;
8import android.content.Context;
9import android.content.Intent;
10import io.flutter.embedding.engine.FlutterEngine;
11import io.flutter.plugin.common.BinaryMessenger;
12import io.flutter.plugin.common.PluginRegistry;
13import io.flutter.plugin.platform.PlatformViewRegistry;
14import io.flutter.plugin.platform.PlatformViewsController;
15import io.flutter.view.FlutterMain;
16import io.flutter.view.FlutterNativeView;
17import io.flutter.view.FlutterView;
18import io.flutter.view.TextureRegistry;
19import java.util.ArrayList;
20import java.util.LinkedHashMap;
21import java.util.List;
22import java.util.Map;
23
24/** @deprecated See https://flutter.dev/go/android-project-migration for migration instructions. */
25@Deprecated
27 implements PluginRegistry,
34 private static final String TAG = "FlutterPluginRegistry";
35
36 private Activity mActivity;
37 private Context mAppContext;
38 private FlutterNativeView mNativeView;
39 private FlutterView mFlutterView;
40
41 private final PlatformViewsController mPlatformViewsController;
42 private final Map<String, Object> mPluginMap = new LinkedHashMap<>(0);
43 private final List<RequestPermissionsResultListener> mRequestPermissionsResultListeners =
44 new ArrayList<>(0);
45 private final List<ActivityResultListener> mActivityResultListeners = new ArrayList<>(0);
46 private final List<NewIntentListener> mNewIntentListeners = new ArrayList<>(0);
47 private final List<UserLeaveHintListener> mUserLeaveHintListeners = new ArrayList<>(0);
48 private final List<WindowFocusChangedListener> mWindowFocusChangedListeners = new ArrayList<>(0);
49 private final List<ViewDestroyListener> mViewDestroyListeners = new ArrayList<>(0);
50
51 public FlutterPluginRegistry(FlutterNativeView nativeView, Context context) {
52 mNativeView = nativeView;
53 mAppContext = context;
54 mPlatformViewsController = new PlatformViewsController();
55 }
56
57 public FlutterPluginRegistry(FlutterEngine engine, Context context) {
58 // TODO(mattcarroll): implement use of engine instead of nativeView.
59 mAppContext = context;
60 mPlatformViewsController = new PlatformViewsController();
61 }
62
63 @Override
64 public boolean hasPlugin(String key) {
65 return mPluginMap.containsKey(key);
66 }
67
68 @Override
69 @SuppressWarnings("unchecked")
70 public <T> T valuePublishedByPlugin(String pluginKey) {
71 return (T) mPluginMap.get(pluginKey);
72 }
73
74 @Override
75 public Registrar registrarFor(String pluginKey) {
76 if (mPluginMap.containsKey(pluginKey)) {
77 throw new IllegalStateException("Plugin key " + pluginKey + " is already in use");
78 }
79 mPluginMap.put(pluginKey, null);
80 return new FlutterRegistrar(pluginKey);
81 }
82
83 public void attach(FlutterView flutterView, Activity activity) {
84 mFlutterView = flutterView;
85 mActivity = activity;
86 mPlatformViewsController.attach(activity, flutterView, flutterView.getDartExecutor());
87 }
88
89 public void detach() {
90 mPlatformViewsController.detach();
91 mPlatformViewsController.onDetachedFromJNI();
92 mFlutterView = null;
93 mActivity = null;
94 }
95
96 public void onPreEngineRestart() {
97 mPlatformViewsController.onPreEngineRestart();
98 }
99
101 return mPlatformViewsController;
102 }
103
104 private class FlutterRegistrar implements Registrar {
105 private final String pluginKey;
106
107 FlutterRegistrar(String pluginKey) {
108 this.pluginKey = pluginKey;
109 }
110
111 @Override
112 public Activity activity() {
113 return mActivity;
114 }
115
116 @Override
117 public Context context() {
118 return mAppContext;
119 }
120
121 @Override
122 public Context activeContext() {
123 return (mActivity != null) ? mActivity : mAppContext;
124 }
125
126 @Override
127 public BinaryMessenger messenger() {
128 return mNativeView;
129 }
130
131 @Override
132 public TextureRegistry textures() {
133 return mFlutterView;
134 }
135
136 @Override
137 public PlatformViewRegistry platformViewRegistry() {
138 return mPlatformViewsController.getRegistry();
139 }
140
141 @Override
142 public FlutterView view() {
143 return mFlutterView;
144 }
145
146 @Override
147 public String lookupKeyForAsset(String asset) {
148 return FlutterMain.getLookupKeyForAsset(asset);
149 }
150
151 @Override
152 public String lookupKeyForAsset(String asset, String packageName) {
153 return FlutterMain.getLookupKeyForAsset(asset, packageName);
154 }
155
156 @Override
157 public Registrar publish(Object value) {
158 mPluginMap.put(pluginKey, value);
159 return this;
160 }
161
162 @Override
164 RequestPermissionsResultListener listener) {
165 mRequestPermissionsResultListeners.add(listener);
166 return this;
167 }
168
169 @Override
170 public Registrar addActivityResultListener(ActivityResultListener listener) {
171 mActivityResultListeners.add(listener);
172 return this;
173 }
174
175 @Override
176 public Registrar addNewIntentListener(NewIntentListener listener) {
177 mNewIntentListeners.add(listener);
178 return this;
179 }
180
181 @Override
182 public Registrar addUserLeaveHintListener(UserLeaveHintListener listener) {
183 mUserLeaveHintListeners.add(listener);
184 return this;
185 }
186
187 @Override
188 public Registrar addWindowFocusChangedListener(WindowFocusChangedListener listener) {
189 mWindowFocusChangedListeners.add(listener);
190 return this;
191 }
192
193 @Override
194 public Registrar addViewDestroyListener(ViewDestroyListener listener) {
195 mViewDestroyListeners.add(listener);
196 return this;
197 }
198 }
199
200 @Override
202 int requestCode, String[] permissions, int[] grantResults) {
203 for (RequestPermissionsResultListener listener : mRequestPermissionsResultListeners) {
204 if (listener.onRequestPermissionsResult(requestCode, permissions, grantResults)) {
205 return true;
206 }
207 }
208 return false;
209 }
210
211 @Override
212 public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
213 for (ActivityResultListener listener : mActivityResultListeners) {
214 if (listener.onActivityResult(requestCode, resultCode, data)) {
215 return true;
216 }
217 }
218 return false;
219 }
220
221 @Override
222 public boolean onNewIntent(Intent intent) {
223 for (NewIntentListener listener : mNewIntentListeners) {
224 if (listener.onNewIntent(intent)) {
225 return true;
226 }
227 }
228 return false;
229 }
230
231 @Override
232 public void onUserLeaveHint() {
233 for (UserLeaveHintListener listener : mUserLeaveHintListeners) {
234 listener.onUserLeaveHint();
235 }
236 }
237
238 @Override
239 public void onWindowFocusChanged(boolean hasFocus) {
240 for (WindowFocusChangedListener listener : mWindowFocusChangedListeners) {
241 listener.onWindowFocusChanged(hasFocus);
242 }
243 }
244
245 @Override
246 public boolean onViewDestroy(FlutterNativeView view) {
247 boolean handled = false;
248 for (ViewDestroyListener listener : mViewDestroyListeners) {
249 if (listener.onViewDestroy(view)) {
250 handled = true;
251 }
252 }
253 return handled;
254 }
255
256 public void destroy() {
257 mPlatformViewsController.onDetachedFromJNI();
258 }
259}
boolean onActivityResult(int requestCode, int resultCode, Intent data)
FlutterPluginRegistry(FlutterNativeView nativeView, Context context)
PlatformViewsController getPlatformViewsController()
public< T > T valuePublishedByPlugin(String pluginKey)
FlutterPluginRegistry(FlutterEngine engine, Context context)
void attach(FlutterView flutterView, Activity activity)
Registrar registrarFor(String pluginKey)
boolean onViewDestroy(FlutterNativeView view)
boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
void attach( @Nullable Context context, @NonNull TextureRegistry textureRegistry, @NonNull DartExecutor dartExecutor)
String getLookupKeyForAsset(String asset)
DartExecutor getDartExecutor()
FlutterEngine engine
Definition: main.cc:68
uint8_t value
Registrar addActivityResultListener(@NonNull ActivityResultListener listener)
Registrar publish(@Nullable Object value)
Registrar addNewIntentListener(@NonNull NewIntentListener listener)
String lookupKeyForAsset(@NonNull String asset)
Registrar addViewDestroyListener(@NonNull ViewDestroyListener listener)
Registrar addRequestPermissionsResultListener( @NonNull RequestPermissionsResultListener listener)
Registrar addUserLeaveHintListener(@NonNull UserLeaveHintListener listener)
Registrar addWindowFocusChangedListener(@NonNull WindowFocusChangedListener listener)
#define T
Definition: precompiler.cc:65
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63