diff --git a/README.en.md b/README.en.md index c65a9933c53b389fdf94800f49cc41f1a28184ca..918c6d18b0f8158775ce306185fdff6dbf3c9efb 100644 --- a/README.en.md +++ b/README.en.md @@ -42,6 +42,7 @@ After the loading is complete, eight customized dialog pop-up types are displaye │ │ └──TwoLevelPageSheet.ets // Semi-modal + full-screen dialog pop-up │ ├──utils │ │ ├──BreakpointSystem.ets // Break point utils +│ │ ├──Logger.ets // Log utils │ │ └──WindowUtil.ets // Window utils │ ├──view │ │ ├──AddPassengers.ets // Add passenger diff --git a/README.md b/README.md index fc5c938dbbf67ef1dc4c5fbca1bf391f680a1010..24b765e64dc2ee909d10442fe761ac46270d1e9c 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ │ │ └──TwoLevelPageSheet.ets // 两级半模态+全屏弹窗页面 │ ├──utils │ │ ├──BreakpointSystem.ets // 断点工具类 +│ │ ├──Logger.ets // 日志工具类 │ │ └──WindowUtil.ets // 窗口工具类 │ ├──view │ │ ├──AddPassengers.ets // 添加乘客页面 diff --git a/build-profile.json5 b/build-profile.json5 index 554ed06013e62c8d3af3ba2c7a1bdee66b0f3526..4fdced670e0ec8f736f8579fd9f93a0cf4c41ab0 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -5,7 +5,8 @@ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "5.0.0(12)", + "compatibleSdkVersion": "5.0.5(17)", + "targetSdkVersion": "5.0.5(17)", "runtimeOS": "HarmonyOS", } ], diff --git a/customdialoggatherslibrary/Index.ets b/customdialoggatherslibrary/Index.ets index 1bfdb762cd65487836637fec904795528a372f81..77726b3d307abe8797a8d6ed6373427dcc80131c 100644 --- a/customdialoggatherslibrary/Index.ets +++ b/customdialoggatherslibrary/Index.ets @@ -1,2 +1,3 @@ export { CustomDialogGathersComponent } from './src/main/ets/component/CustomDialogGathersComponent' -export { CustomDialogGathersController } from './src/main/ets/CustomDialogGathersController'; \ No newline at end of file +export { CustomDialogGathersController } from './src/main/ets/CustomDialogGathersController'; +export { default as Logger } from './src/main/ets/utils/Logger'; \ No newline at end of file diff --git a/customdialoggatherslibrary/README.md b/customdialoggatherslibrary/README.md index 165acad1f9107615012b6d33a39364bb083eb9cd..d7d8f392194fe9df075a79f1213ed8f0904fb4db 100644 --- a/customdialoggatherslibrary/README.md +++ b/customdialoggatherslibrary/README.md @@ -40,7 +40,7 @@ import { CustomDialogGathersController } from '@ohos_samples/customdialoggathers onWindowStageCreate(windowStage: window.WindowStage): void { windowStage.loadContent('pages/Index', (err, data) => { if (err.code) { - hilog.error(0x0000, 'testTag', `Failed to load the content, err code: ${err.code}, message: ${err.message}`); + Logger.error(TAG, `Failed to load the content, err code: ${err.code}, message: ${err.message}`); return; } CustomDialogGathersController.initWindowConfig(windowStage); diff --git a/customdialoggatherslibrary/src/main/ets/component/CalendarView.ets b/customdialoggatherslibrary/src/main/ets/component/CalendarView.ets index 76b60c86c1bf28bdc46ed6bb3fd940fb1884202a..aefe543b34d155d4c92dddf1990fbcc9b39e4375 100644 --- a/customdialoggatherslibrary/src/main/ets/component/CalendarView.ets +++ b/customdialoggatherslibrary/src/main/ets/component/CalendarView.ets @@ -18,6 +18,9 @@ import { CommonConstants } from '../common/constants/CommonConstants'; import { CustomCalendarPickerDialog } from '../view/CustomCalendarPickerDialog'; import { DateModel } from '../viewmodel/DateModel'; import { getRealTimeDate } from '../viewmodel/GetDate'; +import Logger from '../utils/Logger'; + +const TAG = 'CalendarView'; @Builder export function CalendarViewBuilder() { @@ -62,9 +65,13 @@ export struct CalendarView { getResourceString(resource: Resource): string { let resourceString: string = ''; - let hostContext = this.getUIContext().getHostContext(); - if (hostContext) { - resourceString = hostContext.resourceManager.getStringSync(resource.id); + try { + let hostContext = this.getUIContext().getHostContext(); + if (hostContext) { + resourceString = hostContext.resourceManager.getStringSync(resource.id); + } + } catch (err) { + Logger.error(TAG, 'getStringSync get exception'); } return resourceString; } diff --git a/customdialoggatherslibrary/src/main/ets/component/Privacy.ets b/customdialoggatherslibrary/src/main/ets/component/Privacy.ets index 109e4a42ab65fe7cf7d132fe2c8638ef6f1870ce..2b2d8c85b2487fef584726101db37b6292d33467 100644 --- a/customdialoggatherslibrary/src/main/ets/component/Privacy.ets +++ b/customdialoggatherslibrary/src/main/ets/component/Privacy.ets @@ -13,9 +13,11 @@ * limitations under the License. */ -import { hilog } from '@kit.PerformanceAnalysisKit'; import { BreakpointType, BreakpointTypeEnum } from '../utils/BreakpointSystem'; import { CommonConstants } from '../common/constants/CommonConstants'; +import Logger from '../utils/Logger'; + +const TAG = 'Privacy'; @Builder export function PrivacyBuilder() { @@ -49,11 +51,11 @@ struct Privacy { }); onCancel() { - hilog.info(0x0000, 'Privacy', '%{public}s', 'Callback when the first button is clicked'); + Logger.info(TAG, 'Callback when the first button is clicked'); } onAccept() { - hilog.info(0x0000, 'Privacy', '%{public}s', 'Callback when the second button is clicked'); + Logger.info(TAG, 'Callback when the second button is clicked'); } build() { diff --git a/customdialoggatherslibrary/src/main/ets/utils/BreakpointSystem.ets b/customdialoggatherslibrary/src/main/ets/utils/BreakpointSystem.ets index 52ea92dcb32bbdfe1818356a88ae8131dfad1adc..9f06bb5839089b2e1900107c31b722b9bcc7c9a3 100644 --- a/customdialoggatherslibrary/src/main/ets/utils/BreakpointSystem.ets +++ b/customdialoggatherslibrary/src/main/ets/utils/BreakpointSystem.ets @@ -15,8 +15,8 @@ import type { BusinessError } from '@kit.BasicServicesKit'; import { display, window } from '@kit.ArkUI'; -import { hilog } from '@kit.PerformanceAnalysisKit'; import { CommonConstants } from '../common/constants/CommonConstants'; +import Logger from './Logger'; const TAG: string = '[BreakpointSystem]'; @@ -114,7 +114,7 @@ export class BreakpointSystem { this.updateCurrentBreakpoint(widthBp); } catch (error) { const err: BusinessError = error as BusinessError; - hilog.error(0x0000, TAG, `UpdateBreakpoint fail, error code: ${err.code}, message: ${err.message}`); + Logger.info(TAG, `UpdateBreakpoint fail, error code: ${err.code}, message: ${err.message}`); } } } \ No newline at end of file diff --git a/customdialoggatherslibrary/src/main/ets/utils/Logger.ets b/customdialoggatherslibrary/src/main/ets/utils/Logger.ets new file mode 100644 index 0000000000000000000000000000000000000000..42a58eacfe2cf8e5d85a249b9119e1260303c68a --- /dev/null +++ b/customdialoggatherslibrary/src/main/ets/utils/Logger.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + public constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0x0000; + } + + public debug(...args: Object[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + public info(...args: Object[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + public warn(...args: Object[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + public error(...args: Object[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + +export default new Logger('[CustomDialogGathers]'); \ No newline at end of file diff --git a/customdialoggatherslibrary/src/main/ets/utils/WindowUtil.ets b/customdialoggatherslibrary/src/main/ets/utils/WindowUtil.ets index 3be068bbf549855138dbc915e97a62c64925487b..c15ba60c89cef30c312da3d2bc7e37c351d9fa62 100644 --- a/customdialoggatherslibrary/src/main/ets/utils/WindowUtil.ets +++ b/customdialoggatherslibrary/src/main/ets/utils/WindowUtil.ets @@ -14,10 +14,10 @@ */ import type { BusinessError } from '@kit.BasicServicesKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; import { BreakpointSystem } from './BreakpointSystem'; import { CommonConstants } from '../common/constants/CommonConstants'; +import Logger from './Logger'; const TAG: string = '[WindowUtil]'; @@ -30,7 +30,7 @@ export class WindowUtil { WindowUtil.requestFullScreen(); WindowUtil.registerBreakPoint(); } catch (err) { - hilog.error(0x0000, TAG, `WindowUtil initialize Failed. Cause: ${err.message}`); + Logger.error(TAG, `WindowUtil initialize Failed. Cause: ${err.message}`); } } @@ -39,13 +39,12 @@ export class WindowUtil { try { const promise: Promise = WindowUtil.windowClass.setWindowLayoutFullScreen(true); promise.then(() => { - hilog.info(0x0000, TAG, 'Succeeded in setting the window layout to full-screen mode.'); + Logger.info(TAG, 'Succeeded in setting the window layout to full-screen mode.'); }).catch((err: BusinessError) => { - hilog.error(0x0000, TAG, - `Failed to set the window layout to full-screen mode. Cause: ${err.code}, ${err.message}`); + Logger.error(TAG, `Failed to set the window layout to full-screen mode. Cause: ${err.code}, ${err.message}`); }); } catch { - hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode. '); + Logger.error(TAG, 'Failed to set the window layout to full-screen mode. '); } } @@ -59,19 +58,27 @@ export class WindowUtil { } private static updateAvoidArea(windowObj: window.Window) { - WindowUtil.setAvoidArea(window.AvoidAreaType.TYPE_SYSTEM, - windowObj.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM)); - WindowUtil.setAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR, - windowObj.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR)); + try { + WindowUtil.setAvoidArea(window.AvoidAreaType.TYPE_SYSTEM, + windowObj.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM)); + WindowUtil.setAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR, + windowObj.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR)); + } catch (err) { + Logger.error(TAG, 'getWindowAvoidArea get exception'); + } } // Get status bar height and indicator height. private static setAvoidArea(type: window.AvoidAreaType, area: window.AvoidArea) { - let uiContext = WindowUtil.windowClass.getUIContext(); - if (type === window.AvoidAreaType.TYPE_SYSTEM) { - AppStorage.setOrCreate(CommonConstants.AS_KEY_STATUS_BAR_HEIGHT, uiContext.px2vp(area.topRect.height)); - } else if (type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { - AppStorage.setOrCreate(CommonConstants.AS_KEY_NAVIGATOR_BAR_HEIGHT, uiContext.px2vp(area.bottomRect.height)); + try { + let uiContext = WindowUtil.windowClass.getUIContext(); + if (type === window.AvoidAreaType.TYPE_SYSTEM) { + AppStorage.setOrCreate(CommonConstants.AS_KEY_STATUS_BAR_HEIGHT, uiContext.px2vp(area.topRect.height)); + } else if (type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { + AppStorage.setOrCreate(CommonConstants.AS_KEY_NAVIGATOR_BAR_HEIGHT, uiContext.px2vp(area.bottomRect.height)); + } + } catch (err) { + Logger.error(TAG, 'getUIContext get exception'); } } } \ No newline at end of file diff --git a/customdialoggatherslibrary/src/main/ets/view/AddPassengers.ets b/customdialoggatherslibrary/src/main/ets/view/AddPassengers.ets index 7ec88584c450505e96a4cc2751b69bba3c0068f0..782489ebdfbe87adb9a822a0daa7fe36a1df0baa 100644 --- a/customdialoggatherslibrary/src/main/ets/view/AddPassengers.ets +++ b/customdialoggatherslibrary/src/main/ets/view/AddPassengers.ets @@ -14,10 +14,10 @@ */ import { BusinessError } from '@kit.BasicServicesKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; import { BreakpointType, BreakpointTypeEnum } from '../utils/BreakpointSystem'; import { CommonConstants } from '../common/constants/CommonConstants'; import { PersonList, personList } from '../viewmodel/BindContentModel'; +import Logger from '../utils/Logger'; const TAG = '[AddPassengers]'; @@ -42,7 +42,7 @@ export struct AddPassengers { } } catch (error) { const err = error as BusinessError; - hilog.error(0x0000, TAG, `getResourceString catch error, code: ${err.code}, message: ${err.message}`); + Logger.error(TAG, `getResourceString catch error, code: ${err.code}, message: ${err.message}`); } return resourceString; } diff --git a/customdialoggatherslibrary/src/main/ets/view/CustomCalendarPickerDialog.ets b/customdialoggatherslibrary/src/main/ets/view/CustomCalendarPickerDialog.ets index 6fcca565fce6c2fd179fb28f8522e5ddc3ac4100..72a303a2cdad68a5ad789ec1e5ef0bf614b109ec 100644 --- a/customdialoggatherslibrary/src/main/ets/view/CustomCalendarPickerDialog.ets +++ b/customdialoggatherslibrary/src/main/ets/view/CustomCalendarPickerDialog.ets @@ -18,8 +18,11 @@ import { CommonConstants } from '../common/constants/CommonConstants'; import { DataManager } from '../viewmodel/DataManager'; import { DateModel } from '../viewmodel/DateModel'; import { getMonthDate } from '../viewmodel/GetDate'; +import Logger from '../utils/Logger'; import { MonthDataSource, Month } from '../viewmodel/MonthDataSource'; +const TAG = 'CustomCalendarPickerDialog'; + @CustomDialog export struct CustomCalendarPickerDialog { @StorageLink(CommonConstants.AS_KEY_STATUS_BAR_HEIGHT) statusBarHeight: number = 0; @@ -43,9 +46,13 @@ export struct CustomCalendarPickerDialog { getResourceString(resource: Resource): string { let resourceString: string = ''; - let hostContext = this.getUIContext().getHostContext(); - if (hostContext) { - resourceString = hostContext.resourceManager.getStringSync(resource.id); + try { + let hostContext = this.getUIContext().getHostContext(); + if (hostContext) { + resourceString = hostContext.resourceManager.getStringSync(resource.id); + } + } catch (err) { + Logger.error(TAG, 'getStringSync get exception'); } return resourceString; } @@ -168,9 +175,9 @@ export struct CustomCalendarPickerDialog { } .columnsTemplate(CommonConstants.GRID_SEVEN) .rowsTemplate(monthItem.days.length > CommonConstants.MONTH_NUMBER ? - CommonConstants.GRID_SIX : CommonConstants.GRID_FIVE) + CommonConstants.GRID_SIX : CommonConstants.GRID_FIVE) .height(monthItem.days.length > CommonConstants.MONTH_NUMBER ? CommonConstants.GRID_HEIGHT_L : - CommonConstants.GRID_HEIGHT_M) + CommonConstants.GRID_HEIGHT_M) } build() { diff --git a/customdialoggatherslibrary/src/main/ets/view/QueryTicketList.ets b/customdialoggatherslibrary/src/main/ets/view/QueryTicketList.ets index 1655549fbd05ac61088bdeec880e8ea7f8c8fe11..f2f78dbc6c21de9e55c1801fd9c7e7023a481504 100644 --- a/customdialoggatherslibrary/src/main/ets/view/QueryTicketList.ets +++ b/customdialoggatherslibrary/src/main/ets/view/QueryTicketList.ets @@ -14,9 +14,9 @@ */ import { BusinessError } from '@kit.BasicServicesKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; import { BreakpointType, BreakpointTypeEnum } from '../utils/BreakpointSystem'; import { CommonConstants } from '../common/constants/CommonConstants'; +import Logger from '../utils/Logger'; const TAG = '[QueryTicketList]'; @@ -41,7 +41,7 @@ export struct QueryTicketList { } } catch (error) { const err = error as BusinessError; - hilog.error(0x0000, TAG, `getResourceString catch error, code: ${err.code}, message: ${err.message}`); + Logger.error(TAG, `getResourceString catch error, code: ${err.code}, message: ${err.message}`); } return resourceString; } diff --git a/customdialoggatherslibrary/src/main/ets/viewmodel/BindContentModel.ets b/customdialoggatherslibrary/src/main/ets/viewmodel/BindContentModel.ets index 0a0b8727a57d6e2c2c61a1ba191261cf6c5e019d..04b6a1206ea9861f9b6b5e9170ef5953c4b8caa4 100644 --- a/customdialoggatherslibrary/src/main/ets/viewmodel/BindContentModel.ets +++ b/customdialoggatherslibrary/src/main/ets/viewmodel/BindContentModel.ets @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + export interface PersonList { name: ResourceStr, cardNum: string diff --git a/customdialoggatherssample/src/main/ets/entryability/EntryAbility.ets b/customdialoggatherssample/src/main/ets/entryability/EntryAbility.ets index 1f8cf807845a00f49dcfd54995e398773a0d4a6a..f0da267fa73ddba064ae1f3cb714b6fc76a60dac 100644 --- a/customdialoggatherssample/src/main/ets/entryability/EntryAbility.ets +++ b/customdialoggatherssample/src/main/ets/entryability/EntryAbility.ets @@ -14,45 +14,29 @@ */ import { ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; -import { CustomDialogGathersController } from '@ohos_samples/customdialoggatherslibrary'; +import { CustomDialogGathersController, Logger } from '@ohos_samples/customdialoggatherslibrary'; + +const TAG = 'EntryAbility'; export default class EntryAbility extends UIAbility { onCreate(): void { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); - } - - onDestroy(): void { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + Logger.error(TAG, `Failed to setColorMode. Cause: ${JSON.stringify(err)}`); + } } onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); windowStage.loadContent('pages/Index', (err, data) => { if (err.code) { - hilog.error(0x0000, 'testTag', `Failed to load the content, err code: ${err.code}, message: ${err.message}`); + Logger.error(TAG, `Failed to load the content, err code: ${err.code}, message: ${err.message}`); return; } CustomDialogGathersController.initWindowConfig(windowStage); - hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + Logger.info(TAG, `Succeeded in loading the content. Data: ${JSON.stringify(data)}`); }); } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); - } } diff --git a/customdialoggatherssample/src/main/ets/pages/Index.ets b/customdialoggatherssample/src/main/ets/pages/Index.ets index 9f537261efa681ba16450b31fc296750ee12fda2..d7afc91d3b145a81dc4a4a6e0c64ea82f286e3b5 100644 --- a/customdialoggatherssample/src/main/ets/pages/Index.ets +++ b/customdialoggatherssample/src/main/ets/pages/Index.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { CustomDialogGathersComponent } from '@ohos_samples/customdialoggatherslibrary' +import { CustomDialogGathersComponent } from '@ohos_samples/customdialoggatherslibrary'; @Entry @Component