From f165932af3a1c4770f9ea3a8d9047ba78b9ee6ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E5=A4=A7=E4=BE=A0?= <794397348@qq.com> Date: Sat, 24 May 2025 17:19:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=B8=BF=E8=92=99=E4=B8=96=E7=95=8C=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 2 +- README.md | 2 +- build-profile.json5 | 8 +- windowpiplibrary/.gitignore | 6 + windowpiplibrary/BuildProfile.ets | 17 +++ windowpiplibrary/Index.ets | 2 + windowpiplibrary/build-profile.json5 | 28 +++++ windowpiplibrary/consumer-rules.txt | 0 windowpiplibrary/hvigorfile.ts | 6 + windowpiplibrary/obfuscation-rules.txt | 23 ++++ {entry => windowpiplibrary}/oh-package.json5 | 7 +- .../src/main/ets/constants/Constants.ets | 0 .../src/main/ets/pages/AVPlayer.ets | 0 .../src/main/ets/pages/VideoPlay.ets | 0 .../src/main/ets/pages/WindowPipPage.ets | 28 ++--- .../src/main/ets/utils/BreakpointSystem.ets | 118 ++++++++++++++++++ .../src/main/ets/utils/Logger.ets | 0 .../src/main/ets/utils/WindowUtil.ets | 70 +++++++++++ windowpiplibrary/src/main/module.json5 | 11 ++ .../main/resources/base/element/color.json | 0 .../main/resources/base/element/integer.json | 0 .../main/resources/base/element/string.json | 0 .../main/resources/base/media/background.png | Bin .../main/resources/base/media/btn_ground.PNG | Bin .../main/resources/base/media/foreground.png | Bin .../resources/base/media/layered_image.json | 0 .../main/resources/base/media/startIcon.png | Bin .../main/resources/en_US/element/string.json | 0 .../src/main/resources/rawfile/video.mov | Bin .../main/resources/zh_CN/element/string.json | 0 .../build-profile.json5 | 0 {entry => windowpipsample}/hvigorfile.ts | 0 .../obfuscation-rules.txt | 0 windowpipsample/oh-package.json5 | 11 ++ .../main/ets/entryability/EntryAbility.ets | 41 +----- windowpipsample/src/main/ets/pages/Index.ets | 27 ++++ .../src/main/module.json5 | 6 +- .../resources/base/profile/main_pages.json | 2 +- 38 files changed, 346 insertions(+), 69 deletions(-) create mode 100644 windowpiplibrary/.gitignore create mode 100644 windowpiplibrary/BuildProfile.ets create mode 100644 windowpiplibrary/Index.ets create mode 100644 windowpiplibrary/build-profile.json5 create mode 100644 windowpiplibrary/consumer-rules.txt create mode 100644 windowpiplibrary/hvigorfile.ts create mode 100644 windowpiplibrary/obfuscation-rules.txt rename {entry => windowpiplibrary}/oh-package.json5 (60%) rename {entry => windowpiplibrary}/src/main/ets/constants/Constants.ets (100%) rename {entry => windowpiplibrary}/src/main/ets/pages/AVPlayer.ets (100%) rename {entry => windowpiplibrary}/src/main/ets/pages/VideoPlay.ets (100%) rename entry/src/main/ets/pages/WindowPip.ets => windowpiplibrary/src/main/ets/pages/WindowPipPage.ets (85%) create mode 100644 windowpiplibrary/src/main/ets/utils/BreakpointSystem.ets rename {entry => windowpiplibrary}/src/main/ets/utils/Logger.ets (100%) create mode 100644 windowpiplibrary/src/main/ets/utils/WindowUtil.ets create mode 100644 windowpiplibrary/src/main/module.json5 rename {entry => windowpiplibrary}/src/main/resources/base/element/color.json (100%) rename {entry => windowpiplibrary}/src/main/resources/base/element/integer.json (100%) rename {entry => windowpiplibrary}/src/main/resources/base/element/string.json (100%) rename {entry => windowpiplibrary}/src/main/resources/base/media/background.png (100%) rename {entry => windowpiplibrary}/src/main/resources/base/media/btn_ground.PNG (100%) rename {entry => windowpiplibrary}/src/main/resources/base/media/foreground.png (100%) rename {entry => windowpiplibrary}/src/main/resources/base/media/layered_image.json (100%) rename {entry => windowpiplibrary}/src/main/resources/base/media/startIcon.png (100%) rename {entry => windowpiplibrary}/src/main/resources/en_US/element/string.json (100%) rename {entry => windowpiplibrary}/src/main/resources/rawfile/video.mov (100%) rename {entry => windowpiplibrary}/src/main/resources/zh_CN/element/string.json (100%) rename {entry => windowpipsample}/build-profile.json5 (100%) rename {entry => windowpipsample}/hvigorfile.ts (100%) rename {entry => windowpipsample}/obfuscation-rules.txt (100%) create mode 100644 windowpipsample/oh-package.json5 rename {entry => windowpipsample}/src/main/ets/entryability/EntryAbility.ets (63%) create mode 100644 windowpipsample/src/main/ets/pages/Index.ets rename {entry => windowpipsample}/src/main/module.json5 (89%) rename {entry => windowpipsample}/src/main/resources/base/profile/main_pages.json (46%) diff --git a/README.en.md b/README.en.md index 53113a7..8de3e05 100644 --- a/README.en.md +++ b/README.en.md @@ -40,7 +40,7 @@ This sample demonstrates video playback, manual and automatic invocation of Pict - After you touch **Enable**, the app starts a PiP window, and the video is played in the PiP window. When you return to the home screen, the video is still played in the PiP window. After you touch **Disable**, the video is played in the XComponent area, and no PiP window is started when you return to the home screen. - After you enable **Auto PiP**, the app automatically starts a PiP window when you return to the home screen, and the video is played in the PiP window. - When a video is displayed in the PiP window, the XComponent area displays the message "The video is being played in PiP mode." -- The callback information shows the status, error cause, and button event and status. For details, see [VideoPlay.ets](entry/src/main/ets/pages/VideoPlay.ets). +- The callback information shows the status, error cause, and button event and status. For details, see [VideoPlay.ets](windowpiplibrary/src/main/ets/pages/VideoPlay.ets). ## Required Permissions diff --git a/README.md b/README.md index b3b0046..9ba3b96 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ - 点击**开启**后,应用手动拉起画中画,视频在画中画播放,返回桌面视频依旧画中画播放;点击**关闭**后,画中画播放的视频返回**XComponent**播放,同时返回桌面不会拉起画中画。 - 点击**自动拉起画中画**后,返回桌面时应用自动拉起画中画,视频画中画播放。 - 在播放页面进行画中画播放时,XComponent框会提示**当前视频正在以画中画播放**。 -- 回调信息显示框会显示**当前状态**,**错误原因**以及**按钮事件和状态**,参考:[VideoPlay.ets](entry/src/main/ets/pages/VideoPlay.ets)。 +- 回调信息显示框会显示**当前状态**,**错误原因**以及**按钮事件和状态**,参考:[VideoPlay.ets](windowpiplibrary/src/main/ets/pages/VideoPlay.ets)。 ## 相关权限 diff --git a/build-profile.json5 b/build-profile.json5 index c033ce4..1a8dc5b 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -20,8 +20,8 @@ }, "modules": [ { - "name": "entry", - "srcPath": "./entry", + "name": "windowpipsample", + "srcPath": "./windowpipsample", "targets": [ { "name": "default", @@ -30,6 +30,10 @@ ] } ] + }, + { + "name": "windowpiplibrary", + "srcPath": "./windowpiplibrary", } ] } \ No newline at end of file diff --git a/windowpiplibrary/.gitignore b/windowpiplibrary/.gitignore new file mode 100644 index 0000000..e2713a2 --- /dev/null +++ b/windowpiplibrary/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/windowpiplibrary/BuildProfile.ets b/windowpiplibrary/BuildProfile.ets new file mode 100644 index 0000000..3a501e5 --- /dev/null +++ b/windowpiplibrary/BuildProfile.ets @@ -0,0 +1,17 @@ +/** + * Use these variables when you tailor your ArkTS code. They must be of the const type. + */ +export const HAR_VERSION = '1.0.0'; +export const BUILD_MODE_NAME = 'debug'; +export const DEBUG = true; +export const TARGET_NAME = 'default'; + +/** + * BuildProfile Class is used only for compatibility purposes. + */ +export default class BuildProfile { + static readonly HAR_VERSION = HAR_VERSION; + static readonly BUILD_MODE_NAME = BUILD_MODE_NAME; + static readonly DEBUG = DEBUG; + static readonly TARGET_NAME = TARGET_NAME; +} \ No newline at end of file diff --git a/windowpiplibrary/Index.ets b/windowpiplibrary/Index.ets new file mode 100644 index 0000000..2a08d87 --- /dev/null +++ b/windowpiplibrary/Index.ets @@ -0,0 +1,2 @@ +export { WindowPipPage } from './src/main/ets/pages/WindowPipPage'; +export { WindowUtil } from './src/main/ets/utils/WindowUtil'; diff --git a/windowpiplibrary/build-profile.json5 b/windowpiplibrary/build-profile.json5 new file mode 100644 index 0000000..312d38e --- /dev/null +++ b/windowpiplibrary/build-profile.json5 @@ -0,0 +1,28 @@ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": true, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + }, + }, + ], + "targets": [ + { + "name": "default" + } + ] +} diff --git a/windowpiplibrary/consumer-rules.txt b/windowpiplibrary/consumer-rules.txt new file mode 100644 index 0000000..e69de29 diff --git a/windowpiplibrary/hvigorfile.ts b/windowpiplibrary/hvigorfile.ts new file mode 100644 index 0000000..4218707 --- /dev/null +++ b/windowpiplibrary/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. */ +} diff --git a/windowpiplibrary/obfuscation-rules.txt b/windowpiplibrary/obfuscation-rules.txt new file mode 100644 index 0000000..272efb6 --- /dev/null +++ b/windowpiplibrary/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/entry/oh-package.json5 b/windowpiplibrary/oh-package.json5 similarity index 60% rename from entry/oh-package.json5 rename to windowpiplibrary/oh-package.json5 index 248c3b7..0b599cd 100644 --- a/entry/oh-package.json5 +++ b/windowpiplibrary/oh-package.json5 @@ -1,10 +1,9 @@ { - "name": "entry", + "name": "windowpiplibrary", "version": "1.0.0", "description": "Please describe the basic information.", - "main": "", + "main": "Index.ets", "author": "", - "license": "", + "license": "Apache-2.0", "dependencies": {} } - diff --git a/entry/src/main/ets/constants/Constants.ets b/windowpiplibrary/src/main/ets/constants/Constants.ets similarity index 100% rename from entry/src/main/ets/constants/Constants.ets rename to windowpiplibrary/src/main/ets/constants/Constants.ets diff --git a/entry/src/main/ets/pages/AVPlayer.ets b/windowpiplibrary/src/main/ets/pages/AVPlayer.ets similarity index 100% rename from entry/src/main/ets/pages/AVPlayer.ets rename to windowpiplibrary/src/main/ets/pages/AVPlayer.ets diff --git a/entry/src/main/ets/pages/VideoPlay.ets b/windowpiplibrary/src/main/ets/pages/VideoPlay.ets similarity index 100% rename from entry/src/main/ets/pages/VideoPlay.ets rename to windowpiplibrary/src/main/ets/pages/VideoPlay.ets diff --git a/entry/src/main/ets/pages/WindowPip.ets b/windowpiplibrary/src/main/ets/pages/WindowPipPage.ets similarity index 85% rename from entry/src/main/ets/pages/WindowPip.ets rename to windowpiplibrary/src/main/ets/pages/WindowPipPage.ets index c986194..3e909fd 100644 --- a/entry/src/main/ets/pages/WindowPip.ets +++ b/windowpiplibrary/src/main/ets/pages/WindowPipPage.ets @@ -1,21 +1,7 @@ -/* - * 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 { Constants } from "../constants/Constants"; +import Logger from "../utils/Logger"; +import { PlayVideo } from "./VideoPlay"; -import { Constants } from '../constants/Constants'; -import { PlayVideo } from './VideoPlay'; -import Logger from '../utils/Logger'; @Component struct ImageWidthTitle { @@ -54,9 +40,8 @@ struct ImageWidthTitle { } } -@Entry @Component -struct WindowPip { +export struct WindowPipPage { @StorageLink('topRectHeight') topRectHeight: number = 0; @StorageLink('bottomRectHeight') bottomRectHeight: number = 0; @StorageLink('currentBreakpoint') curBp: string = Constants.BREAK_POINT_SM; @@ -78,6 +63,7 @@ struct WindowPip { } } + build() { Navigation(this.pageInfos) { Column() { @@ -130,4 +116,6 @@ struct WindowPip { .size({ width: Constants.NAV_DESTINATION_WIDTH, height: Constants.NAV_DESTINATION_HEIGHT }) .id(this.navigationId) } -} \ No newline at end of file +} + + diff --git a/windowpiplibrary/src/main/ets/utils/BreakpointSystem.ets b/windowpiplibrary/src/main/ets/utils/BreakpointSystem.ets new file mode 100644 index 0000000..aa7581b --- /dev/null +++ b/windowpiplibrary/src/main/ets/utils/BreakpointSystem.ets @@ -0,0 +1,118 @@ +/* + * 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/entry/src/main/ets/utils/Logger.ets b/windowpiplibrary/src/main/ets/utils/Logger.ets similarity index 100% rename from entry/src/main/ets/utils/Logger.ets rename to windowpiplibrary/src/main/ets/utils/Logger.ets diff --git a/windowpiplibrary/src/main/ets/utils/WindowUtil.ets b/windowpiplibrary/src/main/ets/utils/WindowUtil.ets new file mode 100644 index 0000000..e059b5d --- /dev/null +++ b/windowpiplibrary/src/main/ets/utils/WindowUtil.ets @@ -0,0 +1,70 @@ +/* + * 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'; + +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/windowpiplibrary/src/main/module.json5 b/windowpiplibrary/src/main/module.json5 new file mode 100644 index 0000000..8f053be --- /dev/null +++ b/windowpiplibrary/src/main/module.json5 @@ -0,0 +1,11 @@ +{ + "module": { + "name": "windowpiplibrary", + "type": "har", + "deviceTypes": [ + "default", + "tablet", + "2in1" + ] + } +} diff --git a/entry/src/main/resources/base/element/color.json b/windowpiplibrary/src/main/resources/base/element/color.json similarity index 100% rename from entry/src/main/resources/base/element/color.json rename to windowpiplibrary/src/main/resources/base/element/color.json diff --git a/entry/src/main/resources/base/element/integer.json b/windowpiplibrary/src/main/resources/base/element/integer.json similarity index 100% rename from entry/src/main/resources/base/element/integer.json rename to windowpiplibrary/src/main/resources/base/element/integer.json diff --git a/entry/src/main/resources/base/element/string.json b/windowpiplibrary/src/main/resources/base/element/string.json similarity index 100% rename from entry/src/main/resources/base/element/string.json rename to windowpiplibrary/src/main/resources/base/element/string.json diff --git a/entry/src/main/resources/base/media/background.png b/windowpiplibrary/src/main/resources/base/media/background.png similarity index 100% rename from entry/src/main/resources/base/media/background.png rename to windowpiplibrary/src/main/resources/base/media/background.png diff --git a/entry/src/main/resources/base/media/btn_ground.PNG b/windowpiplibrary/src/main/resources/base/media/btn_ground.PNG similarity index 100% rename from entry/src/main/resources/base/media/btn_ground.PNG rename to windowpiplibrary/src/main/resources/base/media/btn_ground.PNG diff --git a/entry/src/main/resources/base/media/foreground.png b/windowpiplibrary/src/main/resources/base/media/foreground.png similarity index 100% rename from entry/src/main/resources/base/media/foreground.png rename to windowpiplibrary/src/main/resources/base/media/foreground.png diff --git a/entry/src/main/resources/base/media/layered_image.json b/windowpiplibrary/src/main/resources/base/media/layered_image.json similarity index 100% rename from entry/src/main/resources/base/media/layered_image.json rename to windowpiplibrary/src/main/resources/base/media/layered_image.json diff --git a/entry/src/main/resources/base/media/startIcon.png b/windowpiplibrary/src/main/resources/base/media/startIcon.png similarity index 100% rename from entry/src/main/resources/base/media/startIcon.png rename to windowpiplibrary/src/main/resources/base/media/startIcon.png diff --git a/entry/src/main/resources/en_US/element/string.json b/windowpiplibrary/src/main/resources/en_US/element/string.json similarity index 100% rename from entry/src/main/resources/en_US/element/string.json rename to windowpiplibrary/src/main/resources/en_US/element/string.json diff --git a/entry/src/main/resources/rawfile/video.mov b/windowpiplibrary/src/main/resources/rawfile/video.mov similarity index 100% rename from entry/src/main/resources/rawfile/video.mov rename to windowpiplibrary/src/main/resources/rawfile/video.mov diff --git a/entry/src/main/resources/zh_CN/element/string.json b/windowpiplibrary/src/main/resources/zh_CN/element/string.json similarity index 100% rename from entry/src/main/resources/zh_CN/element/string.json rename to windowpiplibrary/src/main/resources/zh_CN/element/string.json diff --git a/entry/build-profile.json5 b/windowpipsample/build-profile.json5 similarity index 100% rename from entry/build-profile.json5 rename to windowpipsample/build-profile.json5 diff --git a/entry/hvigorfile.ts b/windowpipsample/hvigorfile.ts similarity index 100% rename from entry/hvigorfile.ts rename to windowpipsample/hvigorfile.ts diff --git a/entry/obfuscation-rules.txt b/windowpipsample/obfuscation-rules.txt similarity index 100% rename from entry/obfuscation-rules.txt rename to windowpipsample/obfuscation-rules.txt diff --git a/windowpipsample/oh-package.json5 b/windowpipsample/oh-package.json5 new file mode 100644 index 0000000..c589e55 --- /dev/null +++ b/windowpipsample/oh-package.json5 @@ -0,0 +1,11 @@ +{ + "name": "windowpipsample", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "windowpiplibrary": "file:../windowpiplibrary" + } +} \ No newline at end of file diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/windowpipsample/src/main/ets/entryability/EntryAbility.ets similarity index 63% rename from entry/src/main/ets/entryability/EntryAbility.ets rename to windowpipsample/src/main/ets/entryability/EntryAbility.ets index 0d332c6..2e837e5 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/windowpipsample/src/main/ets/entryability/EntryAbility.ets @@ -17,32 +17,11 @@ import { Configuration, ConfigurationConstant, UIAbility } from '@kit.AbilityKit import { display, window } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; +import { WindowUtil } from 'windowpiplibrary'; const TAG: string = '[EntryAbility]'; export default class EntryAbility extends UIAbility { - private curBp: string = ''; - - private updateBreakpoint(windowWidth: number): void { - try { - let windowWidthVp: number = windowWidth / display.getDefaultDisplaySync().densityPixels; - let newBp: string = ''; - if (windowWidthVp < 600) { - newBp = 'sm'; - } else if (windowWidthVp < 840) { - newBp = 'md'; - } else { - newBp = 'lg'; - } - if (this.curBp !== newBp) { - this.curBp = newBp; - AppStorage.setOrCreate('currentBreakpoint', this.curBp); - } - } catch (err) { - hilog.error(0x0000, TAG, '%{public}s', - `Update breakpoint failed. code: ${(err as BusinessError).code}, message: ${(err as BusinessError).message}`); - } - } onCreate(): void { hilog.info(0x0000, TAG, '%{public}s', 'Ability onCreate'); @@ -64,23 +43,11 @@ export default class EntryAbility extends UIAbility { } onWindowStageCreate(windowStage: window.WindowStage): void { - windowStage.getMainWindow().then((windowObj: window.Window) => { - windowObj.on('windowSizeChange', (windowSize) => { - this.updateBreakpoint(windowSize.width); - }); - windowObj.setWindowLayoutFullScreen(true).then(() => { - hilog.info(0x0000, TAG, `%{public}s`, 'Succeeded in setting the window layout to full-screen mode.'); - }).catch((error: BusinessError) => { - hilog.error(0x0000, TAG, '%{public}s', - `UFailed to set the window layout to full-screen mode. code: ${error.code}, message: ${error.message}`); - }); - }).catch((error: BusinessError) => { - hilog.error(0x0000, TAG, '%{public}s', - `Failed to get main window. code: ${error.code}, message: ${error.message}`); - }); + WindowUtil.requestFullScreen(windowStage) + WindowUtil.registerBreakPoint(windowStage) // Main window is created, set main page for this ability hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageCreate'); - windowStage.loadContent('pages/WindowPip', (error: BusinessError) => { + windowStage.loadContent('pages/Index', (error: BusinessError) => { if (error.code) { hilog.error(0x0000, TAG, '%{public}s', `Failed to load the content. code: ${error.code}, message: ${error.message}`); diff --git a/windowpipsample/src/main/ets/pages/Index.ets b/windowpipsample/src/main/ets/pages/Index.ets new file mode 100644 index 0000000..6e6da7a --- /dev/null +++ b/windowpipsample/src/main/ets/pages/Index.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { WindowPipPage } from 'windowpiplibrary'; + + +@Entry +@Component +struct WindowPip { + build() { + Stack() { + WindowPipPage() + } + } +} \ No newline at end of file diff --git a/entry/src/main/module.json5 b/windowpipsample/src/main/module.json5 similarity index 89% rename from entry/src/main/module.json5 rename to windowpipsample/src/main/module.json5 index b2b33b8..88610f2 100644 --- a/entry/src/main/module.json5 +++ b/windowpipsample/src/main/module.json5 @@ -1,6 +1,6 @@ { "module": { - "name": "entry", + "name": "windowpipsample", "type": "entry", "description": "$string:module_desc", "mainElement": "EntryAbility", @@ -14,14 +14,14 @@ "pages": "$profile:main_pages", "abilities": [ { - "name": "EntryAbility", + "name": "WindowpipsampleAbility", "srcEntry": "./ets/entryability/EntryAbility.ets", "description": "$string:EntryAbility_desc", "icon": "$media:layered_image", "label": "$string:EntryAbility_label", "startWindowIcon": "$media:startIcon", "startWindowBackground": "$color:start_window_background", - "exported": false, + "exported": true, "skills": [ { "entities": [ diff --git a/entry/src/main/resources/base/profile/main_pages.json b/windowpipsample/src/main/resources/base/profile/main_pages.json similarity index 46% rename from entry/src/main/resources/base/profile/main_pages.json rename to windowpipsample/src/main/resources/base/profile/main_pages.json index 521b733..1898d94 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/windowpipsample/src/main/resources/base/profile/main_pages.json @@ -1,5 +1,5 @@ { "src": [ - "pages/WindowPip" + "pages/Index" ] } -- Gitee