diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..26d33521af10bcc7fd8cea344038eaaeb78d0ef5 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/guide-snippets.iml b/.idea/guide-snippets.iml new file mode 100644 index 0000000000000000000000000000000000000000..61021940449bdc69db005bbd04a05380f5629b2c --- /dev/null +++ b/.idea/guide-snippets.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..db8aa031e3c769f11829c70bbeec448abbce4849 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..35eb1ddfbbc029bcab630581847471d7f238ec53 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Calendar/CalendarEvent/.gitignore b/Calendar/CalendarEvent/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/Calendar/CalendarEvent/.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/Calendar/CalendarEvent/AppScope/app.json5 b/Calendar/CalendarEvent/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1e60bfe78cea398e0e060a73bd33f7a7bc164b73 --- /dev/null +++ b/Calendar/CalendarEvent/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.sample.calendarevent", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/Calendar/CalendarEvent/AppScope/resources/base/element/string.json b/Calendar/CalendarEvent/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7775c478186dd86a16553f23a980d8c638be4b64 --- /dev/null +++ b/Calendar/CalendarEvent/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "CalendarEvent" + } + ] +} diff --git a/Calendar/CalendarEvent/AppScope/resources/base/media/background.png b/Calendar/CalendarEvent/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/Calendar/CalendarEvent/AppScope/resources/base/media/background.png differ diff --git a/Calendar/CalendarEvent/AppScope/resources/base/media/foreground.png b/Calendar/CalendarEvent/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/Calendar/CalendarEvent/AppScope/resources/base/media/foreground.png differ diff --git a/Calendar/CalendarEvent/AppScope/resources/base/media/layered_image.json b/Calendar/CalendarEvent/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/Calendar/CalendarEvent/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/Calendar/CalendarEvent/README.md b/Calendar/CalendarEvent/README.md new file mode 100644 index 0000000000000000000000000000000000000000..85113dc76f12ec84c2330c93f51593d445fee825 --- /dev/null +++ b/Calendar/CalendarEvent/README.md @@ -0,0 +1,62 @@ +# CalendarEvent + +### 介绍 + +日程指特定的事件或者活动安排,日程管理即对这些事件、活动进行规划和控制,能更有效地利用相关资源、提高生产力和效率,使人们更好地管理时间和任务。 + +### 效果预览 + +![Index](screenshots/index.png) + +### 使用说明 + +1. 创建日历账户。 +2. 创建日程。 +3. 修改日程。 +4. 查询所有日程。 +5. 查询指定日程。 +6. 删除指定日程。 + +### 工程目录 + +``` +entry/src/ +|---main +| |---ets +| | |---pages +| | | |---Index.ets // 首页 +|---ohosTest +| |---ets +| | |---tests +| | | |---Ability.test.ets // 自动化测试用例 +``` + +### 相关权限 + +[ohos.permission.READ_CALENDAR](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/permissions-for-all-user#ohospermissionread_calendar) + +[ohos.permission.WRITE_CALENDAR](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/permissions-for-all-user#ohospermissionwrite_calendar) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568、PHONE、Tablet。 + +2.本示例仅支持API20版本SDK,镜像版本号:OpenHarmony 6.0.0.x及之后的版本。 + +3.本示例需要使用DevEco Studio 6.0.0 release (Build Version: 6.0.0.858)才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Calendar/CalendarEvent > .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/Calendar/CalendarEvent/build-profile.json5 b/Calendar/CalendarEvent/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..da0cf6c943d31a5558dd0cda97c213621dc2ddbd --- /dev/null +++ b/Calendar/CalendarEvent/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": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "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/Calendar/CalendarEvent/code-linter.json5 b/Calendar/CalendarEvent/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7f67b9ad794978e0469d9de745934605b23a7cd9 --- /dev/null +++ b/Calendar/CalendarEvent/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/Calendar/CalendarEvent/entry/.gitignore b/Calendar/CalendarEvent/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/Calendar/CalendarEvent/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/Calendar/CalendarEvent/entry/build-profile.json5 b/Calendar/CalendarEvent/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ff78b6612917ebdfca2a27cb9d9432e5dfdc88ac --- /dev/null +++ b/Calendar/CalendarEvent/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/Calendar/CalendarEvent/entry/hvigorfile.ts b/Calendar/CalendarEvent/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..6ef2fb28f052cfaed070b056bd400c6fd48d4814 --- /dev/null +++ b/Calendar/CalendarEvent/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/Calendar/CalendarEvent/entry/obfuscation-rules.txt b/Calendar/CalendarEvent/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/Calendar/CalendarEvent/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/Calendar/CalendarEvent/entry/oh-package.json5 b/Calendar/CalendarEvent/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..95fbdee415709d6dcaa612dae50cf61effc5f99d --- /dev/null +++ b/Calendar/CalendarEvent/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/Calendar/CalendarEvent/entry/src/main/ets/entryability/EntryAbility.ets b/Calendar/CalendarEvent/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..9a57c4020cf12e9955a9d72e5569fcf7e330171a --- /dev/null +++ b/Calendar/CalendarEvent/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,76 @@ +/* +* 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 calendarEvent_entryAbilityImport] +import { abilityAccessCtrl, AbilityConstant, common, PermissionRequestResult, Permissions, UIAbility, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { calendarManager } from '@kit.CalendarKit'; +import { window } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +// [End calendarEvent_entryAbilityImport] + +// [Start calendarEvent_entryAbility] +const DOMAIN = 0x0000; + +export let calendarMgr: calendarManager.CalendarManager | null = null; + +export let mContext: common.UIAbilityContext | null = null; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', "Ability onCreate"); + } + + 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, data) => { + 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.'); + }); + mContext = this.context; + const permissions: Permissions[] = ['ohos.permission.READ_CALENDAR', 'ohos.permission.WRITE_CALENDAR']; + let atManager = abilityAccessCtrl.createAtManager(); + atManager.requestPermissionsFromUser(mContext, permissions).then((result: PermissionRequestResult) => { + hilog.info(DOMAIN, 'testTag', 'get Permission success'); + calendarMgr = calendarManager.getCalendarManager(mContext); + }).catch((error: BusinessError) => { + hilog.error(DOMAIN, 'testTag', 'get Permission error, Cause: %{public}s', JSON.stringify(error)); + }) + } + + 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"); + } +} +// [End calendarEvent_entryAbility] \ No newline at end of file diff --git a/Calendar/CalendarEvent/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/Calendar/CalendarEvent/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..7eb1afb81759bc5d59117077cb08b938ea66d402 --- /dev/null +++ b/Calendar/CalendarEvent/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/Calendar/CalendarEvent/entry/src/main/ets/pages/Index.ets b/Calendar/CalendarEvent/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b5150b2eaa9fc9e6c0c39c19339cf06ffc6cf657 --- /dev/null +++ b/Calendar/CalendarEvent/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,291 @@ +/* +* 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 calendarEvent_indexImport] +import { BusinessError } from '@kit.BasicServicesKit'; +import { calendarMgr } from '../entryability/EntryAbility'; +import { calendarManager } from '@kit.CalendarKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const DOMAIN = 0x0000; + +let calendar: calendarManager.Calendar | undefined = undefined; +// 指定日历账户信息 +const calendarAccount: calendarManager.CalendarAccount = { + name: 'MyCalendar', + type: calendarManager.CalendarType.LOCAL, + // 日历账户显示名称,该字段如果不填,创建的日历账户在界面显示为空字符串。 + displayName: 'MyCalendar' +}; +// 日历配置信息 +const config: calendarManager.CalendarConfig = { + // 打开日程提醒 + enableReminder: true, + // 设置日历账户颜色 + color: '#aabbcc' +}; +// [End calendarEvent_indexImport] + +// [Start calendarEvent_eventParam] +let eventId : number | undefined = undefined; +const date = new Date(); +// [End calendarEvent_eventParam] + +@Entry +@Component +struct Index { + build() { + Column() { + Row() { + Button('1,创建日历账户', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.createCalendar(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('2,创建日程', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.addEvent(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('3,修改日程', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.updateEvent(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('4,查询所有日程', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.getEvents(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('5,查询指定日程', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.getEvent(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('6,删除指定日程', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.deleteEvent(); + }) + .width('100%') + }.padding({ top: 10 }) + } + .height('100%') + .width('100%') + } + + // 根据日历账户信息创建Calendar对象,用于进行日程管理。设置日历配置信息,可以根据需要打开日程提醒、设置日历账户颜色 + createCalendar() { + // [Start calendarEvent_createCalendar] + // 创建日历账户 + calendarMgr?.createCalendar(calendarAccount).then((data: calendarManager.Calendar) => { + hilog.info(DOMAIN, 'testTag', `Succeeded in creating calendar data->${JSON.stringify(data)}`); + calendar = data; + // 请确保日历账户创建成功后,再进行相关日程的管理 + + // 设置日历配置信息,打开日程提醒、设置日历账户颜色 + calendar.setConfig(config).then(() => { + hilog.info(DOMAIN, 'testTag', `Succeeded in setting config, data->${JSON.stringify(config)}`); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN, 'testTag', `Failed to set config. Code: ${err.code}, message: ${err.message}`); + }); + // ... + }).catch((error: BusinessError) => { + hilog.error(DOMAIN, 'testTag', `Failed to create calendar. Code: ${error.code}, message: ${error.message}`); + }); + // [End calendarEvent_createCalendar] + } + + // 目前支持以下两种方式来创建日程。 + // 方式一:可以在日历账户下通过addEvent()或addEvents()接口创建日程。其中可使用addEvent()接口创建单个日程,也可以使用addEvents()接口批量创建日程,此处以创建单个日程为例。 + // 方式二:在获取到日历管理器对象后,可通过editEvent()接口创建单个日程。调用此接口创建日程时,会跳转到日程创建页面,在日程创建页面进行相关操作完成日程的创建, editEvent()不支持自定义周期性日程创建。 + addEvent() { + if (!calendar || calendar === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to add event. calendar is null'); + return; + } + // [Start calendarEvent_addEvent] + const event: calendarManager.Event = { + // 日程标题 + title: 'title', + // 日程类型,不推荐三方开发者使用calendarManager.EventType.IMPORTANT,重要日程类型不支持一键服务跳转功能及无法自定义提醒时间 + type: calendarManager.EventType.NORMAL, + // 日程开始时间 + startTime: date.getTime(), + // 日程结束时间 + endTime: date.getTime() + 60 * 60 * 1000, + // 距开始时间提前10分钟提醒 + reminderTime: [10], + // 日程重复规则,可选属性。如果日程为周期性日程需要填写该属性。 + recurrenceRule: { + // 日程重复规则类型,支持按天、按周、按月、按年重复 + recurrenceFrequency: calendarManager.RecurrenceFrequency.DAILY, + // 日程重复次数,该字段和expire属性只需要填写一个,如果两个都填写按照count属性计算。 + count: 100, + // 重复日程间隔时间,与recurrenceFrequency相关,此示例表示日程每隔2天进行重复。 + interval: 2, + // 日程过期时间,该字段和count属性只需要填写一个,如果两个都填写按照count属性计算。 + expire: date.getTime() + 60 * 60 * 1000 * 3, + // 日程排除日期,将该日期从重复日程中排除掉 + excludedDates: [date.getTime() + 60 * 60 * 1000 * 2] + }, + // 日程服务,可选字段,需要一键服务功能的日程,填写该属性。 + service: { + // 服务类型,比如一键查看、一键入会、一键追剧等。 + type: calendarManager.ServiceType.TRIP, + // 服务的uri。可以跳转到三方应用相应界面,格式为DeepLink。使用DeepLink方式需要在华为HAG云侧进行注册,注册提供的信息为应用包名、应用的服务类型。 + // DeepLink包括scheme、host、path以及参数(不包含参数值) + uri: 'xxx://xxx.xxx.com/xxx', + // 服务辅助描述信息,可选字段 + description: '一键服务' + } + + }; + // 方式一 + calendar.addEvent(event).then((data: number) => { + hilog.info(DOMAIN, 'testTag', `Succeeded in adding event, id -> ${data}`); + eventId = data; + }).catch((err: BusinessError) => { + hilog.error(DOMAIN, 'testTag', `Failed to addEvent. Code: ${err.code}, message: ${err.message}`); + }); + // 方式二 + const eventInfo: calendarManager.Event = { + // 日程标题 + title: 'title', + // 日程类型 + type: calendarManager.EventType.NORMAL, + // 日程开始时间 + startTime: date.getTime(), + // 日程结束时间 + endTime: date.getTime() + 60 * 60 * 1000 + }; + calendarMgr?.editEvent(eventInfo).then((id: number): void => { + hilog.info(DOMAIN, 'testTag', `create Event id = ${id}`); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN, 'testTag', `Failed to create Event. Code: ${err.code}, message: ${err.message}`); + }); + // [End calendarEvent_addEvent] + } + + // 按照日程id进行当前日历账户指定日程的更新,更新日程相关信息。 + updateEvent() { + if (!calendar || calendar === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to update event. calendar is null'); + return; + } + // [Start calendarEvent_updateEvent] + const updateEvent: calendarManager.Event = { + title: 'updateTitle', + description: 'updateEventTest', + type: calendarManager.EventType.NORMAL, + id: eventId, + startTime: date.getTime(), + endTime: date.getTime() + 60 * 60 * 1000 + }; + calendar.updateEvent(updateEvent).then(() => { + hilog.info(DOMAIN, 'testTag', `Succeeded in updating event`); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN, 'testTag', `Failed to update event. Code: ${err.code}, message: ${err.message}`); + }); + // [End calendarEvent_updateEvent] + } + + getEvents() { + if (!calendar || calendar === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to get events. calendar is null'); + return; + } + // [Start calendarEvent_getEvents] + calendar.getEvents().then((data: calendarManager.Event[]) => { + hilog.info(DOMAIN, 'testTag', `Succeeded in getting events, data -> ${JSON.stringify(data)}`); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN, 'testTag', `Failed to get events. Code: ${err.code}, message: ${err.message}`); + }); + // [End calendarEvent_getEvents] + } + + // 还支持根据日程id、日程开始和结束时间、日程标题等查询条件来查询日程。 + getEvent() { + if (!calendar || calendar === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to get event. calendar is null'); + return; + } + // [Start calendarEvent_getEvent] + // 根据日程id查询 + const filterId = calendarManager.EventFilter.filterById([eventId]); + calendar.getEvents(filterId).then((data: calendarManager.Event[]) => { + hilog.info(DOMAIN, 'testTag', `Succeeded in getting events filter by eventId, data -> ${JSON.stringify(data)}`); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN, 'testTag', `Failed to get events. Code: ${err.code}, message: ${err.message}`); + }); + + // 根据日程标题查询 + const filterTitle = calendarManager.EventFilter.filterByTitle('update'); + calendar.getEvents(filterTitle).then((data: calendarManager.Event[]) => { + hilog.info(DOMAIN, 'testTag', `Succeeded in getting events filter by title, data -> ${JSON.stringify(data)}`); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN, 'testTag', `Failed to get events. Code: ${err.code}, message: ${err.message}`); + }); + + // 根据日程开始和结束时间查询 + const filterTime = calendarManager.EventFilter.filterByTime(1686931200000, 1687017600000); + calendar.getEvents(filterTime).then((data: calendarManager.Event[]) => { + hilog.info(DOMAIN, 'testTag', `Succeeded in getting events filter by time, data -> ${JSON.stringify(data)}`); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN, 'testTag', `Failed to filter by time. Code: ${err.code}, message: ${err.message}`); + }); + // [End calendarEvent_getEvent] + } + + deleteEvent() { + if (!calendar || calendar === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to delete event. calendar is null'); + return; + } + // [Start calendarEvent_deleteEvent] + calendar.deleteEvent(eventId).then(() => { + hilog.info(DOMAIN, 'testTag', "Succeeded in deleting event"); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN, 'testTag', `Failed to delete event. Code: ${err.code}, message: ${err.message}`); + }); + // [End calendarEvent_deleteEvent] + } +} \ No newline at end of file diff --git a/Calendar/CalendarEvent/entry/src/main/module.json5 b/Calendar/CalendarEvent/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a75f024a16812fb57dfb59b2a1ccefd4fa3abe76 --- /dev/null +++ b/Calendar/CalendarEvent/entry/src/main/module.json5 @@ -0,0 +1,83 @@ +/* +* 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": [ + "phone", + "tablet", + "2in1" + ], + "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" + } + ], + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.READ_CALENDAR", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "when": "always" + } + }, + { + "name": "ohos.permission.WRITE_CALENDAR", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "when": "always" + } + } + ] + } +} \ No newline at end of file diff --git a/Calendar/CalendarEvent/entry/src/main/resources/base/element/color.json b/Calendar/CalendarEvent/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/Calendar/CalendarEvent/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/Calendar/CalendarEvent/entry/src/main/resources/base/element/float.json b/Calendar/CalendarEvent/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/Calendar/CalendarEvent/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/Calendar/CalendarEvent/entry/src/main/resources/base/element/string.json b/Calendar/CalendarEvent/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/Calendar/CalendarEvent/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": "label" + } + ] +} \ No newline at end of file diff --git a/Calendar/CalendarEvent/entry/src/main/resources/base/media/background.png b/Calendar/CalendarEvent/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/Calendar/CalendarEvent/entry/src/main/resources/base/media/background.png differ diff --git a/Calendar/CalendarEvent/entry/src/main/resources/base/media/foreground.png b/Calendar/CalendarEvent/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/Calendar/CalendarEvent/entry/src/main/resources/base/media/foreground.png differ diff --git a/Calendar/CalendarEvent/entry/src/main/resources/base/media/layered_image.json b/Calendar/CalendarEvent/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/Calendar/CalendarEvent/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/Calendar/CalendarEvent/entry/src/main/resources/base/media/startIcon.png b/Calendar/CalendarEvent/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/Calendar/CalendarEvent/entry/src/main/resources/base/media/startIcon.png differ diff --git a/Calendar/CalendarEvent/entry/src/main/resources/base/profile/backup_config.json b/Calendar/CalendarEvent/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/Calendar/CalendarEvent/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/Calendar/CalendarEvent/entry/src/main/resources/base/profile/main_pages.json b/Calendar/CalendarEvent/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/Calendar/CalendarEvent/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/Calendar/CalendarEvent/entry/src/main/resources/dark/element/color.json b/Calendar/CalendarEvent/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/Calendar/CalendarEvent/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/Calendar/CalendarEvent/entry/src/mock/mock-config.json5 b/Calendar/CalendarEvent/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d76be296f7f7212ba32b65f80a6d2d2ffec8ecce --- /dev/null +++ b/Calendar/CalendarEvent/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/Calendar/CalendarEvent/entry/src/ohosTest/ets/test/Ability.test.ets b/Calendar/CalendarEvent/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c0f63d531059dacd3eb13d669ce473292bbbe4b3 --- /dev/null +++ b/Calendar/CalendarEvent/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,116 @@ +/* +* 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'; +import { Driver, ON, MatchPattern } from '@ohos.UiTest'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import resourceManager from '@ohos.resourceManager'; +import deviceInfo from '@ohos.deviceInfo'; + +const TAG = '[Sample_CalendarEventSample]'; +const DOMAIN = 0xF811; +const BUNDLE = 'CalendarEventSample'; +let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +let manager: resourceManager.ResourceManager; +const driver = Driver.create(); + +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. + abilityDelegator.startAbility({ + bundleName: 'com.sample.calendarevent', + abilityName: 'EntryAbility' + }); + }) + 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('CalendarEventSample_CreateCalendar', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `CreateCalendar, begin`); + let btnAccept = await driver.findComponent(ON.text('1,创建日历账户')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `CreateCalendar, end`); + done(); + }) + it('CalendarEventSample_AddEvent', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `AddEvent, begin`); + let btnAccept = await driver.findComponent(ON.text('2,创建日程')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `AddEvent, end`); + done(); + }) + it('CalendarEventSample_UpdateEvent', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `UpdateEvent, begin`); + let btnAccept = await driver.findComponent(ON.text('3,修改日程')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `UpdateEvent, end`); + done(); + }) + it('CalendarEventSample_GetEvents', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `GetEvents, begin`); + let btnAccept = await driver.findComponent(ON.text('4,查询所有日程')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `GetEvents, end`); + done(); + }) + it('CalendarEventSample_GetEvent', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `GetEvent, begin`); + let btnAccept = await driver.findComponent(ON.text('5,查询指定日程')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `GetEvent, end`); + done(); + }) + it('CalendarEventSample_DeleteEvent', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `DeleteEvent, begin`); + let btnAccept = await driver.findComponent(ON.text('6,删除指定日程')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `DeleteEvent, end`); + done(); + }) + }) +} \ No newline at end of file diff --git a/Calendar/CalendarEvent/entry/src/ohosTest/ets/test/List.test.ets b/Calendar/CalendarEvent/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..2a94e90b4f475cb3ce1237e0c6c637a10af51235 --- /dev/null +++ b/Calendar/CalendarEvent/entry/src/ohosTest/ets/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 abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/Calendar/CalendarEvent/entry/src/ohosTest/module.json5 b/Calendar/CalendarEvent/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..40d0af3f15d64e129c1f8bbe1cdac612440dc851 --- /dev/null +++ b/Calendar/CalendarEvent/entry/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* +* 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": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/Calendar/CalendarEvent/entry/src/test/List.test.ets b/Calendar/CalendarEvent/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3728d4693480fa0b0853121dc892d318a8dd08cf --- /dev/null +++ b/Calendar/CalendarEvent/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/Calendar/CalendarEvent/entry/src/test/LocalUnit.test.ets b/Calendar/CalendarEvent/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..09b5e0b944288ffa51b13b489085e8b2d4455999 --- /dev/null +++ b/Calendar/CalendarEvent/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/Calendar/CalendarEvent/hvigor/hvigor-config.json5 b/Calendar/CalendarEvent/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..295b3094c5e53223db13f12f7e4cd77a36a718a3 --- /dev/null +++ b/Calendar/CalendarEvent/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/Calendar/CalendarEvent/hvigorfile.ts b/Calendar/CalendarEvent/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..4540d29e68aa7e2ee83d7d735dbd11606ae172ca --- /dev/null +++ b/Calendar/CalendarEvent/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/Calendar/CalendarEvent/oh-package.json5 b/Calendar/CalendarEvent/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..26d9e55e3543a38ad2eee882dc8ad91c4a0abc4b --- /dev/null +++ b/Calendar/CalendarEvent/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/Calendar/CalendarEvent/screenshots/index.png b/Calendar/CalendarEvent/screenshots/index.png new file mode 100644 index 0000000000000000000000000000000000000000..0b1225585de40eef2be70ded5ae87d6ba9abcf7d Binary files /dev/null and b/Calendar/CalendarEvent/screenshots/index.png differ diff --git a/Calendar/CalendarEventPractice/.gitignore b/Calendar/CalendarEventPractice/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/Calendar/CalendarEventPractice/.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/Calendar/CalendarEventPractice/AppScope/app.json5 b/Calendar/CalendarEventPractice/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5892478afcf763f9156a01d423358dbf61c31efb --- /dev/null +++ b/Calendar/CalendarEventPractice/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.sample.calendareventpractice", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/Calendar/CalendarEventPractice/AppScope/resources/base/element/string.json b/Calendar/CalendarEventPractice/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..131f6b29f874ee08a16f5101a170d4f71fb19e3e --- /dev/null +++ b/Calendar/CalendarEventPractice/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "CalendarEventPractice" + } + ] +} diff --git a/Calendar/CalendarEventPractice/AppScope/resources/base/media/background.png b/Calendar/CalendarEventPractice/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/Calendar/CalendarEventPractice/AppScope/resources/base/media/background.png differ diff --git a/Calendar/CalendarEventPractice/AppScope/resources/base/media/foreground.png b/Calendar/CalendarEventPractice/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/Calendar/CalendarEventPractice/AppScope/resources/base/media/foreground.png differ diff --git a/Calendar/CalendarEventPractice/AppScope/resources/base/media/layered_image.json b/Calendar/CalendarEventPractice/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/Calendar/CalendarEventPractice/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/Calendar/CalendarEventPractice/README.md b/Calendar/CalendarEventPractice/README.md new file mode 100644 index 0000000000000000000000000000000000000000..fd334398e0db1314123528244a87952a4140ffe7 --- /dev/null +++ b/Calendar/CalendarEventPractice/README.md @@ -0,0 +1,65 @@ +# CalendarEventPractice + +### 介绍 + +通过日历服务,开发者可将带有时间属性的事件作为日程写入,并支持通过“[一键服务](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/calendar-service)”功能快速跳转,帮助用户快速直达对应服务,并完成各类信息的归一化管理。各典型场景选择适用的模板,并按照模板格式填写各个字段信息,确保用户体验完整、一致。 + +### 效果预览 + +![Index](screenshots/index.png) + +### 使用说明 + +1. 出行服务场景 - 创建日程、查询日程、更新日程、删除日程。 +2. 酒店住宿场景 - 创建日程。 +3. 直播预约场景 - 创建日程。 +4. 抢购预约场景 - 创建日程。 +5. 还款提醒场景 - 创建日程。 +6. 课程提醒场景 - 创建日程。 +7. 影音娱乐场景 - 创建日程。 +8. 运动训练场景 - 创建日程 +9. 会议场景 - 创建日程 + +### 工程目录 + +``` +entry/src/ +|---main +| |---ets +| | |---pages +| | | |---Index.ets // 首页 +|---ohosTest +| |---ets +| | |---tests +| | | |---Ability.test.ets // 自动化测试用例 +``` + +### 相关权限 + +[ohos.permission.READ_CALENDAR](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/permissions-for-all-user#ohospermissionread_calendar) + +[ohos.permission.WRITE_CALENDAR](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/permissions-for-all-user#ohospermissionwrite_calendar) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568、PHONE、Tablet。 + +2.本示例仅支持API20版本SDK,镜像版本号:OpenHarmony 6.0.0.x及之后的版本。 + +3.本示例需要使用DevEco Studio 6.0.0 release (Build Version: 6.0.0.858)才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Calendar/CalendarEventPractice > .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/Calendar/CalendarEventPractice/build-profile.json5 b/Calendar/CalendarEventPractice/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..da0cf6c943d31a5558dd0cda97c213621dc2ddbd --- /dev/null +++ b/Calendar/CalendarEventPractice/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": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "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/Calendar/CalendarEventPractice/code-linter.json5 b/Calendar/CalendarEventPractice/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7f67b9ad794978e0469d9de745934605b23a7cd9 --- /dev/null +++ b/Calendar/CalendarEventPractice/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/Calendar/CalendarEventPractice/entry/.gitignore b/Calendar/CalendarEventPractice/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/Calendar/CalendarEventPractice/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/Calendar/CalendarEventPractice/entry/build-profile.json5 b/Calendar/CalendarEventPractice/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ff78b6612917ebdfca2a27cb9d9432e5dfdc88ac --- /dev/null +++ b/Calendar/CalendarEventPractice/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/Calendar/CalendarEventPractice/entry/hvigorfile.ts b/Calendar/CalendarEventPractice/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..6ef2fb28f052cfaed070b056bd400c6fd48d4814 --- /dev/null +++ b/Calendar/CalendarEventPractice/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/Calendar/CalendarEventPractice/entry/obfuscation-rules.txt b/Calendar/CalendarEventPractice/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/Calendar/CalendarEventPractice/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/Calendar/CalendarEventPractice/entry/oh-package.json5 b/Calendar/CalendarEventPractice/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..95fbdee415709d6dcaa612dae50cf61effc5f99d --- /dev/null +++ b/Calendar/CalendarEventPractice/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/Calendar/CalendarEventPractice/entry/src/main/ets/entryability/EntryAbility.ets b/Calendar/CalendarEventPractice/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..c61afc9f3b5d727d40d3a770ebe32503c5213224 --- /dev/null +++ b/Calendar/CalendarEventPractice/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,72 @@ +/* +* 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 { abilityAccessCtrl, AbilityConstant, common, PermissionRequestResult, Permissions, UIAbility, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { calendarManager } from '@kit.CalendarKit'; +import { window } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const DOMAIN = 0x0000; + +export let calendarMgr: calendarManager.CalendarManager | null = null; + +export let mContext: common.UIAbilityContext | null = null; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', "Ability onCreate"); + } + + 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, data) => { + 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.'); + }); + mContext = this.context; + const permissions: Permissions[] = ['ohos.permission.READ_CALENDAR', 'ohos.permission.WRITE_CALENDAR']; + let atManager = abilityAccessCtrl.createAtManager(); + atManager.requestPermissionsFromUser(mContext, permissions).then((result: PermissionRequestResult) => { + hilog.info(DOMAIN, 'testTag', 'get Permission success'); + calendarMgr = calendarManager.getCalendarManager(mContext); + }).catch((error: BusinessError) => { + hilog.error(DOMAIN, 'testTag', 'get Permission error, Cause: %{public}s', JSON.stringify(error)); + }) + } + + 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/Calendar/CalendarEventPractice/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/Calendar/CalendarEventPractice/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..7eb1afb81759bc5d59117077cb08b938ea66d402 --- /dev/null +++ b/Calendar/CalendarEventPractice/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/Calendar/CalendarEventPractice/entry/src/main/ets/pages/Index.ets b/Calendar/CalendarEventPractice/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..9a1b4c81b69de90a1cd8f4e472b9f5548bb43ae3 --- /dev/null +++ b/Calendar/CalendarEventPractice/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,707 @@ +/* +* 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 calendarEventPractice_indexImport] +import { calendarMgr } from '../entryability/EntryAbility'; +import { calendarManager } from '@kit.CalendarKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const DOMAIN = 0x0000; + +let tripCalendar: calendarManager.Calendar | undefined = undefined; +let oriEvent: calendarManager.Event | null = null; +let id: number = 0; +// [End calendarEventPractice_indexImport] + +@Entry +@Component +struct Index { + build() { + Column() { + Row() { + Button('1,出行服务场景 - 创建日程', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.createTripCalendarAndEvent(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('1,出行服务场景 - 查询日程', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.getTripEvent(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('1,出行服务场景 - 更新日程', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.updateTripEvent(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('1,出行服务场景 - 删除日程', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.deleteTripEvent(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('2,酒店住宿场景 - 创建日程', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.createHotelCalendarAndEvent(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('3,直播预约场景 - 创建日程', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.createLiveCalendarAndEvent(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('4,抢购预约场景 - 创建日程', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.createShoppingCalendarAndEvent(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('5,还款提醒场景 - 创建日程', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.createRepaymentCalendarAndEvent(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('6,课程提醒场景 - 创建日程', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.createClassCalendarAndEvent(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('7,影音娱乐场景 - 创建日程', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.createSportsCalendarAndEvent(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('8,运动训练场景 - 创建日程', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.createSportsExerciseEvent(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('9,会议场景 - 创建日程', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.createMeetingEvent(); + }) + .width('100%') + }.padding({ top: 10 }) + } + .height('100%') + .width('100%') + } + + // [Start calendarEventPractice_createTripCalendarAndEvent] + async createTripCalendarAndEvent(): Promise { + // 指定日历账户信息 + const calendarAccount: calendarManager.CalendarAccount = { + name: 'TripCalendar', + type: calendarManager.CalendarType.LOCAL, + // 日历账户显示名称:建议使用应用实际名称。 + displayName: '高铁出行' + }; + // 日历配置信息 + const config: calendarManager.CalendarConfig = { + // 设置日历账户颜色 + color: '#aabbcc' + }; + const startTime = new Date('2025-10-01T08:17:00').getTime(); + const endTime = new Date('2025-10-01T12:51:00').getTime(); + // 日程配置信息 + const event: calendarManager.Event = { + type: calendarManager.EventType.NORMAL, + // 日程标题 + title: '行程信息:G107 上海虹桥-北京南', + // 开始时间 + startTime: startTime, + // 结束时间 + endTime: endTime, + // 是否全天日程 + isAllDay:false, + // 提醒时间 + reminderTime:[120, 240], + // 备注 + description: '检票口:南二楼1口或北广场B2候车室 \n座位号:02车04二等座', + // 一键服务 + service: { + // 服务类型 + type: calendarManager.ServiceType.TRIP, + // 服务的uri,格式为DeepLink类型。请根据“一键服务”指导文档配置。 + uri: 'demo://mobile/player?params=' + } + } + try { + // 创建日历账户 + tripCalendar = await calendarMgr?.createCalendar(calendarAccount); + if (!tripCalendar || tripCalendar === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to create calendar. tripCalendar is null.'); + return; + } + // 请确保日历账户创建成功后,再进行相关日程的管理 + // 设置日历配置信息,设置日历账户颜色 + await tripCalendar.setConfig(config); + // 添加日程 + id = await tripCalendar.addEvent(event); + oriEvent = event; + oriEvent.id = id; + hilog.info(DOMAIN, 'testTag',`Succeeded in creating calendar and event, result: ${JSON.stringify(id)}`); + } catch (error) { + hilog.error(DOMAIN, 'testTag', `Failed to create calendar or event. Code: ${error.code}, message: ${error.message}`); + } + } + // [End calendarEventPractice_createTripCalendarAndEvent] + + // [Start calendarEventPractice_getTripEvent] + async getTripEvent(): Promise { + // 校验calendar是否为空 + if (!tripCalendar || tripCalendar === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to get event, calendar is null.'); + return; + } + try { + // 查询行程 + const filter = calendarManager.EventFilter.filterById([id]); + let data: calendarManager.Event[] = await tripCalendar.getEvents(filter, ['title', 'type', 'startTime', 'endTime']); + if (data && data.length > 0) { + oriEvent = data[0]; + } + hilog.info(DOMAIN, 'testTag',`Succeeded in getting events, data -> ${JSON.stringify(data)}`); + } catch (err) { + hilog.error(DOMAIN, 'testTag', `Failed to get events. Code: ${err.code}, message: ${err.message}`); + } + } + // [End calendarEventPractice_getTripEvent] + + // [Start calendarEventPractice_updateTripEvent] + async updateTripEvent(): Promise { + // 校验calendar是否为空 + if (!tripCalendar || tripCalendar === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to update event, calendar is null.'); + return; + } + if (!oriEvent || oriEvent === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to update event, oriEvent is null'); + return; + } + // 修改行程的开始时间startTime和结束时间endTime + oriEvent.startTime = new Date('2025-10-01T07:03:00').getTime(); + oriEvent.endTime = new Date('2025-10-01T11:51:00').getTime(); + try { + // 更新行程 + await tripCalendar.updateEvent(oriEvent); + hilog.info(DOMAIN, 'testTag',"Succeeded in updating event"); + } catch (err) { + hilog.error(DOMAIN, 'testTag', `Failed to update event. Code: ${err.code}, message: ${err.message}`); + } + } + // [End calendarEventPractice_updateTripEvent] + + // [Start calendarEventPractice_deleteTripEvent] + async deleteTripEvent(): Promise { + // 校验calendar是否为空 + if (!tripCalendar || tripCalendar === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to delete event, calendar is null.'); + return; + } + try { + // 删除行程 + await tripCalendar.deleteEvent(id); + oriEvent = null; + hilog.info(DOMAIN, 'testTag',`Succeeded in deleting Event`); + } catch (err) { + hilog.error(DOMAIN, 'testTag', `Failed to delete Event, Code is ${err.code}, message is ${err.message}`); + } + } + // [End calendarEventPractice_deleteTripEvent] + + // [Start calendarEventPractice_createHotelCalendarAndEvent] + async createHotelCalendarAndEvent(): Promise { + // 指定日历账户信息 + const calendarAccount: calendarManager.CalendarAccount = { + name: 'hotelCalendar', + type: calendarManager.CalendarType.LOCAL, + // 日历账户显示名称:建议使用应用实际名称。 + displayName: '酒店住宿' + }; + // 日历配置信息 + const config: calendarManager.CalendarConfig = { + // 设置日历账户颜色 + color: '#aabbcc' + }; + const startTime = new Date('2025-05-01T15:00:00').getTime(); + const endTime = new Date('2025-05-02T12:00:00').getTime(); + // 日程配置信息 + const event: calendarManager.Event = { + type: calendarManager.EventType.NORMAL, + title: '入住信息:酒店(上海新天地店)', + location: { + location: '上海新天地', + longitude: 121.47506199999998, + latitude: 31.219150000000013 + }, + startTime: startTime, + endTime: endTime, + isAllDay: true, + // 提醒时间:全天日程是按9点往前计算分钟数 + reminderTime: [0, 1440], + description: '入住:15:00后\n离店:12:00前', + // 一键服务 + service: { + type: calendarManager.ServiceType.TRIP, + uri: 'demo://mobile/player?params=' + } + } + try { + // 创建日历账户 + let data: calendarManager.Calendar | undefined= await calendarMgr?.createCalendar(calendarAccount); + if (!data || data === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to create calendar. data is null.'); + return; + } + // 请确保日历账户创建成功后,再进行相关日程的管理 + // 设置日历配置信息,设置日历账户颜色 + await data.setConfig(config); + // 添加日程 + id = await data.addEvent(event); + hilog.info(DOMAIN, 'testTag',`Succeeded in creating calendar and event, result: ${JSON.stringify(id)}`); + } catch (error) { + hilog.error(DOMAIN, 'testTag', `Failed to create calendar or event. Code: ${error.code}, message: ${error.message}`); + } + } + // [End calendarEventPractice_createHotelCalendarAndEvent] + + // [Start calendarEventPractice_createLiveCalendarAndEvent] + async createLiveCalendarAndEvent(): Promise { + // 指定日历账户信息 + const calendarAccount: calendarManager.CalendarAccount = { + name: 'liveCalendar', + type: calendarManager.CalendarType.LOCAL, + // 日历账户显示名称:建议使用应用实际名称。 + displayName: '直播抢购' + }; + // 日历配置信息 + const config: calendarManager.CalendarConfig = { + // 设置日历账户颜色 + color: '#aabbcc' + }; + const startTime = new Date('2025-11-04T21:00:00').getTime(); + const endTime = new Date('2025-11-04T22:00:00').getTime(); + // 日程配置信息 + const event: calendarManager.Event = { + type: calendarManager.EventType.NORMAL, + title: '直播抢购', + startTime: startTime, + endTime: endTime, + isAllDay: false, + reminderTime: [0, 10], + description: '限时特惠,秋季最大福利就在直播间', + // 一键服务 + service: { + type: calendarManager.ServiceType.LIVE, + uri: 'demo://mobile/player?params=' + } + } + try { + // 创建日历账户 + let data: calendarManager.Calendar | undefined= await calendarMgr?.createCalendar(calendarAccount); + if (!data || data === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to create calendar. data is null.'); + return; + } + // 请确保日历账户创建成功后,再进行相关日程的管理 + // 设置日历配置信息,设置日历账户颜色 + await data.setConfig(config); + // 添加日程 + id = await data.addEvent(event); + hilog.info(DOMAIN, 'testTag',`Succeeded in creating calendar and event, result: ${JSON.stringify(id)}`); + } catch (error) { + hilog.error(DOMAIN, 'testTag', `Failed to create calendar or event. Code: ${error.code}, message: ${error.message}`); + } + } + // [End calendarEventPractice_createLiveCalendarAndEvent] + + // [Start calendarEventPractice_createShoppingCalendarAndEvent] + async createShoppingCalendarAndEvent(): Promise { + // 指定日历账户信息 + const calendarAccount: calendarManager.CalendarAccount = { + name: 'shoppingCalendar', + type: calendarManager.CalendarType.LOCAL, + // 日历账户显示名称:建议使用应用实际名称。 + displayName: '购物' + }; + // 日历配置信息 + const config: calendarManager.CalendarConfig = { + // 设置日历账户颜色 + color: '#aabbcc' + }; + const startTime = new Date('2025-12-19T19:00:00').getTime(); + const endTime = new Date('2025-12-19T20:00:00').getTime(); + // 日程配置信息 + const event: calendarManager.Event = { + type: calendarManager.EventType.NORMAL, + title: '购物节预热', + startTime: startTime, + endTime: endTime, + isAllDay: false, + reminderTime: [0, 10], + description: '9.9限时秒杀,还有精彩福利', + // 一键服务 + service: { + type: calendarManager.ServiceType.SHOPPING, + uri: 'demo://mobile/player?params=' + } + } + try { + // 创建日历账户 + let data: calendarManager.Calendar | undefined= await calendarMgr?.createCalendar(calendarAccount); + if (!data || data === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to create calendar. data is null.'); + return; + } + // 请确保日历账户创建成功后,再进行相关日程的管理 + // 设置日历配置信息,设置日历账户颜色 + await data.setConfig(config); + // 添加日程 + id = await data.addEvent(event); + hilog.info(DOMAIN, 'testTag',`Succeeded in creating calendar and event, result: ${JSON.stringify(id)}`); + } catch (error) { + hilog.error(DOMAIN, 'testTag', `Failed to create calendar or event. Code: ${error.code}, message: ${error.message}`); + } + } + // [End calendarEventPractice_createShoppingCalendarAndEvent] + + // [Start calendarEventPractice_createRepaymentCalendarAndEvent] + async createRepaymentCalendarAndEvent(): Promise { + // 指定日历账户信息 + const calendarAccount: calendarManager.CalendarAccount = { + name: 'repaymentCalendar', + type: calendarManager.CalendarType.LOCAL, + // 日历账户显示名称:建议使用应用实际名称。 + displayName: '金融理财' + }; + // 日历配置信息 + const config: calendarManager.CalendarConfig = { + // 设置日历账户颜色 + color: '#aabbcc' + }; + const startTime = new Date('2025-10-20T00:00:00').getTime(); + const endTime = new Date('2025-10-20T23:59:59').getTime(); + // 日程配置信息 + const event: calendarManager.Event = { + type: calendarManager.EventType.NORMAL, + title: '还款提醒', + startTime: startTime, + endTime: endTime, + isAllDay: true, + // 全天日程时,提醒时间为0表示当天上午9点提醒 + reminderTime: [0], + description: '本月账单:待还款10989.35元', + // 一键服务 + service: { + type: calendarManager.ServiceType.REPAYMENT, + uri: 'demo://mobile/player?params=' + } + } + try { + // 创建日历账户 + let data: calendarManager.Calendar | undefined= await calendarMgr?.createCalendar(calendarAccount); + if (!data || data === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to create calendar. data is null.'); + return; + } + // 请确保日历账户创建成功后,再进行相关日程的管理 + // 设置日历配置信息,设置日历账户颜色 + await data.setConfig(config); + // 添加日程 + id = await data.addEvent(event); + hilog.info(DOMAIN, 'testTag',`Succeeded in creating calendar and event, result: ${JSON.stringify(id)}`); + } catch (error) { + hilog.error(DOMAIN, 'testTag', `Failed to create calendar or event. Code: ${error.code}, message: ${error.message}`); + } + } + // [End calendarEventPractice_createRepaymentCalendarAndEvent] + + // [Start calendarEventPractice_createClassCalendarAndEvent] + async createClassCalendarAndEvent(): Promise { + // 指定日历账户信息 + const calendarAccount: calendarManager.CalendarAccount = { + name: 'classCalendar', + type: calendarManager.CalendarType.LOCAL, + // 日历账户显示名称:建议使用应用实际名称。 + displayName: '我的课表' + }; + // 日历配置信息 + const config: calendarManager.CalendarConfig = { + // 设置日历账户颜色 + color: '#aabbcc' + }; + const startTime = new Date('2025-11-03T09:00:00').getTime(); + const endTime = new Date('2025-11-03T09:45:00').getTime(); + // 日程配置信息 + const event: calendarManager.Event = { + type: calendarManager.EventType.NORMAL, + title: '语文课', + startTime: startTime, + endTime: endTime, + isAllDay: false, + reminderTime: [0, 10], + description: '语文课上课前准备诗歌朗读', + // 一键服务 + service: { + type: calendarManager.ServiceType.CLASS, + uri: 'demo://mobile/player?params=' + } + } + try { + // 创建日历账户 + let data: calendarManager.Calendar | undefined= await calendarMgr?.createCalendar(calendarAccount); + if (!data || data === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to create calendar. data is null.'); + return; + } + // 请确保日历账户创建成功后,再进行相关日程的管理 + // 设置日历配置信息,设置日历账户颜色 + await data.setConfig(config); + // 添加日程 + id = await data.addEvent(event); + hilog.info(DOMAIN, 'testTag',`Succeeded in creating calendar and event, result: ${JSON.stringify(id)}`); + } catch (error) { + hilog.error(DOMAIN, 'testTag', `Failed to create calendar or event. Code: ${error.code}, message: ${error.message}`); + } + } + // [End calendarEventPractice_createClassCalendarAndEvent] + + // [Start calendarEventPractice_createSportsCalendarAndEvent] + async createSportsCalendarAndEvent(): Promise { + // 指定日历账户信息 + const calendarAccount: calendarManager.CalendarAccount = { + name: 'sportsEventsCalendar', + type: calendarManager.CalendarType.LOCAL, + // 日历账户显示名称:建议使用应用实际名称。 + displayName: '足球比赛' + }; + // 日历配置信息 + const config: calendarManager.CalendarConfig = { + // 设置日历账户颜色 + color: '#aabbcc' + }; + const startTime = new Date('2025-10-19T20:00:00').getTime(); + const endTime = new Date('2025-10-19T21:30:00').getTime(); + // 日程配置信息 + const event: calendarManager.Event = { + type: calendarManager.EventType.NORMAL, + title: '2026年足球联赛', + startTime: startTime, + endTime: endTime, + isAllDay: false, + reminderTime: [0, 10], + description: 'A组 xx队首战', + // 一键服务 + service: { + type: calendarManager.ServiceType.SPORTS_EVENTS, + uri: 'demo://mobile/player?params=' + } + } + try { + // 创建日历账户 + let data: calendarManager.Calendar | undefined= await calendarMgr?.createCalendar(calendarAccount); + if (!data || data === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to create calendar. data is null.'); + return; + } + // 请确保日历账户创建成功后,再进行相关日程的管理 + // 设置日历配置信息,设置日历账户颜色 + await data.setConfig(config); + // 添加日程 + id = await data.addEvent(event); + hilog.info(DOMAIN, 'testTag',`Succeeded in creating calendar and event, result: ${JSON.stringify(id)}`); + } catch (error) { + hilog.error(DOMAIN, 'testTag', `Failed to create calendar or event. Code: ${error.code}, message: ${error.message}`); + } + } + // [End calendarEventPractice_createSportsCalendarAndEvent] + + // [Start calendarEventPractice_createSportsExerciseEvent] + async createSportsExerciseEvent(): Promise { + // 指定日历账户信息 + const calendarAccount: calendarManager.CalendarAccount = { + name: 'sportsExerciseCalendar', + type: calendarManager.CalendarType.LOCAL, + // 日历账户显示名称:建议使用应用实际名称。 + displayName: '运动健康' + }; + // 日历配置信息 + const config: calendarManager.CalendarConfig = { + // 设置日历账户颜色 + color: '#aabbcc' + }; + const startTime = new Date('2025-10-26T10:30:00').getTime(); + const endTime = new Date('2025-10-26T10:45:00').getTime(); + // 日程配置信息 + const event: calendarManager.Event = { + type: calendarManager.EventType.NORMAL, + title: '健身操·15分钟无跑跳燃脂', + startTime: startTime, + endTime: endTime, + isAllDay: false, + reminderTime: [0, 30], + description: '训练日第17天', + // 一键服务 + service: { + type: calendarManager.ServiceType.SPORTS_EXERCISE, + uri: 'demo://mobile/player?params=' + } + } + try { + // 创建日历账户 + let data: calendarManager.Calendar | undefined= await calendarMgr?.createCalendar(calendarAccount); + if (!data || data === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to create calendar. data is null.'); + return; + } + // 请确保日历账户创建成功后,再进行相关日程的管理 + // 设置日历配置信息,设置日历账户颜色 + await data.setConfig(config); + // 添加日程 + id = await data.addEvent(event); + hilog.info(DOMAIN, 'testTag',`Succeeded in creating calendar and event, result: ${JSON.stringify(id)}`); + } catch (error) { + hilog.error(DOMAIN, 'testTag', `Failed to create calendar or event. Code: ${error.code}, message: ${error.message}`); + } + } + // [End calendarEventPractice_createSportsExerciseEvent] + + // [Start calendarEventPractice_createMeetingEvent] + async createMeetingEvent(): Promise { + // 指定日历账户信息 + const calendarAccount: calendarManager.CalendarAccount = { + name: 'meetingCalendar', + type: calendarManager.CalendarType.LOCAL, + // 日历账户显示名称:建议使用应用实际名称。 + displayName: '会议' + }; + // 日历配置信息 + const config: calendarManager.CalendarConfig = { + // 设置日历账户颜色 + color: '#aabbcc' + }; + // 与会人信息 + let attendee: calendarManager.Attendee[] = [ + { + name: 'Chris', + email: 'test1@xx.com', + role: calendarManager.AttendeeRole.ORGANIZER + }, + { + name: 'Jack', + email: 'test2@xx.com', + role: calendarManager.AttendeeRole.PARTICIPANT, + type: calendarManager.AttendeeType.REQUIRED + }, + { + name: 'Jerry', + email: 'test3@xx.com', + role: calendarManager.AttendeeRole.PARTICIPANT, + type: calendarManager.AttendeeType.REQUIRED + } + ]; + const startTime = new Date('2025-10-20T09:00:00').getTime(); + const endTime = new Date('2025-10-20T10:00:00').getTime(); + // 日程配置信息 + const event: calendarManager.Event = { + type: calendarManager.EventType.NORMAL, + title: 'xxx会议', + startTime: startTime, + endTime: endTime, + isAllDay: false, + reminderTime: [0, 15], + attendee: attendee, + description: 'xx事务评审', + // 一键服务 + service: { + type: calendarManager.ServiceType.MEETING, + uri: 'demo://mobile/player?params=' + } + } + try { + // 创建日历账户 + let data: calendarManager.Calendar | undefined= await calendarMgr?.createCalendar(calendarAccount); + if (!data || data === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to create calendar. data is null.'); + return; + } + // 请确保日历账户创建成功后,再进行相关日程的管理 + // 设置日历配置信息,设置日历账户颜色 + await data.setConfig(config); + // 添加日程 + id = await data.addEvent(event); + hilog.info(DOMAIN, 'testTag',`Succeeded in creating calendar and event, result: ${JSON.stringify(id)}`); + } catch (error) { + hilog.error(DOMAIN, 'testTag', `Failed to create calendar or event. Code: ${error.code}, message: ${error.message}`); + } + } + // [End calendarEventPractice_createMeetingEvent] +} \ No newline at end of file diff --git a/Calendar/CalendarEventPractice/entry/src/main/module.json5 b/Calendar/CalendarEventPractice/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a75f024a16812fb57dfb59b2a1ccefd4fa3abe76 --- /dev/null +++ b/Calendar/CalendarEventPractice/entry/src/main/module.json5 @@ -0,0 +1,83 @@ +/* +* 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": [ + "phone", + "tablet", + "2in1" + ], + "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" + } + ], + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.READ_CALENDAR", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "when": "always" + } + }, + { + "name": "ohos.permission.WRITE_CALENDAR", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "when": "always" + } + } + ] + } +} \ No newline at end of file diff --git a/Calendar/CalendarEventPractice/entry/src/main/resources/base/element/color.json b/Calendar/CalendarEventPractice/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/Calendar/CalendarEventPractice/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/Calendar/CalendarEventPractice/entry/src/main/resources/base/element/float.json b/Calendar/CalendarEventPractice/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/Calendar/CalendarEventPractice/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/Calendar/CalendarEventPractice/entry/src/main/resources/base/element/string.json b/Calendar/CalendarEventPractice/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/Calendar/CalendarEventPractice/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": "label" + } + ] +} \ No newline at end of file diff --git a/Calendar/CalendarEventPractice/entry/src/main/resources/base/media/background.png b/Calendar/CalendarEventPractice/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/Calendar/CalendarEventPractice/entry/src/main/resources/base/media/background.png differ diff --git a/Calendar/CalendarEventPractice/entry/src/main/resources/base/media/foreground.png b/Calendar/CalendarEventPractice/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/Calendar/CalendarEventPractice/entry/src/main/resources/base/media/foreground.png differ diff --git a/Calendar/CalendarEventPractice/entry/src/main/resources/base/media/layered_image.json b/Calendar/CalendarEventPractice/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/Calendar/CalendarEventPractice/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/Calendar/CalendarEventPractice/entry/src/main/resources/base/media/startIcon.png b/Calendar/CalendarEventPractice/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/Calendar/CalendarEventPractice/entry/src/main/resources/base/media/startIcon.png differ diff --git a/Calendar/CalendarEventPractice/entry/src/main/resources/base/profile/backup_config.json b/Calendar/CalendarEventPractice/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/Calendar/CalendarEventPractice/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/Calendar/CalendarEventPractice/entry/src/main/resources/base/profile/main_pages.json b/Calendar/CalendarEventPractice/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/Calendar/CalendarEventPractice/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/Calendar/CalendarEventPractice/entry/src/main/resources/dark/element/color.json b/Calendar/CalendarEventPractice/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/Calendar/CalendarEventPractice/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/Calendar/CalendarEventPractice/entry/src/mock/mock-config.json5 b/Calendar/CalendarEventPractice/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d76be296f7f7212ba32b65f80a6d2d2ffec8ecce --- /dev/null +++ b/Calendar/CalendarEventPractice/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/Calendar/CalendarEventPractice/entry/src/ohosTest/ets/test/Ability.test.ets b/Calendar/CalendarEventPractice/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f9e38c836a4c3a9c388e7ef99d226d3c09fb466b --- /dev/null +++ b/Calendar/CalendarEventPractice/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,176 @@ +/* +* 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'; +import { Driver, ON, MatchPattern } from '@ohos.UiTest'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import resourceManager from '@ohos.resourceManager'; +import deviceInfo from '@ohos.deviceInfo'; + +const TAG = '[Sample_CalendarEventPracticeSample]'; +const DOMAIN = 0xF811; +const BUNDLE = 'CalendarEventPracticeSample'; +let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +let manager: resourceManager.ResourceManager; +const driver = Driver.create(); + +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. + abilityDelegator.startAbility({ + bundleName: 'com.sample.calendareventpractice', + abilityName: 'EntryAbility' + }); + }) + 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('CalendarEventPracticeSample_CreateTripCalendarAndEvent', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `CreateTripCalendarAndEvent, begin`); + let btnAccept = await driver.findComponent(ON.text('1,出行服务场景 - 创建日程')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `CreateTripCalendarAndEvent, end`); + done(); + }) + it('CalendarEventPracticeSample_GetTripEvent', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `GetTripEvent, begin`); + let btnAccept = await driver.findComponent(ON.text('1,出行服务场景 - 查询日程')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `GetTripEvent, end`); + done(); + }) + it('CalendarEventPracticeSample_UpdateTripEvent', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `UpdateTripEvent, begin`); + let btnAccept = await driver.findComponent(ON.text('1,出行服务场景 - 更新日程')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `UpdateTripEvent, end`); + done(); + }) + it('CalendarEventPracticeSample_DeleteTripEvent', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `DeleteTripEvent, begin`); + let btnAccept = await driver.findComponent(ON.text('1,出行服务场景 - 删除日程')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `DeleteTripEvent, end`); + done(); + }) + it('CalendarEventPracticeSample_CreateHotelCalendarAndEvent', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `CreateHotelCalendarAndEvent, begin`); + let btnAccept = await driver.findComponent(ON.text('2,酒店住宿场景 - 创建日程')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `CreateHotelCalendarAndEvent, end`); + done(); + }) + it('CalendarEventPracticeSample_CreateLiveCalendarAndEvent', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `CreateLiveCalendarAndEvent, begin`); + let btnAccept = await driver.findComponent(ON.text('3,直播预约场景 - 创建日程')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `CreateLiveCalendarAndEvent, end`); + done(); + }) + it('CalendarEventPracticeSample_CreateShoppingCalendarAndEvent', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `CreateShoppingCalendarAndEvent, begin`); + let btnAccept = await driver.findComponent(ON.text('4,抢购预约场景 - 创建日程')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `CreateShoppingCalendarAndEvent, end`); + done(); + }) + it('CalendarEventPracticeSample_CreateRepaymentCalendarAndEvent', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `CreateRepaymentCalendarAndEvent, begin`); + let btnAccept = await driver.findComponent(ON.text('5,还款提醒场景 - 创建日程')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `CreateRepaymentCalendarAndEvent, end`); + done(); + }) + it('CalendarEventPracticeSample_CreateClassCalendarAndEvent', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `CreateClassCalendarAndEvent, begin`); + let btnAccept = await driver.findComponent(ON.text('6,课程提醒场景 - 创建日程')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `CreateClassCalendarAndEvent, end`); + done(); + }) + it('CalendarEventPracticeSample_CreateSportsCalendarAndEvent', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `CreateSportsCalendarAndEvent, begin`); + let btnAccept = await driver.findComponent(ON.text('7,影音娱乐场景 - 创建日程')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `CreateSportsCalendarAndEvent, end`); + done(); + }) + it('CalendarEventPracticeSample_CreateSportsExerciseEvent', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `CreateSportsExerciseEvent, begin`); + let btnAccept = await driver.findComponent(ON.text('8,运动训练场景 - 创建日程')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `CreateSportsExerciseEvent, end`); + done(); + }) + it('CalendarEventPracticeSample_CreateMeetingEvent', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `CreateMeetingEvent, begin`); + let btnAccept = await driver.findComponent(ON.text('9,会议场景 - 创建日程')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `CreateMeetingEvent, end`); + done(); + }) + }) +} \ No newline at end of file diff --git a/Calendar/CalendarEventPractice/entry/src/ohosTest/ets/test/List.test.ets b/Calendar/CalendarEventPractice/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..2a94e90b4f475cb3ce1237e0c6c637a10af51235 --- /dev/null +++ b/Calendar/CalendarEventPractice/entry/src/ohosTest/ets/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 abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/Calendar/CalendarEventPractice/entry/src/ohosTest/module.json5 b/Calendar/CalendarEventPractice/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..40d0af3f15d64e129c1f8bbe1cdac612440dc851 --- /dev/null +++ b/Calendar/CalendarEventPractice/entry/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* +* 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": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/Calendar/CalendarEventPractice/entry/src/test/List.test.ets b/Calendar/CalendarEventPractice/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3728d4693480fa0b0853121dc892d318a8dd08cf --- /dev/null +++ b/Calendar/CalendarEventPractice/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/Calendar/CalendarEventPractice/entry/src/test/LocalUnit.test.ets b/Calendar/CalendarEventPractice/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..09b5e0b944288ffa51b13b489085e8b2d4455999 --- /dev/null +++ b/Calendar/CalendarEventPractice/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/Calendar/CalendarEventPractice/hvigor/hvigor-config.json5 b/Calendar/CalendarEventPractice/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..295b3094c5e53223db13f12f7e4cd77a36a718a3 --- /dev/null +++ b/Calendar/CalendarEventPractice/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/Calendar/CalendarEventPractice/hvigorfile.ts b/Calendar/CalendarEventPractice/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..4540d29e68aa7e2ee83d7d735dbd11606ae172ca --- /dev/null +++ b/Calendar/CalendarEventPractice/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/Calendar/CalendarEventPractice/oh-package.json5 b/Calendar/CalendarEventPractice/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..26d9e55e3543a38ad2eee882dc8ad91c4a0abc4b --- /dev/null +++ b/Calendar/CalendarEventPractice/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/Calendar/CalendarEventPractice/screenshots/index.png b/Calendar/CalendarEventPractice/screenshots/index.png new file mode 100644 index 0000000000000000000000000000000000000000..9d5f940bbc7103233c637527862e7704921ccffd Binary files /dev/null and b/Calendar/CalendarEventPractice/screenshots/index.png differ diff --git a/Calendar/CalendarManager/.gitignore b/Calendar/CalendarManager/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/Calendar/CalendarManager/.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/Calendar/CalendarManager/AppScope/app.json5 b/Calendar/CalendarManager/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..33bc2c5dad857af3cbfb7073738ca287556afef7 --- /dev/null +++ b/Calendar/CalendarManager/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.sample.calendarmanager", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/Calendar/CalendarManager/AppScope/resources/base/element/string.json b/Calendar/CalendarManager/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b135e9cc2cf901136e5b3a3ab3394c93e8095cd0 --- /dev/null +++ b/Calendar/CalendarManager/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "CalendarManager" + } + ] +} diff --git a/Calendar/CalendarManager/AppScope/resources/base/media/background.png b/Calendar/CalendarManager/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/Calendar/CalendarManager/AppScope/resources/base/media/background.png differ diff --git a/Calendar/CalendarManager/AppScope/resources/base/media/foreground.png b/Calendar/CalendarManager/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/Calendar/CalendarManager/AppScope/resources/base/media/foreground.png differ diff --git a/Calendar/CalendarManager/AppScope/resources/base/media/layered_image.json b/Calendar/CalendarManager/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/Calendar/CalendarManager/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/Calendar/CalendarManager/README.md b/Calendar/CalendarManager/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f59224110e1c42edf812a2001ec41c1a28a66614 --- /dev/null +++ b/Calendar/CalendarManager/README.md @@ -0,0 +1,66 @@ +# CalendarManager + +### 介绍 + +日历账户‌用于存储和管理个人或团队的日程,通过日历账户,用户可以方便地查看、编辑和共享日程信息。 + +日历管理器[CalendarManager](../reference/apis-calendar-kit/js-apis-calendarManager.md#calendarmanager)用于管理日历账户[Calendar](../reference/apis-calendar-kit/js-apis-calendarManager.md#calendar)。日历账户主要包含账户信息[CalendarAccount](../reference/apis-calendar-kit/js-apis-calendarManager.md#calendaraccount)和配置信息[CalendarConfig](../reference/apis-calendar-kit/js-apis-calendarManager.md#calendarconfig)。 + +开发者可以创建属于应用特有的日历账户,还可以对日历账户进行新增、删除、更新和查询。此外,每个日程[Event](../reference/apis-calendar-kit/js-apis-calendarManager.md#event)归属于某一个特定的日历账户,可以通过日历账户对该账户下面的日程进行管理,具体相关指导可见[日程管理](calendarmanager-event-developer.md)。 + +### 效果预览 + +![Index](screenshots/index.png) + +### 使用说明 + +1. 创建日历账户对象。 +2. 设置日历配置信息。 +3. 查询指定日历账户。 +4. 查询默认日历账户。 +5. 查询所有日历账户。 +6. 删除指定日历账户。 + +### 工程目录 + +``` +entry/src/ +|---main +| |---ets +| | |---pages +| | | |---Index.ets // 首页 +|---ohosTest +| |---ets +| | |---tests +| | | |---Ability.test.ets // 自动化测试用例 +``` + +### 相关权限 + +[ohos.permission.READ_CALENDAR](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/permissions-for-all-user#ohospermissionread_calendar) + +[ohos.permission.WRITE_CALENDAR](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/permissions-for-all-user#ohospermissionwrite_calendar) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568、PHONE、Tablet。 + +2.本示例仅支持API20版本SDK,镜像版本号:OpenHarmony 6.0.0.x及之后的版本。 + +3.本示例需要使用DevEco Studio 6.0.0 release (Build Version: 6.0.0.858)才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Calendar/CalendarManager > .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/Calendar/CalendarManager/build-profile.json5 b/Calendar/CalendarManager/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..da0cf6c943d31a5558dd0cda97c213621dc2ddbd --- /dev/null +++ b/Calendar/CalendarManager/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": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "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/Calendar/CalendarManager/code-linter.json5 b/Calendar/CalendarManager/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7f67b9ad794978e0469d9de745934605b23a7cd9 --- /dev/null +++ b/Calendar/CalendarManager/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/Calendar/CalendarManager/entry/.gitignore b/Calendar/CalendarManager/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/Calendar/CalendarManager/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/Calendar/CalendarManager/entry/build-profile.json5 b/Calendar/CalendarManager/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ff78b6612917ebdfca2a27cb9d9432e5dfdc88ac --- /dev/null +++ b/Calendar/CalendarManager/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/Calendar/CalendarManager/entry/hvigorfile.ts b/Calendar/CalendarManager/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..6ef2fb28f052cfaed070b056bd400c6fd48d4814 --- /dev/null +++ b/Calendar/CalendarManager/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/Calendar/CalendarManager/entry/obfuscation-rules.txt b/Calendar/CalendarManager/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/Calendar/CalendarManager/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/Calendar/CalendarManager/entry/oh-package.json5 b/Calendar/CalendarManager/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..95fbdee415709d6dcaa612dae50cf61effc5f99d --- /dev/null +++ b/Calendar/CalendarManager/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/Calendar/CalendarManager/entry/src/main/ets/entryability/EntryAbility.ets b/Calendar/CalendarManager/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..eb5bd0ec7aac63b32e89c428914bd24699e265de --- /dev/null +++ b/Calendar/CalendarManager/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,77 @@ +/* +* 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 calendarData_entryAbilityImport] +import { abilityAccessCtrl, AbilityConstant, common, PermissionRequestResult, Permissions, UIAbility, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { calendarManager } from '@kit.CalendarKit'; +import { window } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +// [End calendarData_entryAbilityImport] + + +// [Start calendarData_entryAbility] +const DOMAIN = 0x0000; + +export let calendarMgr: calendarManager.CalendarManager | null = null; + +export let mContext: common.UIAbilityContext | null = null; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', "Ability onCreate"); + } + + 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, data) => { + 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.'); + }); + mContext = this.context; + const permissions: Permissions[] = ['ohos.permission.READ_CALENDAR', 'ohos.permission.WRITE_CALENDAR']; + let atManager = abilityAccessCtrl.createAtManager(); + atManager.requestPermissionsFromUser(mContext, permissions).then((result: PermissionRequestResult) => { + hilog.info(DOMAIN, 'testTag', 'get Permission success'); + calendarMgr = calendarManager.getCalendarManager(mContext); + }).catch((error: BusinessError) => { + hilog.error(DOMAIN, 'testTag', 'get Permission error, Cause: %{public}s', JSON.stringify(error)); + }) + } + + 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"); + } +} +// [End calendarData_entryAbility] \ No newline at end of file diff --git a/Calendar/CalendarManager/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/Calendar/CalendarManager/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..7eb1afb81759bc5d59117077cb08b938ea66d402 --- /dev/null +++ b/Calendar/CalendarManager/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/Calendar/CalendarManager/entry/src/main/ets/pages/Index.ets b/Calendar/CalendarManager/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..5f3c12d2e0a571d3744cbf6b134ab92d2e86e59d --- /dev/null +++ b/Calendar/CalendarManager/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,207 @@ +/* +* 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 calendarData_indexImport] +import { BusinessError } from '@kit.BasicServicesKit'; +import { calendarMgr } from '../entryability/EntryAbility'; +import { calendarManager } from '@kit.CalendarKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const DOMAIN = 0x0000; + +let calendar: calendarManager.Calendar | undefined = undefined; +// 指定日历账户信息 +const calendarAccount: calendarManager.CalendarAccount = { + // 日历账户名称 + name: 'MyCalendar', + // 日历账户类型 + type: calendarManager.CalendarType.LOCAL, + // 日历账户显示名称,该字段如果不填,创建的日历账户在界面显示为空字符串。 + displayName: 'MyCalendar' +}; +// [End calendarData_indexImport] + +// [Start calendarData_eventParam] +let eventId : number | undefined = undefined; +const date = new Date(); +// [End calendarData_eventParam] + +@Entry +@Component +struct Index { + build() { + Column() { + Row() { + Button('1,创建日历账户对象', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.createCalendar(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('2,设置日历配置信息', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.setConfig(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('3,查询指定日历账户', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.getCalendarByParam(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('4,查询默认日历账户', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.getDefaultCalendar(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('5,查询所有日历账户', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.getAllCalendars(); + }) + .width('100%') + }.padding({ top: 10 }) + + Row() { + Button('6,删除指定日历账户', { type: ButtonType.Normal, stateEffect: true }) + .borderRadius(8) + .backgroundColor(0x317aff) + .onClick(() => { + this.deleteCalendar(); + }) + .width('100%') + }.padding({ top: 10 }) + } + .height('100%') + .width('100%') + } + + // 根据日历账户信息,创建一个日历账户Calendar对象。 + createCalendar() { + // [Start calendarData_createAccount] + // 创建日历账户 + calendarMgr?.createCalendar(calendarAccount).then((data: calendarManager.Calendar) => { + hilog.info(DOMAIN, 'testTag', '%{public}s', `Succeeded in creating calendar data->${JSON.stringify(data)}`); + calendar = data; + // 请确保日历账户创建成功后,再进行后续相关操作 + // ... + }).catch((error: BusinessError) => { + hilog.error(DOMAIN, 'testTag', `Failed to create calendar. Code: ${error.code}, message: ${error.message}`); + }); + // [End calendarData_createAccount] + } + + // 日历账户创建之后,日历账户颜色默认为黑色,不指定日历账户颜色可能导致部分版本/设备深色模式下显示效果不佳。开发者需要调用setConfig()接口设置日历配置信息,包括是否打开日历账户下的日程提醒能力、设置日历账户颜色。 + setConfig() { + // [Start calendarData_setConfig] + const calendarAccounts: calendarManager.CalendarAccount = { + name: 'MyCalendar', + type: calendarManager.CalendarType.LOCAL, + displayName: 'MyCalendar' + }; + // 日历配置信息 + calendarMgr?.getCalendar(calendarAccounts, (err, data) => { + //获取日历账户 + if (err) { + hilog.error(DOMAIN, 'testTag', `Failed to get calendar, Code is ${err.code}, message is ${err.message}`); + } else { + const config: calendarManager.CalendarConfig = { + // 打开日程提醒 + enableReminder: true, + // 设置日历账户颜色 + color: '#aabbcc' + }; + // 设置日历配置信息 + data.setConfig(config).then(() => { + hilog.info(DOMAIN, 'testTag', '%{public}s', `Succeeded in setting config, data->${JSON.stringify(config)}`); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN, 'testTag', `Failed to set config. Code: ${err.code}, message: ${err.message}`); + }) + } + }); + // [End calendarData_setConfig] + } + + // 查询指定日历账户 + getCalendarByParam() { + // [Start calendarData_getAccountByParam] + calendarMgr?.getCalendar(calendarAccount).then((data: calendarManager.Calendar) => { + hilog.info(DOMAIN, 'testTag', '%{public}s', `Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN, 'testTag', `Failed to get calendar. Code: ${err.code}, message: ${err.message}`); + }); + // [End calendarData_getAccountByParam] + } + + // 查询默认日历账户 + getDefaultCalendar() { + // [Start calendarData_getDefaultAccount] + calendarMgr?.getCalendar().then((data: calendarManager.Calendar) => { + hilog.info(DOMAIN, 'testTag', '%{public}s', `Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN, 'testTag', `Failed to get calendar. Code: ${err.code}, message: ${err.message}`); + }); + // [End calendarData_getDefaultAccount] + } + + // 获取当前应用所有创建的日历账户及默认日历账户Calendar对象 + getAllCalendars() { + // [Start calendarData_getAllCalendars] + calendarMgr?.getAllCalendars().then((data: calendarManager.Calendar[]) => { + hilog.info(DOMAIN, 'testTag', '%{public}s', `Succeeded in getting all calendars, data -> ${JSON.stringify(data)}`); + data.forEach((calendar) => { + const account = calendar.getAccount(); + hilog.info(DOMAIN, 'testTag', '%{public}s', `account -> ${JSON.stringify(account)}`); + }) + }).catch((err: BusinessError) => { + hilog.error(DOMAIN, 'testTag', `Failed to get all calendars. Code: ${err.code}, message: ${err.message}`); + }); + // [End calendarData_getAllCalendars] + } + + // 删除指定的日历账户,删除账户后,该账户下的所有日程会全部删除 + deleteCalendar() { + // [Start calendarData_deleteCalendar] + if (!calendar || calendar === null) { + hilog.error(DOMAIN, 'testTag', 'Failed to delete calendar. calendar is null'); + return; + } + calendarMgr?.deleteCalendar(calendar).then(() => { + hilog.info(DOMAIN, 'testTag', '%{public}s', "Succeeded in deleting calendar"); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN, 'testTag', `Failed to delete calendar. Code: ${err.code}, message: ${err.message}`); + }); + // [End calendarData_deleteCalendar] + } +} \ No newline at end of file diff --git a/Calendar/CalendarManager/entry/src/main/module.json5 b/Calendar/CalendarManager/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a75f024a16812fb57dfb59b2a1ccefd4fa3abe76 --- /dev/null +++ b/Calendar/CalendarManager/entry/src/main/module.json5 @@ -0,0 +1,83 @@ +/* +* 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": [ + "phone", + "tablet", + "2in1" + ], + "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" + } + ], + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.READ_CALENDAR", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "when": "always" + } + }, + { + "name": "ohos.permission.WRITE_CALENDAR", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "when": "always" + } + } + ] + } +} \ No newline at end of file diff --git a/Calendar/CalendarManager/entry/src/main/resources/base/element/color.json b/Calendar/CalendarManager/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/Calendar/CalendarManager/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/Calendar/CalendarManager/entry/src/main/resources/base/element/float.json b/Calendar/CalendarManager/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/Calendar/CalendarManager/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/Calendar/CalendarManager/entry/src/main/resources/base/element/string.json b/Calendar/CalendarManager/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/Calendar/CalendarManager/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": "label" + } + ] +} \ No newline at end of file diff --git a/Calendar/CalendarManager/entry/src/main/resources/base/media/background.png b/Calendar/CalendarManager/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/Calendar/CalendarManager/entry/src/main/resources/base/media/background.png differ diff --git a/Calendar/CalendarManager/entry/src/main/resources/base/media/foreground.png b/Calendar/CalendarManager/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/Calendar/CalendarManager/entry/src/main/resources/base/media/foreground.png differ diff --git a/Calendar/CalendarManager/entry/src/main/resources/base/media/layered_image.json b/Calendar/CalendarManager/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/Calendar/CalendarManager/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/Calendar/CalendarManager/entry/src/main/resources/base/media/startIcon.png b/Calendar/CalendarManager/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/Calendar/CalendarManager/entry/src/main/resources/base/media/startIcon.png differ diff --git a/Calendar/CalendarManager/entry/src/main/resources/base/profile/backup_config.json b/Calendar/CalendarManager/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/Calendar/CalendarManager/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/Calendar/CalendarManager/entry/src/main/resources/base/profile/main_pages.json b/Calendar/CalendarManager/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/Calendar/CalendarManager/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/Calendar/CalendarManager/entry/src/main/resources/dark/element/color.json b/Calendar/CalendarManager/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/Calendar/CalendarManager/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/Calendar/CalendarManager/entry/src/mock/mock-config.json5 b/Calendar/CalendarManager/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d76be296f7f7212ba32b65f80a6d2d2ffec8ecce --- /dev/null +++ b/Calendar/CalendarManager/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/Calendar/CalendarManager/entry/src/ohosTest/ets/test/Ability.test.ets b/Calendar/CalendarManager/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..d38023992e8a80c8161bd8e50f8eb043a610ff5d --- /dev/null +++ b/Calendar/CalendarManager/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,116 @@ +/* +* 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'; +import { Driver, ON, MatchPattern } from '@ohos.UiTest'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import resourceManager from '@ohos.resourceManager'; +import deviceInfo from '@ohos.deviceInfo'; + +const TAG = '[Sample_CalendarManagerSample]'; +const DOMAIN = 0xF811; +const BUNDLE = 'CalendarManagerSample'; +let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +let manager: resourceManager.ResourceManager; +const driver = Driver.create(); + +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. + abilityDelegator.startAbility({ + bundleName: 'com.sample.calendarmanager', + abilityName: 'EntryAbility' + }); + }) + 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('CalendarManagerSample_CreateCalendar', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `CreateCalendar, begin`); + let btnAccept = await driver.findComponent(ON.text('1,创建日历账户对象')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `CreateCalendar, end`); + done(); + }) + it('CalendarManagerSample_SetConfig', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `SetConfig, begin`); + let btnAccept = await driver.findComponent(ON.text('2,设置日历配置信息')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `SetConfig, end`); + done(); + }) + it('CalendarManagerSample_GetCalendarByParam', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `GetCalendarByParam, begin`); + let btnAccept = await driver.findComponent(ON.text('3,查询指定日历账户')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `GetCalendarByParam, end`); + done(); + }) + it('CalendarManagerSample_GetDefaultCalendar', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `GetDefaultCalendar, begin`); + let btnAccept = await driver.findComponent(ON.text('4,查询默认日历账户')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `GetDefaultCalendar, end`); + done(); + }) + it('CalendarManagerSample_GetAllCalendars', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `GetAllCalendars, begin`); + let btnAccept = await driver.findComponent(ON.text('5,查询所有日历账户')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `GetAllCalendars, end`); + done(); + }) + it('CalendarManagerSample_DeleteCalendar', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + `DeleteCalendar, begin`); + let btnAccept = await driver.findComponent(ON.text('6,删除指定日历账户')) + if (btnAccept !== undefined) { + await btnAccept.click(); + await driver.delayMs(2000); + } + hilog.info(DOMAIN, TAG, BUNDLE + `DeleteCalendar, end`); + done(); + }) + }) +} \ No newline at end of file diff --git a/Calendar/CalendarManager/entry/src/ohosTest/ets/test/List.test.ets b/Calendar/CalendarManager/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..2a94e90b4f475cb3ce1237e0c6c637a10af51235 --- /dev/null +++ b/Calendar/CalendarManager/entry/src/ohosTest/ets/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 abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/Calendar/CalendarManager/entry/src/ohosTest/module.json5 b/Calendar/CalendarManager/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..40d0af3f15d64e129c1f8bbe1cdac612440dc851 --- /dev/null +++ b/Calendar/CalendarManager/entry/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* +* 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": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/Calendar/CalendarManager/entry/src/test/List.test.ets b/Calendar/CalendarManager/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3728d4693480fa0b0853121dc892d318a8dd08cf --- /dev/null +++ b/Calendar/CalendarManager/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/Calendar/CalendarManager/entry/src/test/LocalUnit.test.ets b/Calendar/CalendarManager/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..09b5e0b944288ffa51b13b489085e8b2d4455999 --- /dev/null +++ b/Calendar/CalendarManager/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/Calendar/CalendarManager/hvigor/hvigor-config.json5 b/Calendar/CalendarManager/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..295b3094c5e53223db13f12f7e4cd77a36a718a3 --- /dev/null +++ b/Calendar/CalendarManager/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/Calendar/CalendarManager/hvigorfile.ts b/Calendar/CalendarManager/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..4540d29e68aa7e2ee83d7d735dbd11606ae172ca --- /dev/null +++ b/Calendar/CalendarManager/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/Calendar/CalendarManager/oh-package.json5 b/Calendar/CalendarManager/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..26d9e55e3543a38ad2eee882dc8ad91c4a0abc4b --- /dev/null +++ b/Calendar/CalendarManager/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/Calendar/CalendarManager/screenshots/index.png b/Calendar/CalendarManager/screenshots/index.png new file mode 100644 index 0000000000000000000000000000000000000000..d9aa4f936dcc1c246e0a5e4452d04dfb912540fa Binary files /dev/null and b/Calendar/CalendarManager/screenshots/index.png differ