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 deviceInfo from '@ohos.deviceInfo'; 17import i18n from '@ohos.i18n'; 18 19/** 20 * 设备信息工具 21 * 22 * @since 2022-06-06 23 */ 24export namespace DeviceUtils { 25 /** 26 * 获取设备类型 27 * 28 * @return 设备类型 29 */ 30 export function getDeviceType(): string { 31 return deviceInfo.deviceType; 32 } 33 34 /** 35 * 获取显示版本号 36 * 37 * @return 显示版本号 38 */ 39 export function getDisplayVersion(): string { 40 return deviceInfo.displayVersion; 41 } 42 43 /** 44 * 获取系统语言 45 * 46 * @return 系统语言 47 */ 48 export function getSystemLanguage(): string { 49 let language = i18n.getSystemLanguage(); 50 if (language == 'zh-Hans') { 51 language = 'zh-cn'; 52 } else { 53 language = 'en-us'; 54 } 55 return language; 56 } 57 58 /** 59 * 取dialog位置 60 * 61 * @return dialog位置 62 */ 63 export function getDialogLocation(): DialogAlignment{ 64 return DialogAlignment.Bottom; 65 } 66 67 /** 68 * 取dialog偏移 69 * 70 * @return dialog偏移 71 */ 72 export function getDialogOffsetY(): string | Resource { 73 return $r('app.float.dialog_location_offset_y'); 74 } 75}