44
55#include " platform_channel.h"
66
7+ #include < app.h>
8+
9+ #include < map>
10+
711#include " flutter/shell/platform/common/json_method_codec.h"
12+ #include " flutter/shell/platform/tizen/channels/feedback_manager.h"
13+ #include " flutter/shell/platform/tizen/channels/tizen_shell.h"
814#include " flutter/shell/platform/tizen/logger.h"
915
1016namespace flutter {
@@ -19,18 +25,14 @@ constexpr char kClipboardHasStringsMethod[] = "Clipboard.hasStrings";
1925constexpr char kPlaySoundMethod [] = " SystemSound.play" ;
2026constexpr char kHapticFeedbackVibrateMethod [] = " HapticFeedback.vibrate" ;
2127constexpr char kSystemNavigatorPopMethod [] = " SystemNavigator.pop" ;
22- constexpr char kRestoreSystemUIOverlaysMethod [] =
28+ #ifdef COMMON_PROFILE
29+ constexpr char kRestoreSystemUiOverlaysMethod [] =
2330 " SystemChrome.restoreSystemUIOverlays" ;
24- constexpr char kSetApplicationSwitcherDescriptionMethod [] =
25- " SystemChrome.setApplicationSwitcherDescription" ;
26- constexpr char kSetEnabledSystemUIModeMethod [] =
27- " SystemChrome.setEnabledSystemUIMode" ;
28- constexpr char kSetEnabledSystemUIOverlaysMethod [] =
31+ constexpr char kSetEnabledSystemUiOverlaysMethod [] =
2932 " SystemChrome.setEnabledSystemUIOverlays" ;
33+ #endif
3034constexpr char kSetPreferredOrientationsMethod [] =
3135 " SystemChrome.setPreferredOrientations" ;
32- constexpr char kSetSystemUIOverlayStyleMethod [] =
33- " SystemChrome.setSystemUIOverlayStyle" ;
3436
3537constexpr char kTextKey [] = " text" ;
3638constexpr char kValueKey [] = " value" ;
@@ -40,6 +42,13 @@ constexpr char kUnknownClipboardFormatError[] =
4042constexpr char kUnknownClipboardError [] =
4143 " Unknown error during clipboard data retrieval" ;
4244
45+ constexpr char kSoundTypeClick [] = " SystemSoundType.click" ;
46+ constexpr char kSystemUiOverlayBottom [] = " SystemUiOverlay.bottom" ;
47+ constexpr char kPortraitUp [] = " DeviceOrientation.portraitUp" ;
48+ constexpr char kPortraitDown [] = " DeviceOrientation.portraitDown" ;
49+ constexpr char kLandscapeLeft [] = " DeviceOrientation.landscapeLeft" ;
50+ constexpr char kLandscapeRight [] = " DeviceOrientation.landscapeRight" ;
51+
4352// Naive implementation using std::string as a container of internal clipboard
4453// data.
4554std::string text_clipboard = " " ;
@@ -63,10 +72,10 @@ PlatformChannel::PlatformChannel(BinaryMessenger* messenger,
6372PlatformChannel::~PlatformChannel () {}
6473
6574void PlatformChannel::HandleMethodCall (
66- const MethodCall<rapidjson::Document>& call ,
75+ const MethodCall<rapidjson::Document>& method_call ,
6776 std::unique_ptr<MethodResult<rapidjson::Document>> result) {
68- const auto method = call .method_name ();
69- const auto arguments = call .arguments ();
77+ const auto & method = method_call .method_name ();
78+ const auto * arguments = method_call .arguments ();
7079
7180 if (method == kSystemNavigatorPopMethod ) {
7281 SystemNavigatorPop ();
@@ -111,17 +120,19 @@ void PlatformChannel::HandleMethodCall(
111120 document.AddMember (rapidjson::Value (kValueKey , allocator),
112121 rapidjson::Value (!text_clipboard.empty ()), allocator);
113122 result->Success (document);
114- } else if (method == kRestoreSystemUIOverlaysMethod ) {
115- RestoreSystemUIOverlays ();
123+ #ifdef COMMON_PROFILE
124+ } else if (method == kRestoreSystemUiOverlaysMethod ) {
125+ RestoreSystemUiOverlays ();
116126 result->Success ();
117- } else if (method == kSetEnabledSystemUIOverlaysMethod ) {
127+ } else if (method == kSetEnabledSystemUiOverlaysMethod ) {
118128 const auto & list = arguments[0 ];
119129 std::vector<std::string> overlays;
120130 for (auto iter = list.Begin (); iter != list.End (); ++iter) {
121131 overlays.push_back (iter->GetString ());
122132 }
123- SetEnabledSystemUIOverlays (overlays);
133+ SetEnabledSystemUiOverlays (overlays);
124134 result->Success ();
135+ #endif
125136 } else if (method == kSetPreferredOrientationsMethod ) {
126137 const auto & list = arguments[0 ];
127138 std::vector<std::string> orientations;
@@ -130,16 +141,79 @@ void PlatformChannel::HandleMethodCall(
130141 }
131142 SetPreferredOrientations (orientations);
132143 result->Success ();
133- } else if (method == kSetApplicationSwitcherDescriptionMethod ) {
134- result->NotImplemented ();
135- } else if (method == kSetEnabledSystemUIModeMethod ) {
136- result->NotImplemented ();
137- } else if (method == kSetSystemUIOverlayStyleMethod ) {
138- result->NotImplemented ();
139144 } else {
140145 FT_LOG (Info) << " Unimplemented method: " << method;
141146 result->NotImplemented ();
142147 }
143148}
144149
150+ void PlatformChannel::SystemNavigatorPop () {
151+ ui_app_exit ();
152+ }
153+
154+ void PlatformChannel::PlaySystemSound (const std::string& sound_type) {
155+ if (sound_type == kSoundTypeClick ) {
156+ FeedbackManager::GetInstance ().PlayTapSound ();
157+ } else {
158+ FeedbackManager::GetInstance ().PlaySound ();
159+ }
160+ }
161+
162+ void PlatformChannel::HapticFeedbackVibrate (const std::string& feedback_type) {
163+ FeedbackManager::GetInstance ().Vibrate ();
164+ }
165+
166+ void PlatformChannel::RestoreSystemUiOverlays () {
167+ if (!renderer_) {
168+ return ;
169+ }
170+ auto & shell = TizenShell::GetInstance ();
171+ shell.InitializeSoftkey (renderer_->GetWindowId ());
172+
173+ if (shell.IsSoftkeyShown ()) {
174+ shell.ShowSoftkey ();
175+ } else {
176+ shell.HideSoftkey ();
177+ }
178+ }
179+
180+ void PlatformChannel::SetEnabledSystemUiOverlays (
181+ const std::vector<std::string>& overlays) {
182+ if (!renderer_) {
183+ return ;
184+ }
185+ auto & shell = TizenShell::GetInstance ();
186+ shell.InitializeSoftkey (renderer_->GetWindowId ());
187+
188+ if (std::find (overlays.begin (), overlays.end (), kSystemUiOverlayBottom ) !=
189+ overlays.end ()) {
190+ shell.ShowSoftkey ();
191+ } else {
192+ shell.HideSoftkey ();
193+ }
194+ }
195+
196+ void PlatformChannel::SetPreferredOrientations (
197+ const std::vector<std::string>& orientations) {
198+ if (!renderer_) {
199+ return ;
200+ }
201+ static const std::map<std::string, int > orientation_mapping = {
202+ {kPortraitUp , 0 },
203+ {kLandscapeLeft , 90 },
204+ {kPortraitDown , 180 },
205+ {kLandscapeRight , 270 },
206+ };
207+ std::vector<int > rotations;
208+ for (const auto & orientation : orientations) {
209+ rotations.push_back (orientation_mapping.at (orientation));
210+ }
211+ if (rotations.empty ()) {
212+ // The empty list causes the application to defer to the operating system
213+ // default.
214+ rotations = {0 , 90 , 180 , 270 };
215+ }
216+ renderer_->SetPreferredOrientations (rotations);
217+ }
218+
145219} // namespace flutter
0 commit comments