Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Public Attributes | Package Attributes | List of all members
io.flutter.embedding.engine.systemchannels.PlatformChannel Class Reference

Classes

class  AppSwitcherDescription
 
enum  Brightness
 
enum  ClipboardContentFormat
 
enum  DeviceOrientation
 
enum  HapticFeedbackType
 
interface  PlatformMessageHandler
 
enum  SoundType
 
class  SystemChromeStyle
 
enum  SystemUiMode
 
enum  SystemUiOverlay
 

Public Member Functions

 PlatformChannel (@NonNull DartExecutor dartExecutor)
 
void setPlatformMessageHandler (@Nullable PlatformMessageHandler platformMessageHandler)
 
void systemChromeChanged (boolean overlaysAreVisible)
 

Public Attributes

final MethodChannel channel
 

Package Attributes

final MethodChannel.MethodCallHandler parsingMethodCallHandler
 

Detailed Description

System channel that receives requests for host platform behavior, e.g., haptic and sound effects, system chrome configurations, and clipboard interaction.

Definition at line 27 of file PlatformChannel.java.

Constructor & Destructor Documentation

◆ PlatformChannel()

io.flutter.embedding.engine.systemchannels.PlatformChannel.PlatformChannel ( @NonNull DartExecutor  dartExecutor)
inline

Constructs a PlatformChannel that connects Android to the Dart code running in
dartExecutor
.

The given dartExecutor is permitted to be idle or executing code.

See DartExecutor.

Definition at line 213 of file PlatformChannel.java.

213 {
214 channel = new MethodChannel(dartExecutor, "flutter/platform", JSONMethodCodec.INSTANCE);
215 channel.setMethodCallHandler(parsingMethodCallHandler);
216 }
final MethodChannel.MethodCallHandler parsingMethodCallHandler

Member Function Documentation

◆ setPlatformMessageHandler()

void io.flutter.embedding.engine.systemchannels.PlatformChannel.setPlatformMessageHandler ( @Nullable PlatformMessageHandler  platformMessageHandler)
inline

Sets the PlatformMessageHandler which receives all events and requests that are parsed from the underlying platform channel.

Definition at line 222 of file PlatformChannel.java.

222 {
223 this.platformMessageHandler = platformMessageHandler;
224 }

◆ systemChromeChanged()

void io.flutter.embedding.engine.systemchannels.PlatformChannel.systemChromeChanged ( boolean  overlaysAreVisible)
inline

Informs Flutter of a change in the SystemUI overlays.

Definition at line 227 of file PlatformChannel.java.

