• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
15import wm from '@ohos.window'
16
17export let floatingWindowOffsetX: number = 50
18export let floatingWindowOffsetY: number = 200
19export let titleWindowOffsetX: number = 300
20export let titleWindowOffsetY: number = 200
21export let lineChartWindowOffsetX:number=30
22export let lineChartWindowOffsetY:number=20
23export let windowWidth: number = 2560
24export let windowHeight: number = 1600
25
26export function initFloatWindow() {
27  createFloatWindow("sp_currentNow")
28  createFloatWindow("sp_shellBackTemp")
29  createFloatWindow("sp_ddrFrequency")
30  createFloatWindow("sp_gpuFrequency")
31  createFloatWindow("sp_cpu0Frequency")
32  createFloatWindow("sp_cpu1Frequency")
33  createFloatWindow("sp_cpu2Frequency")
34  createFloatWindow("sp_RAM")
35  createFloatWindow("sp_FPS")
36}
37export function createFloatWindow(floatName:string) {
38
39    //5.5SP2  2106 改成 8
40    wm.create(globalThis.abilityContext, floatName, 2106).then((floatWin) => {
41        floatWin.moveTo(lineChartWindowOffsetX, lineChartWindowOffsetY).then(() => {
42          floatWin.resetSize(360*globalThis.coefficient,270*globalThis.coefficient).then(() => {
43            floatWin.getProperties().then((property) => {
44              property.isTransparent = false
45            })
46            if(floatName=="sp_currentNow"){
47              floatWin.loadContent('pages/CurrentNowLineChartPage').then(() => {
48                floatWin.setBackgroundColor("#B3000000").then(() => { //透明
49                  console.log("xhq win setTransparent end.");
50                  floatWin.setBackgroundColor("#59020000").then(() => { //背景颜色
51                  })
52                })
53                floatWin.show().then(() => {
54                  floatWin.hide()
55                })
56              })
57            }else if(floatName=="sp_shellBackTemp"){
58              floatWin.loadContent('pages/ShellBackTempLineChartPage').then(() => {
59                floatWin.setBackgroundColor("#B3000000").then(() => { //透明
60                  console.log("xhq win setTransparent end.");
61                  floatWin.setBackgroundColor("#59020000").then(() => { //背景颜色
62                  })
63                })
64                floatWin.show().then(() => {
65                  floatWin.hide()
66                })
67              })
68            }
69            else if(floatName=="sp_ddrFrequency"){
70              floatWin.loadContent('pages/DDRLineChartPage').then(() => {
71                floatWin.setBackgroundColor("#B3000000").then(() => { //透明
72                  console.log("xhq win setTransparent end.");
73                  floatWin.setBackgroundColor("#59020000").then(() => { //背景颜色
74                  })
75                })
76                floatWin.show().then(() => {
77                  floatWin.hide()
78                })
79              })
80            }
81            else if(floatName=="sp_gpuFrequency"){
82              floatWin.loadContent('pages/GPULineChartPage').then(() => {
83                floatWin.setBackgroundColor("#B3000000").then(() => { //透明
84                  console.log("xhq win setTransparent end.");
85                  floatWin.setBackgroundColor("#59020000").then(() => { //背景颜色
86                  })
87                })
88                floatWin.show().then(() => {
89                  floatWin.hide()
90                })
91              })
92            }
93            else if(floatName=="sp_cpu0Frequency"){
94              floatWin.loadContent('pages/CPU0LineChartPage').then(() => {
95                floatWin.setBackgroundColor("#B3000000").then(() => { //透明
96                  console.log("xhq win setTransparent end.");
97                  floatWin.setBackgroundColor("#59020000").then(() => { //背景颜色
98                  })
99                })
100                floatWin.show().then(() => {
101                  floatWin.hide()
102                })
103              })
104            }
105            else if(floatName=="sp_cpu1Frequency"){
106              floatWin.loadContent('pages/CPU1LineChartPage').then(() => {
107                floatWin.setBackgroundColor("#B3000000").then(() => { //透明
108                  console.log("xhq win setTransparent end.");
109                  floatWin.setBackgroundColor("#59020000").then(() => { //背景颜色
110                  })
111                })
112                floatWin.show().then(() => {
113                  floatWin.hide()
114                })
115              })
116            }
117            else if(floatName=="sp_cpu2Frequency"){
118              floatWin.loadContent('pages/CPU2LineChartPage').then(() => {
119                floatWin.setBackgroundColor("#B3000000").then(() => { //透明
120                  console.log("xhq win setTransparent end.");
121                  floatWin.setBackgroundColor("#59020000").then(() => { //背景颜色
122                  })
123                })
124                floatWin.show().then(() => {
125                  floatWin.hide()
126                })
127              })
128            }
129            else if(floatName=="sp_RAM"){
130              floatWin.loadContent('pages/RAMLineChartPage').then(() => {
131                floatWin.setBackgroundColor("#B3000000").then(() => { //透明
132                  console.log("xhq win setTransparent end.");
133                  floatWin.setBackgroundColor("#59020000").then(() => { //背景颜色
134                  })
135                })
136                floatWin.show().then(() => {
137                  floatWin.hide()
138                })
139              })
140            } else if(floatName=="sp_FPS"){
141              floatWin.loadContent('pages/FpsLineChartPage').then(() => {
142                floatWin.setBackgroundColor("#B3000000").then(() => { //透明
143                  console.log("xhq win setTransparent end.");
144                  floatWin.setBackgroundColor("#59020000").then(() => { //背景颜色
145                  })
146                })
147                floatWin.show().then(() => {
148                  floatWin.hide()
149                })
150              })
151            }
152          })
153        })
154    })
155}
156export function destoryAllFloatWindow() {
157  destroyFloatWindow("sp_currentNow")
158  destroyFloatWindow("sp_shellBackTemp")
159  destroyFloatWindow("sp_ddrFrequency")
160  destroyFloatWindow("sp_gpuFrequency")
161  destroyFloatWindow("sp_cpu0Frequency")
162  destroyFloatWindow("sp_cpu1Frequency")
163  destroyFloatWindow("sp_cpu2Frequency")
164  destroyFloatWindow("sp_RAM")
165  destroyFloatWindow("sp_FPS")
166}
167export function destroyFloatWindow(floatName:string) {
168
169    wm.find(floatName).then((fltWin) => {
170      fltWin.destroy().then(() => {
171        globalThis.showFPSLineChartWindow = false
172      })
173    })
174
175}
176export function hideFloatWindow(floatName:string) {
177
178    wm.find(floatName).then((fltWin) => {
179      fltWin.hide()
180    })
181
182}
183export function showFloatWindow(floatName:string) {
184
185    wm.find(floatName).then((fltWin) => {
186      fltWin.show()
187    })
188
189}
190export function moveFloatWindow(floatName:string,offsetX: number, offsetY: number) {
191  var xx = (floatingWindowOffsetX + offsetX * 2) < 0 ? 0 : ((floatingWindowOffsetX + offsetX * 2) > (windowWidth - 200) ? (windowWidth - 200) : (floatingWindowOffsetX + offsetX * 2))
192  var yy = (floatingWindowOffsetY + offsetY * 2) < 0 ? 0 : ((floatingWindowOffsetY + offsetY * 2) > (windowHeight - 200) ? (windowHeight - 200) : (floatingWindowOffsetY + offsetY * 2))
193
194  wm.find(floatName).then((fltWin) => {
195    fltWin.moveTo(xx, yy)
196  })
197
198}
199export function setFloatWindow(offsetX: number, offsetY: number) {
200    this.floatingWindowOffsetX = (floatingWindowOffsetX + offsetX * 2) < 0 ? 0 : ((floatingWindowOffsetX + offsetX * 2) > (windowWidth - 200) ? (windowWidth - 200) : (floatingWindowOffsetX + offsetX * 2))
201    this.floatingWindowOffsetY = (floatingWindowOffsetY + offsetY * 2) < 0 ? 0 : ((floatingWindowOffsetY + offsetY * 2) > (windowHeight - 200) ? (windowHeight - 200) : (floatingWindowOffsetY + offsetY * 2))
202}