66
77#include < app.h>
88
9+ #include < map>
10+
911#include " flutter/shell/platform/common/cpp/json_method_codec.h"
1012#include " flutter/shell/platform/tizen/tizen_log.h"
1113
1214static constexpr char kChannelName [] = " flutter/platform" ;
1315
14- PlatformChannel::PlatformChannel (flutter::BinaryMessenger* messenger)
16+ PlatformChannel::PlatformChannel (flutter::BinaryMessenger* messenger,
17+ TizenRenderer* renderer)
1518 : channel_(std::make_unique<flutter::MethodChannel<rapidjson::Document>>(
1619 messenger, kChannelName , &flutter::JsonMethodCodec::GetInstance ())) {
1720 channel_->SetMethodCallHandler (
@@ -20,6 +23,9 @@ PlatformChannel::PlatformChannel(flutter::BinaryMessenger* messenger)
2023 std::unique_ptr<flutter::MethodResult<rapidjson::Document>> result) {
2124 HandleMethodCall (call, std::move (result));
2225 });
26+ // renderer pointer is managed by TizenEmbedderEngine
27+ // !! can be nullptr in case of service application !!
28+ tizen_renderer_ = renderer;
2329}
2430
2531PlatformChannel::~PlatformChannel () {}
@@ -43,7 +49,41 @@ void PlatformChannel::HandleMethodCall(
4349 } else if (method == " Clipboard.hasStrings" ) {
4450 result->NotImplemented ();
4551 } 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+ }
4787 } else if (method == " SystemChrome.setApplicationSwitcherDescription" ) {
4888 result->NotImplemented ();
4989 } else if (method == " SystemChrome.setEnabledSystemUIOverlays" ) {
0 commit comments