• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 public:
GetSwitchType()45     int32_t GetSwitchType() const
46     {
47         return switchType_;
48     }
49 
GetSwitchValue()50     int32_t GetSwitchValue() const
51     {
52         return switchValue_;
53     }
54 
GetSwitchMask()55     int32_t GetSwitchMask() const
56     {
57         return updateSwitchMask_;
58     }
59 
SetSwitchType(int32_t type)60     void SetSwitchType(int32_t type)
61     {
62         switchType_ = type;
63     }
64 
SetSwitchValue(int32_t value)65     void SetSwitchValue(int32_t value)
66     {
67         switchValue_ = value;
68     }
69 
SetSwitchMask(int32_t switchMask)70     void SetSwitchMask(int32_t switchMask)
71     {
72         updateSwitchMask_ = switchMask;
73     }
74 
ToString()75     virtual std::string ToString() override
76     {
77         std::string eventStr = InputEvent::ToString();
78         eventStr += ",switchValue:" + std::to_string(switchValue_);
79         eventStr += ",updateSwitchMask:" + std::to_string(updateSwitchMask_);
80         eventStr += ",switchType:" + std::to_string(switchType_);
81         return eventStr;
82     }
83 
SwitchEvent(int32_t value)84     explicit SwitchEvent(int32_t value)
85         : InputEvent(value),
86         switchValue_(value),
87         updateSwitchMask_(0),
88         switchType_(SwitchType::SWITCH_DEFAULT) {}
89 private:
90         int32_t switchValue_ { 0 };
91         int32_t updateSwitchMask_ { 0 };
92         int32_t switchType_ { SwitchType::SWITCH_DEFAULT };
93 };
94 } // namespace MMI
95 } // namespace OHOS
96 #endif // SWITCH_EVENT_H