diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/.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/AppScope/app.json5 b/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b78b7ab12cab551a4a8f5cec4f87c9985d3ac5e9 --- /dev/null +++ b/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.intentvideodemo", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/AppScope/resources/base/element/string.json b/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..dc0f173c52079df372a8e5e3b0a6698dd946fb16 --- /dev/null +++ b/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "IntentsKitVideoDemo" + } + ] +} diff --git a/AppScope/resources/base/media/background.png b/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AppScope/resources/base/media/background.png differ diff --git a/AppScope/resources/base/media/foreground.png b/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/AppScope/resources/base/media/foreground.png differ diff --git a/AppScope/resources/base/media/layered_image.json b/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..4f9ad6307a2bc56beb6d0fce0a49cbf213b20a74 --- /dev/null +++ b/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,6 @@ +{ + "layered-image": { + "background": "$media:background", + "foreground": "$media:foreground" + } +} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..18795a48d6b12fcdc1aa7bac9a9cb99f83815267 --- /dev/null +++ b/LICENSE @@ -0,0 +1,78 @@ + Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved. + + 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. + +Apache License, Version 2.0 +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: +1.You must give any other recipients of the Work or Derivative Works a copy of this License; and +2.You must cause any modified files to carry prominent notices stating that You changed the files; and +3.You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and +4.If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + +You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/README.en.md b/README.en.md index fc7532b541fe8413ae0132aaab5ad832a6a9b076..3327da0686204fa393ea00779e23452267db9f9f 100644 --- a/README.en.md +++ b/README.en.md @@ -1,36 +1,75 @@ -# IntentsKitVideoContinue +# Intent-Based Video Continuation Recommendation -#### Description -{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} +## Introduction -#### Software Architecture -Software architecture description +- This example is based on the intent framework, using `@kit.IntentsKit` to implement intent sharing and `@kit.AbilityKit`'s `InsightIntentExecutor` to achieve intent invocation. Video continuation is realized based on the parameters passed during intent invocation. -#### Installation +## Preview -1. xxxx -2. xxxx -3. xxxx +| Home page | Playback page |Xiaoyi Card Display Shared Intent | Click the intent card to continue. | +|---------------------------------------------------------|----------------------------------------------------|------------------------------------------|----------------------------------------------------| +| ![show home page](screenshots/device/1.png "show page") | ![video playback](screenshots/device/2.png "video playback") |![Xiao Yi suggests displaying interface 0](screenshots/device/3.png "Xiao Yi suggests displaying interface 0") | ![Intent to call 0 ](screenshots/device/2.png "Intent to call 0 ") | -#### Instructions +Instructions: +1. Click the card for `Demo Video 1 or 2` to enter the video playback page. The playback will automatically trigger the call to the shareIntent() interface. The status of the interface execution will be displayed at the bottom of the video page. +2. Once the system completes processing the shared intent, the shared intent will be displayed within the Xiaoyi suggestion card. +3. Click the corresponding Xiaoyi card to relaunch the sample application and continue playing the video. -1. xxxx -2. xxxx -3. xxxx -#### Contribution +## Project Directory -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request +``` +entry/src/main/ +├──ets +| ├──common/constants +| | └──CommonConstants.ets // Common constants +| └──common/utils +| | ├──FileReader.ets // File reader +| | └──Logger.ets // Logger +| ├──entryability +| | └──EntryAbility.ets // Entry Ability +| ├──insightintents +| | └──IntentExecutorImpl.ets // Intent invocation class +| └──pages +| ├──Index.ets // Home page +| └──PlayPage.ets // Video playback page +└──resources + ├──base + | ├──profile + | | ├──insight_intent.json // Intent registration configuration + | | └──main_pages.json // Application page list + └──rawfile + ├──shareIntent.json // Example intent sharing data + └──video.json // Example video information +``` +## Implementation Details -#### Gitee Feature +The intent sharing source code can be found in the `shareIntent` method in `PlayPage.ets`, and the intent invocation source code is in the `onExecuteInUiAbilityForegroundMode` method in `IntentExecutorImpl.ets`. -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +- **Home Page**: Reads video information from the `video.json` file and generates video cards using `ForEach`. The `onClick` event of the cards triggers a jump to the video playback page via `navPathStack.replacePathByName`. +- **Video Playback Page**: Based on the video ID, the playback progress is retrieved using `videoPreference` preferences, and playback resumes from the specified progress by calling `controller.setCurrentTime`. +- **Intent Sharing**: The `Video` component on the playback page calls the `shareIntent` method during the `onStart` event. Based on the video ID, relevant intent data is filtered from the pre-read `shareIntent.json` data, and the `insightIntent.shareIntent` API is called to share the intent data. +- **Intent Invocation**: In the `onExecuteInUIAbilityForegroundMode` method, an `eventHub.emit` broadcast event is used to pass the `entityId` (video ID) parameter. `Index.ets` listens for the event via `eventHub.on` and triggers a jump to the video playback page via `navPathStack.replacePathByName`. +- For hot starts, parameters are passed to the home page via `eventHub`. For cold starts, the `onCreate` method uses the `localStorage` object to pass specific `want` parameters to the home page. +- This example does not heavily involve business or UI logic for intent invocation. Instead, it passes relevant parameters to the business through different channels, leaving the initiative for page jumps to the business itself. The `onExecuteInUIAbilityForegroundMode` interface also provides a `WindowStage` instance, allowing the use of `windowStage.loadContent` to load specific pages. Applications can choose the appropriate method based on actual needs. + +## Timing interaction diagram + +![Timing interaction diagram](screenshots/timing_diagram.png) + +## Required Permissions + +### Dependencies + +1. This example depends on `@ohos/hvigor-ohos-plugin`. +2. If using a DevEco Studio version newer than the recommended version for this example, update the hvigor plugin version as prompted by DevEco Studio. +3. An internet connection is required to log in to a Huawei account and agree to Xiaoyi Suggestions' user agreement and privacy policy. + +### Constraints + +1. **Testing for intent sharing and invocation cannot be independently completed by developers. Please follow the Intents Kit integration process and submit an acceptance application via email to the Huawei intent framework contact. The contact will assist the developer in completing the testing and acceptance.** +2. This example only runs on standard systems and supports Huawei phones and tablets. +3. HarmonyOS version: HarmonyOS 5.0.5 Release or later. +4. DevEco Studio version: DevEco Studio 5.0.5 Release or later. +5. HarmonyOS SDK version: HarmonyOS 5.0.5 Release SDK or later. \ No newline at end of file diff --git a/README.md b/README.md index ef5d7fe6013d40f8e216bc9469d61ed6014f2444..6142c54c05239aff110244482ee52ee8e71d1a82 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,78 @@ -# IntentsKitVideoContinue +# 基于意图框架习惯推荐常用接续 -#### 介绍 -{**以下是 Gitee 平台说明,您可以替换此简介** -Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 -无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} +## 介绍 -#### 软件架构 -软件架构说明 +- 本示例基于意图框架,使用`@kit.IntentsKit`实现意图共享,使用`@kit.AbilityKit`的`InsightIntentExecutor` + 实现意图调用。根据意图调用的参数实现视频接续。 +## 效果预览 -#### 安装教程 +| 主页 | 播放页 | 小艺卡片展示共享意图 | 点击意图卡片实现接续 | +|----------------------------------|-------------------------------------|------------------------------------------|----------------------------------------------------| +| ![界面展示](screenshots/device/1.png "界面展示") | ![视频播放](screenshots/device/2.png "视频播放") |![小艺建议展示界面0](screenshots/device/3.png "小艺建议展示界面0") | ![意图调用0](screenshots/device/2.png "意图调用0") | -1. xxxx -2. xxxx -3. xxxx +使用说明: +1. 点击`演示视频1或2`的卡片进入视频播放页面。视频播放时会自动触发shareIntent()接口的调用。视频页面底部会显示接口执行状态。 +2. 待系统将共享的意图完成处理后,将会在小艺建议的卡片内展示共享的意图。 +3. 点击展示的对应小艺卡片,会重新拉起示例应用,并进行视频接续播放。 -#### 使用说明 -1. xxxx -2. xxxx -3. xxxx +## 工程目录 -#### 参与贡献 +``` +entry/src/main/ +├──ets +| ├──common/constants +| | └──CommonConstants.ets // 公共常量类 +| └──common/utils +| | ├──FileReader.ets // 文件读取类 +| | └──Logger.ets // 日志类 +| ├──entryability +| | └──EntryAbility.ets // 入口Ability +| ├──insightintents +| | └──IntentExecutorImpl.ets // 意图调用类 +| └──pages +| ├──Index.ets // 首页 +| └──PlayPage.ets // 视频播放页 +└──resources + ├──base + | ├──profile + | | ├──insight_intent.json // 意图注册配置 + | | └──main_pages.json // 应用界面列表 + └──rawfile + ├──shareIntent.json // 意图共享数据示例 + └──video.json // 视频信息示例 +``` -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request +## 具体实现 +意图共享源码参考PlayPage.ets中的shareIntent方法,意图调用源码参考IntentExecutorImpl.ets中的onExecuteInUiAbilityForegroundMode方法 -#### 特技 +* 首页:从video.json文件中读取视频信息,ForEach生成视频卡片,卡片的onClick事件中通过navPathStack.replacePathByName跳转到视频播放页面 +* 视频播放页:视频播放页根据视频id,通过videoPreference首选项查找到视频播放的进度,调用controller.setCurrentTime从指定的进度接续播放 +* 意图共享:视频播放页面的Video组件在onStart事件中调用shareIntent方法,根据视频id,在事先读取的shareIntent.json数据中筛选出相关意图数据,然后调用insightIntent.shareIntent + API实现意图数据共享 +* 意图调用:在onExecuteInUIAbilityForegroundMode方法中,使用eventHub.emit广播事件,传递entityId视频id参数。Index.ets中通过eventHub.on监听事件,通过navPathStack.replacePathByName触发跳转到视频播放页面 +* 意图调用热启动时通过eventHub传递参数给首页,冷启动时通过onCreate方法借助localStorage对象将want特定参数传参给首页 +* 本示例意图调用没有过多介入业务逻辑和UI逻辑,只是通过不同渠道把相关参数传递给业务,将页面跳转主动权交给业务本身。onExecuteInUIAbilityForegroundMode接口也提供了WindowStage实例,可以使用windowStage.loadContent加载特定页面,应用根据实际选择合适的方式。 -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +## 时序交互图 + +![时序图](screenshots/timing_diagram.png) + +## 相关权限 + +### 依赖 + +1. 本示例依赖@ohos/hvigor-ohos-plugin。 +2. 使用DevEco Studio版本大于本示例推荐版本,请根据 DevEco Studio 提示更新 hvigor 插件版本。 +3. 需联网登录华为账号并同意小艺建议的用户协议和隐私政策。 + +### 约束与限制 + +1. **意图共享和意图调用的测试,当前无法由开发者独立完成,请根据Intents + Kit接入流程,通过邮箱向华为意图框架接口人提交验收申请,由接口人配合开发者一同完成测试验收。** +2. 本示例仅支持标准系统上运行,支持设备:华为手机、华为平板。 +3. HarmonyOS系统:HarmonyOS 5.0.5 Release及以上。 +4. DevEco Studio版本:DevEco Studio 5.0.5 Release及以上。 +5. HarmonyOS SDK版本:HarmonyOS 5.0.5 Release SDK及以上。 diff --git a/build-profile.json5 b/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c1ea56bce92419b6cb916a4ad05204cd71f7496e --- /dev/null +++ b/build-profile.json5 @@ -0,0 +1,43 @@ +{ + "app": { + "signingConfigs": [ + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "5.0.5(17)", + "compatibleSdkVersion": "5.0.4(16)", + "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/code-linter.json5 b/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..073990fa45394e1f8e85d85418ee60a8953f9b99 --- /dev/null +++ b/code-linter.json5 @@ -0,0 +1,32 @@ +{ + "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/entry/.gitignore b/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/entry/build-profile.json5 b/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4d611879c7913fb0610c686e2399258ab3a6dad1 --- /dev/null +++ b/entry/build-profile.json5 @@ -0,0 +1,28 @@ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/entry/hvigorfile.ts b/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..60e47e178e9702631eaf537cd83a6c400fbbb2da --- /dev/null +++ b/entry/hvigorfile.ts @@ -0,0 +1,6 @@ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/entry/obfuscation-rules.txt b/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/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/entry/oh-package.json5 b/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..248c3b7541a589682a250f86a6d3ecf7414d2d6a --- /dev/null +++ b/entry/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/entry/src/main/ets/common/constants/CommonConstants.ets b/entry/src/main/ets/common/constants/CommonConstants.ets new file mode 100644 index 0000000000000000000000000000000000000000..367e3da9d929eb6bd3b3fcc88aa498755c491db3 --- /dev/null +++ b/entry/src/main/ets/common/constants/CommonConstants.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default class CommonConstants { + /** + * intent execute event name + */ + static readonly PLAY_VIDEO_EVENT: string = 'playVideoEvent'; + /** + * intent execute event name + */ + static readonly STORAGE_KEY: string = 'entityId'; + /** + * video info list file name + */ + static readonly VIDEO_FILE_NAME: string = 'video.json'; + /** + * share intent list file name + */ + static readonly INTENT_FILE_NAME: string = 'shareIntent.json'; + /** + * navDestination name + */ + static PLAY_PATH_NAME: string = 'PlayPage'; + /** + * share status text label + */ + static SHARE_STATUS_TEXT: string = 'share intent status: '; +} + +export enum ShareStatus { + SHARING = 'sharing', + SUCCEEDED = 'succeeded', + FAILED = 'failed' +} \ No newline at end of file diff --git a/entry/src/main/ets/common/utils/FileReader.ets b/entry/src/main/ets/common/utils/FileReader.ets new file mode 100644 index 0000000000000000000000000000000000000000..f2ee9f9f88caca902941b2f834a694dc2ceb9c1e --- /dev/null +++ b/entry/src/main/ets/common/utils/FileReader.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { fileIo as fs } from '@kit.CoreFileKit'; +import { Logger } from './Logger'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { buffer } from '@kit.ArkTS'; + +export class FileReader { + public static async readJson(context: Context, fileName: string): Promise { + try { + return await FileReader.readContent(context.resourceDir + '/' + fileName).then((content: string) => { + return Promise.resolve(JSON.parse(content)); + }) + } catch (err) { + Logger.error('readJson error', err + ' -> Attempting to read the rawfile folder'); + return FileReader.readRawFileContent(context, fileName); + } + } + + private static readContent(filePath: string): Promise { + return fs.readText(filePath); + } + + private static async readRawFileContent(context: Context, filepath: string): Promise { + return await context.resourceManager.getRawFileContent(filepath).then((data: Uint8Array) => { + return JSON.parse(buffer.from(data.buffer).toString()) as object; + }).catch((err: BusinessError) => { + Logger.error('readJson error', 'rawfile error: ' + err); + return new Object; + }) + } +} diff --git a/entry/src/main/ets/common/utils/Logger.ets b/entry/src/main/ets/common/utils/Logger.ets new file mode 100644 index 0000000000000000000000000000000000000000..964b91eedfd363ba28ded1e02028ee19f03b33d2 --- /dev/null +++ b/entry/src/main/ets/common/utils/Logger.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; + +export class Logger { + private static readonly DOMAIN: number = 0xFF00; + private static readonly TAG: string = 'com.example.intentvideodemo'; + private static readonly PREFIX: string = '[intent-video]'; + + public static debug(logTag: string, messageFormat: string, ...args: Object[]): void { + hilog.debug(Logger.DOMAIN, Logger.TAG, `${Logger.PREFIX} ${logTag}: ${messageFormat}`, args); + } + + public static info(logTag: string, messageFormat: string, ...args: Object[]): void { + hilog.info(Logger.DOMAIN, Logger.TAG, `${Logger.PREFIX} ${logTag}: ${messageFormat}`, args); + } + + public static warn(logTag: string, messageFormat: string, ...args: Object[]): void { + hilog.warn(Logger.DOMAIN, Logger.TAG, `${Logger.PREFIX} ${logTag}: ${messageFormat}`, args); + } + + public static error(logTag: string, messageFormat: string, ...args: Object[]): void { + hilog.error(Logger.DOMAIN, Logger.TAG, `${Logger.PREFIX} ${logTag}: ${messageFormat}`, args); + } + + public static fatal(logTag: string, messageFormat: string, ...args: Object[]): void { + hilog.fatal(Logger.DOMAIN, Logger.TAG, `${Logger.PREFIX} ${logTag}: ${messageFormat}`, args); + } + + private constructor() {} +} diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..16a731885b5b29ce3e3beb52fd83b6fae5db1e96 --- /dev/null +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; +import CommonConstants from '../common/constants/CommonConstants'; + +const DOMAIN = 0x0000; +let para: Record = { 'entityId': '' }; + +export default class EntryAbility extends UIAbility { + storage: LocalStorage = new LocalStorage(para); + + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + if (launchParam.launchReason === AbilityConstant.LaunchReason.INSIGHT_INTENT && want && want.parameters) { + this.storage.setOrCreate(CommonConstants.STORAGE_KEY, + (want.parameters?.['ohos.insightIntent.executeParam.param'] as Record)?.entityId); + } + 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', this.storage, (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..02d1130cbd8f8ba2074d42bc000d9a17f993fb40 --- /dev/null +++ b/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +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/entry/src/main/ets/insightintents/IntentExecutorImpl.ets b/entry/src/main/ets/insightintents/IntentExecutorImpl.ets new file mode 100644 index 0000000000000000000000000000000000000000..613efe857d01c5738ea55923d2936f1d80da50b2 --- /dev/null +++ b/entry/src/main/ets/insightintents/IntentExecutorImpl.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { InsightIntentExecutor, insightIntent } from '@kit.AbilityKit'; +import { window } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; +import CommonConstants from '../common/constants/CommonConstants'; +import { Logger } from '../common/utils/Logger'; + +/** + * Entry for insight intent execution. + */ +export default class IntentExecutorImpl extends InsightIntentExecutor { + /** + * Called when a UIAbility executes the insight intent in the foreground. + * @param { string } intentName - Indicates the insight intent name. + * @param { Record } intentParam - Indicates the insight intent parameters. + * @param { window.WindowStage } pageLoader - Indicates the page loader. + * @returns { Promise } The result of insight intent execution. + */ + async onExecuteInUIAbilityForegroundMode(intentName: string, intentParam: Record, + pageLoader: window.WindowStage): Promise { + Logger.debug('intent executor', `intentName => ${intentName}, intentParam => ${JSON.stringify(intentParam)}`); + const result: insightIntent.ExecuteResult = { + code: 0 + }; + pageLoader.getMainWindow().then((windowClass: window.Window) => { + // emit intent execute event and entityId (video id) + windowClass.getUIContext().getHostContext()?.eventHub.emit(CommonConstants.PLAY_VIDEO_EVENT, intentParam.entityId); + }).catch((err: BusinessError) => { + Logger.error('intent executor', 'Failed to obtain the main window. Cause: ' + JSON.stringify(err)); + }) + return Promise.resolve(result); + } +} \ No newline at end of file diff --git a/entry/src/main/ets/model/DataModel.ets b/entry/src/main/ets/model/DataModel.ets new file mode 100644 index 0000000000000000000000000000000000000000..7a7a1adc982272e1373e63e6d6844ba086ff281b --- /dev/null +++ b/entry/src/main/ets/model/DataModel.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export interface IVideoInfo { + id: string; + displayName: string; + description: string; + fileName: string; + thumbnail: string; +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..fc4dd6182d544ac4df189084bb762c9cff30fd63 --- /dev/null +++ b/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { FileReader } from '../common/utils/FileReader'; +import { common } from '@kit.AbilityKit'; +import CommonConstants from '../common/constants/CommonConstants'; +import { IVideoInfo } from '../model/DataModel'; +import { i18n } from '@kit.LocalizationKit'; + +@Entry +@Component +struct Index { + @State videoList: IVideoInfo[] = []; + private storage: LocalStorage | undefined = this.getUIContext().getSharedLocalStorage(); + private abilityContext: common.UIAbilityContext | undefined = + this.getUIContext().getHostContext() as common.UIAbilityContext; + private navPathStack: NavPathStack = new NavPathStack(); + + async aboutToAppear(): Promise { + // listen intent execute event + this.abilityContext?.eventHub.on(CommonConstants.PLAY_VIDEO_EVENT, (entityId: string) => { + this.gotoPlayVideo(entityId); + }); + // read video.json + this.videoList = + await FileReader.readJson(this.abilityContext as common.UIAbilityContext, + CommonConstants.VIDEO_FILE_NAME) as IVideoInfo[]; + if (this.storage?.get('entityId')) { + this.gotoPlayVideo(this.storage?.get('entityId') as string); + } + } + + aboutToDisappear(): void { + this.abilityContext?.eventHub.off(CommonConstants.PLAY_VIDEO_EVENT); + } + + build() { + Navigation(this.navPathStack) { + Column() { + Text($r('app.string.List_title')) + .fontSize(18) + .lineHeight(24) + .fontWeight(FontWeight.Bold) + .width('100%') + .margin({ bottom: 12 }) + List({ space: 24 }) { + ForEach(this.videoList, (item: IVideoInfo) => { + ListItem() { + this.videoCard(item); + } + }, (item: IVideoInfo) => item.id) + } + .width('100%') + .height("100%") + } + .height('100%') + .width('100%') + .padding({ + left: 16, + right: 16, + top: 24, + bottom: 24 + }) + } + .title({ builder: this.titleBuilder, height: 112 }) + .navBarWidth(300) + } + + @Builder + titleBuilder() { + Column() { + Text($r('app.string.Navbar_title')) + .fontSize(i18n.System.getSystemLanguage() === "en-Latn-US" ? 18 : 30) + .lineHeight(40) + .fontWeight(FontWeight.Bold) + .width("100%") + } + .justifyContent(FlexAlign.Center) + .margin({ + left: 16, + right: 16, + top: 64, + bottom: 8 + }) + .height(40) + } + + @Builder + videoCard(item: IVideoInfo) { + Column() { + Stack() { + Image($r(item.thumbnail)) + .width('100%') + .height(200) + .borderRadius(16) + Row() + .width('100%') + .height(200) + .backgroundColor('rgba(0,0,0,0.15)') + .borderRadius(16) + SymbolGlyph($r('sys.symbol.play_circle')) + .fontSize(48) + .fontColor([Color.White]) + } + .onClick(() => { + this.navPathStack.replacePathByName(CommonConstants.PLAY_PATH_NAME, item); + }) + + Column() { + Text($r(item.displayName)) + .width('100%') + .font({ weight: FontWeight.Medium, size: 16 }) + .lineHeight(21) + .margin({ bottom: 4 }) + Text($r(item.description)) + .width('100%') + .font({ weight: FontWeight.Normal, size: 14 }) + .lineHeight(19) + .fontColor(Color.Gray) + } + .padding({ left: 12, right: 12, top: 12 }) + } + .width('100%') + } + + gotoPlayVideo(entityId: string) { + if (entityId) { + let videoItem = this.videoList.find((item: IVideoInfo) => item.id === entityId); + videoItem && this.navPathStack.replacePathByName(CommonConstants.PLAY_PATH_NAME, videoItem); + } + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/PlayPage.ets b/entry/src/main/ets/pages/PlayPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..9cfaac99ff89734104f5874e9a0c4687d615030a --- /dev/null +++ b/entry/src/main/ets/pages/PlayPage.ets @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { insightIntent } from '@kit.IntentsKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { common } from '@kit.AbilityKit'; +import { IVideoInfo } from '../model/DataModel'; +import CommonConstants, { ShareStatus } from '../common/constants/CommonConstants'; +import { FileReader } from '../common/utils/FileReader'; +import { preferences } from '@kit.ArkData'; +import { Logger } from '../common/utils/Logger'; + +@Builder +export function PlayPageBuilder() { + PlayPage(); +} + +interface ProgressUpdateObject { + time: number; +} + +@Component +export struct PlayPage { + @State shareStatus: ShareStatus = ShareStatus.SHARING; + @State navParam: IVideoInfo | undefined = undefined; + private navPathStack: NavPathStack = new NavPathStack(); + private shareIntentList: insightIntent.InsightIntent[] = []; + private intentItem: insightIntent.InsightIntent | undefined = undefined; + private controller: VideoController = new VideoController(); + private abilityContext: common.Context = this.getUIContext().getHostContext() as common.UIAbilityContext; + private videoPreference: preferences.Preferences | undefined = undefined; + + async aboutToAppear(): Promise { + // read video progress + preferences.getPreferences(this.abilityContext, 'video.data', + (err: BusinessError, data: preferences.Preferences) => { + if (err) { + Logger.error('preference', `getPreferences error. code: ${err.code}, message: ${err.message}`); + return; + } + this.videoPreference = data; + }) + // read shareIntent.json + this.shareIntentList = + await FileReader.readJson(this.abilityContext as common.UIAbilityContext, + CommonConstants.INTENT_FILE_NAME) as insightIntent.InsightIntent[]; + } + + aboutToDisappear(): void { + // save video progress + this.videoPreference?.flush().then(() => { + Logger.info('preference', 'Succeeded in flushing.'); + }).catch((err: BusinessError) => { + Logger.error('preference', `Failed to flush. code: ${err.code}, message: ${err.message}`); + }) + } + + build() { + NavDestination() { + Column() { + Video({ + src: $rawfile(this.navParam?.fileName), + controller: this.controller + }) + .autoPlay(true) + .onPrepared(() => { + this.controller.setCurrentTime(this.getProgress(), SeekMode.Accurate); + }) + .onUpdate((e: ProgressUpdateObject) => { + this.updatePreference(e.time); + }) + .onStart(() => { + this.shareIntent(); + }) + .onFinish(() => { + this.controller.stop(); + }) + .height('90%') + Row() { + Row({ space: 8 }) { + if (this.shareStatus === ShareStatus.SUCCEEDED) { + SymbolGlyph($r('sys.symbol.checkmark_circle')) + .fontSize(22) + .fontColor(['#64bb5c']) + } else { + SymbolGlyph($r('sys.symbol.exclamationmark_circle')) + .fontSize(22) + .fontColor(['#E84026']) + } + Text(CommonConstants.SHARE_STATUS_TEXT + this.shareStatus) + .font({ weight: FontWeight.Normal, size: 14 }) + } + .width('100%') + .height(44) + .justifyContent(FlexAlign.Center) + .backgroundColor('rgb(241,243,245)') + .borderRadius(12) + } + .height('10%') + .width('100%') + .padding({ left: 16, right: 16 }) + } + .height('100%') + .width('100%') + } + .title($r(this.navParam?.displayName)) + .systemTransition(NavigationSystemTransitionType.SLIDE_RIGHT) + .onReady((context: NavDestinationContext) => { + this.navPathStack = context.pathStack; + this.navParam = this.navPathStack.getParamByName(CommonConstants.PLAY_PATH_NAME)?.[0] as IVideoInfo; + }) + } + + /** + * get specify video progress + * @returns progress + */ + getProgress(): number { + return this.videoPreference?.getSync(this.navParam?.id, 0) as number; + } + + /** + * update video progress + * @param time + */ + updatePreference(time: number) { + if (this.videoPreference && this.navParam?.id) { + this.videoPreference.put(this.navParam.id, time || 0).then(() => { + Logger.info('preference', 'put succeeded'); + }).catch((err: BusinessError) => { + Logger.error('preference', `put failed. code: ${err.code}, message: ${err.message}`); + }) + } + } + + /** + * share intent to system + */ + shareIntent() { + if (!this.intentItem && this.navParam?.id) { + this.intentItem = + this.shareIntentList.find((shareObject: insightIntent.InsightIntent) => shareObject.intentEntityInfo.entityId === + this.navParam?.id); + } + if (this.intentItem) { + this.shareStatus = ShareStatus.SHARING; + insightIntent.shareIntent(this.abilityContext, [this.intentItem]).then(() => { + this.shareStatus = ShareStatus.SUCCEEDED; + Logger.info('shareIntent', 'succeeded'); + }).catch((err: BusinessError) => { + this.shareStatus = ShareStatus.FAILED; + Logger.error('shareIntent', `failed code: ${err.code}, message: ${err.message}`); + }) + } + } +} \ No newline at end of file diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..30271c7ee8909708fef6d32e4c1bb9e9dbdc7ec1 --- /dev/null +++ b/entry/src/main/module.json5 @@ -0,0 +1,51 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "routerMap": "$profile:router_map", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/color.json b/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/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/entry/src/main/resources/base/element/float.json b/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..59d56425878e171eb38899dabe8b52e8a6b7693a --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,40 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "Intent video continues" + }, + { + "name": "Navbar_title", + "value": "Intent Suggestion - Continue Video" + }, + { + "name": "List_title", + "value": "Demo video" + }, + { + "name": "List_card_first_title", + "value": "Demo video 1" + }, + { + "name": "List_card_first_desc", + "value": "This is the description information for video 1. " + }, + { + "name": "List_card_second_title", + "value": "Demo video 2" + }, + { + "name": "List_card_second_desc", + "value": "This is the description information for video 2. " + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/media/background.png b/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/entry/src/main/resources/base/media/background.png differ diff --git a/entry/src/main/resources/base/media/foreground.png b/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/entry/src/main/resources/base/media/foreground.png differ diff --git a/entry/src/main/resources/base/media/layered_image.json b/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..4f9ad6307a2bc56beb6d0fce0a49cbf213b20a74 --- /dev/null +++ b/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,6 @@ +{ + "layered-image": { + "background": "$media:background", + "foreground": "$media:foreground" + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/media/startIcon.png b/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/entry/src/main/resources/base/media/startIcon.png differ diff --git a/entry/src/main/resources/base/media/video1.PNG b/entry/src/main/resources/base/media/video1.PNG new file mode 100644 index 0000000000000000000000000000000000000000..45a68d89ce4eabbc1dc9482c88c81d5291aa689a Binary files /dev/null and b/entry/src/main/resources/base/media/video1.PNG differ diff --git a/entry/src/main/resources/base/media/video2.PNG b/entry/src/main/resources/base/media/video2.PNG new file mode 100644 index 0000000000000000000000000000000000000000..13665d2df294887324fc4a590535d4dbbdbfdfa6 Binary files /dev/null and b/entry/src/main/resources/base/media/video2.PNG differ diff --git a/entry/src/main/resources/base/profile/backup_config.json b/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/entry/src/main/resources/base/profile/insight_intent.json b/entry/src/main/resources/base/profile/insight_intent.json new file mode 100644 index 0000000000000000000000000000000000000000..e69a6e34ef3757886d81838741df3d7a5ac111b8 --- /dev/null +++ b/entry/src/main/resources/base/profile/insight_intent.json @@ -0,0 +1,16 @@ +{ + "insightIntents": [ + { + "intentName": "PlayVideo", + "domain": "VideosDomain", + "intentVersion": "1.0.1", + "srcEntry": "./ets/insightintents/IntentExecutorImpl.ets", + "uiAbility": { + "ability": "EntryAbility", + "executeMode": [ + "foreground" + ] + } + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/entry/src/main/resources/base/profile/router_map.json b/entry/src/main/resources/base/profile/router_map.json new file mode 100644 index 0000000000000000000000000000000000000000..6db64e298d101113318b86b556a156936e93d92e --- /dev/null +++ b/entry/src/main/resources/base/profile/router_map.json @@ -0,0 +1,12 @@ +{ + "routerMap": [ + { + "name": "PlayPage", + "pageSourceFile": "src/main/ets/pages/PlayPage.ets", + "buildFunction": "PlayPageBuilder", + "data": { + "description": "this is PlayPage" + } + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/dark/element/color.json b/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/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/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..59d56425878e171eb38899dabe8b52e8a6b7693a --- /dev/null +++ b/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,40 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "Intent video continues" + }, + { + "name": "Navbar_title", + "value": "Intent Suggestion - Continue Video" + }, + { + "name": "List_title", + "value": "Demo video" + }, + { + "name": "List_card_first_title", + "value": "Demo video 1" + }, + { + "name": "List_card_first_desc", + "value": "This is the description information for video 1. " + }, + { + "name": "List_card_second_title", + "value": "Demo video 2" + }, + { + "name": "List_card_second_desc", + "value": "This is the description information for video 2. " + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/rawfile/shareIntent.json b/entry/src/main/resources/rawfile/shareIntent.json new file mode 100644 index 0000000000000000000000000000000000000000..45b5e451ead755af146be4147a6291dbf9ddabea --- /dev/null +++ b/entry/src/main/resources/rawfile/shareIntent.json @@ -0,0 +1,46 @@ +[ + { + "intentName": "PlayVideo", + "intentVersion": "1.0.1", + "identifier": "52dac3b0-6520-4974-81e5-25f0879449b5", + "intentActionInfo": { + "actionMode": "EXECUTED", + "currentSerialNumber": 1, + "currentPercentage": 30, + "executedTimeSlots": { + "executedStartTime": 1747208475000, + "executedEndTime": 1747208475000 + } + }, + "intentEntityInfo": { + "entityName": "Video", + "entityId": "12949589", + "displayName": "演示视频1", + "logoURL": "https://gitee.com/lidan_lidan/screenshots/raw/master/media/video1.PNG", + "videoImage": "https://gitee.com/lidan_lidan/screenshots/raw/master/media/video1.PNG", + "videoName": "演示视频1" + } + }, + { + "intentName": "PlayVideo", + "intentVersion": "1.0.1", + "identifier": "52dac3b0-6520-4974-81e5-25f0879449b6", + "intentActionInfo": { + "actionMode": "EXECUTED", + "currentSerialNumber": 1, + "currentPercentage": 30, + "executedTimeSlots": { + "executedStartTime": 1747208475000, + "executedEndTime": 1747208475000 + } + }, + "intentEntityInfo": { + "entityName": "Video", + "entityId": "12949590", + "displayName": "演示视频2", + "logoURL": "https://gitee.com/lidan_lidan/screenshots/raw/master/media/video2.PNG", + "videoImage": "https://gitee.com/lidan_lidan/screenshots/raw/master/media/video2.PNG", + "videoName": "演示视频2" + } + } +] \ No newline at end of file diff --git a/entry/src/main/resources/rawfile/video.json b/entry/src/main/resources/rawfile/video.json new file mode 100644 index 0000000000000000000000000000000000000000..1722227e0067a5dd32d9b038ceecdadd4e514efb --- /dev/null +++ b/entry/src/main/resources/rawfile/video.json @@ -0,0 +1,16 @@ +[ + { + "id": "12949589", + "displayName": "app.string.List_card_first_title", + "fileName": "video1.mp4", + "description": "app.string.List_card_first_desc", + "thumbnail": "app.media.video1" + }, + { + "id": "12949590", + "displayName": "app.string.List_card_second_title", + "fileName": "video2.mp4", + "description": "app.string.List_card_second_desc", + "thumbnail": "app.media.video2" + } +] \ No newline at end of file diff --git a/entry/src/main/resources/rawfile/video1.mp4 b/entry/src/main/resources/rawfile/video1.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..b529170de5433cb2ec4a9d092d923ffd9e3583a4 Binary files /dev/null and b/entry/src/main/resources/rawfile/video1.mp4 differ diff --git a/entry/src/main/resources/rawfile/video2.mp4 b/entry/src/main/resources/rawfile/video2.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..64282e66d7935fb40243769c1ff14d332811fe3b Binary files /dev/null and b/entry/src/main/resources/rawfile/video2.mp4 differ diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0c3bb31709e8e52d770337542305f661e1c52991 --- /dev/null +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,40 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "意图视频接续" + }, + { + "name": "Navbar_title", + "value": "意图推荐-视频接续" + }, + { + "name": "List_title", + "value": "演示视频" + }, + { + "name": "List_card_first_title", + "value": "演示视频1" + }, + { + "name": "List_card_first_desc", + "value": "这是视频1的描述信息" + }, + { + "name": "List_card_second_title", + "value": "演示视频2" + }, + { + "name": "List_card_second_desc", + "value": "这是视频2的描述信息" + } + ] +} \ No newline at end of file diff --git a/entry/src/mock/mock-config.json5 b/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7a73a41bfdf76d6f793007240d80983a52f15f97 --- /dev/null +++ b/entry/src/mock/mock-config.json5 @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/hvigor/hvigor-config.json5 b/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5bebc9755447385d82ce4138f54d991b1f85f348 --- /dev/null +++ b/hvigor/hvigor-config.json5 @@ -0,0 +1,22 @@ +{ + "modelVersion": "5.0.5", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/hvigorfile.ts b/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..20a8c119149bca149dc03919c5c1c022cd4ff077 --- /dev/null +++ b/hvigorfile.ts @@ -0,0 +1,6 @@ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/oh-package-lock.json5 b/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7fcf818273347b97063c0c0a151bb14770ca1c79 --- /dev/null +++ b/oh-package-lock.json5 @@ -0,0 +1,27 @@ +{ + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0", + "@ohos/hypium@1.0.21": "@ohos/hypium@1.0.21" + }, + "packages": { + "@ohos/hamock@1.0.0": { + "name": "@ohos/hamock", + "version": "1.0.0", + "integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==", + "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hamock/-/hamock-1.0.0.har", + "registryType": "ohpm" + }, + "@ohos/hypium@1.0.21": { + "name": "@ohos/hypium", + "version": "1.0.21", + "integrity": "sha512-iyKGMXxE+9PpCkqEwu0VykN/7hNpb+QOeIuHwkmZnxOpI+dFZt6yhPB7k89EgV1MiSK/ieV/hMjr5Z2mWwRfMQ==", + "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.21.har", + "registryType": "ohpm" + } + } +} \ No newline at end of file diff --git a/oh-package.json5 b/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a8aff0c5aff22d78aa26fd19c3861f4320e951ff --- /dev/null +++ b/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "modelVersion": "5.0.5", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/screenshots/device/1.png b/screenshots/device/1.png new file mode 100644 index 0000000000000000000000000000000000000000..f73ccedb9433b73cf802f56ea8b3185b608ff723 Binary files /dev/null and b/screenshots/device/1.png differ diff --git a/screenshots/device/2.png b/screenshots/device/2.png new file mode 100644 index 0000000000000000000000000000000000000000..c2f4f17b7d13567ce2ea85196e774457002294c7 Binary files /dev/null and b/screenshots/device/2.png differ diff --git a/screenshots/device/3.png b/screenshots/device/3.png new file mode 100644 index 0000000000000000000000000000000000000000..c2160661abbc252d949bdab0be1c5fffccc4ef7c Binary files /dev/null and b/screenshots/device/3.png differ diff --git a/screenshots/timing_diagram.png b/screenshots/timing_diagram.png new file mode 100644 index 0000000000000000000000000000000000000000..bb45b63a70f8278d42c2912bc6b7373f95767fb0 Binary files /dev/null and b/screenshots/timing_diagram.png differ