diff --git a/README.en.md b/README.en.md index 53113a7c162634e392925714233fbd27e587d35b..8de3e0535c0d52b7e91712129c13f081f675a399 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 b3b00465ff1f709d5aeac706ff98a8afe4cc2830..9ba3b962985c4ae87a27f4465c018e2348e3a097 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 c033ce4278fb0641d84107c3c134047ac487368e..1a8dc5b8e80a3b334d29b4ab0405261157dd59b1 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 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /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 0000000000000000000000000000000000000000..3a501e5ddee8ea6d28961648fc7dd314a5304bd4 --- /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 0000000000000000000000000000000000000000..2a08d875b30832bd47b39c4abca8acf4cc82603e --- /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 0000000000000000000000000000000000000000..312d38eb08629793b3484c7373213f22840c8d82 --- /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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/windowpiplibrary/hvigorfile.ts b/windowpiplibrary/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..42187071482d292588ad40babeda74f7b8d97a23 --- /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 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /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 248c3b7541a589682a250f86a6d3ecf7414d2d6a..0b599cde31468c0f840776360f294c06c9f87f4a 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 c9861944e29c0c1fcb8be9d008e1486cb124c7c9..3e909fd34236c6d1576afdaa3fef2e7b5770c541 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 0000000000000000000000000000000000000000..aa7581b2047323eac83c8d9a031e21faabc55bd2 --- /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 0000000000000000000000000000000000000000..e059b5d42a30b23c32d1a60fc6c899fb809a72d2 --- /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 0000000000000000000000000000000000000000..8f053bea8d035f4cdf8d028d4aae2c83d8771cd1 --- /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 0000000000000000000000000000000000000000..c589e551c30084e3d7d92e63dff12a2ea6aeece4 --- /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 0d332c6a5669c2e0bd3706139e08060a42206446..2e837e54f4bc1ab0d66cc7aaad1dc24ef596f2c5 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 0000000000000000000000000000000000000000..6e6da7a60b0eb40dfbd48823260519a0b5a8bef8 --- /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 b2b33b8607d3688403661c437df3b87ee32d03ab..88610f26d828e2e2178352766c77120608405bce 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 521b733f03711a7408248c2e58816de7b23ffae6..1898d94f58d6128ab712be2c68acc7c98e9ab9ce 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" ] }