6
6
7
7
#include < app.h>
8
8
9
+ #include < map>
10
+
9
11
#include " flutter/shell/platform/common/cpp/json_method_codec.h"
10
12
#include " flutter/shell/platform/tizen/tizen_log.h"
11
13
12
14
static constexpr char kChannelName [] = " flutter/platform" ;
13
15
14
- PlatformChannel::PlatformChannel (flutter::BinaryMessenger* messenger)
16
+ PlatformChannel::PlatformChannel (flutter::BinaryMessenger* messenger,
17
+ TizenRenderer* renderer)
15
18
: channel_(std::make_unique<flutter::MethodChannel<rapidjson::Document>>(
16
19
messenger, kChannelName , &flutter::JsonMethodCodec::GetInstance ())) {
17
20
channel_->SetMethodCallHandler (
@@ -20,6 +23,9 @@ PlatformChannel::PlatformChannel(flutter::BinaryMessenger* messenger)
20
23
std::unique_ptr<flutter::MethodResult<rapidjson::Document>> result) {
21
24
HandleMethodCall (call, std::move (result));
22
25
});
26
+ // renderer pointer is managed by TizenEmbedderEngine
27
+ // !! can be nullptr in case of service application !!
28
+ tizen_renderer_ = renderer;
23
29
}
24
30
25
31
PlatformChannel::~PlatformChannel () {}
@@ -43,7 +49,41 @@ void PlatformChannel::HandleMethodCall(
43
49
} else if (method == " Clipboard.hasStrings" ) {
44
50
result->NotImplemented ();
45
51
} else if (method == " SystemChrome.setPreferredOrientations" ) {
46
- result->NotImplemented ();
52
+ if (tizen_renderer_) {
53
+ static const std::string kPortraitUp = " DeviceOrientation.portraitUp" ;
54
+ static const std::string kPortraitDown = " DeviceOrientation.portraitDown" ;
55
+ static const std::string kLandscapeLeft =
56
+ " DeviceOrientation.landscapeLeft" ;
57
+ static const std::string kLandscapeRight =
58
+ " DeviceOrientation.landscapeRight" ;
59
+ static const std::map<std::string, int > orientation_mapping = {
60
+ {kPortraitUp , 0 },
61
+ {kLandscapeLeft , 90 },
62
+ {kPortraitDown , 180 },
63
+ {kLandscapeRight , 270 },
64
+ };
65
+
66
+ const auto & list = call.arguments ()[0 ];
67
+ std::vector<int > rotations;
68
+ for (rapidjson::Value::ConstValueIterator itr = list.Begin ();
69
+ itr != list.End (); ++itr) {
70
+ const std::string& rot = itr->GetString ();
71
+ FT_LOGD (" Passed rotation: %s" , rot.c_str ());
72
+ rotations.push_back (orientation_mapping.at (rot));
73
+ }
74
+ if (rotations.size () == 0 ) {
75
+ // According do docs
76
+ // https://api.flutter.dev/flutter/services/SystemChrome/setPreferredOrientations.html
77
+ // "The empty list causes the application to defer to the operating
78
+ // system default."
79
+ FT_LOGD (" No rotations passed, using default values" );
80
+ rotations = {0 , 90 , 180 , 270 };
81
+ }
82
+ tizen_renderer_->SetPreferredOrientations (rotations);
83
+ result->Success ();
84
+ } else {
85
+ result->Error (" Not supported for service applications" );
86
+ }
47
87
} else if (method == " SystemChrome.setApplicationSwitcherDescription" ) {
48
88
result->NotImplemented ();
49
89
} else if (method == " SystemChrome.setEnabledSystemUIOverlays" ) {
0 commit comments