diff --git a/commons/commons/.gitignore b/commons/commons/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/commons/commons/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/commons/commons/Index.ets b/commons/commons/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b4a404b4456fc0e5aed779fe890729f1cc32318d --- /dev/null +++ b/commons/commons/Index.ets @@ -0,0 +1,2 @@ +export { Logger } from './src/main/ets/utils/Logger'; +export { selectImagesFromAlbum } from './src/main/ets/utils/FileUtils' diff --git a/commons/commons/build-profile.json5 b/commons/commons/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..79961f96a6fe0507354b7952a378c3be2ae4bfab --- /dev/null +++ b/commons/commons/build-profile.json5 @@ -0,0 +1,10 @@ +{ + "apiType": "stageMode", + "buildOption": { + }, + "targets": [ + { + "name": "default" + } + ] +} diff --git a/commons/commons/hvigorfile.ts b/commons/commons/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..805c5d7f6809c51cff0b4adcc1142979f8f864b6 --- /dev/null +++ b/commons/commons/hvigorfile.ts @@ -0,0 +1,6 @@ +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. */ +} \ No newline at end of file diff --git a/commons/commons/oh-package.json5 b/commons/commons/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d50184a32b1cf153f7dc71afeb97d601086fa6a7 --- /dev/null +++ b/commons/commons/oh-package.json5 @@ -0,0 +1,9 @@ +{ + "name": "commons", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "Index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": {} +} diff --git a/commons/commons/src/main/ets/utils/FileUtils.ets b/commons/commons/src/main/ets/utils/FileUtils.ets new file mode 100644 index 0000000000000000000000000000000000000000..a9d38a383f9a4ce4566a1b725ff50fc72ff7cbed --- /dev/null +++ b/commons/commons/src/main/ets/utils/FileUtils.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { photoAccessHelper } from '@kit.MediaLibraryKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { Logger } from './Logger'; + +const TAG_LOG = 'FileUtil'; + +/** + * Select a images from the album + * + * @returns {string[]} return selected image uris + */ +export function selectImagesFromAlbum(maxNumber: number = 5): Promise { + const photoPicker = new photoAccessHelper.PhotoViewPicker(); + const photoSelectOptions: photoAccessHelper.PhotoSelectOptions = { + MIMEType: photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE, + maxSelectNumber: maxNumber + }; + return photoPicker.select(photoSelectOptions).then(photoSelectResult => { + return photoSelectResult.photoUris; + }).catch((e: BusinessError) => { + Logger.error(TAG_LOG, `Failed to select images from album: ${e.code}, ${e.message}`); + return []; + }); +} \ No newline at end of file diff --git a/commons/commons/src/main/ets/utils/Logger.ets b/commons/commons/src/main/ets/utils/Logger.ets new file mode 100644 index 0000000000000000000000000000000000000000..c769a6076e62e5ec82a07d80992354b31e0b5702 --- /dev/null +++ b/commons/commons/src/main/ets/utils/Logger.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 ("the License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; + +export class Logger { + private static readonly DOMAIN: number = 0xFF00; + private static readonly TAG: string = 'com.example.customcamera'; + private static readonly PREFIX: string = '[camera-log]'; + + public static debug(logTag: string, messageFormat: string, ...args: Object[]): void { + hilog.debug(Logger.DOMAIN, Logger.TAG, `${Logger.PREFIX} ${logTag}: ${messageFormat}`, args); + } + + public static info(logTag: string, messageFormat: string, ...args: Object[]): void { + hilog.info(Logger.DOMAIN, Logger.TAG, `${Logger.PREFIX} ${logTag}: ${messageFormat}`, args); + } + + public static warn(logTag: string, messageFormat: string, ...args: Object[]): void { + hilog.warn(Logger.DOMAIN, Logger.TAG, `${Logger.PREFIX} ${logTag}: ${messageFormat}`, args); + } + + public static error(logTag: string, messageFormat: string, ...args: Object[]): void { + hilog.error(Logger.DOMAIN, Logger.TAG, `${Logger.PREFIX} ${logTag}: ${messageFormat}`, args); + } + + public static fatal(logTag: string, messageFormat: string, ...args: Object[]): void { + hilog.fatal(Logger.DOMAIN, Logger.TAG, `${Logger.PREFIX} ${logTag}: ${messageFormat}`, args); + } + + private constructor() { + } +} diff --git a/commons/commons/src/main/module.json5 b/commons/commons/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1adf09bd6b0aa0969846d642a9e50eedf6cf31ee --- /dev/null +++ b/commons/commons/src/main/module.json5 @@ -0,0 +1,9 @@ +{ + "module": { + "name": "commons", + "type": "har", + "deviceTypes": [ + "default" + ] + } +} diff --git a/commons/commons/src/main/resources/base/element/float.json b/commons/commons/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/commons/commons/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/commons/commons/src/main/resources/base/element/string.json b/commons/commons/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f51a9c8461a55f6312ef950344e3145b7f82d607 --- /dev/null +++ b/commons/commons/src/main/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "page_show", + "value": "page from package" + } + ] +} diff --git a/features/home/oh-package.json5 b/features/home/oh-package.json5 index 3f480ab37f3c94d804a9741a33d4eb2ffb5b4d00..ddab6f1cb11d482c984f91e7bdd6aed385c3d2c2 100644 --- a/features/home/oh-package.json5 +++ b/features/home/oh-package.json5 @@ -5,5 +5,7 @@ "main": "Index.ets", "author": "", "license": "Apache-2.0", - "dependencies": {} + "dependencies": { + "commons": "file:../../commons/commons" + } } diff --git a/features/home/src/main/ets/view/CommentKeyboard.ets b/features/home/src/main/ets/view/CommentKeyboard.ets index 49d091747e4b32521f4052b6423976517c6525cc..f3899b62a6365213de059f8752b094013bbcde60 100644 --- a/features/home/src/main/ets/view/CommentKeyboard.ets +++ b/features/home/src/main/ets/view/CommentKeyboard.ets @@ -15,6 +15,9 @@ import { window } from "@kit.ArkUI"; import { NavigationDialog } from "./NavigationDialog"; +import { Logger, selectImagesFromAlbum } from 'commons' + +const TAG = 'CommentKeyboard'; interface OperateButton { icon: Resource @@ -59,6 +62,8 @@ export struct CommentKeyboard { @State isEmojiKeyboardVisible: boolean = false; @State isAtFriendListVisible: boolean = false; @Consume navDialogPageInfos: NavPathStack; + // When the photo picker is pulled up, the soft keyboard will also be dismissed, but no need to exit the comment page + @State isPhotoPickerVisible: boolean = false; // [Start comment_keyboard1] aboutToAppear(): void { @@ -79,7 +84,7 @@ export struct CommentKeyboard { addKeyboardHeightListener(win: window.Window) { win.on('keyboardHeightChange', height => { - console.info('keyboard height has changed', this.getUIContext().px2vp(height)); + Logger.info(TAG, 'keyboard height has changed', this.getUIContext().px2vp(height)); if (height !== 0) { this.keyboardHeight = this.getUIContext().px2vp(height); return; @@ -87,8 +92,10 @@ export struct CommentKeyboard { // [StartExclude comment_keyboard1] // if close keyboard, don't set keyboardHeight, avoid EmojiKeyboard height is 0 if (!this.isEmojiKeyboardVisible) { - // handle keyboard close button click - console.info('click soft keyboard close button'); + // When the photo picker is pulled up, the soft keyboard will also be dismissed, but no need to exit the comment page + if (this.isPhotoPickerVisible) return; + // handle system keyboard close button click + Logger.info(TAG, 'click soft keyboard close button'); this.navDialogPageInfos.pop(); } // [EndExclude comment_keyboard1] @@ -107,11 +114,20 @@ export struct CommentKeyboard { icon: this.isEmojiKeyboardVisible ? $r('app.media.keyboard_circle') : $r('app.media.face'), onClick: this.onEmojiButtonClick }, - { icon: $r('app.media.picture') }, + { icon: $r('app.media.picture'), onClick: this.onPictureButtonClick }, { icon: $r('app.media.paper_plane'), onClick: this.onSendComment } ]; } + onPictureButtonClick: () => void = () => { + this.isPhotoPickerVisible = true; + selectImagesFromAlbum(1).then(uris => { + Logger.info(TAG, JSON.stringify(uris)); + }).finally(() => { + this.isPhotoPickerVisible = false; + }); + } + // [Start comment_keyboard2] // features/home/src/main/ets/view/CommentKeyboard.ets onAtButtonClick: (event?: ClickEvent) => void = event => { @@ -162,7 +178,7 @@ export struct CommentKeyboard { richEditorSpans.push(richEditorSpan); }); // [StartExclude comment_keyboard4] - console.info('richEditorContent', JSON.stringify(richEditorSpans)); + Logger.info(TAG, 'richEditorContent', JSON.stringify(richEditorSpans)); this.navDialogPageInfos.pop(); this.navDialogPageInfos.pushPathByName('CommentSendDialog', richEditorSpans); // [EndExclude comment_keyboard4] diff --git a/oh-package.json5 b/oh-package.json5 index bb12751b97530b9a3504e56e8ed09d8c9ba1fa52..0cec98259052cc175d04dbcf61780de4bc9785f4 100644 --- a/oh-package.json5 +++ b/oh-package.json5 @@ -3,8 +3,5 @@ "description": "Please describe the basic information.", "dependencies": { }, - "devDependencies": { - "@ohos/hypium": "1.0.19", - "@ohos/hamock": "1.0.0" - } + "devDependencies": {} }