1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import wm from '@ohos.window' 17import SPLogger from '../../utils/SPLogger' 18 19const TAG = "FloatWindowFun" 20 21export class FloatWindowFun { 22 static floatingWindowOffsetX: number = 50 23 static floatingWindowOffsetY: number = 300 24 static titleWindowOffsetX: number = 300 25 static titleWindowOffsetY: number = 200 26 static lineChartWindowOffsetX: number= 700 27 static lineChartWindowOffsetY: number= 200 28 static windowWidth: number = 2560 29 static windowHeight: number = 1600 30 static atWidth: number = 95 31 static initAllFun() { 32 globalThis.CreateFloatingWindow = (() => { 33 //5.5SP2 2106 改成 8 34 wm.create(globalThis.abilityContext, 'sp_floatingWindow', 2106).then((floatWin) => { 35 floatWin.moveTo(this.floatingWindowOffsetX, this.floatingWindowOffsetY).then(() => { 36 floatWin.resetSize(this.atWidth*globalThis.coefficient, this.atWidth*globalThis.coefficient).then(() => { 37 floatWin.getProperties().then((property) => { 38 property.isTransparent = false 39 }) 40 floatWin.loadContent('pages/FloatBall').then(() => { 41 floatWin.setBackgroundColor("#00000000").then(() => { //透明 42 floatWin.show().then(() => { 43 globalThis.showFloatingWindow = true 44 }) 45 }) 46 }) 47 }) 48 }) 49 }) 50 }) 51 globalThis.MoveFloatingWindow = ((offsetX: number, offsetY: number) => { 52 var xx = (this.floatingWindowOffsetX + offsetX * 2) < 0 ? 0 : ((this.floatingWindowOffsetX + offsetX * 2) > (this.windowWidth - 200) ? (this.windowWidth - 200) : (this.floatingWindowOffsetX + offsetX * 2)) 53 var yy = (this.floatingWindowOffsetY + offsetY * 2) < 0 ? 0 : ((this.floatingWindowOffsetY + offsetY * 2) > (this.windowHeight - 200) ? (this.windowHeight - 200) : (this.floatingWindowOffsetY + offsetY * 2)) 54 55 wm.find("sp_floatingWindow").then((fltWin) => { 56 fltWin.moveTo(xx, yy) 57 }) 58 }) 59 60 globalThis.SetFloatingWindowPosition = ((offsetX: number, offsetY: number) => { 61 this.floatingWindowOffsetX = (this.floatingWindowOffsetX + offsetX * 2) < 0 ? 0 : ((this.floatingWindowOffsetX + offsetX * 2) > (this.windowWidth - 200) ? (this.windowWidth - 200) : (this.floatingWindowOffsetX + offsetX * 2)) 62 this.floatingWindowOffsetY = (this.floatingWindowOffsetY + offsetY * 2) < 0 ? 0 : ((this.floatingWindowOffsetY + offsetY * 2) > (this.windowHeight - 200) ? (this.windowHeight - 200) : (this.floatingWindowOffsetY + offsetY * 2)) 63 }) 64 65 globalThis.DestroyFloatingWindow = (() => { 66 wm.find("sp_floatingWindow").then((fltWin) => { 67 fltWin.destroy().then(() => { 68 globalThis.showFloatingWindow = false 69 }) 70 }) 71 }) 72 73 globalThis.CreateTitleWindow = (() => { 74 wm.create(globalThis.abilityContext, 'sp_TitleWindow', 2106).then((floatWin) => { 75 floatWin.moveTo(this.titleWindowOffsetX, this.titleWindowOffsetY).then(() => { 76 floatWin.resetSize(350*globalThis.coefficient, 480*globalThis.coefficient).then(() => { 77 floatWin.getProperties().then((property) => { 78 property.isTransparent = false 79 }) 80 floatWin.loadContent('pages/TitleWindowPage').then(() => { 81 floatWin.setBackgroundColor("#00000000") 82 floatWin.hide() 83 SPLogger.DEBUG(TAG, 'CreateTitleWindow Done') 84 }) 85 }) 86 }) 87 }) 88 }) 89 90 globalThis.MoveTitleWindow = ((offsetX: number, offsetY: number) => { 91 var xx = (this.titleWindowOffsetX + offsetX * 2) < 0 ? 0 : ((this.titleWindowOffsetX + offsetX * 2) > (this.windowWidth - 500) ? (this.windowWidth - 500) : (this.titleWindowOffsetX + offsetX * 2)) 92 var yy = (this.titleWindowOffsetY + offsetY * 2) < 0 ? 0 : ((this.titleWindowOffsetY + offsetY * 2) > (this.windowHeight - 330) ? (this.windowHeight - 330) : (this.titleWindowOffsetY + offsetY * 2)) 93 wm.find("sp_TitleWindow").then((fltWin) => { 94 fltWin.moveTo(xx, yy) 95 }) 96 }) 97 98 globalThis.SetTitleWindowPosition = ((offsetX: number, offsetY: number) => { 99 this.titleWindowOffsetX = (this.titleWindowOffsetX + offsetX * 2) < 0 ? 0 : ((this.titleWindowOffsetX + offsetX * 2) > (this.windowWidth - 500) ? (this.windowWidth - 500) : (this.titleWindowOffsetX + offsetX * 2)) 100 this.titleWindowOffsetY = (this.titleWindowOffsetY + offsetY * 2) < 0 ? 0 : ((this.titleWindowOffsetY + offsetY * 2) > (this.windowHeight - 330) ? (this.windowHeight - 330) : (this.titleWindowOffsetY + offsetY * 2)) 101 }) 102 103 globalThis.DestroyTitleWindow = (() => { 104 wm.find("sp_TitleWindow").then((fltWin) => { 105 fltWin.destroy().then(() => { 106 }) 107 }) 108 }) 109 110 globalThis.HideTitleWindow = (() => { 111 wm.find("sp_TitleWindow").then((fltWin) => { 112 fltWin.hide() 113 }) 114 }) 115 116 globalThis.ShowTitleWindow = (() => { 117 wm.find("sp_TitleWindow").then((fltWin) => { 118 fltWin.show() 119 }) 120 }) 121 122 } 123} 124 125