1 /* 2 * Copyright (C) 2021 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 #include "keyboard_type.h" 17 18 namespace OHOS { 19 namespace MiscServices { 20 using namespace std; 21 /*! Constructor 22 */ KeyboardType()23 KeyboardType::KeyboardType() 24 { 25 } 26 27 /*! Constructor from another instance 28 \param type the source instance 29 */ KeyboardType(const KeyboardType & type)30 KeyboardType::KeyboardType(const KeyboardType& type) 31 { 32 mId = type.mId; 33 mHashCode = type.mHashCode; 34 mLabelId = type.mLabelId; 35 mIconId = type.mIconId; 36 mIsAsciiCapable = type.mIsAsciiCapable; 37 mLanguage = type.mLanguage; 38 mInputSource = type.mInputSource; 39 mCustomizedValue = type.mCustomizedValue; 40 } 41 42 /*! Destructor 43 */ ~KeyboardType()44 KeyboardType::~KeyboardType() 45 { 46 } 47 48 /*! Get value from another instance 49 \param type source instance 50 \return return this 51 */ operator =(const KeyboardType & type)52 KeyboardType& KeyboardType::operator =(const KeyboardType& type) 53 { 54 if (this == &type) { 55 return *this; 56 } 57 58 mId = type.mId; 59 mHashCode = type.mHashCode; 60 mLabelId = type.mLabelId; 61 mIconId = type.mIconId; 62 mIsAsciiCapable = type.mIsAsciiCapable; 63 mLanguage = type.mLanguage; 64 mInputSource = type.mInputSource; 65 mCustomizedValue = type.mCustomizedValue; 66 67 return *this; 68 } 69 70 /*! Write the details of object to parcel 71 */ Marshalling(Parcel & parcel) const72 bool KeyboardType::Marshalling(Parcel &parcel) const 73 { 74 if (!(parcel.WriteInt32(mId) 75 && parcel.WriteInt32(mHashCode) 76 && parcel.WriteInt32(mLabelId) 77 && parcel.WriteInt32(mIconId) 78 && parcel.WriteBool(mIsAsciiCapable) 79 && parcel.WriteString16(mLanguage) 80 && parcel.WriteString16(mInputSource) 81 && parcel.WriteString16(mCustomizedValue))) 82 return false; 83 return true; 84 } 85 86 /*! Read the details of object from parcel 87 \param parcel read the details of object from this parcel 88 \return ErrorCode::NO_ERROR 89 \return ErrorCode::ERROR_NULL_POINTER parcel is null 90 */ Unmarshalling(Parcel & parcel)91 KeyboardType *KeyboardType::Unmarshalling(Parcel &parcel) 92 { 93 auto info = new KeyboardType(); 94 info->mId = parcel.ReadInt32(); 95 info->mHashCode = parcel.ReadInt32(); 96 info->mLabelId = parcel.ReadInt32(); 97 info->mIconId = parcel.ReadInt32(); 98 info->mIsAsciiCapable = parcel.ReadBool(); 99 info->mLanguage = parcel.ReadString16(); 100 info->mInputSource = parcel.ReadString16(); 101 info->mCustomizedValue = parcel.ReadString16(); 102 return info; 103 } 104 setId(int32_t typeId)105 void KeyboardType::setId(int32_t typeId) 106 { 107 mId = typeId; 108 if (typeId != ID_NONE) { 109 mHashCode = typeId; 110 } else { 111 mHashCode = ID_NONE; 112 } 113 } 114 setLabelId(int32_t labelId)115 void KeyboardType::setLabelId(int32_t labelId) 116 { 117 mLabelId = labelId; 118 } 119 setIconId(int32_t iconId)120 void KeyboardType::setIconId(int32_t iconId) 121 { 122 mIconId = iconId; 123 } 124 setAsciiCapability(bool isAsciiCapable)125 void KeyboardType::setAsciiCapability(bool isAsciiCapable) 126 { 127 mIsAsciiCapable = isAsciiCapable; 128 } 129 setLanguage(u16string language)130 void KeyboardType::setLanguage(u16string language) 131 { 132 mLanguage = language; 133 } 134 setInputSource(u16string inputSource)135 void KeyboardType::setInputSource(u16string inputSource) 136 { 137 mInputSource = inputSource; 138 } 139 setCustomizedValue(u16string keyBoardTypeCustomizedValue)140 void KeyboardType::setCustomizedValue(u16string keyBoardTypeCustomizedValue) 141 { 142 mCustomizedValue = keyBoardTypeCustomizedValue; 143 } 144 getId() const145 int32_t KeyboardType::getId() const 146 { 147 return mId; 148 } 149 getLabelId() const150 int32_t KeyboardType::getLabelId() const 151 { 152 return mLabelId; 153 } 154 getIconId() const155 int32_t KeyboardType::getIconId() const 156 { 157 return mIconId; 158 } 159 160 /*! Get hash code of the object 161 \return return hashCode value 162 */ getHashCode() const163 int KeyboardType::getHashCode() const 164 { 165 return mHashCode; 166 } 167 168 /*! Get language of the object 169 \return return the language of this object 170 */ getLanguage() const171 u16string KeyboardType::getLanguage() const 172 { 173 return mLanguage; 174 } 175 getInputSource() const176 u16string KeyboardType::getInputSource() const 177 { 178 return mInputSource; 179 } 180 getCustomizedValue() const181 u16string KeyboardType::getCustomizedValue() const 182 { 183 return mCustomizedValue; 184 } 185 } 186 }