diff --git a/ArkUIKit/ButtonComponent/AppScope/app.json5 b/ArkUIKit/ButtonComponent/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a06e3dc3db3fa94efa19eca8a2bba0bd9fc70c10 --- /dev/null +++ b/ArkUIKit/ButtonComponent/AppScope/app.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. + */ + +{ + "app": { + "bundleName": "com.samples.buttoncomponent", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ArkUIKit/ButtonComponent/AppScope/resources/base/element/string.json b/ArkUIKit/ButtonComponent/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7aa13a433be744cff4bf694d53059c76e13ac56b --- /dev/null +++ b/ArkUIKit/ButtonComponent/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "DialogProject" + } + ] +} diff --git a/ArkUIKit/ButtonComponent/AppScope/resources/base/media/app_icon.png b/ArkUIKit/ButtonComponent/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ArkUIKit/ButtonComponent/AppScope/resources/base/media/app_icon.png differ diff --git a/ArkUIKit/ButtonComponent/README_zh.md b/ArkUIKit/ButtonComponent/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..74095fe0e7fbf6e141243937b2c777f86a690629 --- /dev/null +++ b/ArkUIKit/ButtonComponent/README_zh.md @@ -0,0 +1,112 @@ +# ArkUI使用文本控件指南文档示例 + +### 介绍 + +本示例通过使用[ArkUI指南文档](https://gitcode.com/openharmony/docs/tree/master/zh-cn/application-dev/ui)中各场景的开发示例,展示在工程中,帮助开发者更好地理解ArkUI提供的弧形组件及组件属性并合理使用。该工程中展示的代码详细描述可查链接:[弧形按钮 (arcbutton)](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/ui/arkts-advanced-components-arcbutton.md)。 +### 效果预览 + +| 下弧形按钮效果 | 上弧形按钮效果 | +|----------------------------------|----------------------------------| +| ![](screenshots/device/img1.png) | ![](screenshots/device/img2.png) | + +### 使用说明 + +1. 在主界面,可以点击对应卡片,选择需要参考的组件示例。 + +3. 进入示例界面,查看参考示例。 + +4. 通过自动测试框架可进行测试及维护。 + +### 工程目录 +``` +entry/src/main/ets/ +|---entryability +|---pages +| |---ButtonAlignBottom.ets +| |---ButtonAlignTop.ets +| |---ButtonBcgColor.ets +| |---ButtonBrightness.ets +| |---ButtonFontColor.ets +| |---ButtonShadow.ets +| |---Index.ets // 应用主页面 +entry/src/ohosTest/ +|---ets +| |---index.test.ets // 示例代码测试代码 +``` +### 具体实现 +实现了弧形按钮使用用例,包含亮度值显示、滑动调节滑块和重置按钮。以下是详细实现过程: +1. 数据定义 + 在结构体BrightnessPage中定义了两个核心数据: + @Local brightnessValue: number = 30:用@Local装饰器声明的本地状态变量,记录当前亮度值,初始值为 30(单位:%)。 + private defaultBrightnessValue: number = 50:私有变量,存储默认亮度值(50%),用于重置功能。 +2. 布局容器 + 使用RelativeContainer作为根容器,通过对齐规则(alignRules) 管理子组件的位置关系,特点是: + 容器尺寸设置为width('100%')和height('100%'),占满整个父容器。 + 背景色设为Color.Black(黑色),形成深色主题。 +3. 子组件实现 + (1)标题文本(Text) + 显示内容:$r('app.string.Brightness'),通过资源管理器引用字符串资源(“亮度”)。 + 样式:白色字体(Color.White)、字号 24、顶部外边距 16px。 + 位置:通过alignRules设置水平居中(middle对齐容器的HorizontalAlign.Center)。 + (2)亮度值显示文本(Text) + 显示内容:${this.brightnessValue} %,动态展示当前亮度值(如 “30 %”)。 + 样式:白色字体、左侧外边距 16px。 + 位置: + start对齐容器的HorizontalAlign.Start(左对齐容器左侧)。 + center对齐容器的VerticalAlign.Center(垂直居中于容器)。 + (3)亮度调节滑块(Slider) + 核心配置: + value: this.brightnessValue:滑块当前值绑定到brightnessValue。 + min: 0、max: 100:调节范围 0~100(对应亮度百分比)。 + style: SliderStyle.InSet:滑块样式为内嵌模式(通常用于紧凑布局)。 + 样式: + 滑块轨道未选中部分:trackColor('#ADD8E6')(浅蓝色)。 + 选中部分:selectedColor('#4169E1')(皇家蓝)。 + 滑块按钮:blockColor('#191970')(深靛蓝)。 + 宽度 150px,左右外边距 16px。 + 交互:onChange事件监听滑块值变化,实时更新brightnessValue(双向绑定)。 + 位置: + center对齐亮度文本(id_brightness_min_text)的垂直中心。 + start对齐亮度文本的右侧(HorizontalAlign.End),即滑块紧接在文本右侧。 + (4)重置按钮(ArcButton) + 配置:通过ArcButtonOptions设置弧形按钮属性: + 文本:$r('app.string.Reset')(引用 “重置” 字符串资源)。 + 样式:styleMode: ArcButtonStyleMode.EMPHASIZED_LIGHT(高亮浅色模式,适合深色背景)。 + 字号:19fp(基于字体像素的自适应单位)。 + 点击事件:onClick回调中将brightnessValue重置为defaultBrightnessValue(50%)。 + 位置: + middle对齐容器水平中心(水平居中)。 + bottom对齐容器底部(垂直靠下)。 +4. 整体效果 + 页面呈现一个深色背景的亮度调节界面: + 顶部居中显示 “亮度” 标题。 + 中间左侧显示当前亮度值(如 “30 %”),右侧紧接一个滑块,可拖动调节亮度(0~100%),滑块值实时同步到文本。 + 底部居中显示 “重置” 按钮,点击后亮度值恢复为 50%。 + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API21版本SDK,版本号:6.0.0.254,镜像版本号:OpenHarmony_5.0.2.57。 + +3.本示例需要使用DevEco Studio NEXT Developer Preview2 (Build Version: 5.0.5.306, built on December 12, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkUISample/ButtonComponent > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/build-profile.json5 b/ArkUIKit/ButtonComponent/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e93cdb10e8c8585d39745a8d6e670c86020faeb8 --- /dev/null +++ b/ArkUIKit/ButtonComponent/build-profile.json5 @@ -0,0 +1,58 @@ +/* + * 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "6.0.0(20)", + "targetSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + }, + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/code-linter.json5 b/ArkUIKit/ButtonComponent/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/ArkUIKit/ButtonComponent/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * 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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/build-profile.json5 b/ArkUIKit/ButtonComponent/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/hvigorfile.ts b/ArkUIKit/ButtonComponent/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkUIKit/ButtonComponent/entry/oh-package.json5 b/ArkUIKit/ButtonComponent/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/ArkUIKit/ButtonComponent/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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkUIKit/ButtonComponent/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUIKit/ButtonComponent/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,57 @@ +/* + * 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. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + 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.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkUIKit/ButtonComponent/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonAlignBottom.ets b/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonAlignBottom.ets new file mode 100644 index 0000000000000000000000000000000000000000..4fd6f070b698ba23c906a6bc901de2d78c2e2a6e --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonAlignBottom.ets @@ -0,0 +1,50 @@ +/* + * 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. + */ + +import { ArcButton, ArcButtonOptions, ArcButtonPosition, ArcButtonStyleMode } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const DOMAIN = 0xF811; +const TAG = '[Sample_Button_Component]' + +@Entry +@ComponentV2 +struct ButtonAlignBottom { + build() { + RelativeContainer() { + // [Start button_align_bottom] + ArcButton({ + options: new ArcButtonOptions({ + label: 'OK', + // [StartExclude button_touch] + position: ArcButtonPosition.BOTTOM_EDGE, + styleMode: ArcButtonStyleMode.EMPHASIZED_LIGHT, + // [EndExclude button_touch] + // [StartExclude button_align_bottom] + onTouch: (event: TouchEvent) => { + hilog.info(DOMAIN, TAG, 'ArcButton onTouch'); + } + // [EndExclude button_align_bottom] + }) + + }) + // [End button_align_bottom] + .alignRules({ + middle: { anchor: '__container__', align: HorizontalAlign.Center }, + bottom: { anchor: '__container__', align: VerticalAlign.Bottom } + }) + } + } +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonAlignTop.ets b/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonAlignTop.ets new file mode 100644 index 0000000000000000000000000000000000000000..754df2be3422242c559899ba91b19b0a4bc372d4 --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonAlignTop.ets @@ -0,0 +1,50 @@ +/* + * 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. + */ + +import { ArcButton, ArcButtonOptions, ArcButtonPosition, ArcButtonStyleMode } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const DOMAIN = 0xF811; +const TAG = '[Sample_Button_Component]' + +@Entry +@ComponentV2 +struct ButtonAlignTop { + build() { + RelativeContainer() { + // [Start button_align_top] + // [Start button_click] + ArcButton({ + options: new ArcButtonOptions({ + label: 'OK', + // [StartExclude button_click] + position: ArcButtonPosition.TOP_EDGE, + styleMode: ArcButtonStyleMode.EMPHASIZED_LIGHT, + // [End button_click] + // [StartExclude button_align_top] + onClick: () => { + hilog.info(DOMAIN, TAG, 'ArcButton onClick'); + }, + // [EndExclude button_align_top] + }) + }) + // [End button_align_top] + // [End button_click] + .alignRules({ + middle: { anchor: '__container__', align: HorizontalAlign.Center }, + }) + } + } +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonBcgColor.ets b/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonBcgColor.ets new file mode 100644 index 0000000000000000000000000000000000000000..3aab334a3a1341de500dcde77d13a94f4f69b550 --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonBcgColor.ets @@ -0,0 +1,38 @@ +/* + * 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. + */ + +import { ArcButton, ArcButtonOptions, ArcButtonStyleMode, ColorMetrics } from '@kit.ArkUI'; + +@Entry +@ComponentV2 +struct ButtonBcgColor { + build() { + RelativeContainer() { + // [Start button_bcg_color] + ArcButton({ + options: new ArcButtonOptions({ + label: 'OK', + styleMode: ArcButtonStyleMode.CUSTOM, + backgroundColor: ColorMetrics.resourceColor('#707070') + }) + }) + // [End button_bcg_color] + .alignRules({ + middle: { anchor: '__container__', align: HorizontalAlign.Center }, + bottom: { anchor: '__container__', align: VerticalAlign.Bottom } + }) + } + } +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonBrightness.ets b/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonBrightness.ets new file mode 100644 index 0000000000000000000000000000000000000000..eca306f1bcfe34a2f1e257025bb35fc9f75b188e --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonBrightness.ets @@ -0,0 +1,87 @@ +/* + * 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. + */ + +// [Start brightness_page] +import { LengthMetrics, LengthUnit, ArcButton, ArcButtonOptions, ArcButtonStyleMode } from '@kit.ArkUI'; + +@Entry +@ComponentV2 +struct BrightnessPage { + @Local brightnessValue: number = 30; + private defaultBrightnessValue: number = 50; + + build() { + RelativeContainer() { + // $r('app.string.Reset')需要替换为开发者所需的资源文件 + Text($r('app.string.Brightness')) + .fontColor(Color.White) + .id('id_brightness_set_text') + .fontSize(24) + .margin({ top: 16 }) + .alignRules({ + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + + Text(`${this.brightnessValue} %`) + .fontColor(Color.White) + .id('id_brightness_min_text') + .margin({ left: 16 }) + .alignRules({ + start: { anchor: '__container__', align: HorizontalAlign.Start }, + center: { anchor: '__container__', align: VerticalAlign.Center } + }) + + Slider({ + value: this.brightnessValue, + min: 0, + max: 100, + style: SliderStyle.InSet + }) + .blockColor('#191970') + .trackColor('#ADD8E6') + .selectedColor('#4169E1') + .width(150) + .id('id_brightness_slider') + .margin({ left: 16, right: 16 }) + .onChange((value: number, mode: SliderChangeMode) => { + this.brightnessValue = value; + }) + .alignRules({ + center: { anchor: 'id_brightness_min_text', align: VerticalAlign.Center }, + start: { anchor: 'id_brightness_min_text', align: HorizontalAlign.End } + }) + + ArcButton({ + options: new ArcButtonOptions({ + // $r('app.string.Reset')需要替换为开发者所需的资源文件 + label: $r('app.string.Reset'), + styleMode: ArcButtonStyleMode.EMPHASIZED_LIGHT, + fontSize: new LengthMetrics(19, LengthUnit.FP), + onClick: () => { + this.brightnessValue = this.defaultBrightnessValue; + } + }) + }) + .alignRules({ + middle: { anchor: '__container__', align: HorizontalAlign.Center }, + bottom: { anchor: '__container__', align: VerticalAlign.Bottom } + }) + } + .height('100%') + .width('100%') + .backgroundColor(Color.Black) + } +} +// [End brightness_page] \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonFontColor.ets b/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonFontColor.ets new file mode 100644 index 0000000000000000000000000000000000000000..a8c3e15f081c1a92f6b0ee0edff74f3312ca945d --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonFontColor.ets @@ -0,0 +1,39 @@ +/* + * 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. + */ + +import { ArcButton, ArcButtonOptions, ArcButtonStyleMode, ColorMetrics } from '@kit.ArkUI'; + +@Entry +@ComponentV2 +struct ButtonFontColor { + build() { + RelativeContainer() { + // [Start button_font_color] + ArcButton({ + options: new ArcButtonOptions({ + label: 'OK', + styleMode: ArcButtonStyleMode.CUSTOM, + backgroundColor: ColorMetrics.resourceColor('#E84026'), + fontColor: ColorMetrics.resourceColor('#707070') + }) + }) + // [End button_font_color] + .alignRules({ + middle: { anchor: '__container__', align: HorizontalAlign.Center }, + bottom: { anchor: '__container__', align: VerticalAlign.Bottom } + }) + } + } +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonShadow.ets b/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonShadow.ets new file mode 100644 index 0000000000000000000000000000000000000000..f332ad1122353e6db0171ddd8ef69cfa5748acae --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/ButtonShadow.ets @@ -0,0 +1,38 @@ +/* + * 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. + */ + +import { ArcButton, ArcButtonOptions, ColorMetrics } from '@kit.ArkUI'; + +@Entry +@ComponentV2 +struct ButtonShadowColor { + build() { + RelativeContainer() { + // [Start button_shadow_color] + ArcButton({ + options: new ArcButtonOptions({ + label: 'OK', + shadowEnabled: true, + shadowColor: ColorMetrics.resourceColor('#ffec1022') + }) + }) + // [End button_shadow_color] + .alignRules({ + middle: { anchor: '__container__', align: HorizontalAlign.Center }, + bottom: { anchor: '__container__', align: VerticalAlign.Bottom } + }) + } + } +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/Index.ets b/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..fe760184d1b44bf48ac03f31f01113ef77c680ec --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,98 @@ +/* + * 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. + */ + +interface listItem { + router?: string; + name: string; +} + +let demandList: listItem[] = [ + { + name: "ButtonAlignTop", + router: "pages/ButtonAlignTop", + }, + { + name: "ButtonAlignBottom", + router: "pages/ButtonAlignBottom", + }, + { + name: "ButtonBcgColor", + router: "pages/ButtonBcgColor", + }, + { + name: "ButtonBrightness", + router: "pages/ButtonBrightness", + }, + { + name: "ButtonFontColor", + router: "pages/ButtonFontColor", + }, + { + name: "ButtonShadow", + router: "pages/ButtonShadow", + }, +] + +@Entry +@Component +struct Index { + @State bgColor: ResourceColor = "#39b5fa"; + build() { + Column() { + Text($r('app.string.ListShow')) + .height('5.00%') + .width('100%') + .textAlign(TextAlign.Center) + .fontSize(10) + .fontWeight(FontWeight.Bold) + .backgroundColor(this.bgColor) + .fontColor(Color.White) + Column() { + List({ space: 5, initialIndex: 0 }) { + ForEach(demandList, (listitem: listItem, index: number) => { + ListItem() { + Column({ space: 10 }) { + Text(listitem.name) + .fontSize(10) + .maxLines(1) + } + .padding('1%') + .width('100%') + .borderRadius(10) + .backgroundColor(this.bgColor) + .borderColor(this.bgColor) + .borderWidth(1) + .onClick(() => { + if (!!listitem.router) { + this.getUIContext().getRouter().pushUrl({ url: listitem.router }) + } + }) + } + }) + } + .listDirection(Axis.Vertical) // 排列方向 + .alignListItem(ListItemAlign.Center) + .scrollBar(BarState.Off) + .margin(1) + .edgeEffect(EdgeEffect.Spring) // 边缘效果设置为Spring + .width('90%') + } + .width('100%') + .height('100%') + .backgroundColor('#fff4f3f3') + .padding({ top: 5 }) + } + } +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/main/module.json5 b/ArkUIKit/ButtonComponent/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f101ab97f73a6c4cc05ba389cba708454ecfc13c --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/module.json5 @@ -0,0 +1,71 @@ +/* + * 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. + */ + +{ + // [Start module_json_config] + "module": { + // [StartExclude module_json_config] + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + // [EndExclude module_json_config] + "deviceTypes": [ + "wearable" + ], + // [StartExclude module_json_config] + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:ButtonComponent", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ], + // [EndExclude module_json_config] + } + // [end module_json_config] +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/main/resources/base/element/color.json b/ArkUIKit/ButtonComponent/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkUIKit/ButtonComponent/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/ArkUIKit/ButtonComponent/entry/src/main/resources/base/element/string.json b/ArkUIKit/ButtonComponent/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3b0f958f0e9eee8099c9a3aae4c04bfc2ba5caa5 --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/resources/base/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "ListShow", + "value": "Show List" + }, + { + "name": "Reset", + "value": "重置" + }, + { + "name": "Brightness", + "value": "设置亮度" + }, + { + "name": "ButtonComponent", + "value": "button" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/main/resources/base/media/layered_image.json b/ArkUIKit/ButtonComponent/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..9921b54060adc51d315a326bdef962e3634e44f4 --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ + + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/main/resources/base/media/startIcon.png b/ArkUIKit/ButtonComponent/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkUIKit/ButtonComponent/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkUIKit/ButtonComponent/entry/src/main/resources/base/profile/backup_config.json b/ArkUIKit/ButtonComponent/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/main/resources/base/profile/main_pages.json b/ArkUIKit/ButtonComponent/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..0f2a97402f0bd771021ec9932c46f70f40ca104c --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,11 @@ +{ + "src": [ + "pages/ButtonAlignBottom", + "pages/ButtonAlignTop", + "pages/ButtonBcgColor", + "pages/ButtonBrightness", + "pages/ButtonFontColor", + "pages/ButtonShadow", + "pages/Index" + ] +} diff --git a/ArkUIKit/ButtonComponent/entry/src/main/resources/dark/element/color.json b/ArkUIKit/ButtonComponent/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/main/resources/en_US/element/string.json b/ArkUIKit/ButtonComponent/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3b0f958f0e9eee8099c9a3aae4c04bfc2ba5caa5 --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "ListShow", + "value": "Show List" + }, + { + "name": "Reset", + "value": "重置" + }, + { + "name": "Brightness", + "value": "设置亮度" + }, + { + "name": "ButtonComponent", + "value": "button" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/main/resources/zh_CN/element/string.json b/ArkUIKit/ButtonComponent/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..de1a7c91dda4843341194f345ea5aedba9832568 --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "ListShow", + "value": "Show List" + }, + { + "name": "Reset", + "value": "重置" + }, + { + "name": "Brightness", + "value": "设置亮度" + }, + { + "name": "ButtonComponent", + "value": "button" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/main/syscap.json b/ArkUIKit/ButtonComponent/entry/src/main/syscap.json new file mode 100644 index 0000000000000000000000000000000000000000..2b9fde62f4293996a85bbcc36aec161d5675a8a8 --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/main/syscap.json @@ -0,0 +1,17 @@ +{ + "devices": { + "general": [ + "wearable" + ], + "custom": [ + { + "xts": [ + "SystemCapability.Account.AppAccount", + "SystemCapability.Account.OsAccount", + "SystemCapability.ArkUI.ArkUI.Circle", + "SystemCapability.ArkUI.ArkUI.Full" + ] + } + ] + } +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkUIKit/ButtonComponent/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // 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. + }) + beforeEach(() => { + // 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. + }) + afterEach(() => { + // 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. + }) + 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('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/ohosTest/ets/test/Index.test.ets b/ArkUIKit/ButtonComponent/entry/src/ohosTest/ets/test/Index.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ce5b692f2479e7dd6391176c37c1f5029354e5fd --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/ohosTest/ets/test/Index.test.ets @@ -0,0 +1,180 @@ +/* + * 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. + */ + +import { describe, it, expect, beforeAll } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; +import hilog from '@ohos.hilog'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +let driver: Driver; +const DOMAIN = 0xF811; +const TAG = '[Sample_Button_Component]' +const BUNDLE = 'ButtonComponent' + +export default function ArcButtonTest() { + describe('ArcButtonTest', () => { + beforeAll(async () => { + // 启动应用 + let want: Want = { + bundleName: "com.samples.buttoncomponent", + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + driver = Driver.create(); + await driver.delayMs(1000); + + // 验证当前页面是否正确 + const ability: UIAbility = await delegator.getCurrentTopAbility(); + hilog.info(DOMAIN, TAG, 'get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }); + + /** + * @tc.number LoadList_001 + * @tc.name test Load List + * @tc.desc 测试首页加载是否成功 + */ + it(BUNDLE + 'LoadList_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + "LoadList_001, begin"); + const title = await driver.findComponent(ON.text('Show List')); + expect(title === null).assertFalse(); + const list = await driver.findComponent(ON.type('List')); + expect(list === null).assertFalse(); + hilog.info(DOMAIN, TAG, BUNDLE + "LoadList_001, end"); + done(); + }); + + /** + * @tc.number ButtonClick_001 + * @tc.name test Top ArcButton And onClick Event + * @tc.desc 测试创建上弧形按钮和点击事件 + */ + it(BUNDLE + 'ButtonClick_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + "ButtonClick_001, begin"); + const listItem = await driver.findComponent(ON.text('ButtonAlignTop')); + expect(listItem === null).assertFalse(); + await listItem.click(); + await driver.delayMs(1000); + const arcButton = await driver.findComponent(ON.text('OK')); + expect(arcButton === null).assertFalse(); + await arcButton.click(); + await driver.delayMs(1000); + await driver.pressBack(); + await driver.delayMs(1000); + hilog.info(DOMAIN, TAG, BUNDLE + "ButtonClick_001, end"); + done(); + }); + + /** + * @tc.number ButtonTouch_001 + * @tc.name test Bottom ArcButton And onTouch Event + * @tc.desc 测试创建下弧形按钮和触摸事件 + */ + it(BUNDLE + 'ButtonTouch_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + "ButtonTouch_001, begin"); + const listItem = await driver.findComponent(ON.text('ButtonAlignBottom')); + expect(listItem === null).assertFalse(); + await listItem.click(); + await driver.delayMs(1000); + const arcButton = await driver.findComponent(ON.text('OK')); + expect(arcButton === null).assertFalse(); + await arcButton.click(); + await driver.delayMs(1000); + await driver.pressBack(); + await driver.delayMs(1000); + hilog.info(DOMAIN, TAG, BUNDLE + "ButtonTouch_001, end"); + done(); + }); + + /** + * @tc.number SetBackgroundColor_001 + * @tc.name test ArcButton Set BackgroundColor + * @tc.desc 测试弧形按钮设置背景色 + */ + it(BUNDLE + 'SetBackgroundColor_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + "SetBackgroundColor_001, begin"); + const listItem = await driver.findComponent(ON.text('ButtonBcgColor')); + expect(listItem === null).assertFalse(); + await listItem.click(); + await driver.delayMs(1000); + const arcButton = await driver.findComponent(ON.text('OK')); + expect(arcButton === null).assertFalse(); + await driver.pressBack(); + await driver.delayMs(1000); + hilog.info(DOMAIN, TAG, BUNDLE + "SetBackgroundColor_001, end"); + done(); + }); + + /** + * @tc.number SetFontColor_001 + * @tc.name test ArcButton Set FontColor + * @tc.desc 测试弧形按钮设置字体颜色 + */ + it(BUNDLE + 'SetFontColor_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + "SetFontColor_001, begin"); + const listItem = await driver.findComponent(ON.text('ButtonFontColor')); + expect(listItem === null).assertFalse(); + await listItem.click(); + await driver.delayMs(1000); + const arcButton = await driver.findComponent(ON.text('OK')); + expect(arcButton === null).assertFalse(); + await driver.pressBack(); + await driver.delayMs(1000); + hilog.info(DOMAIN, TAG, BUNDLE + "SetFontColor_001, end"); + done(); + }); + + /** + * @tc.number SetShadow_001 + * @tc.name test ArcButton Set Shadow + * @tc.desc 测试弧形按钮设置阴影和颜色 + */ + it(BUNDLE + 'SetShadow_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + "SetShadow_001, begin"); + const listItem = await driver.findComponent(ON.text('ButtonShadow')); + expect(listItem === null).assertFalse(); + await listItem.click(); + await driver.delayMs(1000); + const arcButton = await driver.findComponent(ON.text('OK')); + expect(arcButton === null).assertFalse(); + await driver.pressBack(); + await driver.delayMs(1000); + hilog.info(DOMAIN, TAG, BUNDLE + "SetShadow_001, end"); + done(); + }); + + /** + * @tc.number ChangeValue_001 + * @tc.name test ArcButton Change The Interface Value + * @tc.desc 测试弧形按钮更改界面值 + */ + it(BUNDLE + 'ChangeValue_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + "ChangeValue_001, begin"); + const listItem = await driver.findComponent(ON.text('ButtonBrightness')); + expect(listItem === null).assertFalse(); + await listItem.click(); + await driver.delayMs(1000); + let str = delegator.getAppContext().resourceManager.getStringByNameSync('Reset'); + const arcButton = await driver.findComponent(ON.text(str)); + expect(arcButton === null).assertFalse(); + await arcButton.click(); + await driver.pressBack(); + await driver.delayMs(1000); + hilog.info(DOMAIN, TAG, BUNDLE + "ChangeValue_001, end"); + done(); + }); + }); +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/ohosTest/ets/test/List.test.ets b/ArkUIKit/ButtonComponent/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1069fdae653d67fcf8e9060f0ed0330b4c354523 --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,23 @@ +/* + * 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. + */ + + +import ArcButtonTest from './Index.test' +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); + ArcButtonTest() +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/entry/src/ohosTest/module.json5 b/ArkUIKit/ButtonComponent/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ce29d7116158257dcf40da4b1476da62376a617f --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * 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. + */ + + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "wearable" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkUIKit/ButtonComponent/entry/src/ohosTest/syscap.json b/ArkUIKit/ButtonComponent/entry/src/ohosTest/syscap.json new file mode 100644 index 0000000000000000000000000000000000000000..2b9fde62f4293996a85bbcc36aec161d5675a8a8 --- /dev/null +++ b/ArkUIKit/ButtonComponent/entry/src/ohosTest/syscap.json @@ -0,0 +1,17 @@ +{ + "devices": { + "general": [ + "wearable" + ], + "custom": [ + { + "xts": [ + "SystemCapability.Account.AppAccount", + "SystemCapability.Account.OsAccount", + "SystemCapability.ArkUI.ArkUI.Circle", + "SystemCapability.ArkUI.ArkUI.Full" + ] + } + ] + } +} \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/hvigor/hvigor-config.json5 b/ArkUIKit/ButtonComponent/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/ArkUIKit/ButtonComponent/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * 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.1", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkUIKit/ButtonComponent/hvigorfile.ts b/ArkUIKit/ButtonComponent/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/ArkUIKit/ButtonComponent/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkUIKit/ButtonComponent/oh-package.json5 b/ArkUIKit/ButtonComponent/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/ArkUIKit/ButtonComponent/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. + */ + +{ + "modelVersion": "5.0.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkUIKit/ButtonComponent/ohosTest.md b/ArkUIKit/ButtonComponent/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..093f273c18c415ba4d3184180424713e91e62e4e --- /dev/null +++ b/ArkUIKit/ButtonComponent/ohosTest.md @@ -0,0 +1,10 @@ +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +|-------------| ------------ |-----------|------------------| -------- | +| 创建上弧形按钮 | 设备正常运行 | 点击"ButtonAlignTop" | 页面和按钮创建成功 | Pass | +| 按钮点击事件 | 设备正常运行 | 点击"ButtonAlignTop"后点击页面上的OK | 打印日志“ArcButton onClick” | Pass | +| 创建下弧形按钮 | 设备正常运行 | 点击"ButtonAlignBottom" | 页面和按钮创建成功 | Pass | +| 按钮触摸事件 | 设备正常运行 | 点击"ButtonAlignBottom"后点击页面上的OK | 打印日志“ArcButton onTouch” | Pass | +| 设置按钮背景色 | 设备正常运行 | 点击"ButtonBcgColor" | 页面和按钮创建成功 | Pass | +| 设置按钮文本色 | 设备正常运行 | 点击"ButtonFontColor" | 页面和按钮创建成功 | Pass | +| 设置按钮阴影色 | 设备正常运行 | 点击"ButtonShadow" | 页面和按钮创建成功 | Pass | +| 通过按钮更改界面亮度值 | 设备正常运行 | 点击"ButtonBrightness"后点击页面上的OK | 当前亮度调数值更改 | Pass | \ No newline at end of file diff --git a/ArkUIKit/ButtonComponent/screenshots/device/img1.png b/ArkUIKit/ButtonComponent/screenshots/device/img1.png new file mode 100644 index 0000000000000000000000000000000000000000..96eee0a3cbb7440aded476ca6b5898fbb0beeb23 Binary files /dev/null and b/ArkUIKit/ButtonComponent/screenshots/device/img1.png differ diff --git a/ArkUIKit/ButtonComponent/screenshots/device/img2.png b/ArkUIKit/ButtonComponent/screenshots/device/img2.png new file mode 100644 index 0000000000000000000000000000000000000000..4206c55dbdda158c1c2ffcd6034ab685e0c34c4e Binary files /dev/null and b/ArkUIKit/ButtonComponent/screenshots/device/img2.png differ diff --git a/ArkUIKit/ChooseComponent/.gitignore b/ArkUIKit/ChooseComponent/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkUIKit/ChooseComponent/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/AppScope/app.json5 b/ArkUIKit/ChooseComponent/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e84cdde0e36906f043d70e137c07985212f52f21 --- /dev/null +++ b/ArkUIKit/ChooseComponent/AppScope/app.json5 @@ -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. + */ + +{ + "app": { + "bundleName": "com.samples.choosecomponent", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ArkUIKit/ChooseComponent/AppScope/resources/base/element/string.json b/ArkUIKit/ChooseComponent/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8e5e7e57b323d96b2769a0899a6105aae260470b --- /dev/null +++ b/ArkUIKit/ChooseComponent/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ChooseComponent" + } + ] +} diff --git a/ArkUIKit/ChooseComponent/AppScope/resources/base/media/app_icon.png b/ArkUIKit/ChooseComponent/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ArkUIKit/ChooseComponent/AppScope/resources/base/media/app_icon.png differ diff --git a/ArkUIKit/ChooseComponent/README_zh.md b/ArkUIKit/ChooseComponent/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..e1a335f5c5cadf23acc0c926cf8d572fac691729 --- /dev/null +++ b/ArkUIKit/ChooseComponent/README_zh.md @@ -0,0 +1,80 @@ +# ArkUI指南文档示例 + +### 介绍 + +本示例通过使用[ArkUI指南文档](https://gitcode.com/openharmony/docs/tree/master/zh-cn/application-dev/ui)中各场景的开发示例,展示在工程中,帮助开发者更好地理解ArkUI提供的组件及组件属性并合理使用。该工程中展示的代码详细描述可查如下链接: + +1. [按钮 (Button)开发指导](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/ui/arkts-common-components-button.md)。 +2. [单选框 (Radio)开发指导](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/ui/arkts-common-components-radio-button.md)。 +3. [切换按钮 (Toggle)开发指导](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/ui/arkts-common-components-switch.md)。 +### 效果预览 + +| 首页 | 按钮组件目录 | 创建按钮场景示例 | +|------------------------------------|------------------------------------|------------------------------------| +| ![](screenshots/device/image1.png) | ![](screenshots/device/image2.png) | ![](screenshots/device/image3.png) | + +### 使用说明 + +1. 在主界面,可以点击对应卡片,选择需要参考的组件示例。 + +2. 在组件目录选择详细的示例参考。 + +3. 进入示例界面,查看参考示例。 + +4. 通过自动测试框架可进行测试及维护。 + +### 工程目录 +``` +entry/src/main/ets/ +|---entryability +|---pages +| |---button +| | |---CreateButton.ets // 按钮创建示例代码 +| | |---ButtonCustomStyle.ets // 按钮自定义示例代码 +| | |---FloatingButton.ets // 按钮悬浮场景示例代码 +| | |---Index.ets // 第二层级目录 +| | |---SetButtonType.ets // 按钮类型设置示例代码 +| | |---SubmitForm.ets // 按钮注册场景示例代码 +| |---radio +| | |---RadioButton.ets // 2个单选框场景示例代码 +| | |---RadioSample.ets // 单选框场景示例代码 +| | |---Index.ets // 第二层级目录 +| |---toggle +| | |---CreateToggle.ets // 切换按钮创建示例代码 +| | |---ToggleCustomStyle.ets // 切换按钮自定义示例代码 +| | |---ToggleCaseExample.ets // 切换按钮场景示例代码 +| | |---Index.ets // 第二层级目录 +|---pages +| |---Index.ets // 应用主页面 +entry/src/ohosTest/ +|---ets +| |---index.test.ets // 示例代码测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API18版本SDK,版本号:5.1.0.56,镜像版本号:OpenHarmony_5.1.0.56。 + +3.本示例需要使用DevEco Studio NEXT Developer Preview2 (Build Version: 5.0.5.306, built on December 12, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkUISample/ChooseComponent > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/build-profile.json5 b/ArkUIKit/ChooseComponent/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31736e366d1231a361c64efbf5a9b61b9b0e57bb --- /dev/null +++ b/ArkUIKit/ChooseComponent/build-profile.json5 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024-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", + "compileSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "6.0.0(20)", + "targetSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/code-linter.json5 b/ArkUIKit/ChooseComponent/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..eff2dbc9b8a447e5a99b0aab08ca2b766d786bf6 --- /dev/null +++ b/ArkUIKit/ChooseComponent/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * 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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/.gitignore b/ArkUIKit/ChooseComponent/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/build-profile.json5 b/ArkUIKit/ChooseComponent/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31bf2f4c4df15f0403582b255ebdff1354312357 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/hvigorfile.ts b/ArkUIKit/ChooseComponent/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..ac00aaeaf45982325e06e5a576ed7c336bbdb351 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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 { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkUIKit/ChooseComponent/entry/obfuscation-rules.txt b/ArkUIKit/ChooseComponent/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/oh-package.json5 b/ArkUIKit/ChooseComponent/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4e54d14e1b444a338b2c922f94a4fe4deed5be45 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/oh-package.json5 @@ -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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/common/Card.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/common/Card.ets new file mode 100644 index 0000000000000000000000000000000000000000..a9ce32e1f5851798d76f86f8dff6aa2554daa6ed --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/common/Card.ets @@ -0,0 +1,137 @@ +/* + * 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. + */ + +@Component +export struct CompletedRoutableCard { + @Prop + symbol: Resource = $r('sys.symbol.label'); + @Prop + @Require + title: string; + @Prop + @Require + description: ResourceStr; + + build() { + Card({ verticalAlign: VerticalAlign.Top }) { + Button({ type: ButtonType.Circle }) { + SymbolGlyph(this.symbol) + .fontColor(['#fff']) + .fontSize(16) + } + .borderRadius(14) + + Column({ space: 8 }) { + Text(this.title) + .fontColor($r('sys.color.font_primary')) + + Text(this.description) + .fontColor($r('sys.color.font_secondary')) + .fontSize($r('sys.float.Body_S')) + } + .alignItems(HorizontalAlign.Start) + .layoutWeight(1) + } + } +} + +@Component +export struct Card { + @Prop + verticalAlign: VerticalAlign = VerticalAlign.Center; + @BuilderParam + content: () => void; + + build() { + Row({ space: 12 }) { + this.content() + } + .alignItems(this.verticalAlign) + .backgroundColor('#fff') + .borderRadius(12) + .padding(12) + .width('100%') + } +} + +@Component +export struct RoutableCard { + @Prop + icon: Resource = $r('sys.symbol.label'); + @Prop + @Require + title: ResourceStr; + + build() { + Card() { + Button({ type: ButtonType.Circle }) { + SymbolGlyph(this.icon) + .fontColor(['#fff']) + .fontSize(16) + } + .borderRadius(14) + + Text(this.title) + .fontColor($r('sys.color.font_primary')) + .minFontSize(12) + .maxFontSize(16) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + + Blank() + + Button({ type: ButtonType.Normal, buttonStyle: ButtonStyleMode.TEXTUAL }) { + SymbolGlyph($r('sys.symbol.chevron_right')) + .fontSize(18) + .fontColor([$r('sys.color.font_secondary')]) + } + } + } +} + +@Component +export struct ComponentCard { + @Prop + @Require + title: ResourceStr; + @BuilderParam content: () => void; + @Prop + description?: ResourceStr; + + build() { + Column({ space: 8 }) { + Text(this.title) + .fontSize(14) + .fontColor('#666') + Row({ space: 12}) { + this.content(); + } + if (this.description) { + Text(this.description) + .backgroundColor('#eee') + .borderRadius(4) + .padding(4) + .fontSize(12) + .fontColor('#999') + .width('100%') + } + } + .alignItems(HorizontalAlign.Start) + .backgroundColor('#fff') + .borderRadius(12) + .padding(12) + .width('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/common/Route.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/common/Route.ets new file mode 100644 index 0000000000000000000000000000000000000000..67f364e8705e18d5be514dcde5772cc44ffa2da3 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/common/Route.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + +export interface Route { + title: string ; + name: string; + items?: Route[]; + description?: ResourceStr; +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/common/resource.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/common/resource.ets new file mode 100644 index 0000000000000000000000000000000000000000..9d0cd43adf4ca62c85c7a22b883d2bb76a125d2f --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/common/resource.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. + */ + +export class P2PManager { + public resourceToString(resource: Resource): string { + return getContext(this).resourceManager.getStringSync(resource); + } +} + +// 默认导出let +let p2pManager = new P2PManager(); + +export default p2pManager as P2PManager; \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..51bdf85846c3b83c16542085365521bdc35baf50 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,57 @@ +/* + * 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 { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + 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.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b744d7eaa66e51e79fc4e0896e251292ee767c5 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * 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'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/Index.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..d2728aad7b666b4b861f7f78797991ca46c7385b --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,103 @@ +/* + * 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 { BUTTON_ROUTE_PREFIX, buttonDestination } from './button/Index'; +import { LengthMetrics } from '@kit.ArkUI'; +import { radioDestination, RADIO_ROUTE_PREFIX } from './radio/Index'; +import { RoutableCard } from '../common/Card'; +import { Route } from '../common/Route'; +import { toggleDestination, TOGGLE_ROUTE_PREFIX } from './toggle/Index'; +import resource from '../common/resource'; + +const routes: Route[] = [ + { + title: resource.resourceToString($r('app.string.button')), + name: BUTTON_ROUTE_PREFIX + }, + { + title: resource.resourceToString($r('app.string.radio')), + name: RADIO_ROUTE_PREFIX + }, + { + title: resource.resourceToString($r('app.string.toggle')), + name: TOGGLE_ROUTE_PREFIX + } +]; + +@Builder +function destination(name: string) { + if (name.startsWith(BUTTON_ROUTE_PREFIX)) { + buttonDestination(name); + } else if (name.startsWith(RADIO_ROUTE_PREFIX)) { + radioDestination(name); + } else if (name.startsWith(TOGGLE_ROUTE_PREFIX)) { + toggleDestination(name); + } +} + +@Entry +@Component +struct Index { + @State condition: string = ''; + @Provide pathStack: NavPathStack = new NavPathStack(); + + getFilteredRoutes(): Route[] { + if (!this.condition) { + return routes; + } + return routes.filter((route: Route) => { + return route.title.includes(this.condition); + }) + } + + @LocalBuilder + Title() { + Column() { + Search({ value: this.condition }) + .onChange(value => { + this.condition = value; + }) + .margin({ start: LengthMetrics.vp(16), end: LengthMetrics.vp(16) }) + } + .justifyContent(FlexAlign.Center) + .height('100%') + } + + build() { + Navigation(this.pathStack) { + List({ space: 12 }) { + ForEach(this.getFilteredRoutes(), (route: Route) => { + ListItem() { + RoutableCard({ title: route.title }) + } + .width('100%') + .onClick(() => { + this.pathStack.pushPath({ name: route.name }); + }) + }) + } + .padding({ start: LengthMetrics.vp(16), end: LengthMetrics.vp(16) }) + .contentStartOffset(56) + .height('100%') + .width('100%') + } + .backgroundColor('#f1f3f5') + .title({ builder: this.Title, height: 56 }, { + backgroundBlurStyle: BlurStyle.COMPONENT_THICK, + barStyle: BarStyle.STACK + }) + .navDestination(destination) + } +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/ButtonCustomStyle.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/ButtonCustomStyle.ets new file mode 100644 index 0000000000000000000000000000000000000000..dfbc79820732da7a70944289750bfd113e8b5222 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/ButtonCustomStyle.ets @@ -0,0 +1,71 @@ +/* + * 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 { ComponentCard } from '../../common/Card'; + +@Entry +@Component +export struct ButtonCustomStyle { + pathStack: NavPathStack = new NavPathStack(); + + resourceToString(resource: Resource): string { + return getContext(this).resourceManager.getStringSync(resource); + } + + build() { + NavDestination() { + Column({ space: 12 }) { + ComponentCard({ + title: $r('app.string.ButtonCustomStyle_titleOne'), + description: $r('app.string.ButtonCustomStyle_descriptionOne') + }) { + // [Start custom_button_border_radius] + Button('Button', { type: ButtonType.Normal }) + .id('circle_border') + .borderRadius(10) + // [End custom_button_border_radius] + } + + ComponentCard({ + title: $r('app.string.ButtonCustomStyle_titleTwo'), + description: $r('app.string.ButtonCustomStyle_descriptionTwo') + }) { + // [Start custom_font_style] + Button('Button').id('font_style') + .fontSize(20) + .fontColor(Color.Pink) + .fontWeight(800) + // [End custom_font_style] + } + + ComponentCard({ + title: $r('app.string.ButtonCustomStyle_titleThree'), + description: $r('app.string.ButtonCustomStyle_descriptionThree') + }) { + // [Start custom_background_color] + Button('Button').id('background_color') + .backgroundColor(Color.Red) + // [End custom_background_color] + } + } + .width('100%') + .height('100%') + .padding({ left: 12, right: 12 }) + } + .backgroundColor('#f1f2f3') + .title(this.resourceToString($r('app.string.ButtonCustomStyle_title'))) + } +} + diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/CreateButton.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/CreateButton.ets new file mode 100644 index 0000000000000000000000000000000000000000..d903c8599d0ab0c0d8e93fa44da34b2411ddc72d --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/CreateButton.ets @@ -0,0 +1,58 @@ +/* + * 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 { ComponentCard } from '../../common/Card'; + +@Entry +@Component +export struct CreateButton { + resourceToString(resource: Resource): string { + return getContext(this).resourceManager.getStringSync(resource); + } + + build() { + NavDestination() { + Column({ space: 12 }) { + ComponentCard({ + title: $r('app.string.CreateButton_titleOne'), + description: $r('app.string.CreateButton_descriptionOne') + }) { + // [Start create_button_by_label] + Button('Button', { type: ButtonType.Capsule, stateEffect: true }) + .id('button') + // [End create_button_by_label] + } + + ComponentCard({ + title: $r('app.string.CreateButton_titleTwo'), + description: $r('app.string.CreateButton_descriptionTwo') + }) { + // [Start create_button_by_button_options] + Button() { + Row({ space: 4 }) { + Image($r('sys.media.ohos_ic_back')).width(20).height(40).fillColor(0xffffff) + Text('back').fontColor(0xffffff) + }.alignItems(VerticalAlign.Center).justifyContent(FlexAlign.Center).width(90).height(40) + }.id('button_back') + // [End create_button_by_button_options] + } + } + .width('100%') + .height('100%') + .padding({ left: 12, right: 12 }) + } + .backgroundColor('#f1f2f3') + .title(this.resourceToString($r('app.string.CreateButton_title'))) + } +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/FloatingButton.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/FloatingButton.ets new file mode 100644 index 0000000000000000000000000000000000000000..8d8cc3306c0d8817ea76e2569bc4e641e0414f2f --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/FloatingButton.ets @@ -0,0 +1,82 @@ +/* + * 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. + */ + +// [Start floating_button] +@Entry +@Component +export struct FloatingButton { + @State private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; + // [StartExclude floating_button] + pathStack: NavPathStack = new NavPathStack(); + + resourceToString(resource: Resource): string { + return getContext(this).resourceManager.getStringSync(resource); + } + // [EndExclude floating_button] + + build() { + // [StartExclude floating_button] + NavDestination() { + // [EndExclude floating_button] + Stack() { + List({ space: 12, initialIndex: 0 }) { + ForEach(this.arr, (item: number) => { + ListItem() { + Text(`${item}`) + .width('100%') + .height(100) + .fontSize(16) + .textAlign(TextAlign.Center) + .borderRadius(10) + .backgroundColor(0xFFFFFF) + } + }, (item: number) => item.toString()) + } + .id('List') + .width('100%') + .padding({ + left: 15, + right: 15 + }) + + // [Start custom_button_function] + Button() { + Image($r('sys.media.ohos_ic_public_add')) + .fillColor(0xffffff) + .width(24) + .height(24) + } + .id('Button') + .width(40) + .height(40) + .position({ x: '80%', y: 570 }) + .onClick(() => { + // 需要执行的操作 + // [StartExclude custom_button_function] + this.arr.push(this.arr.length); + // [EndExclude custom_button_function] + }) + // [End custom_button_function] + } + .width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 6 }) + } + // [End floating_button] + .backgroundColor('#f1f2f3') + .title(this.resourceToString($r('app.string.FloatingButton_title'))) + } +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/Index.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..f37f6f3bd71096b1f6fd86e9612037192180f1cb --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/Index.ets @@ -0,0 +1,103 @@ +/* + * 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 { ButtonCustomStyle } from './ButtonCustomStyle'; +import { CompletedRoutableCard } from '../../common/Card'; +import { CreateButton } from './CreateButton' +import { FloatingButton } from './FloatingButton'; +import { Route } from '../../common/Route'; +import { SetButtonType } from './SetButtonType'; +import { SubmitForm } from './SubmitForm'; +import resource from '../../common/resource' + +export const BUTTON_ROUTE_PREFIX: string = 'button'; + +const routes: Route[] = [ + { + name: `${BUTTON_ROUTE_PREFIX}/CreateButton`, + title: resource.resourceToString($r('app.string.CreateButton_title')), + description: $r('app.string.CreateButton_description') + }, + { + name: `${BUTTON_ROUTE_PREFIX}/SetButtonType`, + title: resource.resourceToString($r('app.string.SetButtonType_title')), + description: $r('app.string.SetButtonType_description') + }, + { + name: `${BUTTON_ROUTE_PREFIX}/ButtonCustomStyle`, + title: resource.resourceToString($r('app.string.ButtonCustomStyle_title')), + description: $r('app.string.ButtonCustomStyle_description') + }, + { + name: `${BUTTON_ROUTE_PREFIX}/SubmitForm`, + title: resource.resourceToString($r('app.string.SubmitForm_title')), + description: $r('app.string.SubmitForm_description') + }, + { + name: `${BUTTON_ROUTE_PREFIX}/FloatingButton`, + title: resource.resourceToString($r('app.string.FloatingButton_title')), + description: $r('app.string.FloatingButton_description') + }, +] + +@Builder +export function buttonDestination(name: string) { + if (name === BUTTON_ROUTE_PREFIX) { + ButtonExample(); + } else if (name === routes[0].name) { + CreateButton(); + } else if (name === routes[1].name) { + SetButtonType(); + } else if (name === routes[2].name) { + ButtonCustomStyle(); + } else if (name === routes[3].name) { + SubmitForm(); + } else if (name === routes[4].name) { + FloatingButton(); + } +} + +@Entry +@Component +struct ButtonExample { + @Consume pathStack: NavPathStack; + + resourceToString(resource: Resource): string { + return getContext(this).resourceManager.getStringSync(resource); + } + build() { + NavDestination() { + List({ space: 12 }) { + ForEach(routes, (route: Route) => { + ListItem() { + CompletedRoutableCard({ title: route.title, description: route.description }) + } + .width('100%') + .onClick(() => { + this.pathStack.pushPath({ name: route.name }); + }) + }) + } + .contentStartOffset(20) + .padding({ left: 16, right: 16 }) + } + .backgroundColor('#f1f3f5') + .title('Button', { + backgroundBlurStyle: BlurStyle.COMPONENT_THICK, + barStyle: BarStyle.STACK + }) + .title('Button') + } +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/SetButtonType.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/SetButtonType.ets new file mode 100644 index 0000000000000000000000000000000000000000..489944cc97e22d3f1d81c1e1ce544bc4c10e186c --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/SetButtonType.ets @@ -0,0 +1,76 @@ +/* + * 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 { ComponentCard } from '../../common/Card'; + +@Entry +@Component +export struct SetButtonType { + pathStack: NavPathStack = new NavPathStack(); + + resourceToString(resource: Resource): string { + return getContext(this).resourceManager.getStringSync(resource); + } + + build() { + NavDestination() { + Column({ space: 12 }) { + ComponentCard({ + title: $r('app.string.SetButtonType_titleOne'), + description: $r('app.string.SetButtonType_descriptionOne') + }) { + // [Start create_capsule_button] + Button('Button', { type: ButtonType.Capsule }) + .id('Capsule') + // [End create_capsule_button] + } + + ComponentCard({ + title: $r('app.string.SetButtonType_titleTwo'), + description: $r('app.string.SetButtonType_descriptionTwo') + }) { + // [Start create_circle_button] + Button('Button', { type: ButtonType.Circle }) + .id('Circle') + .width(80) + // [End create_circle_button] + } + + ComponentCard({ + title: $r('app.string.SetButtonType_titleThree'), + description: $r('app.string.SetButtonType_descriptionThree') + }) { + // [Start create_normal_button] + Button('Button', { type: ButtonType.Normal }) + .id('Normal') + // [End create_normal_button] + } + + ComponentCard({ + title: $r('app.string.SetButtonType_titleFour'), + description: $r('app.string.SetButtonType_descriptionFour') + }) { + Button('Button', { type: ButtonType.ROUNDED_RECTANGLE }) + .id('Round') + } + } + .width('100%') + .height('100%') + .padding({ left: 12, right: 12 }) + } + .backgroundColor('#f1f2f3') + .title(this.resourceToString($r('app.string.SetButtonType_title'))) + } +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/SubmitForm.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/SubmitForm.ets new file mode 100644 index 0000000000000000000000000000000000000000..8fa9b3a42c08a5da64c3b5767c70a4dad1d477a4 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/button/SubmitForm.ets @@ -0,0 +1,66 @@ +/* + * 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. + */ + +// [Start button_to_log_in_or_register] +@Entry +@Component +export struct SubmitForm { + // [StartExclude button_to_log_in_or_register] + @State username: string = '' + @State password: string = '' + pathStack: NavPathStack = new NavPathStack(); + + resourceToString(resource: Resource): string { + return getContext(this).resourceManager.getStringSync(resource); + } + // [EndExclude button_to_log_in_or_register] + + build() { + // [StartExclude button_to_log_in_or_register] + NavDestination() { + // [EndExclude button_to_log_in_or_register] + Column({ space: 12 }) { + TextInput({ text: this.username, placeholder: 'input your username' }) + .id('username') + // [StartExclude button_to_log_in_or_register] + .onChange((value: string) => { + this.username = value; + }) + // [EndExclude button_to_log_in_or_register] + TextInput({ text: this.password, placeholder: 'input your password' }) + .type(InputType.Password) + .id('password') + // [StartExclude button_to_log_in_or_register] + .onChange((value: string) => { + this.password = value; + }) + // [EndExclude button_to_log_in_or_register] + Button('Register') + .width('100%') + .id('register') + .onClick(() => { + // 需要执行的操作 + // [StartExclude button_to_log_in_or_register] + this.username = 'your username'; + this.password = 'your password'; + // [EndExclude button_to_log_in_or_register] + }) + }.padding(12) + // [End button_to_log_in_or_register] + } + .backgroundColor('#f1f2f3') + .title(this.resourceToString($r('app.string.SubmitForm_title'))) + } +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/radio/Index.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/radio/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..dd185448dc0f0446425d49469754ce1a44b21225 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/radio/Index.ets @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024-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 { RadioSample } from './RadioSample'; +import { RadioSample2 } from './RadioButton'; +import { CompletedRoutableCard } from '../../common/Card'; +import { Route } from '../../common/Route'; +import resource from '../../common/resource'; + +export const RADIO_ROUTE_PREFIX: string = 'radio'; + +const routes: Route[] = [ + { + // $r('app.string.xxx')Ҫ滻ΪַԴļ + name: `${RADIO_ROUTE_PREFIX}/RadioSample`, + title: resource.resourceToString($r('app.string.RadioSample_title')), + description: $r('app.string.RadioSample_description') + }, + { + // $r('app.string.xxx')Ҫ滻ΪַԴļ + name: `${RADIO_ROUTE_PREFIX}/RadioSample2`, + title: resource.resourceToString($r('app.string.RadioSample2_title')), + description: $r('app.string.RadioSample2_description') + } +] + +@Builder +export function radioDestination(name: string) { + if (name === RADIO_ROUTE_PREFIX) { + RadioExample(); + } else if (name === routes[0].name) { + RadioSample(); + } else if (name === routes[1].name) { + RadioSample2() + } +} + +@Entry +@Component +struct RadioExample { + @Consume pathStack: NavPathStack; + + build() { + NavDestination() { + List({ space: 12 }) { + ForEach(routes, (route: Route) => { + ListItem() { + CompletedRoutableCard({ title: route.title, description: route.description }) + } + .width('100%') + .onClick(() => { + this.pathStack.pushPath({ name: route.name }); + }) + }) + } + .contentStartOffset(56) + .padding({ left: 16, right: 16 }) + } + .backgroundColor('#f1f3f5') + .title('Radio', { + backgroundBlurStyle: BlurStyle.COMPONENT_THICK, + barStyle: BarStyle.STACK + }) + } +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/radio/RadioButton.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/radio/RadioButton.ets new file mode 100644 index 0000000000000000000000000000000000000000..8740b6f5c5e6b593342edfd4b1bee6e24f7e0eb6 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/radio/RadioButton.ets @@ -0,0 +1,69 @@ +/* + * 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. + */ + +import { promptAction } from '@kit.ArkUI'; + +@Entry +@Component +export struct RadioSample2 { + build() { + NavDestination() { + Row() { + compRadi1() + compRadi2().visibility(Visibility.None) + }.height('100%').width('100%').justifyContent(FlexAlign.Center) + } + } +} + +@Component struct compRadi1 { + build() { + Row(){ + // [Start click_radio_to_show_function] + Radio({ value: 'Radio1', group: 'radioGroup' }) + .checked(false) + Radio({ value: 'Radio2', group: 'radioGroup' }) + .checked(true) + // [End click_radio_to_show_function] + } + } +} + +@Component struct compRadi2 { + build() { + Row(){ + // [Start click_radio_event_function] + Radio({ value: 'Radio1', group: 'radioGroup' }) + .onChange((isChecked: boolean) => { + if(isChecked) { + //需要执行的操作 + // [StartExclude click_radio_event_function] + promptAction.openToast({ 'message': 'Radio1 is on.' }); + // [EndExclude click_radio_event_function] + } + }) + Radio({ value: 'Radio2', group: 'radioGroup' }) + .onChange((isChecked: boolean) => { + if(isChecked) { + //需要执行的操作 + // [StartExclude click_radio_event_function] + promptAction.openToast({ 'message': 'Radio2 is on.' }); + // [EndExclude click_radio_event_function] + } + }) + // [End click_radio_event_function] + } + } +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/radio/RadioSample.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/radio/RadioSample.ets new file mode 100644 index 0000000000000000000000000000000000000000..405e44697393e3c8692f8c635b09a013d3e19081 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/radio/RadioSample.ets @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2024-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 click_radio_to_change_function] +// xxx.ets +import { promptAction } from '@kit.ArkUI'; + +@Entry +@Component +export struct RadioSample { + @State message: string = 'Ringing'; + pathStack: NavPathStack = new NavPathStack(); + + build() { + // [StartExclude click_radio_to_change_function] + NavDestination() { + // [EndExclude click_radio_to_change_function] + Column({ space: 8 }) { + Column({ space: 8 }) { + Text(this.message).id('message') + Row() { + // [Start set_radio_status] + Radio({ value: 'Ringing', group: 'radioGroup' }) + .checked(true) + // [End set_radio_status] + .id('ringing') + .onChange((isChecked: boolean) => { + if (isChecked) { + // 切换为响铃模式 + // [StartExclude click_radio_to_change_function] + this.message = 'Ringing mode'; + // [EndExclude click_radio_to_change_function] + promptAction.openToast({ 'message': 'Ringing mode.' }); + } + }) + Text('Ringing') + }.width('25%') + + // [Start change_radio_function] + Row() { + Radio({ value: 'Vibration', group: 'radioGroup' }) + .id('vibration') + .onChange((isChecked: boolean) => { + if (isChecked) { + // 切换为振动模式 + // [StartExclude change_radio_function] + this.message = 'Vibration'; + // [EndExclude change_radio_function] + promptAction.openToast({ 'message': 'Vibration mode.' }); + } + }) + Text('Vibration') + }.width('25%') + + Row() { + Radio({ value: 'Silent', group: 'radioGroup' }) + .id('silent') + .onChange((isChecked: boolean) => { + if (isChecked) { + // 切换为静音模式 + // [StartExclude change_radio_function] + this.message = 'Silent'; + // [EndExclude change_radio_function] + promptAction.openToast({ 'message': 'Silent mode.' }); + } + }) + Text('Silent') + }.width('25%') + // [End change_radio_function] + } + .alignItems(HorizontalAlign.Center) + .backgroundColor('#fff') + .borderRadius(12) + .padding(12) + .width('100%') + } + .width('100%') + .height('100%') + .padding({ left: 12, right: 12 }) + // [StartExclude click_radio_to_change_function] + } + // [EndExclude click_radio_to_change_function] + .backgroundColor('#f1f2f3') + // $r('app.string.xxx')需要替换为开发者所需的字符串资源文件 + .title($r('app.string.RadioSample_title')) + } +} +// [End click_radio_to_change_function] \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/toggle/CreateToggle.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/toggle/CreateToggle.ets new file mode 100644 index 0000000000000000000000000000000000000000..6ccb0078fae98541fca5cedb66265fff33393bc4 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/toggle/CreateToggle.ets @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2024-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 { ComponentCard } from '../../common/Card'; +import { promptAction } from '@kit.ArkUI'; + +@Entry +@Component +export struct CreateToggle { + pathStack: NavPathStack = new NavPathStack(); + + build() { + NavDestination() { + Column({ space: 12 }) { + ComponentCard({ + title: 'ToggleType is Checkbox', + }) { + // [Start create_toggle_with_checkbox] + Toggle({ type: ToggleType.Checkbox, isOn: false }).id('toggle1') + Toggle({ type: ToggleType.Checkbox, isOn: true }).id('toggle2') + // [End create_toggle_with_checkbox] + } + + ComponentCard({ + title: 'ToggleType is Switch', + }) { + // [Start create_toggle_with_switch] + Toggle({ type: ToggleType.Switch, isOn: false }).id('toggle3') + Toggle({ type: ToggleType.Switch, isOn: true }).id('toggle4') + // [End create_toggle_with_switch] + + // [Start create_toggle_with_event] + Toggle({ type: ToggleType.Switch, isOn: false }) + .onChange((isOn: boolean) => { + if(isOn) { + // 需要执行的操作 + // [StartExclude create_toggle_with_event] + promptAction.openToast({ 'message': 'Switch is on.' }); + // [EndExclude create_toggle_with_event] + } + }) + // [StartExclude create_toggle_with_event] + .visibility(Visibility.None) + // [EndExclude create_toggle_case] + // [End create_toggle_with_event] + } + + ComponentCard({ + title: 'ToggleType is Button', + }) { + // [Start create_a_toggle_that_contains_subcomponents] + Toggle({ type: ToggleType.Button, isOn: false }) { + Text('status button') + .fontColor('#182431') + .fontSize(12) + }.width(100).id('toggle5') + + Toggle({ type: ToggleType.Button, isOn: true }) { + Text('status button') + .fontColor('#182431') + .fontSize(12) + }.width(100).id('toggle6') + // [End create_a_toggle_that_contains_subcomponents] + } + } + .width('100%') + .height('100%') + .padding({ left: 12, right: 12 }) + } + .backgroundColor('#f1f2f3') + // $r('app.string.xxx')需要替换为开发者所需的字符串资源文件 + .title($r('app.string.CreateToggle_title')) + } +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/toggle/Index.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/toggle/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..84f34c50a59afa9eea7d64464d5e4bc26f2e6478 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/toggle/Index.ets @@ -0,0 +1,87 @@ +/* + * 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 { CompletedRoutableCard } from '../../common/Card'; +import { CreateToggle } from './CreateToggle'; +import { CustomStyle } from './ToggleCustomStyle'; +import { Route } from '../../common/Route'; +import { ToggleSample } from './ToggleCaseExample'; +import resource from '../../common/resource'; + +export const TOGGLE_ROUTE_PREFIX: string = 'toggle'; + +const routes: Route[] = [ + { + // $r('app.string.xxx')Ҫ滻ΪַԴļ + name: `${TOGGLE_ROUTE_PREFIX}/CreateToggle`, + title: resource.resourceToString($r('app.string.CreateToggle_title')), + description: $r('app.string.CreateToggle_description') + }, + { + // $r('app.string.xxx')Ҫ滻ΪַԴļ + name: `${TOGGLE_ROUTE_PREFIX}/ToggleCustomStyle`, + title: resource.resourceToString($r('app.string.ToggleCustomStyle_title')), + description: $r('app.string.ToggleCustomStyle_description') + }, + { + // $r('app.string.xxx')Ҫ滻ΪַԴļ + name: `${TOGGLE_ROUTE_PREFIX}/ToggleCaseExample`, + title: resource.resourceToString($r('app.string.changeToggle_example')), + description: $r('app.string.ToggleCaseExample_description') + } +] + +@Builder +export function toggleDestination(name: string) { + if (name === TOGGLE_ROUTE_PREFIX) { + ToggleExample(); + } else if (name === routes[0].name) { + CreateToggle(); + } else if (name === routes[1].name) { + CustomStyle(); + } else if (name === routes[2].name) { + ToggleSample(); + } +} + +@Entry +@Component +struct ToggleExample { + @Consume pathStack: NavPathStack; + + build() { + NavDestination() { + List({ space: 12 }) { + ForEach(routes, (route: Route) => { + ListItem() { + CompletedRoutableCard({ title: route.title, description: route.description }) + } + .width('100%') + .onClick(() => { + this.pathStack.pushPath({ name: route.name }); + }) + }) + } + .contentStartOffset(56) + .padding({ left: 16, right: 16 }) + } + .backgroundColor('#f1f3f5') + .title('Toggle', { + backgroundBlurStyle: BlurStyle.COMPONENT_THICK, + barStyle: BarStyle.STACK + }) + } +} + diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCaseExample.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCaseExample.ets new file mode 100644 index 0000000000000000000000000000000000000000..25bce6e8c789de5a6d84276f8d4c34b4a88b75b9 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCaseExample.ets @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024-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 the_example_of_bluetooth] +// xxx.ets +import { promptAction } from '@kit.ArkUI'; + +@Entry +@Component +export struct ToggleSample { + @State message: string = 'off'; + pathStack: NavPathStack = new NavPathStack(); + + build() { + // [StartExclude the_example_of_bluetooth] + NavDestination() { + // [EndExclude the_example_of_bluetooth] + Column({ space: 8 }) { + Column({ space: 8 }) { + Text('Bluetooth Mode: ' + this.message) + .id('message') + Row() { + Text('Bluetooth') + Blank() + // [Start create_toggle_case] + Toggle({ type: ToggleType.Switch }) + .id('toggle') + .onChange((isOn: boolean) => { + if (isOn) { + // [StartExclude create_toggle_case] + this.message = 'on'; + // [EndExclude create_toggle_case] + promptAction.openToast({ 'message': 'Bluetooth is on.' }); + } else { + // [StartExclude create_toggle_case] + this.message = 'off'; + // [EndExclude create_toggle_case] + promptAction.openToast({ 'message': 'Bluetooth is off.' }); + } + }) + // [End create_toggle_case] + }.width('100%') + } + .alignItems(HorizontalAlign.Start) + .backgroundColor('#fff') + .borderRadius(12) + .padding(12) + .width('100%') + } + .width('100%') + .height('100%') + .padding({ left: 12, right: 12 }) + // [StartExclude the_example_of_bluetooth] + } + // [EndExclude the_example_of_bluetooth] + .backgroundColor('#f1f2f3') + // $r('app.string.xxx')Ҫ滻ΪַԴļ + .title($r('app.string.ToggleCaseExample_title')) + } +} +// [End the_example_of_bluetooth] \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCustomStyle.ets b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCustomStyle.ets new file mode 100644 index 0000000000000000000000000000000000000000..fe2db8b686bd8a8191d4ff74d3c931b6c350abf6 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/ets/pages/toggle/ToggleCustomStyle.ets @@ -0,0 +1,72 @@ +/* + * 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 { ComponentCard } from '../../common/Card'; + +@Entry +@Component +export struct CustomStyle { + pathStack: NavPathStack = new NavPathStack(); + + build() { + NavDestination() { + Column({ space: 12 }) { + ComponentCard({ + // $r('app.string.xxx')Ҫ滻ΪַԴļ + title: $r('app.string.ToggleCustomStyle_titleOne'), + description: $r('app.string.ToggleCustomStyle_descriptionOne') + }) { + // [Start custom_toggle] + Toggle({ type: ToggleType.Button, isOn: true }) { + Text('status button') + .fontColor(Color.White) + .fontSize(12) + }.width(100) + .selectedColor(Color.Pink) + .id('toggle1') + + Toggle({ type: ToggleType.Checkbox, isOn: true }) + .selectedColor(Color.Pink) + .id('toggle2') + Toggle({ type: ToggleType.Switch, isOn: true }) + .selectedColor(Color.Pink) + .id('toggle3') + // [End custom_toggle] + } + + ComponentCard({ + // $r('app.string.xxx')Ҫ滻ΪַԴļ + title: $r('app.string.ToggleCustomStyle_titleTwo'), + description: $r('app.string.ToggleCustomStyle_descriptionTwo') + }) { + // [Start custom_switch_point_color] + Toggle({ type: ToggleType.Switch, isOn: false }) + .switchPointColor(Color.Pink) + .id('toggle4') + Toggle({ type: ToggleType.Switch, isOn: true }) + .switchPointColor(Color.Pink) + .id('toggle5') + // [End custom_switch_point_color] + } + } + .width('100%') + .height('100%') + .padding({ left: 12, right: 12 }) + } + .backgroundColor('#f1f2f3') + // $r('app.string.xxx')Ҫ滻ΪַԴļ + .title($r('app.string.ToggleCustomStyle_title')) + } +} diff --git a/ArkUIKit/ChooseComponent/entry/src/main/module.json5 b/ArkUIKit/ChooseComponent/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f2f32268ae38567ca0396d11377e0c6a5cec51ef --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/module.json5 @@ -0,0 +1,65 @@ +/* + * 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. + */ + +{ + "module": { + "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.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/resources/base/element/color.json b/ArkUIKit/ChooseComponent/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkUIKit/ChooseComponent/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/ArkUIKit/ChooseComponent/entry/src/main/resources/base/element/string.json b/ArkUIKit/ChooseComponent/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7de4f7438880b75133e55ce1f1e5bf6ce26bfe0a --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/resources/base/element/string.json @@ -0,0 +1,219 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ChooseComponent" + }, + { + "name": "RadioSample_title", + "value": "单选框示例示例" + }, + { + "name": "Sample", + "value": "示例" + }, + { + "name": "RadioSample_description", + "value": "单选框示例,模拟单选框应用效果。" + }, + { + "name": "ToggleCaseExample_title", + "value": "toggle蓝牙示例" + }, + { + "name": "ToggleCaseExample_description", + "value": "Toggle 组件的场景示例,模拟toggle的使用场景。" + }, + { + "name": "ToggleCustomStyle_title", + "value": "自定义切换按钮" + }, + { + "name": "CreateToggle_title", + "value": "创建切换按钮" + }, + { + "name": "CreateToggle_description", + "value": "Toggle 组件的创建,分别创建默认不带子组件的按钮和自定义带子组件的切换按钮。" + }, + { + "name": "ToggleCustomStyle_titleOne", + "value": "selectedColor设置选中后的背景颜色" + }, + { + "name": "ToggleCustomStyle_titleTwo", + "value": "设置Switch类型的圆形滑块颜色" + }, + { + "name": "ToggleCustomStyle_description", + "value": "Toggle 组件具体样式的设置,可对字体、背景等要素进行设置。" + }, + { + "name": "ToggleCustomStyle_descriptionOne", + "value": "通过selectedColor属性设置Toggle打开选中后的背景颜色。" + }, + { + "name": "ToggleCustomStyle_descriptionTwo", + "value": "通过switchPointColor属性设置Switch类型的圆形滑块颜色,仅对type为ToggleType.Switch生效。" + }, + { + "name": "CreateButton_title", + "value": "创建按钮" + }, + { + "name": "CreateButton_titleOne", + "value": "不包含子组件的按钮" + }, + { + "name": "CreateButton_titleTwo", + "value": "包含子组件的按钮" + }, + { + "name": "CreateButton_description", + "value": "Button 组件的创建,分别创建默认不带子组件的按钮和自定义带子组件的按钮。" + }, + { + "name": "CreateButton_descriptionOne", + "value": "通过接口创建按钮,label用来设置按钮文字,type用于设置Button类型,stateEffect属性设置Button是否开启点击效果。" + }, + { + "name": "CreateButton_descriptionTwo", + "value": "通过接口创建带子组件的按钮。使用Row作为子组件容器,Image引用箭头图片,Text显示‘back’文本。" + }, + { + "name": "SetButtonType_test", + "value": "按钮类型" + }, + { + "name": "SetButtonType_title", + "value": "设置按钮类型" + }, + { + "name": "SetButtonType_titleOne", + "value": "胶囊型按钮" + }, + { + "name": "SetButtonType_titleTwo", + "value": "圆形按钮" + }, + { + "name": "SetButtonType_titleThree", + "value": "普通按钮" + }, + { + "name": "SetButtonType_titleFour", + "value": "圆角矩形按钮" + }, + { + "name": "SetButtonType_description", + "value": "Button 组件的类型的设置,共有四种类型:胶囊按钮、圆形按钮、普通按钮、圆角矩形按钮。" + }, + { + "name": "SetButtonType_descriptionOne", + "value": "通过type属性为ButtonType.Capsule,将按钮类型设置为胶囊型按钮(圆角默认为高度的一半)。" + }, + { + "name": "SetButtonType_descriptionTwo", + "value": "通过type属性为ButtonType.Circle,将按钮类型设置为圆形按钮。" + }, + { + "name": "SetButtonType_descriptionThree", + "value": "通过type属性为ButtonType.Normal,将按钮类型设置为普通按钮(默认不带圆角)。" + }, + { + "name": "SetButtonType_descriptionFour", + "value": "通过type属性为ButtonType.ROUNDED_RECTANGLE,将按钮类型设置为圆角矩形按钮。" + }, + { + "name": "ButtonCustomStyle_test", + "value": "按钮样式" + }, + { + "name": "ButtonCustomStyle_title", + "value": "自定义按钮样式" + }, + { + "name": "ButtonCustomStyle_titleOne", + "value": "设置边框弧度" + }, + { + "name": "ButtonCustomStyle_titleTwo", + "value": "设置文本样式" + }, + { + "name": "ButtonCustomStyle_titleThree", + "value": "设置背景颜色" + }, + { + "name": "ButtonCustomStyle_description", + "value": "Button 组件具体样式的设置,可对字体、背景等要素进行设置。" + }, + { + "name": "ButtonCustomStyle_descriptionOne", + "value": "按钮type属性为ButtonType.Normal,通过borderRadius设置边框圆角半径为10。" + }, + { + "name": "ButtonCustomStyle_descriptionTwo", + "value": "通过fontSize设置按钮中字体的大小为20,fontColor设置字体颜色为粉色,fontWeight设置字体的粗细值为800。" + }, + { + "name": "ButtonCustomStyle_descriptionThree", + "value": "通过backgroundColor属性设置按钮里的背景颜色为红色。" + }, + { + "name": "SubmitForm", + "value": "注册" + }, + { + "name": "SubmitForm_title", + "value": "注册登录示例" + }, + { + "name": "SubmitForm_description", + "value": "Button 组件使用的场景示例,对注册/登录页面的模拟。" + }, + { + "name": "FloatingButton_title", + "value": "悬浮按钮示例" + }, { + "name": "FloatingButton", + "value": "Button 组件悬浮按钮的场景示例,在场景中设置悬浮于容器的按钮。" + }, + { + "name": "FloatingButton_description", + "value": "Button 组件悬浮按钮的场景示例,在场景中设置悬浮于容器的按钮。" + }, + { + "name": "changeToggle_example", + "value": "切换按钮示例" + }, + { + "name": "button", + "value": "按钮/Button" + }, + { + "name": "radio", + "value": "单选框/Radio" + }, + { + "name": "toggle", + "value": "切换按钮/Toggle" + }, + { + "name": "RadioSample2_title", + "value": "单选框示例2" + }, + { + "name": "RadioSample2_description", + "value": "单选框示例2,模拟单选框应用效果。" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/resources/base/media/background.png b/ArkUIKit/ChooseComponent/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ArkUIKit/ChooseComponent/entry/src/main/resources/base/media/background.png differ diff --git a/ArkUIKit/ChooseComponent/entry/src/main/resources/base/media/foreground.png b/ArkUIKit/ChooseComponent/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ArkUIKit/ChooseComponent/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkUIKit/ChooseComponent/entry/src/main/resources/base/media/layered_image.json b/ArkUIKit/ChooseComponent/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/resources/base/media/startIcon.png b/ArkUIKit/ChooseComponent/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkUIKit/ChooseComponent/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkUIKit/ChooseComponent/entry/src/main/resources/base/profile/backup_config.json b/ArkUIKit/ChooseComponent/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/resources/base/profile/main_pages.json b/ArkUIKit/ChooseComponent/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..fea96ecefefeef6879b28d68293f12f11459aafe --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,14 @@ +{ + "src": [ + "pages/Index", + "pages/button/CreateButton", + "pages/button/ButtonCustomStyle", + "pages/button/FloatingButton", + "pages/radio/RadioSample", + "pages/button/SetButtonType", + "pages/button/SubmitForm", + "pages/toggle/CreateToggle", + "pages/toggle/ToggleCustomStyle", + "pages/toggle/ToggleCaseExample" + ] +} diff --git a/ArkUIKit/ChooseComponent/entry/src/main/resources/dark/element/color.json b/ArkUIKit/ChooseComponent/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/main/syscap.json b/ArkUIKit/ChooseComponent/entry/src/main/syscap.json new file mode 100644 index 0000000000000000000000000000000000000000..598552fb33d0f5c27fed37e607d9163f836ac5af --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/main/syscap.json @@ -0,0 +1,24 @@ + +{ + "devices": { + "general": [ + "default" + ] + }, + "production": { + "removedSysCaps": [ + "SystemCapability.HiviewDFX.HiDumper", + "SystemCapability.Security.DeviceAuth", + "SystemCapability.Multimedia.Media.AVTranscoder", + "SystemCapability.Tee.TeeClient", + "SystemCapability.Communication.Bluetooth.Core", + "SystemCapability.ArkUi.Graphics3D", + "SystemCapability.DistributedHardware.DeviceManager", + "SystemCapability.Multimedia.Drm.Core", + "SystemCapability.Advertising.Ads", + "SystemCapability.Customization.EnterpriseDeviceManager", + "SystemCapability.Security.DeviceSecurityLevel", + "SystemCapability.UserIAM.UserAuth.PinAuth" + ] + } +} diff --git a/ArkUIKit/ChooseComponent/entry/src/mock/mock-config.json5 b/ArkUIKit/ChooseComponent/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..26ed9f53bc46192a07ad5ab16ea24e7ce9a79328 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * 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. + */ + +{ +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkUIKit/ChooseComponent/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a8ff110e5899c2d1727217919dd5badeacdfe061 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * 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'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // 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. + }) + beforeEach(() => { + // 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. + }) + afterEach(() => { + // 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. + }) + 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('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/ohosTest/ets/test/Index.test.ets b/ArkUIKit/ChooseComponent/entry/src/ohosTest/ets/test/Index.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..40ebdd1f0002615313b7731118edeec704329eb4 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/ohosTest/ets/test/Index.test.ets @@ -0,0 +1,312 @@ +/* + * Copyright (c) 2024-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, it, expect, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON, MouseButton, Component, MatchPattern } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let abilityDelegator: abilityDelegatorRegistry.AbilityDelegator; +abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +let want: Want; + + +function sleep(time: number) { + return new Promise((resolve: Function) => setTimeout(resolve, time)); +} + +async function getResourceString(resource: Resource): Promise { + let manage = abilityDelegator.getAppContext().resourceManager; + let textString: string = await manage.getStringValue(resource); + return textString; +} + + +export default function IndexTest() { + + describe('IndexTest', () => { + + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + await sleep(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info("get top ability"); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + it('testCreateButton', 0, async (done: Function) => { + console.info("uitest: testCreateButton begin"); + let driver = Driver.create(); + let button_list = await driver.findComponent(ON.text('Button', MatchPattern.CONTAINS)); + expect(button_list === null).assertFalse(); + await button_list.click(); + let str = await getResourceString($r('app.string.CreateButton_title')); + let button_search = await driver.findComponent(ON.text(str, MatchPattern.CONTAINS)); + expect(button_search === null).assertFalse(); + await button_search.click(); + + let button_normal = await driver.findComponent(ON.id('button')); + let button_back = await driver.findComponent(ON.id('button_back')); + expect(button_normal === null).assertFalse(); + expect(button_back === null).assertFalse(); + await button_normal.click(); + await button_back.click(); + await driver.pressBack(); + await driver.pressBack(); + done(); + }) + + it('testSetButtonType', 0, async (done: Function) => { + console.info("uitest: testSetButtonType begin"); + let driver = Driver.create(); + let button_list = await driver.findComponent(ON.text('Button', MatchPattern.CONTAINS)); + expect(button_list === null).assertFalse(); + await button_list.click(); + let str = await getResourceString($r('app.string.SetButtonType_test')); + let button_search = await driver.findComponent(ON.text(str, MatchPattern.CONTAINS)); + expect(button_search === null).assertFalse(); + await button_search.click(); + + let button_Capsule = await driver.findComponent(ON.id('Capsule')); + let button_Circle = await driver.findComponent(ON.id('Circle')); + let button_Normal = await driver.findComponent(ON.id('Normal')); + let button_Round = await driver.findComponent(ON.id('Round')); + expect(button_Capsule === null).assertFalse(); + expect(button_Circle === null).assertFalse(); + expect(button_Normal === null).assertFalse(); + expect(button_Round === null).assertFalse(); + await button_Capsule.click(); + await button_Circle.click(); + await button_Normal.click(); + await button_Round.click(); + await driver.pressBack(); + await driver.pressBack(); + done(); + }) + + it('testCustomStyle', 0, async (done: Function) => { + console.info("uitest: testCustomStyle begin"); + let driver = Driver.create(); + let button_list = await driver.findComponent(ON.text('Button', MatchPattern.CONTAINS)); + expect(button_list === null).assertFalse(); + await button_list.click(); + let str = await getResourceString($r('app.string.ButtonCustomStyle_test')); + let button_search = await driver.findComponent(ON.text(str, MatchPattern.CONTAINS)); + expect(button_search === null).assertFalse(); + await button_search.click(); + + let button_circle = await driver.findComponent(ON.id('circle_border')); + let button_font = await driver.findComponent(ON.id('font_style')); + let button_color = await driver.findComponent(ON.id('background_color')); + expect(button_circle === null).assertFalse(); + expect(button_font === null).assertFalse(); + expect(button_color === null).assertFalse(); + await button_circle.click(); + await button_font.click(); + await button_color.click(); + await driver.pressBack(); + await driver.pressBack(); + done(); + }) + + it('testSubmitForm', 0, async (done: Function) => { + console.info("uitest: testSubmitForm begin"); + let driver = Driver.create(); + let button_list = await driver.findComponent(ON.text('Button', MatchPattern.CONTAINS)); + expect(button_list === null).assertFalse(); + await button_list.click(); + let str = await getResourceString($r('app.string.SubmitForm')); + let button_search = await driver.findComponent(ON.text(str, MatchPattern.CONTAINS)); + expect(button_search === null).assertFalse(); + await button_search.click(); + + let username = await driver.findComponent(ON.id('username')); + let password = await driver.findComponent(ON.id('password')); + let registerButton = await driver.findComponent(ON.id('register')); + expect(username === null).assertFalse(); + expect(password === null).assertFalse(); + expect(registerButton === null).assertFalse(); + await username.inputText('username'); + await password.inputText('password'); + expect(await username.getText() === 'username').assertTrue(); + + let point = await password.getBoundsCenter(); + await driver.mouseClick({ + x: point.x + 300, y: point.y + }, MouseButton.MOUSE_BUTTON_LEFT, 0, 0); + expect(await password.getText() === 'password').assertTrue(); + await registerButton.click(); + await driver.pressBack(); + await driver.pressBack(); + await driver.pressBack(); + done(); + }) + + it('testFloatingButton', 0, async (done: Function) => { + console.info("uitest: testFloatingButton begin"); + let driver = Driver.create(); + let button_list = await driver.findComponent(ON.text('Button', MatchPattern.CONTAINS)); + expect(button_list === null).assertFalse(); + await button_list.click(); + let str = await getResourceString($r('app.string.FloatingButton')); + let button_search = await driver.findComponent(ON.text(str, MatchPattern.CONTAINS)); + expect(button_search === null).assertFalse(); + await button_search.click(); + + let floatingButton = await driver.findComponent(ON.id('Button')); + let stackList = await driver.findComponent(ON.id('List')); + expect(floatingButton === null).assertFalse(); + expect(stackList === null).assertFalse(); + await floatingButton.click(); + await stackList.scrollToBottom(); + await driver.pressBack(); + await driver.pressBack(); + done(); + }) + + it('testToggleUiExample1', 0, async (done: Function) => { + let driver: Driver = Driver.create(); + let button_list = await driver.findComponent(ON.text('Toggle', MatchPattern.CONTAINS)); + expect(button_list === null).assertFalse(); + await button_list.click(); + let str = await getResourceString($r('app.string.CreateToggle_title')); + let button_search = await driver.findComponent(ON.text(str, MatchPattern.CONTAINS)); + expect(button_search === null).assertFalse(); + await button_search.click(); + + let toggle1: Component = await driver.findComponent(ON.id('toggle1')); + let toggle2: Component = await driver.findComponent(ON.id('toggle2')); + let toggle3: Component = await driver.findComponent(ON.id('toggle3')); + let toggle4: Component = await driver.findComponent(ON.id('toggle4')); + let toggle5: Component = await driver.findComponent(ON.id('toggle5')); + let toggle6: Component = await driver.findComponent(ON.id('toggle6')); + await toggle1.click(); + await toggle2.click(); + await toggle3.click(); + await toggle4.click(); + await toggle5.click(); + await toggle6.click(); + await driver.pressBack(); + await driver.pressBack(); + done(); + }) + + it('testToggleUiExample2', 0, async (done: Function) => { + let driver: Driver = Driver.create(); + let button_list = await driver.findComponent(ON.text('Toggle', MatchPattern.CONTAINS)); + expect(button_list === null).assertFalse(); + await button_list.click(); + let str = await getResourceString($r('app.string.ToggleCustomStyle_title')); + let button_search = await driver.findComponent(ON.text(str, MatchPattern.CONTAINS)); + expect(button_search === null).assertFalse(); + await button_search.click(); + let toggle1: Component = await driver.findComponent(ON.id('toggle1')); + let toggle2: Component = await driver.findComponent(ON.id('toggle2')); + let toggle3: Component = await driver.findComponent(ON.id('toggle3')); + let toggle4: Component = await driver.findComponent(ON.id('toggle4')); + let toggle5: Component = await driver.findComponent(ON.id('toggle5')); + await toggle1.click(); + await toggle2.click(); + await toggle3.click(); + await toggle4.click(); + await toggle5.click(); + await driver.pressBack(); + await driver.pressBack(); + done(); + }) + + it('testToggleUiExample3', 0, async (done: Function) => { + let driver: Driver = Driver.create(); + let button_list = await driver.findComponent(ON.text('Toggle', MatchPattern.CONTAINS)); + expect(button_list === null).assertFalse(); + await button_list.click(); + let str = await getResourceString($r('app.string.Sample')); + let button_search = await driver.findComponent(ON.text(str, MatchPattern.CONTAINS)); + expect(button_search === null).assertFalse(); + await button_search.click(); + let message: Component = await driver.findComponent(ON.id('message')); + expect(await message.getText() === 'Bluetooth Mode: off').assertTrue(); + let toggle: Component = await driver.findComponent(ON.id('toggle')); + await toggle.click(); + expect(await message.getText() === 'Bluetooth Mode: on').assertTrue(); + await driver.pressBack(); + await driver.pressBack(); + done(); + }) + + /** + * @tc.number testRadioUiExample1 + * @tc.name testRadioUiExample1 + * @tc.desc Test multiple radio button. + * @tc.size MEDIUM + * @tc.level Level 1 + * @tc.type Function + */ + it('testRadioUiExample1', 0, async (done: Function) => { + let driver: Driver = Driver.create(); + let button_list = await driver.findComponent(ON.text('Radio', MatchPattern.CONTAINS)); + expect(button_list === null).assertFalse(); + await button_list.click(); + await sleep(1000); + let str = await getResourceString($r('app.string.RadioSample_title')); + let radio_search = await driver.findComponent(ON.text(str, MatchPattern.CONTAINS)); + expect(radio_search === null).assertFalse(); + await radio_search.click(); + let ringing_search = await driver.findComponent(ON.id('ringing', MatchPattern.CONTAINS)); + expect(ringing_search === null).assertFalse(); + await ringing_search.click(); + let vibration_search = await driver.findComponent(ON.id('vibration', MatchPattern.CONTAINS)); + expect(vibration_search === null).assertFalse(); + await vibration_search.click(); + let silent_search = await driver.findComponent(ON.id('silent', MatchPattern.CONTAINS)); + expect(silent_search === null).assertFalse(); + await silent_search.click(); + await sleep(1000); + await driver.pressBack(); + await driver.pressBack(); + done(); + }) + + /** + * @tc.number testRadioUiExample2 + * @tc.name testRadioUiExample2 + * @tc.desc Test two radio button. + * @tc.size MEDIUM + * @tc.level Level 1 + * @tc.type Function + */ + it('testRadioUiExample2', 0, async (done: Function) => { + let driver: Driver = Driver.create(); + let button_list = await driver.findComponent(ON.text('Radio', MatchPattern.CONTAINS)); + expect(button_list === null).assertFalse(); + await button_list.click(); + await sleep(1000); + let str = await getResourceString($r('app.string.RadioSample2_title')); + let radio_search = await driver.findComponent(ON.text(str, MatchPattern.CONTAINS)); + expect(radio_search === null).assertFalse(); + await radio_search.click(); + await sleep(1000); + await driver.pressBack(); + done(); + }) + }) +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/ohosTest/ets/test/List.test.ets b/ArkUIKit/ChooseComponent/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b702cb892d42ccb442e67abafa97484d540b599c --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,22 @@ +/* + * 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 IndexTest from './Index.test'; +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); + IndexTest(); +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/ohosTest/module.json5 b/ArkUIKit/ChooseComponent/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5f63462032245655b8df990c83c5d7312015c089 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * 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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkUIKit/ChooseComponent/entry/src/test/List.test.ets b/ArkUIKit/ChooseComponent/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ab6445db05608a5b7f851a85add24f32b890b0f8 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * 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 localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/entry/src/test/LocalUnit.test.ets b/ArkUIKit/ChooseComponent/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4b7b4eb2ff9627c7184e386fe88c2ba1b507f905 --- /dev/null +++ b/ArkUIKit/ChooseComponent/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // 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. + }); + beforeEach(() => { + // 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. + }); + afterEach(() => { + // 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. + }); + 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('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/hvigor/hvigor-config.json5 b/ArkUIKit/ChooseComponent/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0df4e83ad09f9c4378b3d49faeeaf118df8bc59c --- /dev/null +++ b/ArkUIKit/ChooseComponent/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * 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. + */ + +{ + "modelVersion": "5.0.1", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkUIKit/ChooseComponent/hvigorfile.ts b/ArkUIKit/ChooseComponent/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..662a6284a1c4416b603fa1da8b52fffa406d70c2 --- /dev/null +++ b/ArkUIKit/ChooseComponent/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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 { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkUIKit/ChooseComponent/oh-package.json5 b/ArkUIKit/ChooseComponent/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..936cf43ead6c6ae132fc8169d8ffb96fcd8e6fa6 --- /dev/null +++ b/ArkUIKit/ChooseComponent/oh-package.json5 @@ -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. + */ + +{ + "modelVersion": "5.0.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkUIKit/ChooseComponent/ohosTest.md b/ArkUIKit/ChooseComponent/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..95d1ceb49b3fcfc428d43e99852853768433ed2e --- /dev/null +++ b/ArkUIKit/ChooseComponent/ohosTest.md @@ -0,0 +1,5 @@ +| 组件 | 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +|-----------------------------------| ------------ | ---------------------- |-----------| -------- | -------- | +| Radio | 首页加载测试 | 设备正常运行 | 验证基础元素展示 | 检查标题和列表组件 | Pass | +| Radio | 单选框示例示例页面加载,页面按钮响应 | 设备正常运行 | 1. 点击"单选框示例示例"。
2. 单选框示例示例页面分别点击ratio按钮:
点击"Ringing"按钮,提示词“Ringing",打印文字”Ringing mode."
点击"Vibration"按钮,提示词“Vibration",打印文字”Vibration mode."
点击"Silent"按钮,提示词“Silent",打印文字”Silent mode." | 页面加载成功
按钮点击响应正常 | Pass | +| Radio | 单选框示例2页面 | 设备正常运行 | 点击"单选框示例2" | 页面加载成功 | Pass | \ No newline at end of file diff --git a/ArkUIKit/ChooseComponent/screenshots/device/image1.png b/ArkUIKit/ChooseComponent/screenshots/device/image1.png new file mode 100644 index 0000000000000000000000000000000000000000..601206d1d753a54f606bdd9f1df32c6e755b31ac Binary files /dev/null and b/ArkUIKit/ChooseComponent/screenshots/device/image1.png differ diff --git a/ArkUIKit/ChooseComponent/screenshots/device/image2.png b/ArkUIKit/ChooseComponent/screenshots/device/image2.png new file mode 100644 index 0000000000000000000000000000000000000000..eb04f65c824dde144cfd7c34adcb28bac6166832 Binary files /dev/null and b/ArkUIKit/ChooseComponent/screenshots/device/image2.png differ diff --git a/ArkUIKit/ChooseComponent/screenshots/device/image3.png b/ArkUIKit/ChooseComponent/screenshots/device/image3.png new file mode 100644 index 0000000000000000000000000000000000000000..29f949276660bf307aeecd7cbcc493998d2d9aa3 Binary files /dev/null and b/ArkUIKit/ChooseComponent/screenshots/device/image3.png differ diff --git a/ArkUIKit/ColorAdaptionApp/AppScope/app.json5 b/ArkUIKit/ColorAdaptionApp/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..71a3deb1cce4d6c7513a7c86a5b005ec93e5c57f --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/AppScope/app.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. + */ + +{ + "app": { + "bundleName": "com.example.ColorAdaption", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/ArkUIKit/ColorAdaptionApp/AppScope/resources/base/element/string.json b/ArkUIKit/ColorAdaptionApp/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..164954414e40e49d83404de4aaa59f26f084498a --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "dark_light_color_adaption" + } + ] +} diff --git a/ArkUIKit/ColorAdaptionApp/AppScope/resources/base/media/background.png b/ArkUIKit/ColorAdaptionApp/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/ColorAdaptionApp/AppScope/resources/base/media/background.png differ diff --git a/ArkUIKit/ColorAdaptionApp/AppScope/resources/base/media/foreground.png b/ArkUIKit/ColorAdaptionApp/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/ArkUIKit/ColorAdaptionApp/AppScope/resources/base/media/foreground.png differ diff --git a/ArkUIKit/ColorAdaptionApp/AppScope/resources/base/media/layered_image.json b/ArkUIKit/ColorAdaptionApp/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/README_zh.md b/ArkUIKit/ColorAdaptionApp/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..8fd87d554273ab5ea4dadf8523e84cd2e62d2294 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/README_zh.md @@ -0,0 +1,78 @@ +# ArkUI应用深浅色适配指南文档示例 + +### 介绍 + +本示例通过使用[ArkUI指南文档](https://gitcode.com/openharmony/docs/tree/master/zh-cn/application-dev/ui)中各场景的开发示例,展示在工程中,帮助开发者更好地理解ArkUI提供的组件及组件属性并合理使用。该工程中展示的代码详细描述可查如下链接: + +1. [应用深浅色适配](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/ui/ui-dark-light-color-adaptation.md)。 + + +### 效果预览 +| 深浅模式切换效果 | 图片及文字深浅模式适配效果 | 应用页面局部深浅色效果 | +| ------------------------------------ | --------------------------------------------- | --------------------------------------------------- | +| ![](screenshots/device/image1.png) | ![](screenshots/device/image2.png) | ![](screenshots/device/image3.png) | + +### 使用说明 + +1. 在主界面,可以点击对应页面,选择需要参考的组件示例。 + +2. 在组件目录选择详细的示例参考。 + +3. 进入示例界面,查看参考示例。 + +4. 通过自动测试框架可进行测试及维护。 + +### 工程目录 +``` +entry/src/main/ets/ +├── entryability +│   └── EntryAbility.ets +├── entrybackupability +│   └── EntryBackupAbility.ets +└── pages + ├── BuilderNodeAdaptation.ets // 自定义节点适配 + ├── ImageAdaptation.ets // 图片资源适配 + ├── Index.ets + └── SwitchColorMode.ets // 切换颜色模式 +entry/src/ohosTest/ +├── ets +│   └── test +│   ├── Ability.test.ets +│   ├── Index.test.ets // 测试用例代码 +│   └── List.test.ets +└── module.json5 +``` + +### 具体实现 + +1. 应用跟随系统的深浅色模式:自定义节点BuilderNode和ComponentContent需手动传递系统环境变化事件,触发节点的全量更新;应用可以主动监听系统深浅色模式变化,进行资源初始化等自定义逻辑。无论应用是否跟随系统深浅色模式变化,该监听方式均可生效。 + +2. 应用主动设置深浅色模式:应用默认配置为跟随系统切换深浅色模式,如不希望应用跟随系统深浅色模式变化,可主动设置应用的深浅色风格。设置后,应用的深浅色模式固定,不会随系统改变。 + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API20版本SDK,版本号:6.0.0.33,镜像版本号:OpenHarmony_6.0.0.33。 + +3.本示例需要使用DevEco Studio 6.0.0 Release (Build Version: 6.0.0.858, built on September 24, 2025)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkUISample/ColorAdaptionApp > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/build-profile.json5 b/ArkUIKit/ColorAdaptionApp/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1e71c80934c45f8b51e8fbcb4c66e4d5b212df12 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * 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. + */ + +{ + "app": { + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "6.0.0(20)", + "targetSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/code-linter.json5 b/ArkUIKit/ColorAdaptionApp/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ed05653cca31b61d64cf6471529eaf50d4f70709 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/code-linter.json5 @@ -0,0 +1,47 @@ +/* + * 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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error" + } +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/build-profile.json5 b/ArkUIKit/ColorAdaptionApp/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6bf0d132e6f78049e712446c63f2633b2d1613d3 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/build-profile.json5 @@ -0,0 +1,48 @@ +/* + * 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/hvigorfile.ts b/ArkUIKit/ColorAdaptionApp/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..cfa8a00f74f409d9647f55cdf270ab6aec69fe41 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/obfuscation-rules.txt b/ArkUIKit/ColorAdaptionApp/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/oh-package.json5 b/ArkUIKit/ColorAdaptionApp/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4bff7f302898a62b74d79ddbfe96d1acfb47ec82 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,66 @@ +/* + * 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. + */ + +import { AbilityConstant, Configuration, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + // [Start create_app] + onCreate(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_DARK); + } + // [End create_app] + // [Start update_app] + onConfigurationUpdate(newConfig: Configuration): void { + AppStorage.setOrCreate('currentColorMode', newConfig.colorMode); + hilog.info(0x0000, 'testTag', 'the newConfig.colorMode is %{public}s', JSON.stringify(AppStorage.get('currentColorMode')) ?? ''); + } + // [End update_app] + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0a97e21bd7a15599af76a806695860ff1eb0ebfe --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,31 @@ +/* + * 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/pages/BuilderNodeAdaptation.ets b/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/pages/BuilderNodeAdaptation.ets new file mode 100644 index 0000000000000000000000000000000000000000..8f09489df187b7cbd1f255884534bf09d35a10bf --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/pages/BuilderNodeAdaptation.ets @@ -0,0 +1,197 @@ +/* + * 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. + */ + +import { NodeController, BuilderNode, FrameNode, UIContext, FrameCallback } from '@kit.ArkUI'; +import { AbilityConstant, Configuration, ConfigurationConstant, EnvironmentCallback } from '@kit.AbilityKit'; +import hilog from '@ohos.hilog'; + +const TAG = '[Sample_ColorAdaption_App]'; +const DOMAIN = 0xFF00; + +class Params { + public text: string = ''; + + constructor(text: string) { + this.text = text; + } +} + +// 自定义组件 +@Component +struct TextBuilder { + // 作为自定义组件中需要更新的属性,数据类型为基础属性,定义为@Prop + @Prop message: string = 'TextBuilder'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 36 }) + } + } + } +} + +@Builder +function buildText(params: Params) { + Column() { + Text(params.text) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 36 }) + TextBuilder({ message: params.text }) // 自定义组件 + }.backgroundColor($r('sys.color.ohos_id_color_background')) +} + +// 继承NodeController实现自定义textNode控制器 +class TextNodeController extends NodeController { + private textNode: BuilderNode<[Params]> | null = null; + private message: string = ''; + + constructor(message: string) { + super(); + this.message = message; + } + + makeNode(context: UIContext): FrameNode | null { + return this.textNode?.getFrameNode() ? this.textNode?.getFrameNode() : null; + } + + createNode(context: UIContext) { + this.textNode = new BuilderNode(context); + this.textNode.build(wrapBuilder<[Params]>(buildText), new Params(this.message)); + builderNodeMap.push(this.textNode); + } + + deleteNode() { + let node = builderNodeMap.pop(); + node?.dispose(); + } + + update(message: string) { + if (this.textNode !== null) { + // 调用update进行更新 + this.textNode.update(new Params(message)); + } + } +} + +// 记录创建的自定义节点对象 +const builderNodeMap: BuilderNode<[Params]>[] = []; + +class MyFrameCallback extends FrameCallback { + onFrame() { + updateColorMode(); + } +} + +function updateColorMode() { + builderNodeMap.forEach((value, index) => { + // 通知BuilderNode环境变量改变,触发深浅色切换 + value.updateConfiguration(); + }) +} + +@Entry +@Component +struct Index { + @State message: string = 'hello'; + private textNodeController: TextNodeController = new TextNodeController(this.message); + // [Start prop] + @StorageProp('currentColorMode') @Watch('onColorModeChange') currentMode: number = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT; + // [End prop] + // [Start color_mode_change_appear] + aboutToAppear(): void { + // [StartExclude color_mode_change_appear] + let environmentCallback: EnvironmentCallback = { + onMemoryLevel: (level: AbilityConstant.MemoryLevel): void => { + hilog.info(DOMAIN, TAG, 'onMemoryLevel'); + }, + onConfigurationUpdated: (config: Configuration): void => { + hilog.info(DOMAIN, TAG, 'onConfigurationUpdated ' + JSON.stringify(config)); + this.getUIContext()?.postFrameCallback(new MyFrameCallback()); + } + }; + // 注册监听回调 + this.getUIContext().getHostContext()?.getApplicationContext().on('environment', environmentCallback); + // 设置应用深浅色跟随系统 + this.getUIContext() + .getHostContext()?.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_DARK); + //创建自定义节点并添加至map + this.textNodeController.createNode(this.getUIContext()); + // [EndExclude color_mode_change_appear] + if (this.currentMode == ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT) { + //当前为浅色模式,资源初始化逻辑 + // [StartExclude color_mode_change_appear] + this.getUIContext() + .getHostContext()?.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT); + // [EndExclude color_mode_change_appear] + } else { + //当前为深色模式,资源初始化逻辑 + // [StartExclude color_mode_change_appear] + this.getUIContext() + .getHostContext()?.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_DARK); + // [EndExclude color_mode_change_appear] + } + } + // [End color_mode_change_appear] + // [Start color_mode_change] + onColorModeChange(): void { + if (this.currentMode == ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT) { + //当前为浅色模式,资源初始化逻辑 + // [StartExclude color_mode_change] + this.getUIContext() + .getHostContext()?.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT); + // [EndExclude color_mode_change] + } else { + //当前为深色模式,资源初始化逻辑 + // [StartExclude color_mode_change] + this.getUIContext() + .getHostContext()?.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_DARK); + // [EndExclude color_mode_change] + } + } + // [End color_mode_change] + aboutToDisappear(): void { + //移除map中的引用,并将自定义节点释放 + this.textNodeController.deleteNode(); + } + + build() { + Row() { + Column() { + NodeContainer(this.textNodeController) + .width('100%') + .height(200) + .backgroundColor('#FFF0F0F0') + Button('Switch to Dark Mode') + .onClick(() => { + this.getUIContext() + .getHostContext()?.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_DARK); + }) + Button('Switch to Light Mode') + .onClick(() => { + this.getUIContext() + .getHostContext()?.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT); + }) + } + .width('100%') + .height('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/pages/ImageAdaptation.ets b/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/pages/ImageAdaptation.ets new file mode 100644 index 0000000000000000000000000000000000000000..232a13ff6bfd9ec32a6d804c11ffeea2703c99e9 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/pages/ImageAdaptation.ets @@ -0,0 +1,34 @@ +/* + * 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. + */ + +@Entry +@Component +struct dark_light_color_adaptation { + + build() { + RelativeContainer() { + Text('Use system-defined colors') + .fontColor($r('sys.color.ohos_id_color_text_primary')) + + Image($rawfile('app.media.pic_svg.svg')) + .width(100) + .margin({top:20}) + .fillColor($r('sys.color.ohos_id_color_text_primary')) + + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/pages/Index.ets b/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..44f1a0a3c9b1fe63245de8b126e359bc0612d3e4 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,48 @@ +/* + * 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. + */ + +interface Ary { + path:string, + name:string +} +@Entry +@Component +struct Index { + ary:Ary[]=[ + { + name:'BuilderNodeAdaptation', + path:'pages/BuilderNodeAdaptation' + }, + { + name:'ImageAdaptation', + path:'pages/ImageAdaptation' + }, + { + name:'SwitchColorMode', + path:'pages/SwitchColorMode' + }, + ] + build() { + Scroll() { + Column({ space: 10 }) { + ForEach(this.ary,(item:Ary)=>{ + Button(item.name) + .onClick(() => this.getUIContext().getRouter().pushUrl({url: item.path})) + },(item:Ary)=>item.name) + } + .width('100%') + } + } +} diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/pages/SwitchColorMode.ets b/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/pages/SwitchColorMode.ets new file mode 100644 index 0000000000000000000000000000000000000000..f19511c47c99a20b5c74dc9acba39067052fe569 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/main/ets/pages/SwitchColorMode.ets @@ -0,0 +1,45 @@ +/* + * 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. + */ + +@Entry +@Component +struct DisplayPage { + @State message: string = 'Hello World'; + @State colorMode: ThemeColorMode = ThemeColorMode.DARK; + + build() { + WithTheme({ colorMode: this.colorMode }) { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button('Switch ColorMode').onClick(() => { + if (this.colorMode === ThemeColorMode.LIGHT) { + this.colorMode = ThemeColorMode.DARK; + } else if (this.colorMode === ThemeColorMode.DARK) { + this.colorMode = ThemeColorMode.LIGHT; + } + }) + } + .width('100%') + } + .backgroundColor($r('sys.color.background_primary')) + .height('100%') + .expandSafeArea( + [SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.END, SafeAreaEdge.BOTTOM, SafeAreaEdge.START]) + } + } +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/module.json5 b/ArkUIKit/ColorAdaptionApp/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e4226557b12a7322c888516a211fcf6c981c7122 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/main/module.json5 @@ -0,0 +1,65 @@ +/* + * 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. + */ + +{ + "module": { + "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.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/element/color.json b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/element/float.json b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/element/string.json b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d24f047b5809106378325441168ca797f5f6ad75 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ColorAdaptionApp" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/media/background.png b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/media/background.png differ diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/media/foreground.png b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/media/layered_image.json b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/media/startIcon.png b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/profile/backup_config.json b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/profile/main_pages.json b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..a0ddf4c5b1e183f3096f5cf773f3ec30084ba904 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,8 @@ +{ + "src": [ + "pages/Index", + "pages/ImageAdaptation", + "pages/BuilderNodeAdaptation", + "pages/SwitchColorMode" + ] +} diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/dark/element/color.json b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/rawfile/app.media.pic_svg.svg b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/rawfile/app.media.pic_svg.svg new file mode 100644 index 0000000000000000000000000000000000000000..4c552a3b11ca3459f2c7b190bfac11408005fad6 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/main/resources/rawfile/app.media.pic_svg.svg @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/mock/mock-config.json5 b/ArkUIKit/ColorAdaptionApp/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/mock/mock-config.json5 @@ -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. + */ + +{ +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkUIKit/ColorAdaptionApp/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // 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. + }) + beforeEach(() => { + // 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. + }) + afterEach(() => { + // 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. + }) + 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('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/ohosTest/ets/test/Index.test.ets b/ArkUIKit/ColorAdaptionApp/entry/src/ohosTest/ets/test/Index.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..918ec0a7532ecaf338da0b8ea41b95dc3a609df7 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/ohosTest/ets/test/Index.test.ets @@ -0,0 +1,94 @@ +/* + * 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. + */ + +import { describe, it, expect, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import hilog from '@ohos.hilog'; +import { abilityDelegatorRegistry, Driver, ON, MatchPattern } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const TAG = '[Sample_MyApp]'; +const DOMAIN = 0xF811; +const BUNDLE = 'MyApp_'; +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function IndexTest() { + describe('IndexTest', () => { + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + let driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * @tc.number ColorAdaptionTest_001 + * @tc.name testColorAdaption + * @tc.desc 测试深浅适配是否显示正常 + */ + it(BUNDLE + 'ColorAdaptionTest_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ColorAdaptionTest_001 begin'); + let driver = Driver.create(); + let button = await driver.findComponent(ON.text('BuilderNodeAdaptation', MatchPattern.CONTAINS)); + await button.click(); + let button1 = await driver.findComponent(ON.text('Switch to Dark Mode', MatchPattern.CONTAINS)); + await button1.click(); + let button2 = await driver.findComponent(ON.text('Switch to Light Mode', MatchPattern.CONTAINS)); + await button2.click(); + await driver.pressBack(); + hilog.info(DOMAIN, TAG, BUNDLE + 'ColorAdaptionTest_001 end'); + done(); + }) + + /** + * @tc.number ColorAdaptionTest_002 + * @tc.name testColorAdaption + * @tc.desc 测试深浅适配是否显示正常 + */ + it(BUNDLE + 'ColorAdaptionTest_002', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ColorAdaptionTest_002 begin'); + let driver = Driver.create(); + let button = await driver.findComponent(ON.text('ImageAdaptation', MatchPattern.CONTAINS)); + await button.click(); + await driver.pressBack(); + hilog.info(DOMAIN, TAG, BUNDLE + 'ColorAdaptionTest_002 end'); + done(); + }) + + /** + * @tc.number ColorAdaptionTest_003 + * @tc.name testColorAdaption + * @tc.desc 测试深浅适配是否显示正常 + */ + it(BUNDLE + 'ColorAdaptionTest_003', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ColorAdaptionTest_003 begin'); + let driver = Driver.create(); + let button = await driver.findComponent(ON.text('SwitchColorMode', MatchPattern.CONTAINS)); + await button.click(); + let button1 = await driver.findComponent(ON.text('Switch ColorMode', MatchPattern.CONTAINS)); + await button1.click(); + await driver.pressBack(); + hilog.info(DOMAIN, TAG, BUNDLE + 'ColorAdaptionTest_003 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/ohosTest/ets/test/List.test.ets b/ArkUIKit/ColorAdaptionApp/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a1951e50c73703b8b1fe39390c5287b68a1bf394 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,22 @@ +/* + * 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. + */ + +import abilityTest from './Ability.test'; +import IndexTest from './Index.test'; + +export default function testsuite() { + abilityTest(); + IndexTest(); +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/ohosTest/module.json5 b/ArkUIKit/ColorAdaptionApp/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..84d30586d591412f4252801cc483bbc6d8554104 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * 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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/test/List.test.ets b/ArkUIKit/ColorAdaptionApp/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/test/List.test.ets @@ -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. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/entry/src/test/LocalUnit.test.ets b/ArkUIKit/ColorAdaptionApp/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // 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. + }); + beforeEach(() => { + // 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. + }); + afterEach(() => { + // 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. + }); + 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('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/hvigor/hvigor-config.json5 b/ArkUIKit/ColorAdaptionApp/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b8fea3f097bd68b0bc4d87de986d2cb7732c1d9b --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/hvigor/hvigor-config.json5 @@ -0,0 +1,38 @@ +/* + * 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": "6.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkUIKit/ColorAdaptionApp/hvigorfile.ts b/ArkUIKit/ColorAdaptionApp/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3340f07e45ddc5dcadbb87012668555def2e6e0 --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/oh-package.json5 b/ArkUIKit/ColorAdaptionApp/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..69cb43cba3addcee1840403c67405134a2a9102c --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/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. + */ + +{ + "modelVersion": "6.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.24", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkUIKit/ColorAdaptionApp/ohosTest.md b/ArkUIKit/ColorAdaptionApp/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..b021f697896cbb658f6df8803611fd3cc59b462f --- /dev/null +++ b/ArkUIKit/ColorAdaptionApp/ohosTest.md @@ -0,0 +1,7 @@ +# ColorAdaption 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------- | -------------- |---------------------------------------|----------| :------- | -------- | +| ColorAdaption示例代码验证 | 设备正常运行 | 进入首页,进行深浅色切换 | 切换成功,显示正常 | 是 | Pass | \ No newline at end of file diff --git a/ArkUIKit/ColorAdaptionApp/screenshots/device/image1.png b/ArkUIKit/ColorAdaptionApp/screenshots/device/image1.png new file mode 100644 index 0000000000000000000000000000000000000000..561b7dac1d9c4062dca6fd16c0d464d2b96e5deb Binary files /dev/null and b/ArkUIKit/ColorAdaptionApp/screenshots/device/image1.png differ diff --git a/ArkUIKit/ColorAdaptionApp/screenshots/device/image2.png b/ArkUIKit/ColorAdaptionApp/screenshots/device/image2.png new file mode 100644 index 0000000000000000000000000000000000000000..339e35aee8e20ce14ca8709dc03e6118d8cab053 Binary files /dev/null and b/ArkUIKit/ColorAdaptionApp/screenshots/device/image2.png differ diff --git a/ArkUIKit/ColorAdaptionApp/screenshots/device/image3.png b/ArkUIKit/ColorAdaptionApp/screenshots/device/image3.png new file mode 100644 index 0000000000000000000000000000000000000000..a7693634bad4fda9f66fd3ee50afd796fe2833aa Binary files /dev/null and b/ArkUIKit/ColorAdaptionApp/screenshots/device/image3.png differ