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 { TIndexInfo } from '../common/entity/DatabaseEntity'; 16import { initFloatWindow, showFloatWindow, hideFloatWindow } from '../common/ui/floatwindow/utils/FloatWindowUtils'; 17import { getCpuCoreInfo} from '../common/utils/SystemUtils'; 18import FloatWindowConstant from '../common/ui/floatwindow/FloatWindowConstant'; 19import CommonEvent from '@ohos.commonEvent'; 20 21 22@Component 23export struct ItemContent { 24 private icon 25 private tittle: string 26 @State value: string = '-1' 27 private onClickCallBack: () => void 28 29 build() { 30 Row() { 31 Image(this.icon).width(16).height(16).margin({ right: '2%' }) 32 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 33 Text(this.tittle).fontSize(10).fontColor(Color.White) 34 Text(this.value).fontSize(10).fontColor(Color.White) 35 }.width('88%').height(20) 36 } 37 .height(22) 38 .width('88%') 39 .onClick(() => { 40 this.onClickCallBack() 41 }) 42 } 43} 44 45@Entry 46@Component 47struct TitleWindowPage { 48 private data: boolean[] = [false, false, false, false, false, false, false, false] 49 @State tIndexInfo: TIndexInfo = new TIndexInfo() 50 offsetX: number = -1 51 offsetY: number = -1 52 cpuCoreArr: Array<Number> 53 @State isInitFloatWindow: boolean = false 54 aboutToAppear() { 55 56 this.cpuCoreArr = getCpuCoreInfo().map(Number).sort() 57 58 let that = this 59 var subscriber 60 //订阅者信息 61 var subscribeInfo = { 62 events: ['event'] 63 }; 64 //订阅公共事件回调 65 function subscribeCallBack(err, data) { 66 if (data.data == '') { 67 } else { 68 console.error('subscriberCurData:' + data.data); 69 that.tIndexInfo = JSON.parse(data.data) 70 globalThis.cpu0Frequency = that.tIndexInfo.cpu0Frequency 71 globalThis.cpu1Frequency = that.tIndexInfo.cpu1Frequency 72 globalThis.cpu2Frequency = that.tIndexInfo.cpu2Frequency 73 74 if (that.tIndexInfo.cpu4Frequency != undefined && that.tIndexInfo.cpu7Frequency != undefined) { 75 globalThis.cpu1Frequency = that.tIndexInfo.cpu4Frequency 76 globalThis.cpu2Frequency = that.tIndexInfo.cpu7Frequency 77 that.tIndexInfo.cpu1Frequency = that.tIndexInfo.cpu4Frequency 78 that.tIndexInfo.cpu2Frequency = that.tIndexInfo.cpu7Frequency 79 that.tIndexInfo.cpu1Load = that.tIndexInfo.cpu1Load 80 that.tIndexInfo.cpu2Load = that.tIndexInfo.cpu2Load 81 } 82 83 globalThis.currentNow = that.tIndexInfo.currentNow 84 globalThis.ddrFrequency = that.tIndexInfo.ddrFrequency 85 globalThis.lineFps = that.tIndexInfo.fps 86 globalThis.gpuFrequency = that.tIndexInfo.gpuFrequency 87 globalThis.pss = that.tIndexInfo.pss 88 globalThis.shellBackTemp = that.tIndexInfo.shellFrameTemp 89 90 } 91 } 92 //创建订阅者回调 93 function createSubscriberCallBack(err, data) { 94 subscriber = data; 95 //订阅公共事件 96 CommonEvent.subscribe(subscriber, subscribeCallBack); 97 } 98 //创建订阅者 99 CommonEvent.createSubscriber(subscribeInfo, createSubscriberCallBack); 100 } 101 102 MoveWindow(offsetX: number, offsetY: number) { 103 globalThis.MoveTitleWindow(offsetX, offsetY) 104 } 105 106 SetWindowPosition(offsetX: number, offsetY: number) { 107 globalThis.SetTitleWindowPosition(offsetX, offsetY) 108 } 109 110 floatWindowEvent(floatName: string, flag: number) { 111 if (!this.isInitFloatWindow) { 112 initFloatWindow() 113 this.isInitFloatWindow = true 114 } 115 if (this.data[flag]) { 116 hideFloatWindow(floatName) 117 this.data[flag] = false 118 } else { 119 showFloatWindow(floatName) 120 this.data[flag] = true 121 } 122 } 123 124 build() { 125 Stack({ alignContent: Alignment.Center }) { 126 Rect({ width: '100%', height: '100%' }).radius(20).opacity(0.4) 127 Column({ space: 2 }) { 128 129 Row() { 130 Image($r('app.media.logo')).width(10).height(10).margin({ left: '2%' }) 131 Text('SmartPerf') 132 .fontSize(12) 133 .fontColor($r('app.color.color_fff')).margin({ left: '2%' }) 134 Image($r('app.media.icon_close_small')).height(15).width(15).margin({ left: '45%' }).onClick(() => { 135 //关闭实时悬浮框 136 globalThis.HideTitleWindow() 137 }) 138 }.height(20) 139 .width('90%') 140 141 142 if (this.tIndexInfo.fps != undefined) { 143 ItemContent({ 144 icon: $r('app.media.icon_average_frame_b'), 145 value: (this.tIndexInfo.fps.toString()) + 'FPS', 146 tittle: '帧率', 147 onClickCallBack: () => { 148 this.floatWindowEvent('sp_FPS', FloatWindowConstant.FPS) 149 } 150 }) 151 } 152 153 if (this.tIndexInfo.currentNow != undefined) { 154 ItemContent({ 155 icon: $r('app.media.icon_normalized_current'), 156 value: (0 - Number(this.tIndexInfo.currentNow)).toString() + 'mA', 157 tittle: '电流', 158 onClickCallBack: () => { 159 this.floatWindowEvent('sp_currentNow', FloatWindowConstant.CURRENT_NOW) 160 } 161 }) 162 } 163 if (this.tIndexInfo.ddrFrequency != undefined) { 164 ItemContent({ 165 icon: $r('app.media.icon_counter'), 166 value: (parseInt(this.tIndexInfo.ddrFrequency.toString()) / 1e6).toString() + 'MHz', 167 tittle: 'DDR频率', 168 onClickCallBack: () => { 169 this.floatWindowEvent('sp_ddrFrequency', FloatWindowConstant.DDR_FREQUENCY) 170 } 171 }) 172 } 173 174 if (this.tIndexInfo['cpu' + this.cpuCoreArr[0] + 'Frequency'] != undefined) { 175 ItemContent({ 176 icon: $r('app.media.icon_counter'), 177 value: (parseInt(this.tIndexInfo['cpu' + this.cpuCoreArr[0] + 'Frequency'].toString()) / 1e3).toString() + 'MHz' + this.tIndexInfo.cpu0Load + '%', 178 tittle: 'CPU-A频率', 179 onClickCallBack: () => { 180 this.floatWindowEvent('sp_cpu0Frequency', FloatWindowConstant.CPU0_FREQUENCY) 181 } 182 }) 183 } 184 185 if (this.tIndexInfo['cpu' + this.cpuCoreArr[1] + 'Frequency'] != undefined) { 186 ItemContent({ 187 icon: $r('app.media.icon_counter'), 188 value: (parseInt(this.tIndexInfo['cpu' + this.cpuCoreArr[1] + 'Frequency'].toString()) / 1e3).toString() + 'MHz' + this.tIndexInfo.cpu1Load + '%', 189 tittle: 'CPU-B频率', 190 onClickCallBack: () => { 191 this.floatWindowEvent('sp_cpu1Frequency', FloatWindowConstant.CPU1_FREQUENCY) 192 } 193 }) 194 } 195 if (this.tIndexInfo['cpu' + this.cpuCoreArr[2] + 'Frequency'] != undefined) { 196 197 ItemContent({ 198 icon: $r('app.media.icon_counter'), 199 value: (parseInt(this.tIndexInfo['cpu' + this.cpuCoreArr[2] + 'Frequency'].toString()) / 1e3).toString() + 'MHz' + this.tIndexInfo.cpu2Load + '%', 200 tittle: 'CPU-C频率', 201 onClickCallBack: () => { 202 this.floatWindowEvent('sp_cpu2Frequency', FloatWindowConstant.CPU2_FREQUENCY) 203 } 204 }) 205 } 206 207 if (this.tIndexInfo.gpuFrequency != undefined) { 208 ItemContent({ 209 icon: $r('app.media.icon_frame_score'), 210 value: (parseInt(this.tIndexInfo.gpuFrequency.toString()) / 1e6).toString() + 'MHz' + this.tIndexInfo.gpuLoad + '%', 211 tittle: 'GPU频点', 212 onClickCallBack: () => { 213 this.floatWindowEvent('sp_gpuFrequency', FloatWindowConstant.GPU_FREQUENCY) 214 } 215 }) 216 } 217 if (this.tIndexInfo.pss != undefined) { 218 ItemContent({ 219 icon: $r('app.media.icon_jank_each_hour'), 220 value: this.tIndexInfo.pss + 'KB', 221 tittle: 'RAM', 222 onClickCallBack: () => { 223 this.floatWindowEvent('sp_RAM', FloatWindowConstant.RAM) 224 } 225 }) 226 } 227 if (this.tIndexInfo.socThermalTemp != undefined) { 228 ItemContent({ 229 icon: $r('app.media.icon_max_temperature'), 230 value: (parseInt(this.tIndexInfo.socThermalTemp.toString()) / 1e3).toString() + '℃', 231 tittle: 'SOC温度', 232 onClickCallBack: () => { 233 this.floatWindowEvent('sp_shellBackTemp', FloatWindowConstant.SHELL_BACK_TEMP) 234 } 235 }) 236 } 237 238 if (this.tIndexInfo.shellFrameTemp != undefined) { 239 ItemContent({ 240 icon: $r('app.media.icon_max_temperature'), 241 value: (parseInt(this.tIndexInfo.shellFrameTemp.toString()) / 1e3).toString() + '℃', 242 tittle: '壳温', 243 onClickCallBack: () => { 244 this.floatWindowEvent('sp_shellBackTemp', FloatWindowConstant.SHELL_BACK_TEMP) 245 } 246 }) 247 } 248 249 }.width('100%') 250 .gesture( 251 GestureGroup(GestureMode.Exclusive, 252 PanGesture({}) 253 .onActionStart((event: GestureEvent) => { 254 }) 255 .onActionUpdate((event: GestureEvent) => { 256 this.offsetX = event.offsetX 257 this.offsetY = event.offsetY 258 }) 259 .onActionEnd(() => { 260 this.MoveWindow(this.offsetX, this.offsetY) 261 this.SetWindowPosition(this.offsetX, this.offsetY) 262 }) 263 )) 264 } 265 } 266}