1/* 2 * Copyright (c) 2023 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 16import inputMethod from '@ohos.inputMethod'; 17import common from '@ohos.app.ability.common'; 18 19class InputAttributeInit { 20 private textInputType: Array<inputMethod.TextInputType> = [inputMethod.TextInputType.NONE, inputMethod.TextInputType.TEXT, inputMethod.TextInputType.NUMBER, inputMethod.TextInputType.PHONE]; 21 private enterKeyType: Array<inputMethod.EnterKeyType> = [inputMethod.EnterKeyType.NONE, inputMethod.EnterKeyType.SEARCH, inputMethod.EnterKeyType.SEND, inputMethod.EnterKeyType.GO]; 22 private inputTypeString: Array<Resource> = [$r('app.string.default_input'), $r('app.string.text_input'), $r('app.string.number_input'), $r('app.string.phone_input')]; 23 private enterTypeString: Array<Resource> = [$r('app.string.default_enter_key'), $r('app.string.search_enter_key'), $r('app.string.send_enter_key'), $r('app.string.go_enter_key')]; 24 25 getInputTypeSource(): Array<Resource> { 26 return this.inputTypeString; 27 } 28 29 getEnterTypeSource(): Array<Resource> { 30 return this.enterTypeString; 31 } 32 33 getInputType(index: number): inputMethod.TextInputType { 34 if (index >= 0 && index < this.textInputType.length) { 35 return this.textInputType[index]; 36 } 37 return inputMethod.TextInputType.NONE; 38 } 39 40 getInputTypeValue(index: number): string { 41 if (index >= 0 && index < this.inputTypeString.length) { 42 return this.getResourceString(this.inputTypeString[index]); 43 } 44 return this.getResourceString($r('app.string.text_input_type')); 45 } 46 47 getEnterType(index: number): inputMethod.EnterKeyType { 48 if (index >= 0 && index < this.enterKeyType.length) { 49 return this.enterKeyType[index]; 50 } 51 return inputMethod.EnterKeyType.NONE; 52 } 53 54 getEnterTypeValue(index: number): string { 55 if (index >= 0 && index < this.enterTypeString.length) { 56 return this.getResourceString(this.enterTypeString[index]); 57 } 58 return this.getResourceString($r('app.string.enter_key_type')); 59 } 60 61 getResourceString(resource: Resource): string { 62 let context = getContext(this) as common.UIAbilityContext; 63 return context.resourceManager.getStringSync(resource.id); 64 } 65} 66 67export const inputAttribute = new InputAttributeInit();