1 /* 2 * Copyright (c) 2021-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 KEY_OPTION_H 17 #define KEY_OPTION_H 18 19 #include <set> 20 #include "parcel.h" 21 22 namespace OHOS { 23 namespace MMI { 24 class KeyOption { 25 public: 26 KeyOption() = default; 27 DISALLOW_COPY_AND_MOVE(KeyOption); 28 29 public: 30 /** 31 * @brief Obtains previous keys. 32 * @return Returns previous keys. 33 * @since 9 34 */ 35 std::set<int32_t> GetPreKeys() const; 36 37 /** 38 * @brief Sets previous keys, that is, the keys that are pressed first in a combination key. 39 * There is no requirement on the sequence of previous keys. 40 * @param preKeys Indicates the previous keys to set. 41 * @return void 42 * @since 9 43 */ 44 void SetPreKeys(const std::set<int32_t>& preKeys); 45 46 /** 47 * @brief Obtains the final key. 48 * @return Returns the final key. 49 * @since 9 50 */ 51 int32_t GetFinalKey() const; 52 53 /** 54 * @brief Sets the final key, that is, the key that is last pressed or released in a combination key. 55 * @param finalKey Indicates the final key. 56 * @return void 57 * @since 9 58 */ 59 void SetFinalKey(int32_t finalKey); 60 61 /** 62 * @brief Checks whether the final key in a combination key is pressed or released. 63 * @return Returns <b>true</b> if the key is pressed; returns <b>false</b> if the key is released. 64 * @since 9 65 */ 66 bool IsFinalKeyDown() const; 67 68 /** 69 * @brief Sets whether the final key in a combination key is pressed or released. 70 * @param pressed Indicates whether the key is pressed. The value <b>true</b> means that the key 71 * is pressed, and the value <b>false</b> means that the key is released. 72 * @return void 73 * @since 9 74 */ 75 void SetFinalKeyDown(bool pressed); 76 77 /** 78 * @brief Obtains the duration when the final key is held down or the maximum duration between 79 * when the key is pressed and when the key is released. 80 * If the final key is pressed, this parameter indicates the duration when the final key is held down. 81 * If the last key is released, this parameter indicates the maximum duration between when the key 82 * is pressed and when the key is released. 83 * @return Returns the duration when the final key is held down or the maximum duration between 84 * when the key is pressed and when the key is released. 85 * @since 9 86 */ 87 int32_t GetFinalKeyDownDuration() const; 88 89 /** 90 * @brief Get the delay time of lifting the last key. When the last key is lifted, the subscription 91 * will be delayed and triggered. 92 * @return Return to the delay time of lifting the last key. 93 * @since 9 94 */ 95 int32_t GetFinalKeyUpDelay() const; 96 97 /** 98 * @brief Sets the duration when the final key is held down or the maximum duration between when 99 * the key is pressed and when the key is released. 100 * If the final key is pressed, this parameter indicates the duration when the final key is held down. 101 * If the last key is released, this parameter indicates the maximum duration between when the key 102 * is pressed and when the key is released. 103 * @param duration Indicates the duration when the final key is held down or the maximum duration 104 * between when the key is pressed and when the key is released. 105 * @return void 106 * @since 9 107 */ 108 void SetFinalKeyDownDuration(int32_t duration); 109 110 /** 111 * @brief Set the delay time for lifting the last key. 112 * @param delay Delay time for lifting the last key. 113 * @return void 114 * @since 9 115 */ 116 void SetFinalKeyUpDelay(int32_t delay); 117 118 bool IsRepeat() const; 119 120 void SetRepeat(bool repeat); 121 122 public: 123 /** 124 * @brief Writes data to a <b>Parcel</b> object. 125 * @param out Indicates the object into which data will be written. 126 * @return Returns <b>true</b> if the data is successfully written; returns <b>false</b> otherwise. 127 * @since 9 128 */ 129 bool WriteToParcel(Parcel &out) const; 130 131 /** 132 * @brief Reads data from a <b>Parcel</b> object. 133 * @param in Indicates the object from which data will be read. 134 * @return Returns <b>true</b> if the data is successfully read; returns <b>false</b> otherwise. 135 * @since 9 136 */ 137 bool ReadFromParcel(Parcel &in); 138 139 private: 140 std::set<int32_t> preKeys_ {}; 141 int32_t finalKey_ { -1 }; 142 bool isFinalKeyDown_ { false }; 143 int32_t finalKeyDownDuration_ { 0 }; 144 int32_t finalKeyUpDelay_ { 0 }; 145 bool isRepeat_ { true }; 146 }; 147 148 class KeyMonitorOption final { 149 public: 150 KeyMonitorOption() = default; 151 ~KeyMonitorOption() = default; 152 153 int32_t GetKey() const; 154 int32_t GetAction() const; 155 bool IsRepeat() const; 156 157 void SetKey(int32_t key); 158 void SetAction(int32_t action); 159 void SetRepeat(bool repeat); 160 161 bool Marshalling(Parcel &parcel) const; 162 bool Unmarshalling(Parcel &parcel); 163 164 private: 165 int32_t key_ {}; 166 int32_t action_ {}; 167 bool isRepeat_ {}; 168 }; 169 } // namespace MMI 170 } // namespace OHOS 171 #endif // KEY_OPTION_H 172