diff --git a/build-profile.json5 b/build-profile.json5 index 468b2e741d959704d664af70740b4c85600fa8e2..329baeabb21110c14f3cd5a9a2302e74ce67fbde 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -1,17 +1,31 @@ { "app": { - "signingConfigs": [], + "signingConfigs": [ + { + "name": "default", + "type": "HarmonyOS", + "material": { + "certpath": "C:\\Users\\gyb\\.ohos\\config\\default_component-stack2_yXX7QxUHzyHkjI8uTaQlG6nbka5rvSJ-joYVuTE1MBU=.cer", + "keyAlias": "debugKey", + "keyPassword": "0000001B96932818AB7578DED7C2D5FA79053A3686D0FB8018BEC69393A4CFC8021E7AEDEED5762879B7DC", + "profile": "C:\\Users\\gyb\\.ohos\\config\\default_component-stack2_yXX7QxUHzyHkjI8uTaQlG6nbka5rvSJ-joYVuTE1MBU=.p7b", + "signAlg": "SHA256withECDSA", + "storeFile": "C:\\Users\\gyb\\.ohos\\config\\default_component-stack2_yXX7QxUHzyHkjI8uTaQlG6nbka5rvSJ-joYVuTE1MBU=.p12", + "storePassword": "0000001B7FF23E45E321A0123AA47C8076202BF9C083264AE3FFFE1FB170016F5287DD66720C06D5085728" + } + } + ], "products": [ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "5.0.0(12)", - "runtimeOS": "HarmonyOS", + "compatibleSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS" } ], "buildModeSet": [ { - "name": "debug", + "name": "debug" }, { "name": "release" diff --git a/componentstacklibrary/Index.ets b/componentstacklibrary/Index.ets index baab691a7deaca7fdf1d65bf08570a84aaa098ae..c3c48fe78b8a5b7e6a1c97cc1c1a8d8116164060 100644 --- a/componentstacklibrary/Index.ets +++ b/componentstacklibrary/Index.ets @@ -1,3 +1,5 @@ export { ComponentStackComponent } from './src/main/ets/component/ComponentStackComponent'; -export { ComponentStackController } from './src/main/ets/ComponentStackController.ets'; \ No newline at end of file +export { ComponentStackController } from './src/main/ets/ComponentStackController'; + +export { default as Logger } from './src/main/ets/utils/Logger'; \ No newline at end of file diff --git a/componentstacklibrary/src/main/ets/utils/BreakpointSystem.ets b/componentstacklibrary/src/main/ets/utils/BreakpointSystem.ets index 02feb5558f7f7ba545e737597ca4283a476a1dbb..aab12172f048e72d6c8f4d54a8be09ff28707d99 100644 --- a/componentstacklibrary/src/main/ets/utils/BreakpointSystem.ets +++ b/componentstacklibrary/src/main/ets/utils/BreakpointSystem.ets @@ -14,9 +14,8 @@ */ import { window } from '@kit.ArkUI'; -import type { BusinessError } from '@kit.BasicServicesKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; import { CommonConstants } from '../constants/CommonConstants'; +import Logger from './Logger'; const TAG: string = '[BreakpointSystem]'; @@ -111,8 +110,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.error(TAG, `UpdateBreakpoint fail.`); } } } \ No newline at end of file diff --git a/componentstacklibrary/src/main/ets/utils/Logger.ets b/componentstacklibrary/src/main/ets/utils/Logger.ets new file mode 100644 index 0000000000000000000000000000000000000000..730761472184cbb4a4de3b7d94d32c6bb20925fe --- /dev/null +++ b/componentstacklibrary/src/main/ets/utils/Logger.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 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('[ComponentStack]'); \ No newline at end of file diff --git a/componentstacklibrary/src/main/ets/utils/WindowUtil.ets b/componentstacklibrary/src/main/ets/utils/WindowUtil.ets index 6a37e2bf56a7344f4a2d13c4d73d7822c1718dd9..d537e535be7ef211294ee28fed1ede1ba0f47e63 100644 --- a/componentstacklibrary/src/main/ets/utils/WindowUtil.ets +++ b/componentstacklibrary/src/main/ets/utils/WindowUtil.ets @@ -15,10 +15,10 @@ import { window } from '@kit.ArkUI'; import type { BusinessError } from '@kit.BasicServicesKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { common, Configuration, ConfigurationConstant } from '@kit.AbilityKit'; +import { common, ConfigurationConstant } from '@kit.AbilityKit'; import { CommonConstants } from '../constants/CommonConstants'; import { BreakpointSystem } from './BreakpointSystem'; +import Logger from './Logger'; const TAG: string = '[WindowUtil]'; @@ -35,7 +35,7 @@ export class WindowUtil { WindowUtil.registerBreakPoint(windowStage); WindowUtil.requestFullScreen(windowStage); } catch (err) { - hilog.error(0x0000, TAG, `WindowUtil initialize failed. Cause: ${err.code} ${err.message}`); + Logger.error(TAG, `WindowUtil initialize failed. Cause: ${err.code} ${err.message}`); } } @@ -49,13 +49,13 @@ export class WindowUtil { try { const promise: Promise = 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, + 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.'); } }); } @@ -63,7 +63,7 @@ export class WindowUtil { public static registerBreakPoint(windowStage: window.WindowStage) { windowStage.getMainWindow((err: BusinessError, data: window.Window) => { if (err.code) { - hilog.error(0x0000, TAG, `Failed to get main window: ${err.message}`); + Logger.error(TAG, `Failed to get main window: ${err.message}`); return; } BreakpointSystem.getInstance().updateWidthBp(data); @@ -96,6 +96,10 @@ export class WindowUtil { } public static updatedColorMode(context: common.UIAbilityContext): void { - context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + try { + context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (error) { + Logger.error(TAG, `updatedColorMode fail.`); + } } } \ No newline at end of file diff --git a/componentstacklibrary/src/main/ets/view/ProductList.ets b/componentstacklibrary/src/main/ets/view/ProductList.ets index b0631581818ee2ff9fa2f99bd3ea779a536b3084..9e8a6e4f86d60ad82b25c648f99baff83eca0cb6 100644 --- a/componentstacklibrary/src/main/ets/view/ProductList.ets +++ b/componentstacklibrary/src/main/ets/view/ProductList.ets @@ -16,10 +16,12 @@ import { ProductDataModel } from '../viewmodel/IconViewModel'; import { ProductDataSource } from '../viewmodel/DataSource'; import { PRODUCT_DATA } from '../model/IconModel'; -import { hilog } from '@kit.PerformanceAnalysisKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { CommonConstants } from '../constants/CommonConstants'; import { BreakpointTypeEnum } from '../utils/BreakpointSystem'; +import Logger from '../utils/Logger'; + +const TAG: string = '[ProductList]'; @Component export struct ProductList { @@ -79,7 +81,7 @@ export struct ProductList { this.getUIContext().getPromptAction().showToast({ message: $r('app.string.component_stack_other_function') }); } catch (error) { const err = error as BusinessError; - hilog.error(0x000, 'ProductList', `showToast catch error, code: ${err.code}, message: ${err.message}`); + Logger.error(TAG, `showToast catch error, code: ${err.code}, message: ${err.message}`); } }); } diff --git a/componentstacklibrary/src/main/resources/base/element/string.json b/componentstacklibrary/src/main/resources/base/element/string.json index bc32604f2a0bda23aa4a0b7b22dd06d6a78e4a4c..62493b45e237bad0715a5359197789bdd3c37aa2 100644 --- a/componentstacklibrary/src/main/resources/base/element/string.json +++ b/componentstacklibrary/src/main/resources/base/element/string.json @@ -1,5 +1,9 @@ { "string": [ + { + "name": "product_title00", + "value": "充电宝" + }, { "name": "product_title01", "value": "笔记本电脑" diff --git a/componentstacklibrary/src/main/resources/en_US/element/string.json b/componentstacklibrary/src/main/resources/en_US/element/string.json index f3cda33454dbb0d5df8eb11804a5aa84490f3d5d..c098fbe9351a4e4801fc560172d3eb432037662e 100644 --- a/componentstacklibrary/src/main/resources/en_US/element/string.json +++ b/componentstacklibrary/src/main/resources/en_US/element/string.json @@ -1,5 +1,9 @@ { "string": [ + { + "name": "product_title00", + "value": "powerbank" + }, { "name": "product_title01", "value": "laptop" diff --git a/componentstacklibrary/src/main/resources/zh_CN/element/string.json b/componentstacklibrary/src/main/resources/zh_CN/element/string.json index bc32604f2a0bda23aa4a0b7b22dd06d6a78e4a4c..62493b45e237bad0715a5359197789bdd3c37aa2 100644 --- a/componentstacklibrary/src/main/resources/zh_CN/element/string.json +++ b/componentstacklibrary/src/main/resources/zh_CN/element/string.json @@ -1,5 +1,9 @@ { "string": [ + { + "name": "product_title00", + "value": "充电宝" + }, { "name": "product_title01", "value": "笔记本电脑" diff --git a/componentstacksample/src/main/ets/entryability/EntryAbility.ets b/componentstacksample/src/main/ets/entryability/EntryAbility.ets index 097d76182fef98fde27ab25a801a3725840aa6b5..b1e5bbfb82cd0fa424f1669aee6be826c39aef0d 100644 --- a/componentstacksample/src/main/ets/entryability/EntryAbility.ets +++ b/componentstacksample/src/main/ets/entryability/EntryAbility.ets @@ -13,49 +13,48 @@ * limitations under the License. */ -import { ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; +import { UIAbility } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; -import { ComponentStackController } from '@ohos_sample/componentstacklibrary'; +import { ComponentStackController, Logger } from '@ohos_sample/componentstacklibrary'; const TAG = '[EntryAbility]'; export default class EntryAbility extends UIAbility { onCreate(): void { - hilog.info(0x0000, TAG, '%{public}s', 'Ability onCreate'); + Logger.info(TAG, '%{public}s', 'Ability onCreate'); ComponentStackController.updatedColorMode(this.context); } onDestroy(): void { - hilog.info(0x0000, TAG, '%{public}s', 'Ability onDestroy'); + Logger.info(TAG, '%{public}s', 'Ability onDestroy'); } onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability. - hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageCreate'); + Logger.info(TAG, '%{public}s', 'Ability onWindowStageCreate'); windowStage.loadContent('pages/Index', (err) => { if (err.code) { - hilog.error(0x0000, TAG, `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; } ComponentStackController.initWindowConfig(windowStage); - hilog.info(0x0000, TAG, 'Succeeded in loading the content.'); + Logger.info(TAG, 'Succeeded in loading the content.'); }); } onWindowStageDestroy(): void { // Main window is destroyed, release UI related resources - hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageDestroy'); + Logger.info(TAG, '%{public}s', 'Ability onWindowStageDestroy'); } onForeground(): void { // Ability has brought to foreground - hilog.info(0x0000, TAG, '%{public}s', 'Ability onForeground'); + Logger.info(TAG, '%{public}s', 'Ability onForeground'); } onBackground(): void { // Ability has back to background - hilog.info(0x0000, TAG, '%{public}s', 'Ability onBackground'); + Logger.info(TAG, '%{public}s', 'Ability onBackground'); } } \ No newline at end of file diff --git a/componentstacksample/src/main/resources/en_US/element/string.json b/componentstacksample/src/main/resources/en_US/element/string.json index 3ddc584e6a68ab7b0b7fd680068a0c227f49b2bd..6c097bd1c7dae0a8c5fc887b9968df81808f48bd 100644 --- a/componentstacksample/src/main/resources/en_US/element/string.json +++ b/componentstacksample/src/main/resources/en_US/element/string.json @@ -11,10 +11,6 @@ { "name": "EntryAbility_label", "value": "Component stacking" - }, - { - "name": "product_title00", - "value": "powerbank" } ] } \ No newline at end of file