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 console.log('cm-floatWindowUtils-initFloatWindow1'); 28 createFloatWindow('sp_currentNow'); 29 createFloatWindow('sp_shellBackTemp'); 30 createFloatWindow('sp_ddrFrequency'); 31 createFloatWindow('sp_gpuFrequency'); 32 createFloatWindow('sp_cpu0Frequency'); 33 createFloatWindow('sp_cpu1Frequency'); 34 createFloatWindow('sp_cpu2Frequency'); 35 createFloatWindow('sp_RAM'); 36 createFloatWindow('sp_FPS'); 37 console.log('cm-floatWindowUtils-initFloatWindow2'); 38} 39export function createFloatWindow(floatName: string) { 40 //5.5SP2 2106 改成 8 41 console.log('cm-floatWindowUtils-createFloatWindow1'); 42 wm.create(globalThis.abilityContext, floatName, wm.WindowType.TYPE_FLOAT).then((floatWin) => { 43 console.log('cm-floatWindowUtils-createFloatWindow2'); 44 floatWin.moveTo(lineChartWindowOffsetX, lineChartWindowOffsetY).then(() => { 45 floatWin.resetSize(360 * globalThis.coefficient, 270 * globalThis.coefficient).then(() => { 46 floatWin.getProperties().then((property) => { 47 property.isTransparent = false; 48 }); 49 console.log('cm-floatWindowUtils-createFloatWindow3'); 50 if (floatName == 'sp_currentNow') { 51 floatWin.loadContent('pages/CurrentNowLineChartPage').then(() => { 52 floatWin.setBackgroundColor('#B3000000').then(() => { 53 //透明 54 console.log('xhq win setTransparent end.'); 55 floatWin.setBackgroundColor('#59020000').then(() => { 56 //背景颜色 57 }); 58 }); 59 floatWin.show().then(() => { 60 floatWin.hide(); 61 }); 62 }); 63 } else if (floatName == 'sp_shellBackTemp') { 64 floatWin.loadContent('pages/ShellBackTempLineChartPage').then(() => { 65 floatWin.setBackgroundColor('#B3000000').then(() => { 66 //透明 67 console.log('xhq win setTransparent end.'); 68 floatWin.setBackgroundColor('#59020000').then(() => { 69 //背景颜色 70 }); 71 }); 72 floatWin.show().then(() => { 73 floatWin.hide(); 74 }); 75 }); 76 } else if (floatName == 'sp_ddrFrequency') { 77 floatWin.loadContent('pages/DDRLineChartPage').then(() => { 78 floatWin.setBackgroundColor('#B3000000').then(() => { 79 //透明 80 console.log('xhq win setTransparent end.'); 81 floatWin.setBackgroundColor('#59020000').then(() => { 82 //背景颜色 83 }); 84 }); 85 floatWin.show().then(() => { 86 floatWin.hide(); 87 }); 88 }); 89 } else if (floatName == 'sp_gpuFrequency') { 90 console.log('cm-floatWindowUtils-sp_gpuFrequency1'); 91 floatWin.loadContent('pages/GPULineChartPage').then(() => { 92 console.log('cm-floatWindowUtils-sp_gpuFrequency2'); 93 floatWin.setBackgroundColor('#B3000000').then(() => { 94 //透明 95 console.log('xhq win setTransparent end.'); 96 floatWin.setBackgroundColor('#59020000').then(() => { 97 //背景颜色 98 }); 99 }); 100 floatWin.show().then(() => { 101 console.log('cm-floatWindowUtils-sp_gpuFrequency-hide1'); 102 floatWin.hide(); 103 console.log('cm-floatWindowUtils-sp_gpuFrequency-hide2'); 104 }); 105 }); 106 } else if (floatName == 'sp_cpu0Frequency') { 107 floatWin.loadContent('pages/CPU0LineChartPage').then(() => { 108 floatWin.setBackgroundColor('#B3000000').then(() => { 109 //透明 110 console.log('xhq win setTransparent end.'); 111 floatWin.setBackgroundColor('#59020000').then(() => { 112 //背景颜色 113 }); 114 }); 115 floatWin.show().then(() => { 116 floatWin.hide(); 117 }); 118 }); 119 } else if (floatName == 'sp_cpu1Frequency') { 120 floatWin.loadContent('pages/CPU1LineChartPage').then(() => { 121 floatWin.setBackgroundColor('#B3000000').then(() => { 122 //透明 123 console.log('xhq win setTransparent end.'); 124 floatWin.setBackgroundColor('#59020000').then(() => { 125 //背景颜色 126 }); 127 }); 128 floatWin.show().then(() => { 129 floatWin.hide(); 130 }); 131 }); 132 } else if (floatName == 'sp_cpu2Frequency') { 133 floatWin.loadContent('pages/CPU2LineChartPage').then(() => { 134 floatWin.setBackgroundColor('#B3000000').then(() => { 135 //透明 136 console.log('xhq win setTransparent end.'); 137 floatWin.setBackgroundColor('#59020000').then(() => { 138 //背景颜色 139 }); 140 }); 141 floatWin.show().then(() => { 142 floatWin.hide(); 143 }); 144 }); 145 } else if (floatName == 'sp_RAM') { 146 floatWin.loadContent('pages/RAMLineChartPage').then(() => { 147 floatWin.setBackgroundColor('#B3000000').then(() => { 148 //透明 149 console.log('xhq win setTransparent end.'); 150 floatWin.setBackgroundColor('#59020000').then(() => { 151 //背景颜色 152 }); 153 }); 154 floatWin.show().then(() => { 155 floatWin.hide(); 156 }); 157 }); 158 } else if (floatName == 'sp_FPS') { 159 floatWin.loadContent('pages/FpsLineChartPage').then(() => { 160 floatWin.setBackgroundColor('#B3000000').then(() => { 161 //透明 162 console.log('xhq win setTransparent end.'); 163 floatWin.setBackgroundColor('#59020000').then(() => { 164 //背景颜色 165 }); 166 }); 167 floatWin.show().then(() => { 168 floatWin.hide(); 169 }); 170 }); 171 } 172 }); 173 }); 174 }); 175} 176export function destoryAllFloatWindow() { 177 console.log('cm-floatWindowUtils-destoryAllFloatWindow'); 178 destroyFloatWindow('sp_currentNow'); 179 destroyFloatWindow('sp_shellBackTemp'); 180 destroyFloatWindow('sp_ddrFrequency'); 181 destroyFloatWindow('sp_gpuFrequency'); 182 destroyFloatWindow('sp_cpu0Frequency'); 183 destroyFloatWindow('sp_cpu1Frequency'); 184 destroyFloatWindow('sp_cpu2Frequency'); 185 destroyFloatWindow('sp_RAM'); 186 destroyFloatWindow('sp_FPS'); 187} 188export function destroyFloatWindow(floatName: string) { 189 console.log('cm-floatWindowUtils-destoryAllFloatWindow1'); 190 wm.find(floatName).then((fltWin) => { 191 fltWin.destroy().then(() => { 192 globalThis.showFPSLineChartWindow = false; 193 }); 194 }); 195} 196export function hideFloatWindow(floatName: string) { 197 wm.find(floatName).then((fltWin) => { 198 fltWin.hide(); 199 }); 200} 201export function showFloatWindow(floatName: string) { 202 wm.find(floatName).then((fltWin) => { 203 fltWin.show(); 204 }); 205} 206export function moveFloatWindow(floatName: string, offsetX: number, offsetY: number) { 207 var xx = 208 floatingWindowOffsetX + offsetX * 2 < 0 209 ? 0 210 : floatingWindowOffsetX + offsetX * 2 > windowWidth - 200 211 ? windowWidth - 200 212 : floatingWindowOffsetX + offsetX * 2; 213 var yy = 214 floatingWindowOffsetY + offsetY * 2 < 0 215 ? 0 216 : floatingWindowOffsetY + offsetY * 2 > windowHeight - 200 217 ? windowHeight - 200 218 : floatingWindowOffsetY + offsetY * 2; 219 220 wm.find(floatName).then((fltWin) => { 221 fltWin.moveTo(xx, yy); 222 }); 223} 224export function setFloatWindow(offsetX: number, offsetY: number) { 225 floatingWindowOffsetX = 226 floatingWindowOffsetX + offsetX * 2 < 0 227 ? 0 228 : floatingWindowOffsetX + offsetX * 2 > windowWidth - 200 229 ? windowWidth - 200 230 : floatingWindowOffsetX + offsetX * 2; 231 floatingWindowOffsetY = 232 floatingWindowOffsetY + offsetY * 2 < 0 233 ? 0 234 : floatingWindowOffsetY + offsetY * 2 > windowHeight - 200 235 ? windowHeight - 200 236 : floatingWindowOffsetY + offsetY * 2; 237} 238