diff --git a/AppScope/app.json5 b/AppScope/app.json5 index fe0115d15d270c906ed9621b3a5cf939cba0d3be..6b79553936c1be172bbae8bdc57686a1ce305bb7 100644 --- a/AppScope/app.json5 +++ b/AppScope/app.json5 @@ -17,8 +17,8 @@ "app": { "bundleName": "com.samples.picker", "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", + "versionCode": 1000001, + "versionName": "1.0.1", "icon": "$media:app_icon", "label": "$string:app_name" } diff --git a/README.en.md b/README.en.md index 2f5bab850fca1a83c9ec09a04e53ccf9c2144674..2b7edf4ad730cf605e2692b19939197fdb629bce 100644 --- a/README.en.md +++ b/README.en.md @@ -2,7 +2,7 @@ ### Overview -This sample shows how to use the APIs provided by @ohos.file.picker, @ohos.file.photoAccessHelper and @ohos.file.fs to select and save documents, select and view photos in the system album, and select and play videos. +This sample shows how to select and save documents, select and view photos in the system album, and select and play videos. ### Preview @@ -17,24 +17,25 @@ This sample shows how to use the APIs provided by @ohos.file.picker, @ohos.file. 3. On the page for viewing images, the picker displays the images in the system album. You can select a maximum of four images to view. You can tap an image to view the image name and size. 4. On the page for viewing video, the picker displays the videos in the system album. You can select a maximum of four images to view. You can tap a video to view the video name and size. -### Project Directory +### Library Directory ``` ├──entry/src/main/ets/ │ ├──common -│ │ ├──Common.ets -│ │ ├──Constants.ets // Constants -│ │ └──Logger.ets // Logging utility -│ ├──entryability -│ │ └──EntryAbility.ets // Ability +│ │ ├──CommonConstants.ets // Constants +│ │ └──Logger.ets // Logging utility +│ ├──component +│ │ ├──EditFile.ets // Page for viewing and editing a document +│ │ ├──PickerComponent.ets // Home page +│ │ └──ViewMedia.ets // Page for viewing images and videos │ ├──media -│ │ └──MediaFileUri.ets // APIs for media files -│ └──pages -│ ├──EditFile.ets // Page for viewing and editing a document -│ └──Index.ets // Home page -│ └──ViewMedia.ets // Page for viewing images and videos -└──entry/src/main/resources // Static resources of the app - +│ │ └──MediaFileUri.ets // APIs for media files +│ ├──utils +│ │ ├──BreakpointSystem.ets // Breakpoint utils +│ │ ├──StringUtils.ets // String utils +│ │ └──WindowUtil.ets // Window utils +│ └──PickerController.ets // Export utils +└──entry/src/main/resources // Static resources of the app ``` ### How to Implement diff --git a/README.md b/README.md index 1189a0c9cea3164e1162f62d8b297486be15424d..dc8bdb8b715bc3b14d0b94d5a19b9abb376dd39b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ### 介绍 -应用使用@ohos.file.picker、@ohos.file.photoAccessHelper、@ohos.file.fs等接口,实现了拉起文档编辑保存、拉起系统相册图片查看、拉起视频并播放的功能。 +应用实现了拉起文档编辑保存、拉起系统相册图片查看、拉起视频并播放的功能。 ### 效果预览 @@ -19,24 +19,25 @@ 3. 在查看图片界面,拉起系统相册,用户至多可选择四张图片查看,点击图片可以切换所显示的图片名及大小信息。 4. 在查看视频界面,拉起系统相册,用户至多可选择四个视频查看,点击视频播放并且可以显示的视频名及大小信息。 -### 工程目录 +### 库目录 ``` ├──entry/src/main/ets/ │ ├──common -│ │ ├──Common.ets -│ │ ├──Constants.ets // 常量 +│ │ ├──CommonConstants.ets // 常量 │ │ └──Logger.ets // 日志工具 -│ ├──entryability -│ │ └──EntryAbility.ets // ability类 +│ ├──component +│ │ ├──EditFile.ets // 查看并编辑文档界面 +│ │ ├──PickerComponent.ets // 首页 +│ │ └──ViewMedia.ets // 查看图片和视频界面 │ ├──media │ │ └──MediaFileUri.ets // 媒体文件相关函数 -│ └──pages -│ ├──EditFile.ets // 查看并编辑文档界面 -│ ├──Index.ets // 首页 -│ └──ViewMedia.ets // 查看图片和视频界面 -└──entry/src/main/resources // 应用静态资源目录 - +│ ├──utils +│ │ ├──BreakpointSystem.ets // 断点工具 +│ │ ├──StringUtils.ets // 字符串工具 +│ │ └──WindowUtil.ets // 窗口工具 +│ └──PickerController.ets // 导出工具类 +└──entry/src/main/resources // 应用静态资源目录 ``` ### 具体实现 diff --git a/pickerlibrary/.gitignore b/pickerlibrary/.gitignore deleted file mode 100644 index e2713a2779c5a3e0eb879efe6115455592caeea5..0000000000000000000000000000000000000000 --- a/pickerlibrary/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/pickerlibrary/CHANGELOG.md b/pickerlibrary/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..b99e6b459c6f388a83104a0c32f4c4cdcb4fbc22 --- /dev/null +++ b/pickerlibrary/CHANGELOG.md @@ -0,0 +1,6 @@ +# 版本记录 +## 1.0.0(2025.07.11) + +--- +### Initial +- 初始版本 \ No newline at end of file diff --git a/pickerlibrary/Index.ets b/pickerlibrary/Index.ets index 6bea31dcb4ba03b9ea29e5d3895934a931cafa55..fc5106f34a33012b45a0513e5b64a6093b61f792 100644 --- a/pickerlibrary/Index.ets +++ b/pickerlibrary/Index.ets @@ -1,3 +1,2 @@ -export { PickerPage } from './src/main/ets/pages/PickerPage' -export { WindowUtil } from './src/main/ets/utils/WindowUtil' -export { Logger } from './src/main/ets/common/Logger' +export { PickerComponent } from './src/main/ets/component/PickerComponent'; +export { PickerController } from './src/main/ets/PickerController'; \ No newline at end of file diff --git a/pickerlibrary/LICENSE b/pickerlibrary/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..daeafe2766b25138cf257ffb195f956a5b957e43 --- /dev/null +++ b/pickerlibrary/LICENSE @@ -0,0 +1,78 @@ + Copyright (c) 2024 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/pickerlibrary/README.md b/pickerlibrary/README.md new file mode 100644 index 0000000000000000000000000000000000000000..916a57e8ad2ad505752b1a79d9a154d872a60fb7 --- /dev/null +++ b/pickerlibrary/README.md @@ -0,0 +1,50 @@ +## 实现选择和查看文件功能 + +### 介绍 + +应用实现了拉起文档编辑保存、拉起系统相册图片查看、拉起视频并播放的功能。 + +### 下载安装 + +使用ohpm安装依赖 + +``` +ohpm install @ohos_samples/pickerlibrary +``` + +或者按需在模块中修改oh-package.json5 + +``` +{ + "dependencies": { + "@ohos_samples/pickerlibrary": "^1.0.0" + } +} +``` + +### 使用说明 + +``` +import { PickerComponent } from '@ohos_samples/pickerlibrary'; +``` +按需在文件中使用导出模块即可,其中PickerComponent是整个sample的入口页面。示例如下: +``` +// Index.ets +import { PickerComponent } from '@ohos_samples/pickerlibrary'; +Stack() { + PickerComponent() +} + +// EntryAbility.ets +import { PickerController } from '@ohos_samples/pickerlibrary'; + +onWindowStageCreate(windowStage: window.WindowStage): void { + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', `Failed to load the content, err code: ${err.code}, message: ${err.message}`); + return; + } + PickerController.initWindowConfig(windowStage); + }); +} +``` \ No newline at end of file diff --git a/pickerlibrary/oh-package.json5 b/pickerlibrary/oh-package.json5 index cfb28c865aa85997cc1331d3bc4a4b2410e457ef..38dcbcd1f502f59a6ab397cfff934e2ea6fe7634 100644 --- a/pickerlibrary/oh-package.json5 +++ b/pickerlibrary/oh-package.json5 @@ -1,9 +1,10 @@ { - "name": "pickerlibrary", + "name": "@ohos_samples/pickerlibrary", "version": "1.0.0", - "description": "Please describe the basic information.", + "description": "This sample shows how to use the APIs provided by @ohos.file.picker, @ohos.file.photoAccessHelper and @ohos.file.fs to select and save documents, select and view photos in the system album, and select and play videos.", "main": "Index.ets", - "author": "", + "author": "@ohos_samples", "license": "Apache-2.0", + "repository": "https://gitee.com/harmonyos_samples/picker/tree/br_release_hmos", "dependencies": {} } diff --git a/pickersample/oh_modules/pickerlibrary/src/main/ets/common/Common.ets b/pickerlibrary/src/main/ets/PickerController.ets similarity index 53% rename from pickersample/oh_modules/pickerlibrary/src/main/ets/common/Common.ets rename to pickerlibrary/src/main/ets/PickerController.ets index 57a4bd3eee23c771bf5ac8d6539cd875d269a1b5..a58ceafc2ced37eb0aacb842683ea3c30b079e0f 100644 --- a/pickersample/oh_modules/pickerlibrary/src/main/ets/common/Common.ets +++ b/pickerlibrary/src/main/ets/PickerController.ets @@ -1,24 +1,23 @@ -/* - * 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 { util } from '@kit.ArkTS'; - -export function bufferToString(buffer: ArrayBuffer): string { - let textDecoder = util.TextDecoder.create('utf-8', { ignoreBOM: true }) - let resultPut = textDecoder.decodeToString(new Uint8Array(buffer), { - stream: true - }); - return resultPut; +/* + * 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 { window } from '@kit.ArkUI'; +import { WindowUtil } from './utils/WindowUtil'; + +export class PickerController { + public static initWindowConfig(windowStage: window.WindowStage): void { + WindowUtil.initialize(windowStage); + } } \ No newline at end of file diff --git a/pickerlibrary/src/main/ets/common/Constants.ets b/pickerlibrary/src/main/ets/common/CommonConstants.ets similarity index 52% rename from pickerlibrary/src/main/ets/common/Constants.ets rename to pickerlibrary/src/main/ets/common/CommonConstants.ets index bd3af91b3a4fc622fb1d7850048fc40738cb9b69..00bf9446f993238b15c8c7a432961f4fd8ba8c35 100644 --- a/pickerlibrary/src/main/ets/common/Constants.ets +++ b/pickerlibrary/src/main/ets/common/CommonConstants.ets @@ -13,74 +13,105 @@ * limitations under the License. */ -export class Constants { +export class CommonConstants { /** * The full percentage of component. */ public static readonly FULL_PERCENT: string = '100%'; - /** * Forty-five percent. */ public static readonly FORTY_FIVE_PERCENT: string = '45%'; - /** * Padding top. */ public static readonly PADDING_TOP: string = '4%'; - /** * 1.5%. */ public static readonly ONE_POINT_FIVE_PERCENT: string = '1.5%'; - /** * Margin 0.5%. */ public static readonly MARGIN_ZERO_POINT_FIVE_PERCENT: string = '0.5%'; - /** * Margin top. */ public static readonly MARGIN_TOP: string = '0.4%'; - /** * Margin 0.3%. */ public static readonly MARGIN_ZERO_POINT_THREE_PERCENT: string = '0.3%'; - /** * Text fontWight. */ public static readonly TEXT_FONT_WIGHT: number = 700; - /** * Text lineHeight. */ public static readonly TEXT_LINE_HEIGHT: number = 28; - /** * Text lineHeight 19. */ public static readonly TEXT_LINE_HEIGHT_19: number = 19; - /** * Text fontWight 400. */ public static readonly TEXT_FONT_WIGHT_400: number = 400; - /** * Text opacity. */ public static readonly TEXT_OPACITY: number = 0.6; - /** * TextArea placeholder. */ public static readonly TEXT_AREA_PLACEHOLDER: string = 'Input text here...'; - /** - * Breakpoint sm. + * The prefix of app store key. + */ + public static readonly PREFIX: string = 'picker_'; + /** + * The key of break point. + */ + public static readonly AS_KEY_BREAK_POINT: string = `${CommonConstants.PREFIX}currentBreakpoint`; + /** + * The key of status bar height. + */ + public static readonly AS_KEY_STATUS_BAR_HEIGHT: string = `${CommonConstants.PREFIX}statusBarHeight`; + /** + * The key of navigator bar height. + */ + public static readonly AS_KEY_NAVIGATOR_BAR_HEIGHT: string = `${CommonConstants.PREFIX}navigatorBarHeight`; + /** + * The key of path stack. + */ + public static readonly AS_KEY_PATH_STACK: string = `${CommonConstants.PREFIX}pathStack`; + /** + * The key of file name list. + */ + public static readonly AS_KEY_FILE_NAME_LIST: string = `${CommonConstants.PREFIX}fileNameList`; + /** + * The key of file uri list. + */ + public static readonly AS_KEY_FILE_URI_LIST: string = `${CommonConstants.PREFIX}fileUriList`; + /** + * The key of file size list. + */ + public static readonly AS_KEY_FILE_SIZE_LIST: string = `${CommonConstants.PREFIX}fileSizeList`; + /** + * The key of editable. + */ + public static readonly AS_KEY_EDITABLE: string = `${CommonConstants.PREFIX}editable`; + /** + * The key of my file name. + */ + public static readonly AS_KEY_MY_FILE_NAME: string = `${CommonConstants.PREFIX}myFileName`; + /** + * The key of my file size. + */ + public static readonly AS_KEY_MY_FILE_SIZE: string = `${CommonConstants.PREFIX}myFileSize`; + /** + * The key of my file content. */ - public static readonly BREAK_POINT_SM: string = 'sm'; + public static readonly AS_KEY_MY_FILE_CONTENT: string = `${CommonConstants.PREFIX}myFileContent`; } diff --git a/pickersample/oh_modules/pickerlibrary/src/main/ets/pages/EditFile.ets b/pickerlibrary/src/main/ets/component/EditFile.ets similarity index 76% rename from pickersample/oh_modules/pickerlibrary/src/main/ets/pages/EditFile.ets rename to pickerlibrary/src/main/ets/component/EditFile.ets index 81144168bf1883447d4827b383b2f7ee38ee28e5..2d9c3221d1bc8e86c6cad69ce7c6736acb95bc64 100644 --- a/pickersample/oh_modules/pickerlibrary/src/main/ets/pages/EditFile.ets +++ b/pickerlibrary/src/main/ets/component/EditFile.ets @@ -13,25 +13,22 @@ * limitations under the License. */ -import { promptAction } from '@kit.ArkUI'; -import { fileIo, picker } from '@kit.CoreFileKit'; import { BusinessError } from '@kit.BasicServicesKit'; -import MediaFileUri from '../media/MediaFileUri'; +import { fileIo, picker } from '@kit.CoreFileKit'; +import { BreakpointType, BreakpointTypeEnum } from '../utils/BreakpointSystem'; +import { CommonConstants } from '../common/CommonConstants'; +import { FileParam } from './PickerComponent'; import Logger from '../common/Logger'; -import { Constants } from '../common/Constants'; -import { BreakpointType } from '../utils/BreakpointSystem'; -import { FileParam } from './PickerPage'; +import MediaFileUri from '../media/MediaFileUri'; const TAG = 'EditFile: '; -let storage = LocalStorage.getShared(); const OPACITY_VALUE = 0.6; @Builder export function EditFileBuilder(name: string, params: FileParam) { - EditFile({ params }); + EditFile(); } -@Entry(storage) @Component struct EditFile { @LocalStorageLink('loadFlag') loadFlag: Boolean = false; @@ -39,23 +36,22 @@ struct EditFile { @LocalStorageLink('loadFileName') loadFileName: string = ''; @LocalStorageLink('loadFileContent') loadFileContent: string = ''; @LocalStorageLink('loadUri') loadUri: string = ''; - @StorageLink('editable') editable: Boolean = false; - @StorageLink('myFileSize') myFileSize: number = 0; - @StorageLink('myFileContent') myFileContent: string = ''; + @StorageLink(CommonConstants.AS_KEY_EDITABLE) editable: Boolean = false; + @StorageLink(CommonConstants.AS_KEY_MY_FILE_SIZE) myFileSize: number = 0; + @StorageLink(CommonConstants.AS_KEY_MY_FILE_CONTENT) myFileContent: string = ''; @State myUri: string = ''; + @State myFileName: string = ''; @State opacityValue: number = OPACITY_VALUE; @State uriSave: string = ''; - @State myFileName: string = ''; - @StorageProp('bottomRectHeight') bottomRectHeight: number = 0; - @StorageProp('topRectHeight') topRectHeight: number = 0; - @StorageProp('currentBreakpoint') curBp: string = Constants.BREAK_POINT_SM; + @StorageProp(CommonConstants.AS_KEY_NAVIGATOR_BAR_HEIGHT) navigatorBarHeight: number = 0; + @StorageProp(CommonConstants.AS_KEY_STATUS_BAR_HEIGHT) statusBarHeight: number = 0; + @StorageProp(CommonConstants.AS_KEY_BREAK_POINT) curBp: string = BreakpointTypeEnum.SM; public fileContentFlag: boolean = false; newFileContent: string = ''; scroller: Scroller = new Scroller(); controller: TextAreaController = new TextAreaController(); mediaFileUri: MediaFileUri = new MediaFileUri(); - @Consume('pathStack') pageStack: NavPathStack; - params?: FileParam + @Consume(CommonConstants.AS_KEY_PATH_STACK) pageStack: NavPathStack; getFileInfo(): void { if (this.loadFlag) { @@ -65,14 +61,19 @@ struct EditFile { this.myUri = this.loadUri; Logger.info(TAG, 'Successfully obtained the name, content and size of the load file.'); } else { - this.myUri = this.params?.myUri || ''; - this.myFileName = this.params?.fileName || ''; + if (this.pageStack.getParamByName('EditFile').length === 0) { + return; + } + let fileParam = this.pageStack.getParamByName('EditFile')[0] as FileParam; + this.myUri = fileParam.myUri; + this.myFileName = fileParam.fileName; this.myFileContent = this.mediaFileUri.readFileContent(this.myUri); this.myFileSize = this.mediaFileUri.myGetFileSize(this.myUri, fileIo.OpenMode.READ_ONLY); Logger.info(TAG, 'Successfully obtained the name, content and size of the file.') } - AppStorage.setOrCreate('myFileContent', this.myFileContent); - AppStorage.setOrCreate('myFileSize', this.myFileSize); + AppStorage.setOrCreate(CommonConstants.AS_KEY_MY_FILE_CONTENT, this.myFileContent); + AppStorage.setOrCreate(CommonConstants.AS_KEY_MY_FILE_SIZE, this.myFileSize); + console.log('editable===' + this.editable); } async writeContentForSaveAsFile(myUri: string, wrFlag: Boolean = false): Promise { @@ -125,7 +126,7 @@ struct EditFile { .margin({ right: $r('sys.float.padding_level4') }) .backgroundColor($r('sys.color.comp_background_tertiary')) .onClick(() => { - this.pageStack.pop() + this.pageStack.pop(); }) // File name and information. @@ -138,34 +139,34 @@ struct EditFile { .fontFamily('HarmonyHeiTi-Bold') .fontColor($r('sys.color.font_primary')) .textAlign(TextAlign.Start) - .fontWeight(Constants.TEXT_FONT_WIGHT) - .lineHeight(Constants.TEXT_LINE_HEIGHT) + .fontWeight(CommonConstants.TEXT_FONT_WIGHT) + .lineHeight(CommonConstants.TEXT_LINE_HEIGHT) .maxLines(1) .textOverflow({ overflow: TextOverflow.Ellipsis }) } - .width(Constants.FULL_PERCENT) + .width(CommonConstants.FULL_PERCENT) .align(Alignment.Start) .margin({ - top: Constants.MARGIN_TOP, - bottom: Constants.MARGIN_ZERO_POINT_THREE_PERCENT + top: CommonConstants.MARGIN_TOP, + bottom: CommonConstants.MARGIN_ZERO_POINT_THREE_PERCENT }) Row() { Text('size: ' + JSON.stringify(this.myFileSize) + 'B') .focusable(true) .focusOnTouch(true) - .opacity(Constants.TEXT_OPACITY) + .opacity(CommonConstants.TEXT_OPACITY) .fontFamily('HarmonyHeiTi') .fontSize($r('app.float.text_font_size_14')) .fontColor($r('sys.color.font_primary')) .textAlign(TextAlign.Start) - .lineHeight(Constants.TEXT_LINE_HEIGHT_19) - .fontWeight(Constants.TEXT_FONT_WIGHT_400) + .lineHeight(CommonConstants.TEXT_LINE_HEIGHT_19) + .fontWeight(CommonConstants.TEXT_FONT_WIGHT_400) } - .width(Constants.FULL_PERCENT) + .width(CommonConstants.FULL_PERCENT) .margin({ - top: Constants.MARGIN_ZERO_POINT_THREE_PERCENT, - bottom: Constants.MARGIN_ZERO_POINT_FIVE_PERCENT + top: CommonConstants.MARGIN_ZERO_POINT_THREE_PERCENT, + bottom: CommonConstants.MARGIN_ZERO_POINT_FIVE_PERCENT }) .align(Alignment.Start) } @@ -183,7 +184,8 @@ struct EditFile { .id('saveAs') .margin({ right: new BreakpointType({ - sm: $r('sys.float.padding_level4'), md: $r('sys.float.padding_level6'), + sm: $r('sys.float.padding_level4'), + md: $r('sys.float.padding_level6'), lg: $r('sys.float.padding_level8') }).getValue(this.curBp) }) @@ -205,7 +207,8 @@ struct EditFile { .id('editable') .margin({ right: new BreakpointType({ - sm: $r('sys.float.padding_level4'), md: $r('sys.float.padding_level6'), + sm: $r('sys.float.padding_level4'), + md: $r('sys.float.padding_level6'), lg: $r('sys.float.padding_level8') }).getValue(this.curBp) }) @@ -214,9 +217,9 @@ struct EditFile { .backgroundColor($r('sys.color.comp_background_tertiary')) .onClick(() => { this.editable = true; - AppStorage.setOrCreate('editable', this.editable); + AppStorage.setOrCreate(CommonConstants.AS_KEY_EDITABLE, this.editable); this.controller.caretPosition(this.myFileContent.length); - promptAction.showToast({ message: $r('app.string.editable') }); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.editable') }); }) Button({ type: ButtonType.Circle }) { @@ -234,7 +237,7 @@ struct EditFile { if (this.fileContentFlag) { let flage: boolean = true; this.myFileContent = this.newFileContent; - AppStorage.setOrCreate('myFileContent', this.myFileContent); + AppStorage.setOrCreate(CommonConstants.AS_KEY_MY_FILE_CONTENT, this.myFileContent); Logger.info(TAG, 'save onClick myFileContent succeed.'); if (this.loadFlag) { let file = fileIo.openSync(this.loadUri, @@ -243,7 +246,7 @@ struct EditFile { fileIo.write(file.fd, this.myFileContent).then(() => { Logger.info(TAG, 'write data to file succeed.'); this.myFileSize = fileIo.statSync(file.fd).size; - AppStorage.setOrCreate('myFileSize', this.myFileSize); + AppStorage.setOrCreate(CommonConstants.AS_KEY_MY_FILE_SIZE, this.myFileSize); Logger.info(TAG, 'save onClick fileSize succeed.'); }).catch((err: BusinessError) => { Logger.error(TAG, `write data to file failed, ErrorCode: ${err.code}, Message: ${err.message}`); @@ -254,12 +257,12 @@ struct EditFile { let file = fileIo.openSync(this.myUri, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.TRUNC); fileIo.write(file.fd, this.myFileContent).then(() => { this.myFileSize = fileIo.statSync(file.fd).size; - AppStorage.setOrCreate('myFileSize', this.myFileSize); + AppStorage.setOrCreate(CommonConstants.AS_KEY_MY_FILE_SIZE, this.myFileSize); Logger.info(TAG, 'write data to file succeed.'); }).catch((err: BusinessError) => { flage = false; Logger.error(TAG, `save data to file failed ErrorCode: ${err.code}, Message: ${err.message}`); - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.show_toast_message'), duration: 6500 }) @@ -269,8 +272,8 @@ struct EditFile { } if (flage) { this.editable = false; - AppStorage.setOrCreate('editable', this.editable); - promptAction.showToast({ message: $r('app.string.saved') }); + AppStorage.setOrCreate(CommonConstants.AS_KEY_EDITABLE, this.editable); + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.saved') }); } } }) @@ -280,15 +283,17 @@ struct EditFile { } .padding({ left: new BreakpointType({ - sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level12'), + sm: $r('sys.float.padding_level8'), + md: $r('sys.float.padding_level12'), lg: $r('sys.float.padding_level16') }).getValue(this.curBp), right: new BreakpointType({ - sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level12'), + sm: $r('sys.float.padding_level8'), + md: $r('sys.float.padding_level12'), lg: $r('sys.float.padding_level16') }).getValue(this.curBp) }) - .width(Constants.FULL_PERCENT) + .width(CommonConstants.FULL_PERCENT) .height(56) .zIndex(2) @@ -297,14 +302,14 @@ struct EditFile { Row() { TextArea({ text: this.newFileContent ? this.newFileContent : this.myFileContent, - placeholder: Constants.TEXT_AREA_PLACEHOLDER, + placeholder: CommonConstants.TEXT_AREA_PLACEHOLDER, controller: this.controller }) .id('textArea') .fontSize($r('app.float.text_area_font_size')) .fontColor($r('sys.color.font_primary')) .opacity(this.opacityValue) - .fontWeight(Constants.TEXT_FONT_WIGHT_400) + .fontWeight(CommonConstants.TEXT_FONT_WIGHT_400) .align(Alignment.TopStart) .textAlign(TextAlign.Start) .backgroundColor($r('sys.color.gray_01')) @@ -330,22 +335,22 @@ struct EditFile { }) } .padding({ - top: Constants.PADDING_TOP, + top: CommonConstants.PADDING_TOP, left: 16, right: 16 }) } - .padding({ bottom: this.bottomRectHeight }) + .padding({ bottom: this.navigatorBarHeight }) } .align(Alignment.Start) .layoutWeight(1) } .backgroundColor($r('sys.color.gray_01')) - .height(Constants.FULL_PERCENT) - .padding({ top: this.topRectHeight }) + .height(CommonConstants.FULL_PERCENT) + .padding({ top: this.statusBarHeight }) } .hideTitleBar(true) - .onWillShow(()=>{ + .onAppear(() => { this.getFileInfo(); this.editable = false; }) diff --git a/pickersample/oh_modules/pickerlibrary/src/main/ets/pages/PickerPage.ets b/pickerlibrary/src/main/ets/component/PickerComponent.ets similarity index 81% rename from pickersample/oh_modules/pickerlibrary/src/main/ets/pages/PickerPage.ets rename to pickerlibrary/src/main/ets/component/PickerComponent.ets index 9899cbb36b90cd7ddcc300511274cd61234c811e..cba2ebe16c17db01baf91ab041c087cc42ace852 100644 --- a/pickersample/oh_modules/pickerlibrary/src/main/ets/pages/PickerPage.ets +++ b/pickerlibrary/src/main/ets/component/PickerComponent.ets @@ -13,18 +13,18 @@ * limitations under the License. */ -import { picker } from '@kit.CoreFileKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { photoAccessHelper } from '@kit.MediaLibraryKit'; +import { picker } from '@kit.CoreFileKit'; +import { BreakpointType, BreakpointTypeEnum } from '../utils/BreakpointSystem'; +import { CommonConstants } from '../common/CommonConstants'; import Logger from '../common/Logger'; import MediaFileUri from '../media/MediaFileUri'; -import { Constants } from '../common/Constants'; -import { BreakpointType } from '../utils/BreakpointSystem'; const MAX_SELECT_NUM = 4; // Select the maximum number of media files. const TAG = 'pickerIndex'; -export interface UrisParam { +export interface UrisParam { uris: string[]; } @@ -34,16 +34,16 @@ export interface FileParam { } @Component -export struct PickerPage { +export struct PickerComponent { @State uri: string = 'Hello World'; @State filename: string = ''; - @StorageProp('bottomRectHeight') bottomRectHeight: number = 0; - @StorageProp('topRectHeight') topRectHeight: number = 0; - @StorageProp('currentBreakpoint') curBp: string = Constants.BREAK_POINT_SM; - @StorageLink('fileSizeList') fileSizeList: Array = []; - @StorageLink('fileNameList') fileNameList: Array = []; - @StorageLink('fileUriList') fileUriList: Array = []; - @Provide('pathStack') pathStack: NavPathStack = new NavPathStack(); + @StorageProp(CommonConstants.AS_KEY_NAVIGATOR_BAR_HEIGHT) navigatorBarHeight: number = 0; + @StorageProp(CommonConstants.AS_KEY_STATUS_BAR_HEIGHT) statusBarHeight: number = 0; + @StorageProp(CommonConstants.AS_KEY_BREAK_POINT) curBp: string = BreakpointTypeEnum.SM; + @StorageLink(CommonConstants.AS_KEY_FILE_NAME_LIST) fileNameList: Array = []; + @StorageLink(CommonConstants.AS_KEY_FILE_SIZE_LIST) fileSizeList: Array = []; + @StorageLink(CommonConstants.AS_KEY_FILE_URI_LIST) fileUriList: Array = []; + @Provide(CommonConstants.AS_KEY_PATH_STACK) pathStack: NavPathStack = new NavPathStack(); mediaFileUri: MediaFileUri = new MediaFileUri(); scroller: Scroller = new Scroller(); @@ -193,38 +193,42 @@ export struct PickerPage { this.callFilePickerSelectFile(); }) } - .height(Constants.FULL_PERCENT) - .width(Constants.FULL_PERCENT) + .height(CommonConstants.FULL_PERCENT) + .width(CommonConstants.FULL_PERCENT) .justifyContent(FlexAlign.End) .padding({ + top: this.statusBarHeight, + bottom: this.navigatorBarHeight, right: new BreakpointType({ - sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level0'), + sm: $r('sys.float.padding_level8'), + md: $r('sys.float.padding_level0'), lg: $r('sys.float.padding_level0') }).getValue(this.curBp), left: new BreakpointType({ - sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level0'), + sm: $r('sys.float.padding_level8'), + md: $r('sys.float.padding_level0'), lg: $r('sys.float.padding_level0') }).getValue(this.curBp) }) } .titleMode(NavigationTitleMode.Full) .mode(NavigationMode.Stack) - .title(getContext(this).resourceManager.getStringSync($r('app.string.last_open').id)) + .title(this.getUIContext().getHostContext()?.resourceManager.getStringSync($r('app.string.last_open').id)) } .padding({ - top: this.topRectHeight, - bottom: this.bottomRectHeight, right: new BreakpointType({ - sm: $r('sys.float.padding_level0'), md: $r('sys.float.padding_level4'), + sm: $r('sys.float.padding_level0'), + md: $r('sys.float.padding_level4'), lg: $r('sys.float.padding_level8') }).getValue(this.curBp), left: new BreakpointType({ - sm: $r('sys.float.padding_level0'), md: $r('sys.float.padding_level4'), + sm: $r('sys.float.padding_level0'), + md: $r('sys.float.padding_level4'), lg: $r('sys.float.padding_level8') }).getValue(this.curBp) }) - .height(Constants.FULL_PERCENT) - .width(Constants.FULL_PERCENT) + .height(CommonConstants.FULL_PERCENT) + .width(CommonConstants.FULL_PERCENT) .backgroundColor($r('sys.color.background_secondary')) } } diff --git a/pickerlibrary/src/main/ets/pages/ViewMedia.ets b/pickerlibrary/src/main/ets/component/ViewMedia.ets similarity index 70% rename from pickerlibrary/src/main/ets/pages/ViewMedia.ets rename to pickerlibrary/src/main/ets/component/ViewMedia.ets index 201dfa9212df2c936dbbfcf31d740889bcbdd222..36072dfb4cb8a0a385af53707d11afe80b2013f1 100644 --- a/pickerlibrary/src/main/ets/pages/ViewMedia.ets +++ b/pickerlibrary/src/main/ets/component/ViewMedia.ets @@ -14,52 +14,49 @@ */ import { fileIo } from '@kit.CoreFileKit'; -import MediaFileUri from '../media/MediaFileUri'; +import { BreakpointType, BreakpointTypeEnum } from '../utils/BreakpointSystem'; +import { CommonConstants } from '../common/CommonConstants'; import Logger from '../common/Logger'; -import { Constants } from '../common/Constants'; -import { BreakpointType } from '../utils/BreakpointSystem'; -import { image } from '@kit.ImageKit'; -import { UrisParam } from './PickerPage'; +import MediaFileUri from '../media/MediaFileUri'; +import { UrisParam } from './PickerComponent'; const TAG = 'ViewMedia'; -interface myParams extends Object { - uris: string[], - thumbnailList: image.PixelMap[] -}; - @Builder export function ViewMediaBuilder(name: string, params: UrisParam) { - ViewMedia({ params }); + ViewMedia(); } -@Entry @Component struct ViewMedia { @State myFileSizes: number[] = []; @State myFileNames: string[] = []; @State myFileTypes: number[] = []; @State controls: Array = []; - @State myUris: string[] = this.params?.uris || []; - @StorageLink('myFileName') myFileName: string = ''; - @StorageLink('myFileSize') myFileSize: number = 0; + @State myUris: string[] = []; + @StorageLink(CommonConstants.AS_KEY_MY_FILE_NAME) myFileName: string = ''; + @StorageLink(CommonConstants.AS_KEY_MY_FILE_SIZE) myFileSize: number = 0; @StorageLink('showPauses') showPauses: Array = []; - @StorageProp('bottomRectHeight') bottomRectHeight: number = 0; - @StorageProp('topRectHeight') topRectHeight: number = 0; - @StorageProp('currentBreakpoint') curBp: string = Constants.BREAK_POINT_SM; + @StorageProp(CommonConstants.AS_KEY_NAVIGATOR_BAR_HEIGHT) navigatorBarHeight: number = 0; + @StorageProp(CommonConstants.AS_KEY_STATUS_BAR_HEIGHT) statusBarHeight: number = 0; + @StorageProp(CommonConstants.AS_KEY_BREAK_POINT) curBp: string = BreakpointTypeEnum.SM; mediaFileUri: MediaFileUri = new MediaFileUri(); scroller: Scroller = new Scroller(); controllers: Array = []; - params?: UrisParam - @Consume('pathStack') pageStack: NavPathStack; + @Consume(CommonConstants.AS_KEY_PATH_STACK) pageStack: NavPathStack; - onPageShow() { + aboutToAppear(): void { + if (this.pageStack.getParamByName('ViewMedia').length === 0) { + return; + } + let uriParams: UrisParam = this.pageStack.getParamByName('ViewMedia')[0] as UrisParam; + this.myUris = uriParams.uris; this.getImagesInfo(); this.myFileName = this.myFileNames[0]; this.myFileSize = this.myFileSizes[0]; Logger.info(TAG, 'onPageShow getFilenameByUriForMedia begin'); - AppStorage.setOrCreate('myFileName', this.myFileName); - AppStorage.setOrCreate('myFileSize', this.myFileSize); + AppStorage.setOrCreate(CommonConstants.AS_KEY_MY_FILE_NAME, this.myFileName); + AppStorage.setOrCreate(CommonConstants.AS_KEY_MY_FILE_SIZE, this.myFileSize); } async getMediaNameByUri(myUri: string, index: number) { @@ -70,7 +67,8 @@ struct ViewMedia { getImagesInfo() { for (let index = 0; index < this.myUris.length; index++) { - Logger.info(TAG, 'getFilenameByUriForMedia getImagesInfo index: ' + index); + Logger.info(TAG, + 'getFilenameByUriForMedia getImagesInfo index: ' + index + '===' + JSON.stringify(this.myUris[index])); this.controllers[index] = new VideoController(); this.controls[index] = false; this.getMediaNameByUri(this.myUris[index], index); @@ -94,7 +92,7 @@ struct ViewMedia { .aspectRatio(1) .backgroundColor($r('sys.color.comp_background_tertiary')) .onClick(() => { - this.pageStack.pop() + this.pageStack.pop(); }) // File name and information. @@ -107,52 +105,54 @@ struct ViewMedia { .fontFamily('HarmonyHeiTi-Bold') .fontColor($r('sys.color.font_primary')) .textAlign(TextAlign.Start) - .fontWeight(Constants.TEXT_FONT_WIGHT) + .fontWeight(CommonConstants.TEXT_FONT_WIGHT) .lineHeight($r('app.float.text_height')) .maxLines(1) .textOverflow({ overflow: TextOverflow.Ellipsis }) } - .width(Constants.FULL_PERCENT) + .width(CommonConstants.FULL_PERCENT) .align(Alignment.Start) .margin({ - top: Constants.MARGIN_TOP, - bottom: Constants.MARGIN_ZERO_POINT_THREE_PERCENT + top: CommonConstants.MARGIN_TOP, + bottom: CommonConstants.MARGIN_ZERO_POINT_THREE_PERCENT }) Row() { Text('size: ' + JSON.stringify(this.myFileSize) + 'B') .focusable(true) .focusOnTouch(true) - .opacity(Constants.TEXT_OPACITY) + .opacity(CommonConstants.TEXT_OPACITY) .fontFamily('HarmonyHeiTi') .fontSize($r('app.float.text_font_size_14')) .fontColor($r('sys.color.font_primary')) .textAlign(TextAlign.Start) .lineHeight($r('app.float.text_height_19')) - .fontWeight(Constants.TEXT_FONT_WIGHT_400) + .fontWeight(CommonConstants.TEXT_FONT_WIGHT_400) } - .width(Constants.FULL_PERCENT) + .width(CommonConstants.FULL_PERCENT) .margin({ - top: Constants.MARGIN_ZERO_POINT_THREE_PERCENT, - bottom: Constants.MARGIN_ZERO_POINT_FIVE_PERCENT + top: CommonConstants.MARGIN_ZERO_POINT_THREE_PERCENT, + bottom: CommonConstants.MARGIN_ZERO_POINT_FIVE_PERCENT }) .align(Alignment.Start) } .margin({ left: $r('sys.float.padding_level4') }) - .width(Constants.FORTY_FIVE_PERCENT) + .width(CommonConstants.FORTY_FIVE_PERCENT) } .padding({ left: new BreakpointType({ - sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level12'), + sm: $r('sys.float.padding_level8'), + md: $r('sys.float.padding_level12'), lg: $r('sys.float.padding_level16') }).getValue(this.curBp), right: new BreakpointType({ - sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level12'), + sm: $r('sys.float.padding_level8'), + md: $r('sys.float.padding_level12'), lg: $r('sys.float.padding_level16') }).getValue(this.curBp) }) .height(56) - .width(Constants.FULL_PERCENT) + .width(CommonConstants.FULL_PERCENT) .zIndex(2) Column() { @@ -166,7 +166,8 @@ struct ViewMedia { .borderRadius(16) .margin({ bottom: new BreakpointType({ - sm: $r('sys.float.padding_level6'), md: $r('sys.float.padding_level8'), + sm: $r('sys.float.padding_level6'), + md: $r('sys.float.padding_level8'), lg: $r('sys.float.padding_level10') }).getValue(this.curBp) }) @@ -175,8 +176,8 @@ struct ViewMedia { this.myFileSize = this.myFileSizes[index]; this.myFileName = this.myFileNames[index]; } - AppStorage.setOrCreate('myFileName', this.myFileName); - AppStorage.setOrCreate('myFileSize', this.myFileSize); + AppStorage.setOrCreate(CommonConstants.AS_KEY_MY_FILE_NAME, this.myFileName); + AppStorage.setOrCreate(CommonConstants.AS_KEY_MY_FILE_SIZE, this.myFileSize); Logger.info(TAG, 'Obtain the name and size of the clicked image.'); }) if (uri.substring(uri.length, uri.length - 3) === 'mp4') { @@ -196,7 +197,8 @@ struct ViewMedia { } : {}) .margin({ bottom: new BreakpointType({ - sm: $r('sys.float.padding_level6'), md: $r('sys.float.padding_level8'), + sm: $r('sys.float.padding_level6'), + md: $r('sys.float.padding_level8'), lg: $r('sys.float.padding_level10') }).getValue(this.curBp) }) @@ -222,8 +224,8 @@ struct ViewMedia { this.myFileSize = this.myFileSizes[index]; this.myFileName = this.myFileNames[index]; - AppStorage.setOrCreate('myFileName', this.myFileName); - AppStorage.setOrCreate('myFileSize', this.myFileSize); + AppStorage.setOrCreate(CommonConstants.AS_KEY_MY_FILE_NAME, this.myFileName); + AppStorage.setOrCreate(CommonConstants.AS_KEY_MY_FILE_SIZE, this.myFileSize); }) .visibility(this.controls[index] === false ? Visibility.Visible : Visibility.Hidden) } @@ -231,45 +233,48 @@ struct ViewMedia { this.myFileSize = this.myFileSizes[index]; this.myFileName = this.myFileNames[index]; - AppStorage.setOrCreate('myFileName', this.myFileName); - AppStorage.setOrCreate('myFileSize', this.myFileSize); + AppStorage.setOrCreate(CommonConstants.AS_KEY_MY_FILE_NAME, this.myFileName); + AppStorage.setOrCreate(CommonConstants.AS_KEY_MY_FILE_SIZE, this.myFileSize); }) } } - .height(Constants.FULL_PERCENT) + .height(CommonConstants.FULL_PERCENT) } .height(190) }, (item: string) => item) } .lanes(new BreakpointType({ sm: 1, md: 2, lg: 4 }).getValue(this.curBp), 20) - .width(Constants.FULL_PERCENT) + .width(CommonConstants.FULL_PERCENT) .height(new BreakpointType({ - sm: 190 * this.myUris.length, md: 190 * Math.ceil(this.myUris.length / 2), + sm: 190 * this.myUris.length, + md: 190 * Math.ceil(this.myUris.length / 2), lg: 190 }).getValue(this.curBp)) .id('picScroller') .scrollBar(BarState.Auto) } .padding({ - top: Constants.ONE_POINT_FIVE_PERCENT, + top: CommonConstants.ONE_POINT_FIVE_PERCENT, left: new BreakpointType({ - sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level12'), + sm: $r('sys.float.padding_level8'), + md: $r('sys.float.padding_level12'), lg: $r('sys.float.padding_level16') }).getValue(this.curBp), right: new BreakpointType({ - sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level12'), + sm: $r('sys.float.padding_level8'), + md: $r('sys.float.padding_level12'), lg: $r('sys.float.padding_level16') }).getValue(this.curBp) }) } - .padding({ bottom: this.bottomRectHeight }) + .padding({ bottom: this.navigatorBarHeight }) } .align(Alignment.Start) .layoutWeight(1) } .backgroundColor($r('sys.color.gray_01')) - .height(Constants.FULL_PERCENT) - .padding({ top: this.topRectHeight }) + .height(CommonConstants.FULL_PERCENT) + .padding({ top: this.statusBarHeight }) } .hideTitleBar(true) } diff --git a/pickerlibrary/src/main/ets/media/MediaFileUri.ets b/pickerlibrary/src/main/ets/media/MediaFileUri.ets index e5a0e4388529aefe0024be620e7fa5c5122b647a..387c6f6cbbf36b20c9df84bc3a5be12c1c92fc48 100644 --- a/pickerlibrary/src/main/ets/media/MediaFileUri.ets +++ b/pickerlibrary/src/main/ets/media/MediaFileUri.ets @@ -14,8 +14,9 @@ */ import { fileIo } from '@kit.CoreFileKit'; +import { bufferToString } from '../utils/StringUtils'; +import { CommonConstants } from '../common/CommonConstants'; import Logger from '../common/Logger'; -import { bufferToString } from '../common/Common'; const TAG = 'MediaFileUri'; // File read/write buffer size @@ -62,8 +63,8 @@ export default class MediaFileUri { async getAllFiles(): Promise { Logger.info(TAG, 'getAllFiles begin'); - AppStorage.setOrCreate('fileNameList', this.fileNameList); - AppStorage.setOrCreate('fileSizeList', this.fileSizeList); - AppStorage.setOrCreate('fileUriList', this.fileUriList); + AppStorage.setOrCreate(CommonConstants.AS_KEY_FILE_NAME_LIST, this.fileNameList); + AppStorage.setOrCreate(CommonConstants.AS_KEY_FILE_SIZE_LIST, this.fileSizeList); + AppStorage.setOrCreate(CommonConstants.AS_KEY_FILE_URI_LIST, this.fileUriList); } } \ No newline at end of file diff --git a/pickerlibrary/src/main/ets/pages/EditFile.ets b/pickerlibrary/src/main/ets/pages/EditFile.ets deleted file mode 100644 index 81144168bf1883447d4827b383b2f7ee38ee28e5..0000000000000000000000000000000000000000 --- a/pickerlibrary/src/main/ets/pages/EditFile.ets +++ /dev/null @@ -1,353 +0,0 @@ -/* - * 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 { promptAction } from '@kit.ArkUI'; -import { fileIo, picker } from '@kit.CoreFileKit'; -import { BusinessError } from '@kit.BasicServicesKit'; -import MediaFileUri from '../media/MediaFileUri'; -import Logger from '../common/Logger'; -import { Constants } from '../common/Constants'; -import { BreakpointType } from '../utils/BreakpointSystem'; -import { FileParam } from './PickerPage'; - -const TAG = 'EditFile: '; -let storage = LocalStorage.getShared(); -const OPACITY_VALUE = 0.6; - -@Builder -export function EditFileBuilder(name: string, params: FileParam) { - EditFile({ params }); -} - -@Entry(storage) -@Component -struct EditFile { - @LocalStorageLink('loadFlag') loadFlag: Boolean = false; - @LocalStorageLink('loadFileSize') loadFileSize: number = 0; - @LocalStorageLink('loadFileName') loadFileName: string = ''; - @LocalStorageLink('loadFileContent') loadFileContent: string = ''; - @LocalStorageLink('loadUri') loadUri: string = ''; - @StorageLink('editable') editable: Boolean = false; - @StorageLink('myFileSize') myFileSize: number = 0; - @StorageLink('myFileContent') myFileContent: string = ''; - @State myUri: string = ''; - @State opacityValue: number = OPACITY_VALUE; - @State uriSave: string = ''; - @State myFileName: string = ''; - @StorageProp('bottomRectHeight') bottomRectHeight: number = 0; - @StorageProp('topRectHeight') topRectHeight: number = 0; - @StorageProp('currentBreakpoint') curBp: string = Constants.BREAK_POINT_SM; - public fileContentFlag: boolean = false; - newFileContent: string = ''; - scroller: Scroller = new Scroller(); - controller: TextAreaController = new TextAreaController(); - mediaFileUri: MediaFileUri = new MediaFileUri(); - @Consume('pathStack') pageStack: NavPathStack; - params?: FileParam - - getFileInfo(): void { - if (this.loadFlag) { - this.myFileName = this.loadFileName; - this.myFileContent = this.loadFileContent; - this.myFileSize = this.loadFileSize; - this.myUri = this.loadUri; - Logger.info(TAG, 'Successfully obtained the name, content and size of the load file.'); - } else { - this.myUri = this.params?.myUri || ''; - this.myFileName = this.params?.fileName || ''; - this.myFileContent = this.mediaFileUri.readFileContent(this.myUri); - this.myFileSize = this.mediaFileUri.myGetFileSize(this.myUri, fileIo.OpenMode.READ_ONLY); - Logger.info(TAG, 'Successfully obtained the name, content and size of the file.') - } - AppStorage.setOrCreate('myFileContent', this.myFileContent); - AppStorage.setOrCreate('myFileSize', this.myFileSize); - } - - async writeContentForSaveAsFile(myUri: string, wrFlag: Boolean = false): Promise { - if (wrFlag) { - Logger.info(TAG, 'fileAsset.displayName wrFlag is true'); - this.mediaFileUri.writeFileContent(myUri, this.myFileContent); - } - } - - // Pull up the picker to save the file. - async callFilePickerSaveFile(): Promise { - try { - let documentSaveOptions = new picker.DocumentSaveOptions(); - documentSaveOptions.newFileNames = ['MyDocument_01.txt']; - let documentPicker = new picker.DocumentViewPicker(); - documentPicker.save(documentSaveOptions).then((documentSaveResult) => { - Logger.info(TAG, - 'DocumentViewPicker.save successfully.'); - if (documentSaveResult !== null && documentSaveResult !== undefined) { - this.uriSave = documentSaveResult[0]; - Logger.info(TAG, `save callFilePickerSaveFile file succeed.`); - } - Logger.info(TAG, 'fileAsset.displayName wrFlag myFileContent.'); - // Retrieve URI using media library and perform write operation. - this.writeContentForSaveAsFile(this.uriSave, true); - }).catch((err: BusinessError) => { - Logger.error(TAG, - `DocumentViewPicker.save failed with err, ErrorCode: ${err.code}, Message: ${err.message}`); - }); - } catch (err) { - Logger.error(TAG, - `DocumentViewPicker failed with err, ErrorCode: ${(err as BusinessError).code}, Message: ${(err as BusinessError).message}`); - } - } - - build() { - NavDestination() { - Column() { - Row() { - Button({ type: ButtonType.Circle }) { - SymbolGlyph($r('sys.symbol.chevron_backward')) - .fontSize($r('sys.float.Title_M')) - .fontColor([$r('sys.color.font_primary')]) - } - .focusable(true) - .focusOnTouch(true) - .id('backIndex') - .height(40) - .aspectRatio(1) - .margin({ right: $r('sys.float.padding_level4') }) - .backgroundColor($r('sys.color.comp_background_tertiary')) - .onClick(() => { - this.pageStack.pop() - }) - - // File name and information. - Column() { - Row() { - Text(this.myFileName) - .focusable(true) - .focusOnTouch(true) - .fontSize($r('app.float.text_font_size')) - .fontFamily('HarmonyHeiTi-Bold') - .fontColor($r('sys.color.font_primary')) - .textAlign(TextAlign.Start) - .fontWeight(Constants.TEXT_FONT_WIGHT) - .lineHeight(Constants.TEXT_LINE_HEIGHT) - .maxLines(1) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - } - .width(Constants.FULL_PERCENT) - .align(Alignment.Start) - .margin({ - top: Constants.MARGIN_TOP, - bottom: Constants.MARGIN_ZERO_POINT_THREE_PERCENT - }) - - Row() { - Text('size: ' + JSON.stringify(this.myFileSize) + 'B') - .focusable(true) - .focusOnTouch(true) - .opacity(Constants.TEXT_OPACITY) - .fontFamily('HarmonyHeiTi') - .fontSize($r('app.float.text_font_size_14')) - .fontColor($r('sys.color.font_primary')) - .textAlign(TextAlign.Start) - .lineHeight(Constants.TEXT_LINE_HEIGHT_19) - .fontWeight(Constants.TEXT_FONT_WIGHT_400) - } - .width(Constants.FULL_PERCENT) - .margin({ - top: Constants.MARGIN_ZERO_POINT_THREE_PERCENT, - bottom: Constants.MARGIN_ZERO_POINT_FIVE_PERCENT - }) - .align(Alignment.Start) - } - .layoutWeight(1) - - // Three icons on the right. - Row() { - Button({ type: ButtonType.Circle }) { - SymbolGlyph($r('sys.symbol.plus_square_on_square')) - .fontSize($r('sys.float.Title_M')) - .fontColor([$r('sys.color.font_primary')]) - } - .focusable(true) - .focusOnTouch(true) - .id('saveAs') - .margin({ - right: new BreakpointType({ - sm: $r('sys.float.padding_level4'), md: $r('sys.float.padding_level6'), - lg: $r('sys.float.padding_level8') - }).getValue(this.curBp) - }) - .height(40) - .aspectRatio(1) - .backgroundColor($r('sys.color.comp_background_tertiary')) - .onClick(() => { - this.callFilePickerSaveFile(); - }) - .visibility(this.loadFlag ? Visibility.Hidden : Visibility.Visible) - - Button({ type: ButtonType.Circle }) { - SymbolGlyph($r('sys.symbol.square_and_pencil')) - .fontSize($r('sys.float.Title_M')) - .fontColor([$r('sys.color.font_primary')]) - } - .focusable(true) - .focusOnTouch(true) - .id('editable') - .margin({ - right: new BreakpointType({ - sm: $r('sys.float.padding_level4'), md: $r('sys.float.padding_level6'), - lg: $r('sys.float.padding_level8') - }).getValue(this.curBp) - }) - .height(40) - .aspectRatio(1) - .backgroundColor($r('sys.color.comp_background_tertiary')) - .onClick(() => { - this.editable = true; - AppStorage.setOrCreate('editable', this.editable); - this.controller.caretPosition(this.myFileContent.length); - promptAction.showToast({ message: $r('app.string.editable') }); - }) - - Button({ type: ButtonType.Circle }) { - SymbolGlyph($r('sys.symbol.save')) - .fontSize($r('sys.float.Title_M')) - .fontColor([$r('sys.color.font_primary')]) - } - .focusable(true) - .focusOnTouch(true) - .id('save') - .height(40) - .aspectRatio(1) - .backgroundColor($r('sys.color.comp_background_tertiary')) - .onClick(() => { - if (this.fileContentFlag) { - let flage: boolean = true; - this.myFileContent = this.newFileContent; - AppStorage.setOrCreate('myFileContent', this.myFileContent); - Logger.info(TAG, 'save onClick myFileContent succeed.'); - if (this.loadFlag) { - let file = fileIo.openSync(this.loadUri, - fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.TRUNC); - Logger.info(TAG, 'save onClick file.fd succeed. '); - fileIo.write(file.fd, this.myFileContent).then(() => { - Logger.info(TAG, 'write data to file succeed.'); - this.myFileSize = fileIo.statSync(file.fd).size; - AppStorage.setOrCreate('myFileSize', this.myFileSize); - Logger.info(TAG, 'save onClick fileSize succeed.'); - }).catch((err: BusinessError) => { - Logger.error(TAG, `write data to file failed, ErrorCode: ${err.code}, Message: ${err.message}`); - }).finally(() => { - fileIo.closeSync(file); - }) - } else { - let file = fileIo.openSync(this.myUri, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.TRUNC); - fileIo.write(file.fd, this.myFileContent).then(() => { - this.myFileSize = fileIo.statSync(file.fd).size; - AppStorage.setOrCreate('myFileSize', this.myFileSize); - Logger.info(TAG, 'write data to file succeed.'); - }).catch((err: BusinessError) => { - flage = false; - Logger.error(TAG, `save data to file failed ErrorCode: ${err.code}, Message: ${err.message}`); - promptAction.showToast({ - message: $r('app.string.show_toast_message'), - duration: 6500 - }) - }).finally(() => { - fileIo.closeSync(file); - }) - } - if (flage) { - this.editable = false; - AppStorage.setOrCreate('editable', this.editable); - promptAction.showToast({ message: $r('app.string.saved') }); - } - } - }) - } - .margin({ left: $r('sys.float.padding_level8') }) - .justifyContent(FlexAlign.End) - } - .padding({ - left: new BreakpointType({ - sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level12'), - lg: $r('sys.float.padding_level16') - }).getValue(this.curBp), - right: new BreakpointType({ - sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level12'), - lg: $r('sys.float.padding_level16') - }).getValue(this.curBp) - }) - .width(Constants.FULL_PERCENT) - .height(56) - .zIndex(2) - - Column() { - Scroll(this.scroller) { - Row() { - TextArea({ - text: this.newFileContent ? this.newFileContent : this.myFileContent, - placeholder: Constants.TEXT_AREA_PLACEHOLDER, - controller: this.controller - }) - .id('textArea') - .fontSize($r('app.float.text_area_font_size')) - .fontColor($r('sys.color.font_primary')) - .opacity(this.opacityValue) - .fontWeight(Constants.TEXT_FONT_WIGHT_400) - .align(Alignment.TopStart) - .textAlign(TextAlign.Start) - .backgroundColor($r('sys.color.gray_01')) - .fontFamily('HarmonyHeiTi') - .padding({ - top: $r('app.float.padding_top_bottom'), - right: $r('app.float.padding_left_right'), - left: $r('app.float.padding_left_right'), - bottom: $r('app.float.padding_top_bottom') - }) - .focusable(this.editable ? true : false) - .focusOnTouch(true) - .defaultFocus(false) - .onFocus(() => { - this.opacityValue = 1; - }) - .onBlur(() => { - this.opacityValue = OPACITY_VALUE; - }) - .onChange((value: string) => { - this.newFileContent = value; - this.fileContentFlag = true; - }) - } - .padding({ - top: Constants.PADDING_TOP, - left: 16, - right: 16 - }) - } - .padding({ bottom: this.bottomRectHeight }) - } - .align(Alignment.Start) - .layoutWeight(1) - } - .backgroundColor($r('sys.color.gray_01')) - .height(Constants.FULL_PERCENT) - .padding({ top: this.topRectHeight }) - } - .hideTitleBar(true) - .onWillShow(()=>{ - this.getFileInfo(); - this.editable = false; - }) - } -} \ No newline at end of file diff --git a/pickerlibrary/src/main/ets/pages/PickerPage.ets b/pickerlibrary/src/main/ets/pages/PickerPage.ets deleted file mode 100644 index 9899cbb36b90cd7ddcc300511274cd61234c811e..0000000000000000000000000000000000000000 --- a/pickerlibrary/src/main/ets/pages/PickerPage.ets +++ /dev/null @@ -1,231 +0,0 @@ -/* - * 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 { picker } from '@kit.CoreFileKit'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { photoAccessHelper } from '@kit.MediaLibraryKit'; -import Logger from '../common/Logger'; -import MediaFileUri from '../media/MediaFileUri'; -import { Constants } from '../common/Constants'; -import { BreakpointType } from '../utils/BreakpointSystem'; - -const MAX_SELECT_NUM = 4; // Select the maximum number of media files. -const TAG = 'pickerIndex'; - -export interface UrisParam { - uris: string[]; -} - -export interface FileParam { - fileName: string; - myUri: string; -} - -@Component -export struct PickerPage { - @State uri: string = 'Hello World'; - @State filename: string = ''; - @StorageProp('bottomRectHeight') bottomRectHeight: number = 0; - @StorageProp('topRectHeight') topRectHeight: number = 0; - @StorageProp('currentBreakpoint') curBp: string = Constants.BREAK_POINT_SM; - @StorageLink('fileSizeList') fileSizeList: Array = []; - @StorageLink('fileNameList') fileNameList: Array = []; - @StorageLink('fileUriList') fileUriList: Array = []; - @Provide('pathStack') pathStack: NavPathStack = new NavPathStack(); - mediaFileUri: MediaFileUri = new MediaFileUri(); - scroller: Scroller = new Scroller(); - - // Pull up the picker to select files. - async callFilePickerSelectFile(): Promise { - try { - let documentSelectOptions = new picker.DocumentSelectOptions(); - let documentPicker = new picker.DocumentViewPicker(); - documentPicker.select(documentSelectOptions).then((documentSelectResult) => { - Logger.info(TAG, 'DocumentViewPicker.select successfully'); - let editFlag = false; - if (documentSelectResult !== null && documentSelectResult !== undefined) { - documentSelectResult.forEach((value) => { - this.uri = value; - editFlag = true; - Logger.info(TAG, `select file succeed`); - }) - } - if (editFlag) { - this.getFilenameByUri(this.uri); - } - }).catch((err: BusinessError) => { - Logger.error(TAG, - `DocumentViewPicker.select failed with err, ErrorCode: ${err.code}, Message: ${err.message}`); - }); - } catch (err) { - Logger.error(TAG, 'DocumentViewPicker failed.'); - } - } - - // Pull up the picker to save the file. - async callFilePickerSaveFile(): Promise { - try { - let documentSaveOptions = new picker.DocumentSaveOptions(); - documentSaveOptions.newFileNames = ['MyDocument_01.txt']; - let documentPicker = new picker.DocumentViewPicker(); - documentPicker.save(documentSaveOptions).then((documentSaveResult) => { - Logger.info(TAG, - 'DocumentViewPicker.save successfully.'); - if (documentSaveResult !== null && documentSaveResult !== undefined) { - this.uri = documentSaveResult[0]; - Logger.info(TAG, `save file uri succeed.`); - } - this.getFilenameByUri(this.uri); - }).catch((err: BusinessError) => { - Logger.error(TAG, `DocumentViewPicker.save failed, ErrorCode: ${err.code}, Message: ${err.message}`); - }); - } catch (err) { - Logger.error(TAG, 'DocumentViewPicker failed.'); - } - } - - async getFilenameByUriForMedia(myUris: string[]) { - const params: UrisParam = { - uris: myUris - } - this.pathStack.pushPathByName('ViewMedia', params) - } - - async getFilenameByUri(myUri: string): Promise { - this.filename = (myUri.split('/').pop()) as string; - const params: FileParam = { - fileName: this.filename, - myUri: myUri - } - this.pathStack.pushPathByName('EditFile', params) - } - - // Pull up the picker to select images/videos. - async callFilePickerSelectImage(): Promise { - let array: string[]; - try { - let photoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); - photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_VIDEO_TYPE; - photoSelectOptions.maxSelectNumber = MAX_SELECT_NUM; - let mediaFlag = false; - // Create a PhotoViewPicker object. - let photoPicker = new photoAccessHelper.PhotoViewPicker(); - photoPicker.select(photoSelectOptions).then((photoSelectResult) => { - Logger.info(TAG, - 'PhotoViewPicker.select successfully.'); - if (photoSelectResult !== null && photoSelectResult !== undefined) { - // Declare variable array, whose value is the array in PhotoSelectResult. - array = photoSelectResult['photoUris']; - array.forEach((value) => { - this.uri = value; - mediaFlag = true; - Logger.info(TAG, `select image/video succeed.`); - }) - } - if (mediaFlag) { - this.getFilenameByUriForMedia(array); - } - }).catch((err: BusinessError) => { - Logger.error(TAG, `PhotoViewPicker.select failed, ErrorCode: ${err.code}, Message: ${err.message}`); - }); - } catch (err) { - Logger.error(TAG, 'PhotoViewPicker failed.'); - } - } - - aboutToDisappear(): void { - this.fileNameList = []; - this.fileSizeList = []; - this.fileUriList = []; - } - - onPageShow(): void { - this.mediaFileUri.getAllFiles(); - } - - build() { - Scroll(this.scroller) { - Row() { - Navigation(this.pathStack) { - Column() { - Button($r('app.string.new_file')) - .id('newFile') - .fontSize(16) - .width(this.curBp === 'sm' ? '100%' : 448) - .height(40) - .margin({ bottom: $r('sys.float.padding_level6') }) - .backgroundColor($r('sys.color.brand')) - .onClick(() => { - this.callFilePickerSaveFile(); - }) - - Button($r('app.string.picture')) - .id('picture') - .fontSize(16) - .width(this.curBp === 'sm' ? '100%' : 448) - .height(40) - .margin({ bottom: $r('sys.float.padding_level6') }) - .backgroundColor($r('sys.color.brand')) - .onClick(() => { - this.callFilePickerSelectImage(); - }) - - Button($r('app.string.edit_file')) - .id('folder') - .fontSize(16) - .width(this.curBp === 'sm' ? '100%' : 448) - .height(40) - .margin({ bottom: $r('sys.float.padding_level6') }) - .backgroundColor($r('sys.color.brand')) - .onClick(() => { - this.callFilePickerSelectFile(); - }) - } - .height(Constants.FULL_PERCENT) - .width(Constants.FULL_PERCENT) - .justifyContent(FlexAlign.End) - .padding({ - right: new BreakpointType({ - sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level0'), - lg: $r('sys.float.padding_level0') - }).getValue(this.curBp), - left: new BreakpointType({ - sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level0'), - lg: $r('sys.float.padding_level0') - }).getValue(this.curBp) - }) - } - .titleMode(NavigationTitleMode.Full) - .mode(NavigationMode.Stack) - .title(getContext(this).resourceManager.getStringSync($r('app.string.last_open').id)) - } - .padding({ - top: this.topRectHeight, - bottom: this.bottomRectHeight, - right: new BreakpointType({ - sm: $r('sys.float.padding_level0'), md: $r('sys.float.padding_level4'), - lg: $r('sys.float.padding_level8') - }).getValue(this.curBp), - left: new BreakpointType({ - sm: $r('sys.float.padding_level0'), md: $r('sys.float.padding_level4'), - lg: $r('sys.float.padding_level8') - }).getValue(this.curBp) - }) - .height(Constants.FULL_PERCENT) - .width(Constants.FULL_PERCENT) - .backgroundColor($r('sys.color.background_secondary')) - } - } -} \ No newline at end of file diff --git a/pickerlibrary/src/main/ets/utils/BreakpointSystem.ets b/pickerlibrary/src/main/ets/utils/BreakpointSystem.ets index aa7581b2047323eac83c8d9a031e21faabc55bd2..3f0b49da401cd5997f1a4c20010b034322603f8b 100644 --- a/pickerlibrary/src/main/ets/utils/BreakpointSystem.ets +++ b/pickerlibrary/src/main/ets/utils/BreakpointSystem.ets @@ -13,9 +13,10 @@ * limitations under the License. */ -import { window } from '@kit.ArkUI'; import type { BusinessError } from '@kit.BasicServicesKit'; +import { display, window } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; +import { CommonConstants } from '../common/CommonConstants'; const TAG: string = '[BreakpointSystem]'; @@ -69,9 +70,10 @@ export class BreakpointType { export class BreakpointSystem { private static instance: BreakpointSystem; - private currentBreakpoint: BreakpointTypeEnum = BreakpointTypeEnum.MD; + private currentBreakpoint: BreakpointTypeEnum = BreakpointTypeEnum.SM; private constructor() { + AppStorage.setOrCreate(CommonConstants.AS_KEY_BREAK_POINT, this.currentBreakpoint); } public static getInstance(): BreakpointSystem { @@ -84,7 +86,7 @@ export class BreakpointSystem { public updateCurrentBreakpoint(breakpoint: BreakpointTypeEnum): void { if (this.currentBreakpoint !== breakpoint) { this.currentBreakpoint = breakpoint; - AppStorage.setOrCreate('currentBreakpoint', this.currentBreakpoint); + AppStorage.setOrCreate(CommonConstants.AS_KEY_BREAK_POINT, this.currentBreakpoint); } } @@ -96,8 +98,8 @@ export class BreakpointSystem { try { const mainWindow: window.WindowProperties = window.getWindowProperties(); const windowWidth: number = mainWindow.windowRect.width; - const windowWidthVp = px2vp(windowWidth); - let widthBp: BreakpointTypeEnum = BreakpointTypeEnum.MD; + const windowWidthVp = windowWidth / display.getDefaultDisplaySync().densityPixels; + let widthBp: BreakpointTypeEnum = BreakpointTypeEnum.SM; if (windowWidthVp < 320) { widthBp = BreakpointTypeEnum.XS; } else if (windowWidthVp >= 320 && windowWidthVp < 600) { diff --git a/pickerlibrary/src/main/ets/common/Common.ets b/pickerlibrary/src/main/ets/utils/StringUtils.ets similarity index 100% rename from pickerlibrary/src/main/ets/common/Common.ets rename to pickerlibrary/src/main/ets/utils/StringUtils.ets diff --git a/pickerlibrary/src/main/ets/utils/WindowUtil.ets b/pickerlibrary/src/main/ets/utils/WindowUtil.ets index 89e954364f2d8ebdac8a96584dc71504a721d9a2..97cfbe0e76fed629edf2d223ca8939a2c334bea6 100644 --- a/pickerlibrary/src/main/ets/utils/WindowUtil.ets +++ b/pickerlibrary/src/main/ets/utils/WindowUtil.ets @@ -13,59 +13,65 @@ * limitations under the License. */ -import { window } from '@kit.ArkUI'; import type { BusinessError } from '@kit.BasicServicesKit'; -import { BreakpointSystem } from './BreakpointSystem'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { ConfigurationConstant, Configuration, UIAbility } from '@kit.AbilityKit'; +import { window } from '@kit.ArkUI'; +import { BreakpointSystem } from './BreakpointSystem'; +import { CommonConstants } from '../common/CommonConstants'; const TAG: string = '[WindowUtil]'; export class WindowUtil { - public static requestFullScreen(windowStage: window.WindowStage): void { - windowStage.getMainWindow((err: BusinessError, data: window.Window) => { - if (err.code) { - return; - } - const windowClass: window.Window = data; - // Realize the immersive effect. - try { - const promise: Promise = windowClass.setWindowLayoutFullScreen(true); - promise.then(() => { - hilog.info(0x0000, TAG, 'Succeeded in setting the window layout to full-screen mode.'); - }).catch((err: BusinessError) => { - hilog.info(0x0000, TAG, - `Failed to set the window layout to full-screen mode. Cause: ${err.code}, ${err.message}`); - }); - } catch { - hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode. '); - } - }); + private static windowClass: window.Window; + + public static initialize(windowStage: window.WindowStage): void { + try { + WindowUtil.windowClass = windowStage.getMainWindowSync(); + WindowUtil.requestFullScreen(); + WindowUtil.registerBreakPoint(); + } catch (err) { + hilog.error(0x0000, TAG, `WindowUtil initialize Failed. Cause: ${err.message}`); + } } - public static registerBreakPoint(windowStage: window.WindowStage) { - windowStage.getMainWindow((err: BusinessError, data: window.Window) => { - if (err.code) { - hilog.error(0x0000, TAG, `Failed to get main window: ${err.message}`); - return; - } - BreakpointSystem.getInstance().updateWidthBp(data); - data.on('windowSizeChange', () => BreakpointSystem.getInstance().onWindowSizeChange(data)); - data.on('avoidAreaChange', (avoidAreaOption) => { - if (avoidAreaOption.type === window.AvoidAreaType.TYPE_SYSTEM || - avoidAreaOption.type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { - WindowUtil.setAvoidArea(avoidAreaOption.type, avoidAreaOption.area); - } + private static requestFullScreen(): void { + // Realize the immersive effect. + try { + const promise: Promise = WindowUtil.windowClass.setWindowLayoutFullScreen(true); + promise.then(() => { + hilog.info(0x0000, TAG, 'Succeeded in setting the window layout to full-screen mode.'); + }).catch((err: BusinessError) => { + hilog.error(0x0000, TAG, + `Failed to set the window layout to full-screen mode. Cause: ${err.code}, ${err.message}`); }); - }) + } catch { + hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode. '); + } + } + + private static registerBreakPoint() { + BreakpointSystem.getInstance().updateWidthBp(WindowUtil.windowClass); + WindowUtil.updateAvoidArea(WindowUtil.windowClass); + WindowUtil.windowClass.on('windowSizeChange', + () => BreakpointSystem.getInstance().onWindowSizeChange(WindowUtil.windowClass)); + WindowUtil.windowClass.on('avoidAreaChange', + (avoidAreaOption) => WindowUtil.setAvoidArea(avoidAreaOption.type, avoidAreaOption.area)); + } + + private static updateAvoidArea(windowObj: window.Window) { + WindowUtil.setAvoidArea(window.AvoidAreaType.TYPE_SYSTEM, + windowObj.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM)); + WindowUtil.setAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR, + windowObj.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR)); } // Get status bar height and indicator height. - public static setAvoidArea(type: window.AvoidAreaType, area: window.AvoidArea) { + private static setAvoidArea(type: window.AvoidAreaType, area: window.AvoidArea) { + let uiContext = WindowUtil.windowClass.getUIContext(); if (type === window.AvoidAreaType.TYPE_SYSTEM) { - AppStorage.setOrCreate('topRectHeight', px2vp(area.topRect.height)); - } else { - AppStorage.setOrCreate('bottomRectHeight', px2vp(area.bottomRect.height)); + AppStorage.setOrCreate(CommonConstants.AS_KEY_STATUS_BAR_HEIGHT, uiContext.px2vp(area.topRect.height)); + } else if (type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { + AppStorage.setOrCreate(CommonConstants.AS_KEY_NAVIGATOR_BAR_HEIGHT, uiContext.px2vp(area.bottomRect.height)); } } } \ No newline at end of file diff --git a/pickerlibrary/src/main/resources/base/element/string.json b/pickerlibrary/src/main/resources/base/element/string.json index 6afb318083a76c9eea54bc823675526ec2f8e705..0a48c36658f3e9ec361c3c4873f5c9ef7aa9648c 100644 --- a/pickerlibrary/src/main/resources/base/element/string.json +++ b/pickerlibrary/src/main/resources/base/element/string.json @@ -1,13 +1,5 @@ { "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, { "name": "last_open", "value": "Selecting and View Files" diff --git a/pickerlibrary/src/main/resources/base/profile/route_map.json b/pickerlibrary/src/main/resources/base/profile/route_map.json index 5eade36f59d1d8947fbd2d6963dc2e48a43e2210..b2af7d20e650d806734dac885126678bb5b8549b 100644 --- a/pickerlibrary/src/main/resources/base/profile/route_map.json +++ b/pickerlibrary/src/main/resources/base/profile/route_map.json @@ -2,7 +2,7 @@ "routerMap": [ { "name": "EditFile", - "pageSourceFile": "src/main/ets/pages/EditFile.ets", + "pageSourceFile": "src/main/ets/component/EditFile.ets", "buildFunction": "EditFileBuilder", "data": { "description": "this is EditFile" @@ -10,7 +10,7 @@ }, { "name": "ViewMedia", - "pageSourceFile": "src/main/ets/pages/ViewMedia.ets", + "pageSourceFile": "src/main/ets/component/ViewMedia.ets", "buildFunction": "ViewMediaBuilder", "data": { "description": "this is ViewMedia" diff --git a/pickerlibrary/src/main/resources/en_US/element/string.json b/pickerlibrary/src/main/resources/en_US/element/string.json index 6afb318083a76c9eea54bc823675526ec2f8e705..0a48c36658f3e9ec361c3c4873f5c9ef7aa9648c 100644 --- a/pickerlibrary/src/main/resources/en_US/element/string.json +++ b/pickerlibrary/src/main/resources/en_US/element/string.json @@ -1,13 +1,5 @@ { "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, { "name": "last_open", "value": "Selecting and View Files" diff --git a/pickerlibrary/src/main/resources/zh_CN/element/string.json b/pickerlibrary/src/main/resources/zh_CN/element/string.json index b171ee460a6247d7e6ab942b54062ba30a6f264c..82b5e20272d0202c635b03e91a76afac2ef82b3b 100644 --- a/pickerlibrary/src/main/resources/zh_CN/element/string.json +++ b/pickerlibrary/src/main/resources/zh_CN/element/string.json @@ -1,13 +1,5 @@ { "string": [ - { - "name": "module_desc", - "value": "模块描述" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, { "name": "last_open", "value": "选择并查看文件" diff --git a/pickersample/obfuscation-rules.txt b/pickersample/obfuscation-rules.txt index 272efb6ca3f240859091bbbfc7c5802d52793b0b..45766a4c056a93ca6e1771be475724ccc40cbb57 100644 --- a/pickersample/obfuscation-rules.txt +++ b/pickersample/obfuscation-rules.txt @@ -17,7 +17,7 @@ # -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-property-obfuscation +#-enable-filename-obfuscation -enable-toplevel-obfuscation --enable-filename-obfuscation -enable-export-obfuscation \ No newline at end of file diff --git a/pickersample/oh-package.json5 b/pickersample/oh-package.json5 index d0eb9c5c665fa91649e36219de51a57b88347aa9..3e15e6ea58cf365c2b2d535753314d44119c0793 100644 --- a/pickersample/oh-package.json5 +++ b/pickersample/oh-package.json5 @@ -1,12 +1,12 @@ { + "name": "pickersample", "license": "", "devDependencies": {}, "author": "", - "name": "pickersample", "description": "Please describe the basic information.", "main": "", "version": "1.0.0", "dependencies": { - "pickerlibrary": "file:../pickerlibrary" + "@ohos_samples/pickerlibrary": "file:../pickerlibrary" } } \ No newline at end of file diff --git a/pickersample/oh_modules/pickerlibrary/.gitignore b/pickersample/oh_modules/pickerlibrary/.gitignore deleted file mode 100644 index e2713a2779c5a3e0eb879efe6115455592caeea5..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/pickersample/oh_modules/pickerlibrary/Index.ets b/pickersample/oh_modules/pickerlibrary/Index.ets deleted file mode 100644 index 6bea31dcb4ba03b9ea29e5d3895934a931cafa55..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/Index.ets +++ /dev/null @@ -1,3 +0,0 @@ -export { PickerPage } from './src/main/ets/pages/PickerPage' -export { WindowUtil } from './src/main/ets/utils/WindowUtil' -export { Logger } from './src/main/ets/common/Logger' diff --git a/pickersample/oh_modules/pickerlibrary/build-profile.json5 b/pickersample/oh_modules/pickerlibrary/build-profile.json5 deleted file mode 100644 index e6773f9f5d76a66d6d19fddc9c6ddb3f5621d3b1..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/build-profile.json5 +++ /dev/null @@ -1,31 +0,0 @@ -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - }, - "consumerFiles": [ - "./consumer-rules.txt" - ] - } - }, - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest" - } - ] -} diff --git a/pickersample/oh_modules/pickerlibrary/consumer-rules.txt b/pickersample/oh_modules/pickerlibrary/consumer-rules.txt deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/pickersample/oh_modules/pickerlibrary/hvigorfile.ts b/pickersample/oh_modules/pickerlibrary/hvigorfile.ts deleted file mode 100644 index 42187071482d292588ad40babeda74f7b8d97a23..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/hvigorfile.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { harTasks } from '@ohos/hvigor-ohos-plugin'; - -export default { - system: harTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ - plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ -} diff --git a/pickersample/oh_modules/pickerlibrary/obfuscation-rules.txt b/pickersample/oh_modules/pickerlibrary/obfuscation-rules.txt deleted file mode 100644 index 272efb6ca3f240859091bbbfc7c5802d52793b0b..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/pickersample/oh_modules/pickerlibrary/oh-package.json5 b/pickersample/oh_modules/pickerlibrary/oh-package.json5 deleted file mode 100644 index cfb28c865aa85997cc1331d3bc4a4b2410e457ef..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/oh-package.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "pickerlibrary", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "Index.ets", - "author": "", - "license": "Apache-2.0", - "dependencies": {} -} diff --git a/pickersample/oh_modules/pickerlibrary/src/main/ets/common/Constants.ets b/pickersample/oh_modules/pickerlibrary/src/main/ets/common/Constants.ets deleted file mode 100644 index bd3af91b3a4fc622fb1d7850048fc40738cb9b69..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/src/main/ets/common/Constants.ets +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export class Constants { - /** - * The full percentage of component. - */ - public static readonly FULL_PERCENT: string = '100%'; - - /** - * Forty-five percent. - */ - public static readonly FORTY_FIVE_PERCENT: string = '45%'; - - /** - * Padding top. - */ - public static readonly PADDING_TOP: string = '4%'; - - /** - * 1.5%. - */ - public static readonly ONE_POINT_FIVE_PERCENT: string = '1.5%'; - - /** - * Margin 0.5%. - */ - public static readonly MARGIN_ZERO_POINT_FIVE_PERCENT: string = '0.5%'; - - /** - * Margin top. - */ - public static readonly MARGIN_TOP: string = '0.4%'; - - /** - * Margin 0.3%. - */ - public static readonly MARGIN_ZERO_POINT_THREE_PERCENT: string = '0.3%'; - - /** - * Text fontWight. - */ - public static readonly TEXT_FONT_WIGHT: number = 700; - - /** - * Text lineHeight. - */ - public static readonly TEXT_LINE_HEIGHT: number = 28; - - /** - * Text lineHeight 19. - */ - public static readonly TEXT_LINE_HEIGHT_19: number = 19; - - /** - * Text fontWight 400. - */ - public static readonly TEXT_FONT_WIGHT_400: number = 400; - - /** - * Text opacity. - */ - public static readonly TEXT_OPACITY: number = 0.6; - - /** - * TextArea placeholder. - */ - public static readonly TEXT_AREA_PLACEHOLDER: string = 'Input text here...'; - - /** - * Breakpoint sm. - */ - public static readonly BREAK_POINT_SM: string = 'sm'; -} diff --git a/pickersample/oh_modules/pickerlibrary/src/main/ets/common/Logger.ets b/pickersample/oh_modules/pickerlibrary/src/main/ets/common/Logger.ets deleted file mode 100644 index 8cbb4628fe5d0d9422ea276b825549fd492d116c..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/src/main/ets/common/Logger.ets +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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'; - -/** - * Common log for all features. - */ -export class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0x0000; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } - - fatal(...args: string[]): void { - hilog.fatal(this.domain, this.prefix, this.format, args); - } - - isLoggable(level: number): void { - hilog.isLoggable(this.domain, this.prefix, level); - } -} - -export default new Logger('[Picker]'); \ No newline at end of file diff --git a/pickersample/oh_modules/pickerlibrary/src/main/ets/media/MediaFileUri.ets b/pickersample/oh_modules/pickerlibrary/src/main/ets/media/MediaFileUri.ets deleted file mode 100644 index e5a0e4388529aefe0024be620e7fa5c5122b647a..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/src/main/ets/media/MediaFileUri.ets +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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 } from '@kit.CoreFileKit'; -import Logger from '../common/Logger'; -import { bufferToString } from '../common/Common'; - -const TAG = 'MediaFileUri'; -// File read/write buffer size -const BUFFER_SIZE = 4096; - -export default class MediaFileUri { - private fileSizeList: Array = []; - private fileNameList: Array = []; - private fileUriList: Array = []; - - readFileContent(uri: string): string { - let content = ''; - let file = fileIo.openSync(uri, fileIo.OpenMode.READ_ONLY); - try { - let buffer = new ArrayBuffer(BUFFER_SIZE); - fileIo.readSync(file.fd, buffer, { - offset: 0 - }); - content = bufferToString(buffer); - } catch (err) { - Logger.error(TAG, 'openReadSync: open file failed.'); - } - fileIo.closeSync(file); - return content; - } - - myGetFileSize(uri: string, mode: number): number { - let file = fileIo.openSync(uri, mode); - let stat = fileIo.statSync(file.fd); - fileIo.close(file) - Logger.info(TAG, 'get file info succeed.'); - return stat.size; - } - - writeFileContent(uri: string, content: string): void { - Logger.info(TAG, 'writeFileContent begin'); - let file = fileIo.openSync(uri, fileIo.OpenMode.READ_WRITE); - fileIo.write(file.fd, content).then(() => { - Logger.info(TAG, 'writeFileContent write data to file succeed.'); - }).finally(() => { - fileIo.closeSync(file); - }) - } - - async getAllFiles(): Promise { - Logger.info(TAG, 'getAllFiles begin'); - AppStorage.setOrCreate('fileNameList', this.fileNameList); - AppStorage.setOrCreate('fileSizeList', this.fileSizeList); - AppStorage.setOrCreate('fileUriList', this.fileUriList); - } -} \ No newline at end of file diff --git a/pickersample/oh_modules/pickerlibrary/src/main/ets/pages/ViewMedia.ets b/pickersample/oh_modules/pickerlibrary/src/main/ets/pages/ViewMedia.ets deleted file mode 100644 index 201dfa9212df2c936dbbfcf31d740889bcbdd222..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/src/main/ets/pages/ViewMedia.ets +++ /dev/null @@ -1,276 +0,0 @@ -/* - * 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 } from '@kit.CoreFileKit'; -import MediaFileUri from '../media/MediaFileUri'; -import Logger from '../common/Logger'; -import { Constants } from '../common/Constants'; -import { BreakpointType } from '../utils/BreakpointSystem'; -import { image } from '@kit.ImageKit'; -import { UrisParam } from './PickerPage'; - -const TAG = 'ViewMedia'; - -interface myParams extends Object { - uris: string[], - thumbnailList: image.PixelMap[] -}; - -@Builder -export function ViewMediaBuilder(name: string, params: UrisParam) { - ViewMedia({ params }); -} - -@Entry -@Component -struct ViewMedia { - @State myFileSizes: number[] = []; - @State myFileNames: string[] = []; - @State myFileTypes: number[] = []; - @State controls: Array = []; - @State myUris: string[] = this.params?.uris || []; - @StorageLink('myFileName') myFileName: string = ''; - @StorageLink('myFileSize') myFileSize: number = 0; - @StorageLink('showPauses') showPauses: Array = []; - @StorageProp('bottomRectHeight') bottomRectHeight: number = 0; - @StorageProp('topRectHeight') topRectHeight: number = 0; - @StorageProp('currentBreakpoint') curBp: string = Constants.BREAK_POINT_SM; - mediaFileUri: MediaFileUri = new MediaFileUri(); - scroller: Scroller = new Scroller(); - controllers: Array = []; - params?: UrisParam - @Consume('pathStack') pageStack: NavPathStack; - - onPageShow() { - this.getImagesInfo(); - this.myFileName = this.myFileNames[0]; - this.myFileSize = this.myFileSizes[0]; - Logger.info(TAG, 'onPageShow getFilenameByUriForMedia begin'); - AppStorage.setOrCreate('myFileName', this.myFileName); - AppStorage.setOrCreate('myFileSize', this.myFileSize); - } - - async getMediaNameByUri(myUri: string, index: number) { - Logger.info(TAG, 'getMediaNameByUri getFilenameByUriForMedia begin'); - this.myFileName = (myUri.split('/').pop()) as string; - this.myFileNames[index] = this.myFileName; - } - - getImagesInfo() { - for (let index = 0; index < this.myUris.length; index++) { - Logger.info(TAG, 'getFilenameByUriForMedia getImagesInfo index: ' + index); - this.controllers[index] = new VideoController(); - this.controls[index] = false; - this.getMediaNameByUri(this.myUris[index], index); - this.myFileSizes[index] = this.mediaFileUri.myGetFileSize(this.myUris[index], fileIo.OpenMode.READ_ONLY); - } - } - - build() { - NavDestination() { - Column() { - Row() { - Button({ type: ButtonType.Circle }) { - SymbolGlyph($r('sys.symbol.chevron_backward')) - .fontSize($r('sys.float.Title_M')) - .fontColor([$r('sys.color.font_primary')]) - } - .focusable(true) - .focusOnTouch(true) - .id('back2Index') - .height(40) - .aspectRatio(1) - .backgroundColor($r('sys.color.comp_background_tertiary')) - .onClick(() => { - this.pageStack.pop() - }) - - // File name and information. - Column() { - Row() { - Text(this.myFileName) - .focusable(true) - .focusOnTouch(true) - .fontSize($r('app.float.text_font_size')) - .fontFamily('HarmonyHeiTi-Bold') - .fontColor($r('sys.color.font_primary')) - .textAlign(TextAlign.Start) - .fontWeight(Constants.TEXT_FONT_WIGHT) - .lineHeight($r('app.float.text_height')) - .maxLines(1) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - } - .width(Constants.FULL_PERCENT) - .align(Alignment.Start) - .margin({ - top: Constants.MARGIN_TOP, - bottom: Constants.MARGIN_ZERO_POINT_THREE_PERCENT - }) - - Row() { - Text('size: ' + JSON.stringify(this.myFileSize) + 'B') - .focusable(true) - .focusOnTouch(true) - .opacity(Constants.TEXT_OPACITY) - .fontFamily('HarmonyHeiTi') - .fontSize($r('app.float.text_font_size_14')) - .fontColor($r('sys.color.font_primary')) - .textAlign(TextAlign.Start) - .lineHeight($r('app.float.text_height_19')) - .fontWeight(Constants.TEXT_FONT_WIGHT_400) - } - .width(Constants.FULL_PERCENT) - .margin({ - top: Constants.MARGIN_ZERO_POINT_THREE_PERCENT, - bottom: Constants.MARGIN_ZERO_POINT_FIVE_PERCENT - }) - .align(Alignment.Start) - } - .margin({ left: $r('sys.float.padding_level4') }) - .width(Constants.FORTY_FIVE_PERCENT) - } - .padding({ - left: new BreakpointType({ - sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level12'), - lg: $r('sys.float.padding_level16') - }).getValue(this.curBp), - right: new BreakpointType({ - sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level12'), - lg: $r('sys.float.padding_level16') - }).getValue(this.curBp) - }) - .height(56) - .width(Constants.FULL_PERCENT) - .zIndex(2) - - Column() { - Scroll(this.scroller) { - Column() { - List() { - ForEach(this.myUris, (uri: string, index: number) => { - ListItem() { - Column() { - Image(uri) - .borderRadius(16) - .margin({ - bottom: new BreakpointType({ - sm: $r('sys.float.padding_level6'), md: $r('sys.float.padding_level8'), - lg: $r('sys.float.padding_level10') - }).getValue(this.curBp) - }) - .onClick(() => { - if (index !== undefined) { - this.myFileSize = this.myFileSizes[index]; - this.myFileName = this.myFileNames[index]; - } - AppStorage.setOrCreate('myFileName', this.myFileName); - AppStorage.setOrCreate('myFileSize', this.myFileSize); - Logger.info(TAG, 'Obtain the name and size of the clicked image.'); - }) - if (uri.substring(uri.length, uri.length - 3) === 'mp4') { - Stack({ alignContent: Alignment.Center }) { - Video({ - src: uri, - controller: this.controllers[index], - previewUri: $r('app.media.img') - }) - .foregroundBlurStyle( - this.controls[index] === false ? BlurStyle.Thin : BlurStyle.NONE, - this.controls[index] === false ? { - colorMode: ThemeColorMode.SYSTEM, - adaptiveColor: AdaptiveColor.DEFAULT, - blurOptions: { grayscale: [50, 50] }, - scale: 0.5 - } : {}) - .margin({ - bottom: new BreakpointType({ - sm: $r('sys.float.padding_level6'), md: $r('sys.float.padding_level8'), - lg: $r('sys.float.padding_level10') - }).getValue(this.curBp) - }) - .onStart(() => { - this.controls[index] = true; - }) - .onFinish(() => { - this.controls[index] = false; - }) - .onPause(() => { - this.controls[index] = false; - }) - .autoPlay(false) - .controls(this.controls[index]) - .borderRadius(16) - - Image($r('app.media.ic_PAUSE')) - .width(40) - .height(40) - .onClick(() => { - this.controllers[index].start(); - this.showPauses[index] = 0; - - this.myFileSize = this.myFileSizes[index]; - this.myFileName = this.myFileNames[index]; - AppStorage.setOrCreate('myFileName', this.myFileName); - AppStorage.setOrCreate('myFileSize', this.myFileSize); - }) - .visibility(this.controls[index] === false ? Visibility.Visible : Visibility.Hidden) - } - .onClick(() => { - this.myFileSize = this.myFileSizes[index]; - this.myFileName = this.myFileNames[index]; - - AppStorage.setOrCreate('myFileName', this.myFileName); - AppStorage.setOrCreate('myFileSize', this.myFileSize); - }) - } - } - .height(Constants.FULL_PERCENT) - } - .height(190) - }, (item: string) => item) - } - .lanes(new BreakpointType({ sm: 1, md: 2, lg: 4 }).getValue(this.curBp), 20) - .width(Constants.FULL_PERCENT) - .height(new BreakpointType({ - sm: 190 * this.myUris.length, md: 190 * Math.ceil(this.myUris.length / 2), - lg: 190 - }).getValue(this.curBp)) - .id('picScroller') - .scrollBar(BarState.Auto) - } - .padding({ - top: Constants.ONE_POINT_FIVE_PERCENT, - left: new BreakpointType({ - sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level12'), - lg: $r('sys.float.padding_level16') - }).getValue(this.curBp), - right: new BreakpointType({ - sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level12'), - lg: $r('sys.float.padding_level16') - }).getValue(this.curBp) - }) - } - .padding({ bottom: this.bottomRectHeight }) - } - .align(Alignment.Start) - .layoutWeight(1) - } - .backgroundColor($r('sys.color.gray_01')) - .height(Constants.FULL_PERCENT) - .padding({ top: this.topRectHeight }) - } - .hideTitleBar(true) - } -} \ No newline at end of file diff --git a/pickersample/oh_modules/pickerlibrary/src/main/ets/utils/BreakpointSystem.ets b/pickersample/oh_modules/pickerlibrary/src/main/ets/utils/BreakpointSystem.ets deleted file mode 100644 index aa7581b2047323eac83c8d9a031e21faabc55bd2..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/src/main/ets/utils/BreakpointSystem.ets +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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 { window } from '@kit.ArkUI'; -import type { BusinessError } from '@kit.BasicServicesKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG: string = '[BreakpointSystem]'; - -export enum BreakpointTypeEnum { - XS = 'xs', - SM = 'sm', - MD = 'md', - LG = 'lg', - XL = 'xl', -} - -export interface BreakpointTypes { - xs?: T; - sm: T; - md: T; - lg: T; - xl?: T; -} - -export class BreakpointType { - private xs: T; - private sm: T; - private md: T; - private lg: T; - private xl: T; - - public constructor(param: BreakpointTypes) { - this.xs = param.xs || param.sm; - this.sm = param.sm; - this.md = param.md; - this.lg = param.lg; - this.xl = param.xl || param.lg; - } - - public getValue(currentBreakpoint: string): T { - if (currentBreakpoint === BreakpointTypeEnum.XS) { - return this.xs; - } - if (currentBreakpoint === BreakpointTypeEnum.SM) { - return this.sm; - } - if (currentBreakpoint === BreakpointTypeEnum.MD) { - return this.md; - } - if (currentBreakpoint === BreakpointTypeEnum.XL) { - return this.xl; - } - return this.lg; - } -} - -export class BreakpointSystem { - private static instance: BreakpointSystem; - private currentBreakpoint: BreakpointTypeEnum = BreakpointTypeEnum.MD; - - private constructor() { - } - - public static getInstance(): BreakpointSystem { - if (!BreakpointSystem.instance) { - BreakpointSystem.instance = new BreakpointSystem(); - } - return BreakpointSystem.instance; - } - - public updateCurrentBreakpoint(breakpoint: BreakpointTypeEnum): void { - if (this.currentBreakpoint !== breakpoint) { - this.currentBreakpoint = breakpoint; - AppStorage.setOrCreate('currentBreakpoint', this.currentBreakpoint); - } - } - - public onWindowSizeChange(window: window.Window): void { - this.updateWidthBp(window); - } - - public updateWidthBp(window: window.Window): void { - try { - const mainWindow: window.WindowProperties = window.getWindowProperties(); - const windowWidth: number = mainWindow.windowRect.width; - const windowWidthVp = px2vp(windowWidth); - let widthBp: BreakpointTypeEnum = BreakpointTypeEnum.MD; - if (windowWidthVp < 320) { - widthBp = BreakpointTypeEnum.XS; - } else if (windowWidthVp >= 320 && windowWidthVp < 600) { - widthBp = BreakpointTypeEnum.SM; - } else if (windowWidthVp >= 600 && windowWidthVp < 840) { - widthBp = BreakpointTypeEnum.MD; - } else if (windowWidthVp >= 840 && windowWidthVp < 1440) { - widthBp = BreakpointTypeEnum.LG; - } else { - widthBp = BreakpointTypeEnum.XL; - } - this.updateCurrentBreakpoint(widthBp); - } catch (error) { - const err: BusinessError = error as BusinessError; - hilog.error(0x0000, TAG, `UpdateBreakpoint fail, error code: ${err.code}, message: ${err.message}`); - } - } -} \ No newline at end of file diff --git a/pickersample/oh_modules/pickerlibrary/src/main/ets/utils/WindowUtil.ets b/pickersample/oh_modules/pickerlibrary/src/main/ets/utils/WindowUtil.ets deleted file mode 100644 index 89e954364f2d8ebdac8a96584dc71504a721d9a2..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/src/main/ets/utils/WindowUtil.ets +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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 { window } from '@kit.ArkUI'; -import type { BusinessError } from '@kit.BasicServicesKit'; -import { BreakpointSystem } from './BreakpointSystem'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { ConfigurationConstant, Configuration, UIAbility } from '@kit.AbilityKit'; - -const TAG: string = '[WindowUtil]'; - -export class WindowUtil { - public static requestFullScreen(windowStage: window.WindowStage): void { - windowStage.getMainWindow((err: BusinessError, data: window.Window) => { - if (err.code) { - return; - } - const windowClass: window.Window = data; - // Realize the immersive effect. - try { - const promise: Promise = windowClass.setWindowLayoutFullScreen(true); - promise.then(() => { - hilog.info(0x0000, TAG, 'Succeeded in setting the window layout to full-screen mode.'); - }).catch((err: BusinessError) => { - hilog.info(0x0000, TAG, - `Failed to set the window layout to full-screen mode. Cause: ${err.code}, ${err.message}`); - }); - } catch { - hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode. '); - } - }); - } - - public static registerBreakPoint(windowStage: window.WindowStage) { - windowStage.getMainWindow((err: BusinessError, data: window.Window) => { - if (err.code) { - hilog.error(0x0000, TAG, `Failed to get main window: ${err.message}`); - return; - } - BreakpointSystem.getInstance().updateWidthBp(data); - data.on('windowSizeChange', () => BreakpointSystem.getInstance().onWindowSizeChange(data)); - data.on('avoidAreaChange', (avoidAreaOption) => { - if (avoidAreaOption.type === window.AvoidAreaType.TYPE_SYSTEM || - avoidAreaOption.type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { - WindowUtil.setAvoidArea(avoidAreaOption.type, avoidAreaOption.area); - } - }); - }) - } - - // Get status bar height and indicator height. - public static setAvoidArea(type: window.AvoidAreaType, area: window.AvoidArea) { - if (type === window.AvoidAreaType.TYPE_SYSTEM) { - AppStorage.setOrCreate('topRectHeight', px2vp(area.topRect.height)); - } else { - AppStorage.setOrCreate('bottomRectHeight', px2vp(area.bottomRect.height)); - } - } -} \ No newline at end of file diff --git a/pickersample/oh_modules/pickerlibrary/src/main/module.json5 b/pickersample/oh_modules/pickerlibrary/src/main/module.json5 deleted file mode 100644 index d95d82e26ab08ef72c21824afdd8f72dabbbb757..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/src/main/module.json5 +++ /dev/null @@ -1,12 +0,0 @@ -{ - "module": { - "name": "pickerlibrary", - "type": "har", - "deviceTypes": [ - "default", - "tablet", - "2in1" - ], - "routerMap": "$profile:route_map" - } -} diff --git a/pickersample/oh_modules/pickerlibrary/src/main/resources/base/element/color.json b/pickersample/oh_modules/pickerlibrary/src/main/resources/base/element/color.json deleted file mode 100644 index 3c712962da3c2751c2b9ddb53559afcbd2b54a02..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/pickersample/oh_modules/pickerlibrary/src/main/resources/base/element/float.json b/pickersample/oh_modules/pickerlibrary/src/main/resources/base/element/float.json deleted file mode 100644 index 9ecdea91f1b6963d7e946c423de2cdc732a182c5..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/src/main/resources/base/element/float.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "float": [ - { - "name": "text_font_size", - "value": "20fp" - }, - { - "name": "text_font_size_14", - "value": "14fp" - }, - { - "name": "text_area_font_size", - "value": "16fp" - }, - { - "name": "padding_top_bottom", - "value": "8vp" - }, - { - "name": "padding_left_right", - "value": "16vp" - }, - { - "name": "text_height", - "value": "28vp" - }, - { - "name": "text_height_19", - "value": "19vp" - } - ] -} \ No newline at end of file diff --git a/pickersample/oh_modules/pickerlibrary/src/main/resources/base/element/string.json b/pickersample/oh_modules/pickerlibrary/src/main/resources/base/element/string.json deleted file mode 100644 index 6afb318083a76c9eea54bc823675526ec2f8e705..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/src/main/resources/base/element/string.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "last_open", - "value": "Selecting and View Files" - }, - { - "name": "editable", - "value": "Editable" - }, - { - "name": "saved", - "value": "Saved" - }, - { - "name": "show_toast_message", - "value": "Save failed, file operation without permission." - }, - { - "name": "new_file", - "value": "New File" - }, - { - "name": "picture", - "value": "Selecting and View Media Files" - }, - { - "name": "edit_file", - "value": "Selecting and View Files" - } - ] -} \ No newline at end of file diff --git a/pickersample/oh_modules/pickerlibrary/src/main/resources/base/media/ic_PAUSE.svg b/pickersample/oh_modules/pickerlibrary/src/main/resources/base/media/ic_PAUSE.svg deleted file mode 100644 index c5f5c46b757ff9251360497ef2deefe600695823..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/src/main/resources/base/media/ic_PAUSE.svg +++ /dev/null @@ -1,13 +0,0 @@ - - - ic_PAUSE - - - - - - - - - - \ No newline at end of file diff --git a/pickersample/oh_modules/pickerlibrary/src/main/resources/base/media/icon.png b/pickersample/oh_modules/pickerlibrary/src/main/resources/base/media/icon.png deleted file mode 100644 index ce307a8827bd75456441ceb57d530e4c8d45d36c..0000000000000000000000000000000000000000 Binary files a/pickersample/oh_modules/pickerlibrary/src/main/resources/base/media/icon.png and /dev/null differ diff --git a/pickersample/oh_modules/pickerlibrary/src/main/resources/base/media/img.png b/pickersample/oh_modules/pickerlibrary/src/main/resources/base/media/img.png deleted file mode 100644 index 5f4aca510894e606263a8df2a9f90dd29a0b44cf..0000000000000000000000000000000000000000 Binary files a/pickersample/oh_modules/pickerlibrary/src/main/resources/base/media/img.png and /dev/null differ diff --git a/pickersample/oh_modules/pickerlibrary/src/main/resources/en_US/element/string.json b/pickersample/oh_modules/pickerlibrary/src/main/resources/en_US/element/string.json deleted file mode 100644 index 6afb318083a76c9eea54bc823675526ec2f8e705..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/src/main/resources/en_US/element/string.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "last_open", - "value": "Selecting and View Files" - }, - { - "name": "editable", - "value": "Editable" - }, - { - "name": "saved", - "value": "Saved" - }, - { - "name": "show_toast_message", - "value": "Save failed, file operation without permission." - }, - { - "name": "new_file", - "value": "New File" - }, - { - "name": "picture", - "value": "Selecting and View Media Files" - }, - { - "name": "edit_file", - "value": "Selecting and View Files" - } - ] -} \ No newline at end of file diff --git a/pickersample/oh_modules/pickerlibrary/src/main/resources/zh_CN/element/string.json b/pickersample/oh_modules/pickerlibrary/src/main/resources/zh_CN/element/string.json deleted file mode 100644 index b171ee460a6247d7e6ab942b54062ba30a6f264c..0000000000000000000000000000000000000000 --- a/pickersample/oh_modules/pickerlibrary/src/main/resources/zh_CN/element/string.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "模块描述" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "last_open", - "value": "选择并查看文件" - }, - { - "name": "editable", - "value": "进入编辑状态" - }, - { - "name": "saved", - "value": "已保存" - }, - { - "name": "show_toast_message", - "value": "保存失败,文件操作无权限" - }, - { - "name": "new_file", - "value": "新建文件" - }, - { - "name": "picture", - "value": "选择并查看媒体文件" - }, - { - "name": "edit_file", - "value": "选择并查看/编辑文件" - } - ] -} \ No newline at end of file diff --git a/pickersample/src/main/ets/entryability/EntryAbility.ets b/pickersample/src/main/ets/entryability/EntryAbility.ets index 511964a95a86ac6fc5ce2ba0d99c2329180ef86a..78331a49e1260f5a748c9013692499b4838cdff4 100644 --- a/pickersample/src/main/ets/entryability/EntryAbility.ets +++ b/pickersample/src/main/ets/entryability/EntryAbility.ets @@ -13,66 +13,48 @@ * limitations under the License. */ -import { Configuration, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { window } from '@kit.ArkUI'; -import { WindowUtil } from 'pickerlibrary'; -import WantUtil, { TAG } from 'pickerlibrary/src/main/ets/utils/WantUtil'; -import Logger from 'pickerlibrary/src/main/ets/common/Logger'; +import { ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; +import { window } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { PickerController } from '@ohos_samples/pickerlibrary'; -export default class EntryAbility extends UIAbility { +const TAG = 'EntryAbility: '; +export default class EntryAbility extends UIAbility { onCreate(): void { - Logger.info(TAG, 'Ability onCreate'); - AppStorage.setOrCreate('systemColorMode', this.context.config.colorMode); + hilog.info(0x0000, TAG, '%{public}s', 'Ability onCreate'); this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); } - onConfigurationUpdate(newConfig: Configuration): void { - let newColorMode: ConfigurationConstant.ColorMode = - newConfig.colorMode || ConfigurationConstant.ColorMode.COLOR_MODE_DARK; - let currentColorMode = AppStorage.get('systemColorMode'); - if (newColorMode !== currentColorMode) { - AppStorage.setOrCreate('systemColorMode', newColorMode); - } - } - - onNewWant(want: Want): void { - Logger.info(TAG, 'Ability onNewWant'); - WantUtil.getWantInfo(want); - } - onDestroy(): void { - Logger.info(TAG, 'Ability onDestroy'); + hilog.info(0x0000, TAG, '%{public}s', 'Ability onDestroy'); } onWindowStageCreate(windowStage: window.WindowStage): void { - WantUtil.windowStage = windowStage; - WindowUtil.requestFullScreen(windowStage) - WindowUtil.registerBreakPoint(windowStage) - // Main window is created, set main page for this ability - Logger.info(TAG, 'Ability onWindowStageCreate'); - windowStage.loadContent('pages/Index', (err) => { + hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageCreate'); + windowStage.loadContent('pages/Index', (err, data) => { if (err.code) { - Logger.error(TAG, 'Failed to load the content.'); + hilog.error(0x0000, TAG, `Failed to load the content, code: ${err.code}, message: ${err.message}}.`); return; } - Logger.info(TAG, 'Succeeded in loading the content.'); + PickerController.initWindowConfig(windowStage); + hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in loading the content.'); }); } onWindowStageDestroy(): void { // Main window is destroyed, release UI related resources - Logger.info(TAG, 'Ability onWindowStageDestroy'); + hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageDestroy'); } onForeground(): void { // Ability has brought to foreground - Logger.info(TAG, 'Ability onForeground'); + hilog.info(0x0000, TAG, '%{public}s', 'Ability onForeground'); } onBackground(): void { // Ability has back to background - Logger.info(TAG, 'Ability onBackground'); + hilog.info(0x0000, TAG, '%{public}s', 'Ability onBackground'); } } \ No newline at end of file diff --git a/pickersample/src/main/ets/pages/Index.ets b/pickersample/src/main/ets/pages/Index.ets index 237d9256081e0fc590d4e7b955f9a401d6071758..78577ea7189994deaf01adf3d3d2ff46c0e8c914 100644 --- a/pickersample/src/main/ets/pages/Index.ets +++ b/pickersample/src/main/ets/pages/Index.ets @@ -13,14 +13,14 @@ * limitations under the License. */ -import { PickerPage } from 'pickerlibrary' +import { PickerComponent } from '@ohos_samples/pickerlibrary' @Entry @Component struct Index { build() { Stack() { - PickerPage() + PickerComponent() } } } \ No newline at end of file diff --git a/pickerlibrary/src/main/resources/base/element/color.json b/pickersample/src/main/resources/base/element/color.json similarity index 100% rename from pickerlibrary/src/main/resources/base/element/color.json rename to pickersample/src/main/resources/base/element/color.json diff --git a/pickersample/src/main/resources/base/element/string.json b/pickersample/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a03dbe2a62c5b8da1bf1a4ef572514488c3cea5e --- /dev/null +++ b/pickersample/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + } + ] +} \ No newline at end of file diff --git a/pickerlibrary/src/main/resources/base/media/icon.png b/pickersample/src/main/resources/base/media/icon.png similarity index 100% rename from pickerlibrary/src/main/resources/base/media/icon.png rename to pickersample/src/main/resources/base/media/icon.png diff --git a/pickersample/src/main/resources/en_US/element/string.json b/pickersample/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a03dbe2a62c5b8da1bf1a4ef572514488c3cea5e --- /dev/null +++ b/pickersample/src/main/resources/en_US/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + } + ] +} \ No newline at end of file diff --git a/pickersample/src/main/resources/zh_CN/element/string.json b/pickersample/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1e95d07cfc80625b442842fa5cd869c8016b401f --- /dev/null +++ b/pickersample/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + } + ] +} \ No newline at end of file