diff --git a/README.md b/README.md index a0d84f27d4e801838a2cd0a8e95820948bd7addd..5a5524c1a67ceb59ce332d65b5f57c5127467687 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ 本示例实现使用router、call和message三种事件,以及定点刷新的方式实现卡片信息的刷新。 ### 效果预览 -![](screenshots/form.png) +![](screenshots/device/form.png) ### 工程目录 diff --git a/README_EN.md b/README_EN.md new file mode 100644 index 0000000000000000000000000000000000000000..3ba4e31d370a46169343529d584fed2d5333ef31 --- /dev/null +++ b/README_EN.md @@ -0,0 +1,62 @@ +# Widget Update + +### Overview + +This sample demonstrates how to use the router, call, and message events, as well as timed updates, to update widget information. + +### Preview +![](screenshots/device/form.en.png) + +### Project Directory + +``` +├──entry/src/main/ets // Core code +│ ├──common +│ │ ├──CommonConstants.ets // Widget data +│ │ └──CommonData.ets // Utility class for widget data +│ ├──entryability +│ │ └──EntryAbility.ets // Entry ability +│ ├──entrybackupability +│ │ └──EntryBackupAbility.ets +│ ├──entryformability +│ │ └──EntryFormAbility.ets // Widget lifecycle class +│ ├──pages +│ │ ├──Index.ets // Home page +│ └──widget +│ ├──pages +│ │ └──WidgetCard.ets // Widget page +│ ├──view +│ │ └──CardListComponent.ets +│ └──viewmodel +│ └──CardListParameter.ets +└──entry/src/main/resources // Static resources +``` + +### How to Use + +1. Install the sample app, and touch and hold the app icon to add a widget. +2. Touch the router event button to go to the app page. When you return to the home screen, you can see that the widget information is updated. +3. Touch the call event. The widget information is updated. +4. Touch the message event. The widget information is updated. +5. Set the **scheduledUpdateTime** field in the **src/main/resources/base/profile/form_config.json** file to a time point. The widget information is updated at the specified time point. + +### How to Implement + +1. The router event calls the **updateForm** method of **formProvider** in the lifecycle callback of the EntryAbility to update the widget information. +2. The call event updates the widget information in the **onAddForm** method of the EntryFormAbility and triggers the **onFormTimeChange** method of the widget UI. The **updateCardInfo** information carried in the **postCardAction** method is used to trigger the callee listening in the EntryAbility, thereby updating the widget information in the listening method. +3. The message event updates the widget information in the **onFormEvent** callback of the EntryFormAbility. + +#### NOTE +1. Widgets can also be periodically updated by configuring the **updateDuration** field in the **form_config.json** file. If both scheduled update and timed update are configured, scheduled update takes precedence. This sample demonstrates the timed update only. For details about how to implement scheduled update, see the development guide. +2. The widget information in this project uses the data configured in the code. In actual scenarios, you can encapsulate a method to obtain the information. + +### Required Permissions + +**ohos.permission.KEEP_BACKGROUND_RUNNING**: allows a ServiceAbility to keep running in the background. The provider app must have the permission to run the call event in the background. + +### Constraints + +1. The sample app is supported only on Huawei phones running the standard system. +2. The HarmonyOS version must be HarmonyOS NEXT Developer Beta5 or later. +3. The DevEco Studio version must be DevEco Studio NEXT Developer Beta5 or later. +4. The HarmonyOS SDK version must be HarmonyOS NEXT Developer Beta5 or later. diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 03a2021435aec76e709e31e691013582746f3d54..0bc4b171d5891be5d82565e5d1b5ace4f32f1441 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -38,15 +38,15 @@ }, { "name": "router", - "value": "router events" + "value": "router event" }, { "name": "call", - "value": "call events" + "value": "call event" }, { "name": "message", - "value": "message events" + "value": "message event" }, { "name": "title1", diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json index b42f30989642ca77aa95a82c1fcf5816e1e8c3b5..6c47a203d3816d27e02a99331d21e4fd2e2c1c92 100644 --- a/entry/src/main/resources/en_US/element/string.json +++ b/entry/src/main/resources/en_US/element/string.json @@ -38,15 +38,15 @@ }, { "name": "router", - "value": "router events" + "value": "router event" }, { "name": "call", - "value": "call events" + "value": "call event" }, { "name": "message", - "value": "message events" + "value": "message event" }, { "name": "title1", diff --git a/screenshots/device/form.en.png b/screenshots/device/form.en.png new file mode 100644 index 0000000000000000000000000000000000000000..802f8606c6dbcdc7ffea1f31ee0e49232fa22fb8 Binary files /dev/null and b/screenshots/device/form.en.png differ diff --git a/screenshots/form.png b/screenshots/device/form.png similarity index 100% rename from screenshots/form.png rename to screenshots/device/form.png