diff --git a/Form/ArkTSCardDocsSample/.gitignore b/Form/ArkTSCardDocsSample/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..fbabf771011fe78f9919db0b1195ab6cadffc2b0 --- /dev/null +++ b/Form/ArkTSCardDocsSample/.gitignore @@ -0,0 +1,11 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/AppScope/app.json5 b/Form/ArkTSCardDocsSample/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1a0cc96dea058485e0b360617525f79a07fac76a --- /dev/null +++ b/Form/ArkTSCardDocsSample/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023-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. + */ + +{ + "app": { + "bundleName": "com.samples.arktscarddocssample", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/Form/ArkTSCardDocsSample/AppScope/resources/base/element/string.json b/Form/ArkTSCardDocsSample/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..544e724a79b49919349dd88b3c3ee75afd9b0036 --- /dev/null +++ b/Form/ArkTSCardDocsSample/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyArkTSCardDemo" + } + ] +} diff --git a/Form/ArkTSCardDocsSample/AppScope/resources/base/media/app_icon.png b/Form/ArkTSCardDocsSample/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/Form/ArkTSCardDocsSample/AppScope/resources/base/media/app_icon.png differ diff --git a/Form/ArkTSCardDocsSample/README_zh.md b/Form/ArkTSCardDocsSample/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..1340b382c6eb8e74b60e8631121f5779784e1ab3 --- /dev/null +++ b/Form/ArkTSCardDocsSample/README_zh.md @@ -0,0 +1,150 @@ +# 服务卡片开发指导:开发卡片页面 + +### 介绍 + +此Sample为开发指南中**服务卡片开发指导(Stage模型)**章节中**开发卡片页面**三小节示例代码的完整工程。 + +[卡片页面能力说明](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/form/arkts-ui-widget-page-overview.md) +[卡片使用动效能力](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/form/arkts-ui-widget-page-animation.md) +[卡片使用自定义绘制能力](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/form/arkts-ui-widget-page-custom-drawing.md) + +### 效果预览 +|默认卡片|动效卡片|自定义绘制卡片| +|--------------------------------|--------------------------------|--------------------------------| +|![FormHelloWorld](./screenshots/device/FormHelloWorld.jpeg)|![FormAnimation](./screenshots/device/FormAnimation.jpeg)|![FormCanvas](./screenshots/device/FormCanvas.jpeg)| + +使用说明: + +1.长按ArkTSCardDemo应用图标,弹出菜单后点击**服务卡片**选项进入卡片预览界面。 + +2.卡片预览界面默认显示第一张默认卡片(helloworld卡片),向右滑动可以看到第二张(动效卡片)和第三张(自定义绘制)卡片。 + +3.点击下方**添加到桌面**按钮即可以将卡片添加到桌面。 + + +### 工程目录 +```shell +├── AppScope +│   ├── app.json5 +│   └── resources +│   └── base +│   ├── element +│   │   └── string.json +│   └── media +│   └── app_icon.png +├── README_zh.md +├── build-profile.json5 +├── entry +│   ├── build-profile.json5 +│   ├── hvigorfile.ts +│   ├── oh-package.json5 +│   └── src +│   ├── main +│   │   ├── ets +│   │   │   ├── entryability +│   │   │   │   └── EntryAbility.ts +│   │   │   ├── entryformability +│   │   │   │   └── EntryFormAbility.ts +│   │   │   ├── pages +│   │   │   │   └── Index.ets +│   │   │   └── widget +│   │   │   └── pages +│   │   │   ├── AnimationCard.ets // 动效卡片 +│   │   │   ├── CanvasCard.ets // 自定义绘制卡片 +│   │   │   └── WidgetCard.ets // 默认Helloworld卡片 +│   │   ├── module.json5 +│   │   └── resources +│   │   ├── base +│   │   │   ├── element +│   │   │   │   ├── color.json +│   │   │   │   ├── float.json +│   │   │   │   └── string.json +│   │   │   ├── media +│   │   │   │   └── icon.png +│   │   │   └── profile +│   │   │   ├── form_config.json +│   │   │   └── main_pages.json +│   │   ├── en_US +│   │   │   └── element +│   │   │   └── string.json +│   │   ├── rawfile +│   │   └── zh_CN +│   │   └── element +│   │   └── string.json +│   └── ohosTest +│   ├── ets +│   │   ├── test +│   │   │   ├── Index.test.ets // UI自动化用例 +│   │   │   └── List.test.ets +│   │   ├── testability +│   │   │   ├── TestAbility.ets +│   │   │   └── pages +│   │   │   └── Index.ets +│   │   └── testrunner +│   │   └── OpenHarmonyTestRunner.ts +│   ├── module.json5 +│   └── resources +│   └── base +│   ├── element +│   │   ├── color.json +│   │   └── string.json +│   ├── media +│   │   └── icon.png +│   └── profile +│   └── test_pages.json +├── hvigor +│   ├── hvigor-config.json5 +│   └── hvigor-wrapper.js +├── hvigorfile.ts +├── hvigorw +├── hvigorw.bat +├── oh-package.json5 +├── ohosTest.md +└── screenshots + └── device + ├── FormAnimation.jpeg // 动效卡片效果图 + ├── FormCanvas.jpeg // 自定义绘制卡片效果图 + └── FormHelloWorld.jpeg // 默认Helloworld卡片效果图 +``` + +### 具体实现 + +可参考服务卡片开发指南如下三个章节: + +[卡片页面能力说明](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/form/arkts-ui-widget-page-overview.md) + +[卡片使用动效能力](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/form/arkts-ui-widget-page-animation.md) + +[卡片使用自定义绘制能力](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/form/arkts-ui-widget-page-custom-drawing.md) + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.4 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.4 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.4 Release及以上。 + +5. 高等级APL特殊签名说明:无; + +### 下载 + +如需单独下载本工程,执行如下命令: + +```shell +git init +git config core.sparsecheckout true +echo code/DocsSample/Form/ArkTSCardDocsSample/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/Form/ArkTSCardDocsSample/build-profile.json5 b/Form/ArkTSCardDocsSample/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d83c13225811a91b69b9adc859dde2c17f1d2 --- /dev/null +++ b/Form/ArkTSCardDocsSample/build-profile.json5 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023-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. + */ + +{ + "app": { + "signingConfigs": [ + + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "5.0.4(16)", + "compatibleSdkVersion": "5.0.4(16)", + "runtimeOS": "HarmonyOS" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/.gitignore b/Form/ArkTSCardDocsSample/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/build-profile.json5 b/Form/ArkTSCardDocsSample/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e649b50a377a8f8ed911e7cc0a64869a866f071a --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/build-profile.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023-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. + */ + +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/hvigorfile.ts b/Form/ArkTSCardDocsSample/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f9973af5eb59e35539012ef41c858ede21a4e1c9 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/hvigorfile.ts @@ -0,0 +1,17 @@ +/* + * 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. + */ + +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { hapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/Form/ArkTSCardDocsSample/entry/oh-package.json5 b/Form/ArkTSCardDocsSample/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..08ac4501e6cd32341d549be8b4b778eb913467c0 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/Form/ArkTSCardDocsSample/entry/src/main/ets/entryability/EntryAbility.ts b/Form/ArkTSCardDocsSample/entry/src/main/ets/entryability/EntryAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..16e58b6e65093ddbca0d3eabfe3f9a2a66349186 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/main/ets/entryability/EntryAbility.ts @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023-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 UIAbility from '@ohos.app.ability.UIAbility'; +import hilog from '@ohos.hilog'; +import window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // 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. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/Form/ArkTSCardDocsSample/entry/src/main/ets/entryformability/EntryFormAbility.ts b/Form/ArkTSCardDocsSample/entry/src/main/ets/entryformability/EntryFormAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..0b4d91245d2628ab1d9c58d4070a60a91a707289 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/main/ets/entryformability/EntryFormAbility.ts @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2023-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 formInfo from '@ohos.app.form.formInfo'; +import formBindingData from '@ohos.app.form.formBindingData'; +import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; +import formProvider from '@ohos.app.form.formProvider'; + +export default class EntryFormAbility extends FormExtensionAbility { + onAddForm(want) { + console.info('[EntryFormAbility] onAddForm'); + // 在入参want中可以取出卡片的唯一标识:formId + let formId: string = want.parameters[formInfo.FormParam.IDENTITY_KEY]; + // 使用方创建卡片时触发,提供方需要返回卡片数据绑定类 + let obj = { + 'title': 'titleOnAddForm', + 'detail': 'detailOnAddForm' + }; + let formData = formBindingData.createFormBindingData(obj); + return formData; + } + + onCastToNormalForm(formId) { + // Called when the form provider is notified that a temporary form is successfully + // converted to a normal form. + // 使用方将临时卡片转换为常态卡片触发,提供方需要做相应的处理 + console.info(`[EntryFormAbility] onCastToNormalForm, formId: ${formId}`); + } + + onUpdateForm(formId) { + // 若卡片支持定时更新/定点更新/卡片使用方主动请求更新功能,则提供方需要重写该方法以支持数据更新 + console.info('[EntryFormAbility] onUpdateForm'); + let obj = { + 'title': 'titleOnUpdateForm', + 'detail': 'detailOnUpdateForm' + }; + let formData = formBindingData.createFormBindingData(obj); + formProvider.updateForm(formId, formData).catch((err) => { + if (err) { + // 异常分支打印 + console.error(`[EntryFormAbility] Failed to updateForm. Code: ${err.code}, message: ${err.message}`); + return; + } + }); + } + + onChangeFormVisibility(newStatus) { + // Called when the form provider receives form events from the system. + // 需要配置formVisibleNotify为true,且为系统应用才会回调 + console.info('[EntryFormAbility] onChangeFormVisibility'); + } + + onFormEvent(formId, message) { + // Called when a specified message event defined by the form provider is triggered. + // 若卡片支持触发事件,则需要重写该方法并实现对事件的触发 + console.info('[EntryFormAbility] onFormEvent'); + } + + onRemoveForm(formId) { + // Called to notify the form provider that a specified form has been destroyed. + // 当对应的卡片删除时触发的回调,入参是被删除的卡片ID + console.info('[EntryFormAbility] onRemoveForm'); + } + + onConfigurationUpdate(config) { + // 当系统配置信息置更新时触发的回调 + console.info('[EntryFormAbility] configurationUpdate:' + JSON.stringify(config)); + } + + onAcquireFormState(want) { + // Called to return a {@link FormState} object. + // 卡片提供方接收查询卡片状态通知接口,默认返回卡片初始状态。 + return formInfo.FormState.READY; + } +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/main/ets/pages/Index.ets b/Form/ArkTSCardDocsSample/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..c52d22ee52a086164aa13b19997dd92e70c66fcf --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023-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. + */ + +@Entry +@Component +struct Index { + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/main/ets/widget/pages/AnimationCard.ets b/Form/ArkTSCardDocsSample/entry/src/main/ets/widget/pages/AnimationCard.ets new file mode 100644 index 0000000000000000000000000000000000000000..a41673f8cc6d5f191802f9aad5104da3ab44db12 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/main/ets/widget/pages/AnimationCard.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023-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. + */ + +// [Start animation_card] +@Entry +@Component +struct AnimationCard { + @State rotateAngle: number = 0; + + build() { + Row() { + Button('change rotate angle') + .height('20%') + .width('90%') + .margin('5%') + .onClick(() => { + this.rotateAngle = (this.rotateAngle === 0 ? 90 : 0); + }) + .rotate({ angle: this.rotateAngle }) + .animation({ + curve: Curve.EaseOut, + playMode: PlayMode.Normal, + }) + }.height('100%') + .alignItems(VerticalAlign.Center) + } +} +// [End animation_card] \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/main/ets/widget/pages/CanvasCard.ets b/Form/ArkTSCardDocsSample/entry/src/main/ets/widget/pages/CanvasCard.ets new file mode 100644 index 0000000000000000000000000000000000000000..ab4e6339642c02b119d05ea2d693f1eaf5433050 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/main/ets/widget/pages/CanvasCard.ets @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2023-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. + */ + +// [Start canvas_card] +@Entry +@Component +struct CanvasCard { + private canvasWidth: number = 0; + private canvasHeight: number = 0; + // 初始化CanvasRenderingContext2D和RenderingContextSettings + private settings: RenderingContextSettings = new RenderingContextSettings(true); + private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings); + + build() { + Column() { + Row() { + Canvas(this.context) + .margin('5%') + .width('90%') + .height('90%') + .onReady(() => { + console.info('[ArkTSCard] onReady for canvas draw content'); + // 在onReady回调中获取画布的实际宽和高 + this.canvasWidth = this.context.width; + this.canvasHeight = this.context.height; + // 绘制画布的背景 + this.context.fillStyle = '#EEF0FF'; + this.context.fillRect(0, 0, this.canvasWidth, this.canvasHeight); + // 在画布的中心绘制一个圆 + this.context.beginPath(); + let radius = this.context.width / 3; + let circleX = this.context.width / 2; + let circleY = this.context.height / 2; + this.context.moveTo(circleX - radius, circleY); + this.context.arc(circleX, circleY, radius, 2 * Math.PI, 0, true); + this.context.closePath(); + this.context.fillStyle = '#5A5FFF'; + this.context.fill(); + // 绘制笑脸的左眼 + let leftR = radius / 13; + let leftX = circleX - (radius / 2.3); + let leftY = circleY - (radius / 4.5); + this.context.beginPath(); + this.context.arc(leftX, leftY, leftR, 0, 2 * Math.PI, true); + this.context.strokeStyle = '#FFFFFF'; + this.context.lineWidth = 15; + this.context.stroke(); + // 绘制笑脸的右眼 + let rightR = radius / 13; + let rightX = circleX + (radius / 2.3); + let rightY = circleY - (radius / 4.5); + this.context.beginPath(); + this.context.arc(rightX, rightY, rightR, 0, 2 * Math.PI, true); + this.context.strokeStyle = '#FFFFFF'; + this.context.lineWidth = 15; + this.context.stroke(); + // 绘制笑脸的鼻子 + let startX = circleX; + let startY = circleY - 20; + this.context.beginPath(); + this.context.moveTo(startX, startY); + this.context.lineTo(startX - 8, startY + 40); + this.context.lineTo(startX + 8, startY + 40); + this.context.strokeStyle = '#FFFFFF'; + this.context.lineWidth = 15; + this.context.lineCap = 'round' + this.context.lineJoin = 'round' + this.context.stroke(); + // 绘制笑脸的嘴巴 + let mouthR = radius / 2; + let mouthX = circleX; + let mouthY = circleY + 10; + this.context.beginPath(); + this.context.arc(mouthX, mouthY, mouthR, Math.PI / 1.4, Math.PI / 3.4, true); + this.context.strokeStyle = '#FFFFFF'; + this.context.lineWidth = 15; + this.context.stroke(); + this.context.closePath(); + }) + } + }.height('100%').width('100%') + } +} +// [End canvas_card] \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/main/ets/widget/pages/WidgetCard.ets b/Form/ArkTSCardDocsSample/entry/src/main/ets/widget/pages/WidgetCard.ets new file mode 100644 index 0000000000000000000000000000000000000000..f9e154104995f3dfc1c679d4729dcbc96f757527 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/main/ets/widget/pages/WidgetCard.ets @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2023-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. + */ + +@Entry +@Component +struct WidgetCard { + /* + * The title. + */ + readonly TITLE: string = 'Hello World'; + + /* + * The action type. + */ + readonly ACTION_TYPE: string = 'router'; + + /* + * The ability name. + */ + readonly ABILITY_NAME: string = 'EntryAbility'; + + /* + * The message. + */ + readonly MESSAGE: string = 'add detail'; + + /* + * The with percentage setting. + */ + readonly FULL_WIDTH_PERCENT: string = '100%'; + + /* + * The height percentage setting. + */ + readonly FULL_HEIGHT_PERCENT: string = '100%'; + + build() { + Row() { + Column() { + Text(this.TITLE) + .fontSize($r('app.float.font_size')) + } + .width(this.FULL_WIDTH_PERCENT) + } + .height(this.FULL_HEIGHT_PERCENT) + .onClick(() => { + postCardAction(this, { + "action": this.ACTION_TYPE, + "abilityName": this.ABILITY_NAME, + "params": { + "message": this.MESSAGE + } + }); + }) + } +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/main/module.json5 b/Form/ArkTSCardDocsSample/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..62247c90f13745e0e86779365c3866bc6b560c9d --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/main/module.json5 @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2023-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. + */ + +// [Start module_config_extensionAbilities] +{ + "module": { + //[StartExclude module_config_extensionAbilities] + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + // [EndExclude module_config_extensionAbilities] + "extensionAbilities": [ + { + "name": "EntryFormAbility", + "srcEntry": "./ets/entryformability/EntryFormAbility.ts", + "label": "$string:EntryFormAbility_label", + "description": "$string:EntryFormAbility_desc", + "type": "form", + "metadata": [ + { + "name": "ohos.extension.form", + "resource": "$profile:form_config" + } + ] + } + ] + } +} +//[End module_config_extensionAbilities] \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/main/resources/base/element/color.json b/Form/ArkTSCardDocsSample/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/main/resources/base/element/float.json b/Form/ArkTSCardDocsSample/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..c8d10991d67b86589cd2d8fc78970850f27999ab --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "font_size", + "value": "16fp" + } + ] +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/main/resources/base/element/string.json b/Form/ArkTSCardDocsSample/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65b5f0a1c34b584981c5335605826e579fc726b5 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ArkTSCardDemo" + }, + { + "name": "EntryFormAbility_desc", + "value": "form_description" + }, + { + "name": "EntryFormAbility_label", + "value": "form_label" + } + ] +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/main/resources/base/media/icon.png b/Form/ArkTSCardDocsSample/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/Form/ArkTSCardDocsSample/entry/src/main/resources/base/media/icon.png differ diff --git a/Form/ArkTSCardDocsSample/entry/src/main/resources/base/profile/form_config.json b/Form/ArkTSCardDocsSample/entry/src/main/resources/base/profile/form_config.json new file mode 100644 index 0000000000000000000000000000000000000000..2f1d1ed6e7ec71904923e36acaafb64635248c71 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/main/resources/base/profile/form_config.json @@ -0,0 +1,61 @@ +{ + "forms": [ + { + "name": "widget", + "description": "This is a service widget.", + "src": "./ets/widget/pages/WidgetCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": true, + "updateEnabled": true, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + }, + { + "name": "animation", + "description": "This is a service widget for animation.", + "src": "./ets/widget/pages/AnimationCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": false, + "updateEnabled": false, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "4*4", + "supportDimensions": [ + "4*4" + ] + }, + { + "name": "canvas", + "description": "This is a service widget for canvas.", + "src": "./ets/widget/pages/CanvasCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": false, + "updateEnabled": false, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "4*4", + "supportDimensions": [ + "4*4" + ] + } + ] +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/main/resources/base/profile/main_pages.json b/Form/ArkTSCardDocsSample/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/Form/ArkTSCardDocsSample/entry/src/main/resources/en_US/element/string.json b/Form/ArkTSCardDocsSample/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65b5f0a1c34b584981c5335605826e579fc726b5 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ArkTSCardDemo" + }, + { + "name": "EntryFormAbility_desc", + "value": "form_description" + }, + { + "name": "EntryFormAbility_label", + "value": "form_label" + } + ] +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/main/resources/zh_CN/element/string.json b/Form/ArkTSCardDocsSample/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..eb64e39e84c88054d716ddddd2fdd242da42a072 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ArkTSCardDemo" + }, + { + "name": "EntryFormAbility_desc", + "value": "form_description" + }, + { + "name": "EntryFormAbility_label", + "value": "form_label" + } + ] +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts b/Form/ArkTSCardDocsSample/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..1cca92ecec425ce8abece76a11435e5289c98c39 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023-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 '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined; +var abilityDelegatorArguments = undefined; + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/ohosTest/ets/test/Index.test.ets b/Form/ArkTSCardDocsSample/entry/src/ohosTest/ets/test/Index.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..612db475543cf9b676dbe6b0b19629961c02d8b9 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/ohosTest/ets/test/Index.test.ets @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2023-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 { describe, beforeAll, beforeEach, afterEach, afterAll, it } from '@ohos/hypium' +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import { Driver, ON, Component, MatchPattern } from '@ohos.UiTest'; +import hilog from '@ohos.hilog'; + +const TAG = '[Sample_ArkTSCardDemo]' +const DOMAIN = 0xF811 +const BUNDLE = 'ArkTSCard'; +const DELAYTIME01 = 500; +const DELAYTIME02 = 1000; + +export default function IndexTest() { + let driver = Driver.create(); + const delegator = AbilityDelegatorRegistry.getAbilityDelegator() + + let getResourceString: (resource: Resource) => Promise = + // 资源本地化 + async (resource: Resource): Promise => { + let manage = delegator.getAppContext().resourceManager; + let text = await manage.getStringValue(resource); + return text; + }; + + describe('IndexTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(async () => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + // 回到桌面并进入测试应用的服务卡片预览界面 + hilog.info(DOMAIN, TAG, 'Back to desktop start'); + await driver.delayMs(DELAYTIME01); + await driver.pressHome(); + await driver.delayMs(DELAYTIME01); + hilog.info(DOMAIN, TAG, 'Back to desktop finish'); + }); + beforeEach(async () => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + hilog.info(DOMAIN, TAG, 'Enter Card preview page start'); + await driver.assertComponentExist(ON.text('ArkTSCardDemo')); + let ArkTSCardDemo: Component = await driver.findComponent(ON.text('ArkTSCardDemo')); + // 获取文件控件边框 + let rect = await ArkTSCardDemo.getBounds(); + // 计算文字控件高度 + let height = rect.bottom - rect.top; + // 获取文字控件中心点 + let point = await ArkTSCardDemo.getBoundsCenter(); + await driver.longClick(point.x, point.y - height * 2); + await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.add_form_to_desktop')))); + let serviceCard: Component = + await driver.findComponent(ON.text(await getResourceString($r('app.string.add_form_to_desktop')))); + await serviceCard.click(); + await driver.delayMs(DELAYTIME01); + hilog.info(DOMAIN, TAG, 'Enter Card preview page finish'); + }); + afterEach(async () => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + hilog.info(DOMAIN, TAG, 'Back to first page start'); + await driver.delayMs(DELAYTIME02); + await driver.swipe(70, 870, 670, 870, 600); + await driver.delayMs(DELAYTIME02); + await driver.swipe(70, 870, 670, 870, 600); + await driver.delayMs(DELAYTIME02); + hilog.info(DOMAIN, TAG, 'Back to first page finish'); + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it(BUNDLE + '_HelloWorld_001', 0, async () => { + hilog.info(DOMAIN, TAG, 'ArkTSCard_HelloWorld test start'); + await driver.assertComponentExist(ON.text('widget', MatchPattern.CONTAINS)); + await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.add_to_desktop')))); + let addCard: Component = + await driver.findComponent(ON.text(await getResourceString($r('app.string.add_to_desktop')))); + await addCard.click(); + await driver.delayMs(500); + // 校验是否添加成功 + await driver.assertComponentExist(ON.text('ArkTSCardDemo')); + hilog.info(DOMAIN, TAG, 'ArkTSCard_HelloWorld test start'); + }); + it(BUNDLE + '_Animation_002', 0, async () => { + hilog.info(DOMAIN, TAG, 'ArkTSCard_Animation test start'); + await driver.delayMs(DELAYTIME02); + await driver.swipe(670, 870, 70, 870, 600); + await driver.delayMs(DELAYTIME02); + await driver.assertComponentExist(ON.text('animation', MatchPattern.CONTAINS)); + await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.add_to_desktop')))); + let addCard: Component = + await driver.findComponent(ON.text(await getResourceString($r('app.string.add_to_desktop')))); + await addCard.click(); + await driver.delayMs(DELAYTIME02); + // 校验是否添加成功 + await driver.assertComponentExist(ON.text('ArkTSCardDemo')); + hilog.info(DOMAIN, TAG, 'ArkTSCard_Animation test start'); + }); + it(BUNDLE + '_Canvas_003', 0, async () => { + hilog.info(DOMAIN, TAG, 'ArkTSCard_Canvas test start'); + await driver.delayMs(DELAYTIME02); + await driver.swipe(670, 870, 70, 870, 600); + await driver.delayMs(1000); + await driver.swipe(670, 870, 70, 870, 600); + await driver.delayMs(DELAYTIME02); + await driver.assertComponentExist(ON.text('canvas', MatchPattern.CONTAINS)); + await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.add_to_desktop')))); + let addCard: Component = + await driver.findComponent(ON.text(await getResourceString($r('app.string.add_to_desktop')))); + await addCard.click(); + await driver.delayMs(DELAYTIME01); + // 校验是否添加成功 + await driver.assertComponentExist(ON.text('ArkTSCardDemo')); + hilog.info(DOMAIN, TAG, 'ArkTSCard_Canvas test finish'); + }); + }) +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/ohosTest/ets/test/List.test.ets b/Form/ArkTSCardDocsSample/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..75c147cd20c1206dceb147fdd0e978c0aa81d15d --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023-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 IndexTest from './Index.test' + +export default function testsuite() { + IndexTest() +} diff --git a/Form/ArkTSCardDocsSample/entry/src/ohosTest/ets/testability/TestAbility.ets b/Form/ArkTSCardDocsSample/entry/src/ohosTest/ets/testability/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..cd661f712c1026a5a5ca852ff15820e0838a1c99 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2023-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 UIAbility from '@ohos.app.ability.UIAbility'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import hilog from '@ohos.hilog'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../test/List.test'; +import window from '@ohos.window'; +import { AbilityConstant, Want } from '@kit.AbilityKit'; + +export default class TestAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? ''); + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + let abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/ohosTest/ets/testability/pages/Index.ets b/Form/ArkTSCardDocsSample/entry/src/ohosTest/ets/testability/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6d512dfc24f1015553dbc9c3dd6c115010327e0d --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/ohosTest/ets/testability/pages/Index.ets @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023-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 '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + } + .type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(() => { + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/ohosTest/module.json5 b/Form/ArkTSCardDocsSample/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..85c0d054d4dc3816bf02841ee084208c65bca1ac --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/ohosTest/module.json5 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023-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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/Form/ArkTSCardDocsSample/entry/src/ohosTest/resources/base/element/color.json b/Form/ArkTSCardDocsSample/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/ohosTest/resources/base/element/string.json b/Form/ArkTSCardDocsSample/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..33fde6a287888ca7902e55dce61a7cd682e211f6 --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + }, + { + "name": "add_form_to_desktop", + "value": "服务卡片" + }, + { + "name": "add_to_desktop", + "value": "添加到桌面" + } + ] +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/entry/src/ohosTest/resources/base/media/icon.png b/Form/ArkTSCardDocsSample/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/Form/ArkTSCardDocsSample/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/Form/ArkTSCardDocsSample/entry/src/ohosTest/resources/base/profile/test_pages.json b/Form/ArkTSCardDocsSample/entry/src/ohosTest/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..b7e7343cacb32ce982a45e76daad86e435e054fe --- /dev/null +++ b/Form/ArkTSCardDocsSample/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "testability/pages/Index" + ] +} diff --git a/Form/ArkTSCardDocsSample/hvigor/hvigor-config.json5 b/Form/ArkTSCardDocsSample/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..006374173a4ca5cdca753c1fc58b39c1dc23c558 --- /dev/null +++ b/Form/ArkTSCardDocsSample/hvigor/hvigor-config.json5 @@ -0,0 +1,20 @@ +/* + * 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. + */ + +{ + "modelVersion": "5.0.0", + "dependencies": { + } +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/hvigorfile.ts b/Form/ArkTSCardDocsSample/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f6a51f2e343d74ccf67d082b5f8e6b3006858cec --- /dev/null +++ b/Form/ArkTSCardDocsSample/hvigorfile.ts @@ -0,0 +1,17 @@ +/* + * 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. + */ + +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { appTasks } from '@ohos/hvigor-ohos-plugin'; \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/oh-package.json5 b/Form/ArkTSCardDocsSample/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..454848e112fb5aa969e9da6229b09798138c95dd --- /dev/null +++ b/Form/ArkTSCardDocsSample/oh-package.json5 @@ -0,0 +1,13 @@ +{ + "modelVersion": "5.0.0", + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "arktscarddocssample", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/ohosTest.md b/Form/ArkTSCardDocsSample/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..ff3129cdf8fdac75536da1f2075c16b82e85348b --- /dev/null +++ b/Form/ArkTSCardDocsSample/ohosTest.md @@ -0,0 +1,9 @@ +# ArkTSCardDemo测试用例归档 + +## 用例表 + +|测试功能|预置条件|输入|预期输出|是否自动|测试结果| +|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------| +|添加helloworld卡片| 位于首页 | 1、长按应用图标点击服务卡片
2、进入卡片预览界面后添加首张helloworld卡片 |1、长按后菜单右服务卡片选项
2、点击服务卡片可以进入卡片预览界面
3、第一张卡片可以添加至桌面|是|Pass| +|添加动效卡片| 位于首页 | 1、长按应用图标点击服务卡片
2、进入卡片预览界面后右滑一次
3、添加第二张动效卡片 |1、长按后菜单右服务卡片选项
2、点击服务卡片可以进入卡片预览界面
3、第二张卡片可以添加至桌面|是|Pass| +|添加自定义绘制卡片| 位于首页 | 1、长按应用图标点击服务卡片
2、进入卡片预览界面后右滑两次
3、添加第三张自定义绘制卡片 |1、长按后菜单右服务卡片选项
2、点击服务卡片可以进入卡片预览界面
3、第三张卡片可以添加至桌面|是|Pass| \ No newline at end of file diff --git a/Form/ArkTSCardDocsSample/screenshots/device/FormAnimation.jpeg b/Form/ArkTSCardDocsSample/screenshots/device/FormAnimation.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..9985f3a285afa3867c2606555d928d96ebca9370 Binary files /dev/null and b/Form/ArkTSCardDocsSample/screenshots/device/FormAnimation.jpeg differ diff --git a/Form/ArkTSCardDocsSample/screenshots/device/FormCanvas.jpeg b/Form/ArkTSCardDocsSample/screenshots/device/FormCanvas.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..2aeeb038023324ce24e9c5baad0d1ac10c97d780 Binary files /dev/null and b/Form/ArkTSCardDocsSample/screenshots/device/FormCanvas.jpeg differ diff --git a/Form/ArkTSCardDocsSample/screenshots/device/FormHelloWorld.jpeg b/Form/ArkTSCardDocsSample/screenshots/device/FormHelloWorld.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..c2b3a4ff51cec99aa4412f8206a2430a2d0f1a59 Binary files /dev/null and b/Form/ArkTSCardDocsSample/screenshots/device/FormHelloWorld.jpeg differ