1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_MEDIA_QUERY_MEDIA_QUERY_INFO_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_MEDIA_QUERY_MEDIA_QUERY_INFO_H 18 19 #include <string> 20 21 #include "base/json/json_util.h" 22 #include "base/memory/ace_type.h" 23 #include "base/utils/macros.h" 24 #include "base/utils/noncopyable.h" 25 #include "base/utils/system_properties.h" 26 27 namespace OHOS::Ace::Framework { 28 29 class ACE_FORCE_EXPORT MediaQueryInfo : public AceType { 30 DECLARE_ACE_TYPE(MediaQueryInfo, AceType); 31 32 public: 33 MediaQueryInfo() = default; 34 ~MediaQueryInfo() override = default; 35 36 static std::unique_ptr<JsonValue> GetMediaQueryJsonInfo(); 37 std::string GetMediaQueryInfo() const; 38 39 static std::string GetDeviceType(); 40 41 static std::string GetOrientation(); 42 GetIsInit()43 bool GetIsInit() const 44 { 45 return isInit_; 46 } 47 SetIsInit(bool init)48 void SetIsInit(bool init) 49 { 50 isInit_ = init; 51 } 52 SetListenerId(const std::string & listenerId)53 void SetListenerId(const std::string& listenerId) 54 { 55 listenerId_ = listenerId; 56 backupListenerId_ = listenerId; 57 } 58 GetListenerId()59 const std::string& GetListenerId() const 60 { 61 return listenerId_; 62 } 63 64 // reset listenerId when it was consumed to handle multi-page case. ResetListenerId()65 void ResetListenerId() 66 { 67 listenerId_.clear(); 68 } 69 70 // ensure listenerId is valid to handle split screen case. EnsureListenerIdValid()71 void EnsureListenerIdValid() 72 { 73 listenerId_ = backupListenerId_; 74 } 75 76 private: 77 bool isInit_ = true; 78 std::string listenerId_; 79 // backupListenerId_ is used for backup listenerId_ to handle split screen case. 80 // under the circumstances, the viewsizechanged event will be triggered, but the 81 // method of addListener will not run, so the listenerId is empty. this backup 82 // can ensure listenerId_ is valid when screen is split. 83 std::string backupListenerId_; 84 85 ACE_DISALLOW_COPY_AND_MOVE(MediaQueryInfo); 86 }; 87 88 } // namespace OHOS::Ace::Framework 89 90 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_MEDIA_QUERY_MEDIA_QUERY_INFO_H 91