227 {
228 Log.v(TAG, "Sending 'systemUIChange' message.");
229 channel.invokeMethod("SystemChrome.systemUIChange", Arrays.asList(overlaysAreVisible));
230 }
void Log(const char *format,...) SK_PRINTF_LIKE(1

Member Data Documentation

◆ channel

final MethodChannel io.flutter.embedding.engine.systemchannels.PlatformChannel.channel

Definition at line 30 of file PlatformChannel.java.

◆ parsingMethodCallHandler

final MethodChannel.MethodCallHandler io.flutter.embedding.engine.systemchannels.PlatformChannel.parsingMethodCallHandler
package

Definition at line 34 of file PlatformChannel.java.

35 {
36 @Override
37 public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
38 if (platformMessageHandler == null) {
39 // If no explicit PlatformMessageHandler has been registered then we don't
40 // need to forward this call to an API. Return.
41 return;
42 }
43
44 String method = call.method;
45 Object arguments = call.arguments;
46 Log.v(TAG, "Received '" + method + "' message.");
47 try {
48 switch (method) {
49 case "SystemSound.play":
50 try {
51 SoundType soundType = SoundType.fromValue((String) arguments);
52 platformMessageHandler.playSystemSound(soundType);
53 result.success(null);
54 } catch (NoSuchFieldException exception) {
55 // The desired sound type does not exist.
56 result.error("error", exception.getMessage(), null);
57 }
58 break;
59 case "HapticFeedback.vibrate":
60 try {
61 HapticFeedbackType feedbackType =
62 HapticFeedbackType.fromValue((String) arguments);
63 platformMessageHandler.vibrateHapticFeedback(feedbackType);
64 result.success(null);
65 } catch (NoSuchFieldException exception) {
66 // The desired feedback type does not exist.
67 result.error("error", exception.getMessage(), null);
68 }
69 break;
70 case "SystemChrome.setPreferredOrientations":
71 try {
72 int androidOrientation = decodeOrientations((JSONArray) arguments);
73 platformMessageHandler.setPreferredOrientations(androidOrientation);
74 result.success(null);
75 } catch (JSONException | NoSuchFieldException exception) {
76 // JSONException: One or more expected fields were either omitted or referenced an
77 // invalid type.
78 // NoSuchFieldException: One or more expected fields were either omitted or
79 // referenced an invalid type.
80 result.error("error", exception.getMessage(), null);
81 }
82 break;
83 case "SystemChrome.setApplicationSwitcherDescription":
84 try {
85 AppSwitcherDescription description =
86 decodeAppSwitcherDescription((JSONObject) arguments);
87 platformMessageHandler.setApplicationSwitcherDescription(description);
88 result.success(null);
89 } catch (JSONException exception) {
90 // One or more expected fields were either omitted or referenced an invalid type.
91 result.error("error", exception.getMessage(), null);
92 }
93 break;
94 case "SystemChrome.setEnabledSystemUIOverlays":
95 try {
96 List<SystemUiOverlay> overlays = decodeSystemUiOverlays((JSONArray) arguments);
97 platformMessageHandler.showSystemOverlays(overlays);
98 result.success(null);
99 } catch (JSONException | NoSuchFieldException exception) {
100 // JSONException: One or more expected fields were either omitted or referenced an
101 // invalid type.
102 // NoSuchFieldException: One or more of the overlay names are invalid.
103 result.error("error", exception.getMessage(), null);
104 }
105 break;
106 case "SystemChrome.setEnabledSystemUIMode":
107 try {
108 SystemUiMode mode = decodeSystemUiMode((String) arguments);
109 platformMessageHandler.showSystemUiMode(mode);
110 result.success(null);
111 } catch (JSONException | NoSuchFieldException exception) {
112 // JSONException: One or more expected fields were either omitted or referenced an
113 // invalid type.
114 // NoSuchFieldException: One or more of the overlay names are invalid.
115 result.error("error", exception.getMessage(), null);
116 }
117 break;
118 case "SystemChrome.setSystemUIChangeListener":
119 platformMessageHandler.setSystemUiChangeListener();
120 result.success(null);
121 break;
122 case "SystemChrome.restoreSystemUIOverlays":
123 platformMessageHandler.restoreSystemUiOverlays();
124 result.success(null);
125 break;
126 case "SystemChrome.setSystemUIOverlayStyle":
127 try {
128 SystemChromeStyle systemChromeStyle =
129 decodeSystemChromeStyle((JSONObject) arguments);
130 platformMessageHandler.setSystemUiOverlayStyle(systemChromeStyle);
131 result.success(null);
132 } catch (JSONException | NoSuchFieldException exception) {
133 // JSONException: One or more expected fields were either omitted or referenced an
134 // invalid type.
135 // NoSuchFieldException: One or more of the brightness names are invalid.
136 result.error("error", exception.getMessage(), null);
137 }
138 break;
139 case "SystemNavigator.setFrameworkHandlesBack":
140 {
141 boolean frameworkHandlesBack = (boolean) arguments;
142 platformMessageHandler.setFrameworkHandlesBack(frameworkHandlesBack);
143 result.success(null);
144 break;
145 }
146 case "SystemNavigator.pop":
147 platformMessageHandler.popSystemNavigator();
148 result.success(null);
149 break;
150 case "Clipboard.getData":
151 {
152 String contentFormatName = (String) arguments;
153 ClipboardContentFormat clipboardFormat = null;
154 if (contentFormatName != null) {
155 try {
156 clipboardFormat = ClipboardContentFormat.fromValue(contentFormatName);
157 } catch (NoSuchFieldException exception) {
158 // An unsupported content format was requested. Return failure.
159 result.error(
160 "error", "No such clipboard content format: " + contentFormatName, null);
161 }
162 }
163
164 CharSequence clipboardContent =
165 platformMessageHandler.getClipboardData(clipboardFormat);
166 if (clipboardContent != null) {
167 JSONObject response = new JSONObject();
168 response.put("text", clipboardContent);
169 result.success(response);
170 } else {
171 result.success(null);
172 }
173 break;
174 }
175 case "Clipboard.setData":
176 {
177 String clipboardContent = ((JSONObject) arguments).getString("text");
178 platformMessageHandler.setClipboardData(clipboardContent);
179 result.success(null);
180 break;
181 }
182 case "Clipboard.hasStrings":
183 {
184 boolean hasStrings = platformMessageHandler.clipboardHasStrings();
185 JSONObject response = new JSONObject();
186 response.put("value", hasStrings);
187 result.success(response);
188 break;
189 }
190 case "Share.invoke":
191 String text = (String) arguments;
192 platformMessageHandler.share(text);
193 result.success(null);
194 break;
195 default:
196 result.notImplemented();
197 break;
198 }
199 } catch (JSONException e) {
200 result.error("error", "JSON error: " + e.getMessage(), null);
201 }
202 }
203 };
static ::testing::Matcher< GBytes * > MethodCall(const std::string &name, ::testing::Matcher< FlValue * > args)
GAsyncResult * result
CharSequence getClipboardData(@Nullable ClipboardContentFormat format)
void setApplicationSwitcherDescription(@NonNull AppSwitcherDescription description)
void setSystemUiOverlayStyle(@NonNull SystemChromeStyle systemUiOverlayStyle)
std::u16string text
call(args)
Definition dom.py:159
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition switches.h:228

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