1 /* 2 * Copyright (c) 2024 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 SWITCH_EVENT_H 17 #define SWITCH_EVENT_H 18 19 #include "input_event.h" 20 21 namespace OHOS { 22 namespace MMI { 23 class SwitchEvent : public InputEvent { 24 public: 25 static constexpr int32_t SWITCH_ON = 0; 26 static constexpr int32_t SWITCH_OFF = 1; 27 28 /** 29 * @brief Enumerated values of switch type. 30 * 31 * @since 12 32 */ 33 enum SwitchType { 34 /** Default, used to be compatible with calls to previously none switch type parameter */ 35 SWITCH_DEFAULT = 0, 36 /** Lid switch type */ 37 SWITCH_LID, 38 /** Tablet switch type */ 39 SWITCH_TABLET, 40 /** Privacy switch type */ 41 SWITCH_PRIVACY 42 }; 43 44 enum SwitchState { 45 STATE_UNKNOW = -1, 46 STATE_ON, 47 STATE_OFF 48 }; 49 50 public: GetSwitchType()51 int32_t GetSwitchType() const 52 { 53 return switchType_; 54 } 55 GetSwitchValue()56 int32_t GetSwitchValue() const 57 { 58 return switchValue_; 59 } 60 GetSwitchMask()61 int32_t GetSwitchMask() const 62 { 63 return updateSwitchMask_; 64 } 65 SetSwitchType(int32_t type)66 void SetSwitchType(int32_t type) 67 { 68 switchType_ = type; 69 } 70 SetSwitchValue(int32_t value)71 void SetSwitchValue(int32_t value) 72 { 73 switchValue_ = value; 74 } 75 SetSwitchMask(int32_t switchMask)76 void SetSwitchMask(int32_t switchMask) 77 { 78 updateSwitchMask_ = switchMask; 79 } 80 ToString()81 virtual std::string ToString() override 82 { 83 std::string eventStr = InputEvent::ToString(); 84 eventStr += ",switchValue:" + std::to_string(switchValue_); 85 eventStr += ",updateSwitchMask:" + std::to_string(updateSwitchMask_); 86 eventStr += ",switchType:" + std::to_string(switchType_); 87 return eventStr; 88 } 89 SwitchEvent(int32_t value)90 explicit SwitchEvent(int32_t value) 91 : InputEvent(value), 92 switchValue_(value), 93 updateSwitchMask_(0), 94 switchType_(SwitchType::SWITCH_DEFAULT) {} 95 private: 96 int32_t switchValue_ { 0 }; 97 int32_t updateSwitchMask_ { 0 }; 98 int32_t switchType_ { SwitchType::SWITCH_DEFAULT }; 99 }; 100 } // namespace MMI 101 } // namespace OHOS 102 #endif // SWITCH_EVENT_H