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 0000000000000000000000000000000000000000..57c2c26c0494f0ac76fd0672b580ccc9b32084b6 --- /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 716b3235ea6faa360123fcb9fd8ec9edfdec00d8..61093901ddc0f8d5ba83f5cb4181411c8c475827 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] +// Define an event with an eventId of 1 and a priority of 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 +// Send an event with eventId 1 and the event content is eventData +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 0000000000000000000000000000000000000000..b3cb1aeb2d5749d5ab500cbe2fcf12ebc52c9599 --- /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 0000000000000000000000000000000000000000..54bb47ccda5d4364b5fe612aaf0ae976d4b306e6 --- /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] + // Define an event with an eventId of 1 + let event: emitter.InnerEvent = { + 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) + }); + }; + + // Subscribe to events with 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 3ff71f7b305808f27fa81909cdcc041f77fa758f..0fa0a40036989179bf4083f7c0b96c7b976bc433 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 82a27592e115553391b18e6c03f217fde6ffffa1..1104f92c89b93d9b1d1d1a22cca74dcd154fd9f2 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 465e2325408bbd0a73911c8d3e5967e37e55c06c..76696f7c3e7edbdf4c0a38762d29769acaa52ff0 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