From c1623fd0d82e0660c33acbc6ecddd07d3b555bdc Mon Sep 17 00:00:00 2001 From: birdswu Date: Fri, 16 May 2025 09:08:05 +0800 Subject: [PATCH 1/3] =?UTF-8?q?AbilityKit=20FAQ=E6=A0=87=E8=AE=B0=E4=BF=AE?= =?UTF-8?q?=E6=94=B92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ets/entryability/EntryAbilitySouce.ets | 17 +++++ .../src/main/ets/pages/EmitterAndEventHub.ets | 57 +++++------------ .../main/ets/pages/EmitterAndEventHub1.ets | 25 ++++++++ .../main/ets/pages/EmitterAndEventHub2.ets | 64 +++++++++++++++++++ .../ets/pages/JumpSystemFileManagement.ets | 4 +- .../ets/pages/SetAppAutomaticallyRestart.ets | 4 +- .../src/main/ets/pages/SourceAppLaunch.ets | 17 +---- 7 files changed, 128 insertions(+), 60 deletions(-) create mode 100644 AbilityKit/entry/src/main/ets/entryability/EntryAbilitySouce.ets create mode 100644 AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub1.ets create mode 100644 AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub2.ets diff --git a/AbilityKit/entry/src/main/ets/entryability/EntryAbilitySouce.ets b/AbilityKit/entry/src/main/ets/entryability/EntryAbilitySouce.ets new file mode 100644 index 0000000..57c2c26 --- /dev/null +++ b/AbilityKit/entry/src/main/ets/entryability/EntryAbilitySouce.ets @@ -0,0 +1,17 @@ +/* +* FAQ:如何判断App的启动来源 +*/ + +// [Start SourceAppLaunch2] +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', `app resource is:${want.parameters?.['ohos.aafwk.param.callerBundleName']}`); + // ... + } + + // ... +} +// [End SourceAppLaunch2] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub.ets b/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub.ets index 716b323..4f7a35d 100644 --- a/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub.ets +++ b/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub.ets @@ -17,51 +17,26 @@ * FAQ:关于emitter、eventHub的使用场景 */ -// DocsCode 1 -import { emitter } from '@kit.BasicServicesKit'; - -const TAG: string = 'ThreadModel'; -// DocsCode 1 +// [Start EmitterAndEventHub3] +import { emitter } from '@kit.BasicServicesKit'; + +// [End EmitterAndEventHub3] -// DocsCode 2 -// 定义一个eventId为1的事件 +// [Start EmitterAndEventHub4] +// 定义一个eventId为1的事件,事件优先级为Low let event: emitter.InnerEvent = { - eventId: 1 + eventId: 1, + priority: emitter.EventPriority.LOW }; -// 收到eventId为1的事件后执行该回调 -let callback = (eventData: emitter.EventData): void => { - this.getUIContext().getPromptAction().showToast({ - message: JSON.stringify(eventData) - }); +let eventData: emitter.EventData = { + data: { + content: 'c', + id: 1, + isEmpty: false + } }; -// 订阅eventId为1的事件 -emitter.on(event, callback); -this.getUIContext().getPromptAction().showToast({ - message: $r('app.string.emitter_subscribe_success_toast') -}); -// DocsCode 2 - -// DocsCode 3 -import { emitter } from '@kit.BasicServicesKit'; -// DocsCode 3 - -// DocsCode 4 -// 定义一个eventId为1的事件,事件优先级为Low -let event: emitter.InnerEvent = { - eventId: 1, - priority: emitter.EventPriority.LOW -}; - -let eventData: emitter.EventData = { - data: { - content: 'c', - id: 1, - isEmpty: false - } -}; - // 发送eventId为1的事件,事件内容为eventData -emitter.emit(event, eventData); -// DocsCode 4 \ No newline at end of file +emitter.emit(event,eventData); +// [End EmitterAndEventHub4] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub1.ets b/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub1.ets new file mode 100644 index 0000000..b3cb1ae --- /dev/null +++ b/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub1.ets @@ -0,0 +1,25 @@ +/* +* 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. +*/ + +/* +* FAQ:关于emitter、eventHub的使用场景 + */ + +// [Start EmitterAndEventHub1] +import { emitter } from '@kit.BasicServicesKit'; + +const TAG: string = 'ThreadModel'; +// [End EmitterAndEventHub1] + diff --git a/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub2.ets b/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub2.ets new file mode 100644 index 0000000..b2f8998 --- /dev/null +++ b/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub2.ets @@ -0,0 +1,64 @@ +/* +* 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 { emitter } from '@kit.BasicServicesKit'; + +/* +* FAQ:关于emitter、eventHub的使用场景 + */ + + +@Entry +@Component +struct Index { + set() { + // [Start EmitterAndEventHub2] + // 定义一个eventId为1的事件 + let event: emitter.InnerEvent = { + eventId: 1 + }; + + // 收到eventId为1的事件后执行该回调 + let callback = (eventData: emitter.EventData): void => { + this.getUIContext().getPromptAction().showToast({ + message: JSON.stringify(eventData) + }); + }; + + // 订阅eventId为1的事件 + emitter.on(event,callback); + this.getUIContext().getPromptAction().showToast({ + message: 'subscribe_success' + }); + // [End EmitterAndEventHub2] + } + + build() { + RelativeContainer() { + Text('Hello World') + .id('HelloWorld') + .fontSize($r('app.float.page_text_font_size')) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__',align: VerticalAlign.Center }, + middle: { anchor: '__container__',align: HorizontalAlign.Center } + }) + .onClick(() => { + }) + } + .height('100%') + .width('100%') + } +} + diff --git a/AbilityKit/entry/src/main/ets/pages/JumpSystemFileManagement.ets b/AbilityKit/entry/src/main/ets/pages/JumpSystemFileManagement.ets index 3ff71f7..0fa0a40 100644 --- a/AbilityKit/entry/src/main/ets/pages/JumpSystemFileManagement.ets +++ b/AbilityKit/entry/src/main/ets/pages/JumpSystemFileManagement.ets @@ -17,7 +17,7 @@ * FAQ:如何跳转到系统文件管理App界面 */ -// DocsCode 1 +// [Start JumpSystemFileManagement] import { common, OpenLinkOptions } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { BusinessError } from '@kit.BasicServicesKit'; @@ -64,4 +64,4 @@ struct Index { .height('100%') } } -// DocsCode 1 \ No newline at end of file +// [End JumpSystemFileManagement] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/pages/SetAppAutomaticallyRestart.ets b/AbilityKit/entry/src/main/ets/pages/SetAppAutomaticallyRestart.ets index 82a2759..1104f92 100644 --- a/AbilityKit/entry/src/main/ets/pages/SetAppAutomaticallyRestart.ets +++ b/AbilityKit/entry/src/main/ets/pages/SetAppAutomaticallyRestart.ets @@ -17,7 +17,7 @@ * FAQ:如何设置应用自动重启 */ -// DocsCode 1 +// [Start SetAppAutomaticallyRestart] import { Want } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { common } from '@kit.AbilityKit'; @@ -57,4 +57,4 @@ struct Index { .width('100%') } } -// DocsCode 1 \ No newline at end of file +// [End SetAppAutomaticallyRestart] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/pages/SourceAppLaunch.ets b/AbilityKit/entry/src/main/ets/pages/SourceAppLaunch.ets index 465e232..76696f7 100644 --- a/AbilityKit/entry/src/main/ets/pages/SourceAppLaunch.ets +++ b/AbilityKit/entry/src/main/ets/pages/SourceAppLaunch.ets @@ -17,7 +17,7 @@ * FAQ:如何判断App的启动来源 */ -// DocsCode 1 +// [Start SourceAppLaunch1] import { common, Want } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @@ -53,18 +53,5 @@ struct Index { .height('100%') } } -// DocsCode 1 +// [End SourceAppLaunch1] -// DocsCode 2 -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(0x0000, 'testTag', `app resource is:${want.parameters?.['ohos.aafwk.param.callerBundleName']}`); - // ... - } - - // ... -} -// DocsCode 2 \ No newline at end of file -- Gitee From f33be310b6a33b63a94946addb96eddf228c8b68 Mon Sep 17 00:00:00 2001 From: birdswu Date: Fri, 16 May 2025 10:05:13 +0000 Subject: [PATCH 2/3] update AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub.ets. Signed-off-by: birdswu --- AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub.ets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub.ets b/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub.ets index 4f7a35d..6109390 100644 --- a/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub.ets +++ b/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub.ets @@ -23,7 +23,7 @@ import { emitter } from '@kit.BasicServicesKit'; // [End EmitterAndEventHub3] // [Start EmitterAndEventHub4] -// 定义一个eventId为1的事件,事件优先级为Low +// Define an event with an eventId of 1 and a priority of Low let event: emitter.InnerEvent = { eventId: 1, priority: emitter.EventPriority.LOW @@ -37,6 +37,6 @@ let eventData: emitter.EventData = { } }; -// 发送eventId为1的事件,事件内容为eventData +// Send an event with eventId 1 and the event content is eventData emitter.emit(event,eventData); // [End EmitterAndEventHub4] \ No newline at end of file -- Gitee From ca97fb46c832edafd3d5f6b72b8544a2777ae56c Mon Sep 17 00:00:00 2001 From: birdswu Date: Fri, 16 May 2025 10:06:46 +0000 Subject: [PATCH 3/3] update AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub2.ets. Signed-off-by: birdswu --- AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub2.ets | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub2.ets b/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub2.ets index b2f8998..54bb47c 100644 --- a/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub2.ets +++ b/AbilityKit/entry/src/main/ets/pages/EmitterAndEventHub2.ets @@ -24,19 +24,19 @@ import { emitter } from '@kit.BasicServicesKit'; struct Index { set() { // [Start EmitterAndEventHub2] - // 定义一个eventId为1的事件 + // Define an event with an eventId of 1 let event: emitter.InnerEvent = { eventId: 1 }; - // 收到eventId为1的事件后执行该回调 + // Execute the callback after receiving an event with eventId 1 let callback = (eventData: emitter.EventData): void => { this.getUIContext().getPromptAction().showToast({ message: JSON.stringify(eventData) }); }; - // 订阅eventId为1的事件 + // Subscribe to events with eventId 1 emitter.on(event,callback); this.getUIContext().getPromptAction().showToast({ message: 'subscribe_success' -- Gitee