1bea4f105Sopenharmony_ci/* 2bea4f105Sopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3bea4f105Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4bea4f105Sopenharmony_ci * you may not use this file except in compliance with the License. 5bea4f105Sopenharmony_ci * You may obtain a copy of the License at 6bea4f105Sopenharmony_ci * 7bea4f105Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8bea4f105Sopenharmony_ci * 9bea4f105Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10bea4f105Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11bea4f105Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12bea4f105Sopenharmony_ci * See the License for the specific language governing permissions and 13bea4f105Sopenharmony_ci * limitations under the License. 14bea4f105Sopenharmony_ci */ 15bea4f105Sopenharmony_ci 16bea4f105Sopenharmony_ciimport window from '@ohos.window'; 17bea4f105Sopenharmony_ciimport prompt from '@ohos.prompt'; 18bea4f105Sopenharmony_ciimport { getResourceString } from './Tools'; 19bea4f105Sopenharmony_ciimport { MILLISECOND, FILENAME_REGEXP } from '../constants/Constant'; 20bea4f105Sopenharmony_ciimport Logger from '../log/Logger'; 21bea4f105Sopenharmony_ci 22bea4f105Sopenharmony_ciconst TAG = 'commonUtil'; 23bea4f105Sopenharmony_ci 24bea4f105Sopenharmony_ciexport const toast = (text: string | Resource, time = MILLISECOND.ONE_SECOND) => { 25bea4f105Sopenharmony_ci let resourceString: string | undefined = undefined; 26bea4f105Sopenharmony_ci if (typeof text !== 'string') { 27bea4f105Sopenharmony_ci resourceString = getResourceString(text); 28bea4f105Sopenharmony_ci } else { 29bea4f105Sopenharmony_ci resourceString = text; 30bea4f105Sopenharmony_ci } 31bea4f105Sopenharmony_ci prompt.showToast({ message: resourceString, duration: time }); 32bea4f105Sopenharmony_ci} 33bea4f105Sopenharmony_ci 34bea4f105Sopenharmony_ci/** 35bea4f105Sopenharmony_ci * 设置导航栏、状态栏背景、文字颜色 36bea4f105Sopenharmony_ci * 37bea4f105Sopenharmony_ci * @param navigationBarColor 导航栏背景颜色 38bea4f105Sopenharmony_ci * @param statusBarColor 状态栏背景颜色 39bea4f105Sopenharmony_ci * @param navigationBarContentColor 导航栏文字颜色 40bea4f105Sopenharmony_ci * @param statusBarContentColor 状态栏文字颜色 41bea4f105Sopenharmony_ci */ 42bea4f105Sopenharmony_ciexport const setSystemBar = async (navigationBarColor?: string, statusBarColor?: string, 43bea4f105Sopenharmony_ci navigationBarContentColor?: string, statusBarContentColor?: string) => { 44bea4f105Sopenharmony_ci let w = await window.getTopWindow(getContext(this)); 45bea4f105Sopenharmony_ci await w.setSystemBarProperties({ 46bea4f105Sopenharmony_ci navigationBarColor, 47bea4f105Sopenharmony_ci statusBarColor, 48bea4f105Sopenharmony_ci navigationBarContentColor, 49bea4f105Sopenharmony_ci statusBarContentColor 50bea4f105Sopenharmony_ci }); 51bea4f105Sopenharmony_ci} 52bea4f105Sopenharmony_ci 53bea4f105Sopenharmony_ci/** 54bea4f105Sopenharmony_ci * 设置沉浸式 55bea4f105Sopenharmony_ci * 56bea4f105Sopenharmony_ci * @param isImmersion 是否沉浸式 57bea4f105Sopenharmony_ci */ 58bea4f105Sopenharmony_ciexport const setImmersion = (isImmersion: boolean) => { 59bea4f105Sopenharmony_ci let TAG = 'setImmersion'; 60bea4f105Sopenharmony_ci if (!globalThis.windowClass) { 61bea4f105Sopenharmony_ci return; 62bea4f105Sopenharmony_ci } 63bea4f105Sopenharmony_ci globalThis.windowClass.setFullScreen(isImmersion, (err, data) => { 64bea4f105Sopenharmony_ci if (err.code) { 65bea4f105Sopenharmony_ci Logger.e(TAG, 'Failed to enable the full-screen mode. Cause:' + JSON.stringify(err)); 66bea4f105Sopenharmony_ci return; 67bea4f105Sopenharmony_ci } 68bea4f105Sopenharmony_ci Logger.i(TAG, 'Succeeded in enabling the full-screen mode. Data: ' + JSON.stringify(data)); 69bea4f105Sopenharmony_ci }) 70bea4f105Sopenharmony_ci} 71bea4f105Sopenharmony_ci 72bea4f105Sopenharmony_ci/** 73bea4f105Sopenharmony_ci * 校验文件名合法性 74bea4f105Sopenharmony_ci * 75bea4f105Sopenharmony_ci * @param fileName 文件名 76bea4f105Sopenharmony_ci * @return 是否合法 77bea4f105Sopenharmony_ci */ 78bea4f105Sopenharmony_ciexport function isValidFileName(fileName): boolean { 79bea4f105Sopenharmony_ci return FILENAME_REGEXP.test(fileName); 80bea4f105Sopenharmony_ci} 81bea4f105Sopenharmony_ci 82