1/** 2 * Copyright (c) 2021-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 deviceInfo from '@ohos.deviceInfo'; 17import parameter from '@ohos.systemparameter'; 18import OverdrawController from '../controller/developerOptions/OverdrawController'; 19import UsbDebuggingController from '../controller/developerOptions/UsbDebuggingController'; 20import LogUtil from '../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil'; 21import ConfigData from '../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData'; 22import HeadComponent from '../../../../../../common/component/src/main/ets/default/headComponent'; 23import LayoutBoundariesController from '../controller/developerOptions/LayoutBoundariesController'; 24import SwitchComponent from '../../../../../../common/component/src/main/ets/default/switchComponent'; 25import { SubEntryComponent } from '../../../../../../common/component/src/main/ets/default/subEntryComponent'; 26import { BusinessError } from '@ohos.base'; 27 28const deviceTypeInfo = deviceInfo.deviceType; 29const MODULE_TAG = ConfigData.TAG + '.developerOptions -> '; 30const GRAPHIC_ANIMATION_SCALE_NAME = "persist.sys.graphic.animationscale"; 31const ARKUI_ANIMATION_SCALE_NAME = "persist.sys.arkui.animationscale"; 32 33/** 34 * Developer options 35 */ 36@Entry 37@Component 38struct developerOptions { 39 @State columnMargin: string = '24vp'; 40 @State AnimationText:Resource = $r("app.string.endTextEmpty"); 41 @State checked: string = "1"; 42 @State controllerLayoutBoundariesIsOn: boolean = false; 43 @State controllerOverdrawIsOn: boolean = false; 44 @State controllerDebugIsOn: boolean = false; 45 @State isPhoneOrRK: boolean = false; 46 @State getAnimationMultiplier: string = parameter.getSync(ARKUI_ANIMATION_SCALE_NAME); 47 48 private controller: UsbDebuggingController = new UsbDebuggingController(); 49 private controllerOverdraw: OverdrawController = new OverdrawController(); 50 private controllerLayoutBoundaries: LayoutBoundariesController = new LayoutBoundariesController(); 51 private AnimationMultiplier: string[] = ["0", "0.5", "1", "1.5", "2", "5", "10"]; 52 53 private AnimationScalingDialog: CustomDialogController | null = new CustomDialogController({ 54 builder: AnimationScalingInformation({ 55 AnimationMultiplier: this.AnimationMultiplier, 56 AnimationText: $AnimationText, 57 checked: $checked, 58 isPhoneOrRK: $isPhoneOrRK 59 }), 60 alignment: this.isPhoneOrRK ? DialogAlignment.Bottom : DialogAlignment.Center, 61 offset: ({ dx: 0, dy: this.isPhoneOrRK ? '-24dp' : 0 }), 62 autoCancel: true, 63 customStyle: true 64 }); 65 66 aboutToAppear() { 67 LogUtil.info(MODULE_TAG + "aboutToAppear"); 68 69 if (deviceTypeInfo === 'phone' || deviceTypeInfo === 'default') { 70 this.isPhoneOrRK = true; 71 } else { 72 this.isPhoneOrRK = false; 73 } 74 75 this.AnimationText = this.getAnimationMultiplier === "" ? $r("app.string.Animation_Zooms") : 76 (this.getAnimationMultiplier === "0" ? $r("app.string.Close_Animation") : $r("app.string.Animation_Multiplier", this.getAnimationMultiplier)); 77 this.checked = this.getAnimationMultiplier === "" ? "1" : this.getAnimationMultiplier; 78 79 if (parameter.getSync("debug.graphic.overdraw") === "false") { 80 this.controllerOverdrawIsOn = false; 81 } else { 82 this.controllerOverdrawIsOn = Boolean(parameter.getSync("debug.graphic.overdraw")); 83 } 84 85 if (parameter.getSync("persist.ace.debug.boundary.enabled") === "false") { 86 this.controllerLayoutBoundariesIsOn = false; 87 } else { 88 this.controllerLayoutBoundariesIsOn = Boolean(parameter.getSync("persist.ace.debug.boundary.enabled")); 89 } 90 LogUtil.info(MODULE_TAG + "aboutToAppear end"); 91 } 92 93 aboutToDisappear() { 94 this.AnimationScalingDialog = null; 95 } 96 97 build() { 98 Column() { 99 GridContainer({ gutter: ConfigData.GRID_CONTAINER_GUTTER_24, margin: ConfigData.GRID_CONTAINER_MARGIN_24 }) { 100 Column() { 101 HeadComponent({ headName: $r("app.string.developerOptionsTab"), isActive: true }); 102 103 SwitchComponent({ 104 title: $r("app.string.usbDebugging"), 105 summary: $r("app.string.locationServicesPromptInfo"), 106 isOn: $controllerDebugIsOn, 107 controller: this.controller, 108 switchHeight: $r("app.float.wh_value_72") 109 }) 110 .margin({ top: $r("app.float.distance_8") }) 111 112 Column() { 113 List() { 114 ListItem() { 115 SwitchComponent({ 116 title: $r("app.string.Show_Layout_Boundaries"), 117 summary: $r("app.string.Show_boundaries_Margin"), 118 isOn: $controllerLayoutBoundariesIsOn, 119 controller: this.controllerLayoutBoundaries, 120 switchHeight: $r("app.float.wh_value_64") 121 }) 122 } 123 124 ListItem() { 125 Row() { 126 Column() { 127 Text($r("app.string.Global_Animation")) 128 .fontColor($r('sys.color.ohos_fa_text_primary')) 129 .fontFamily("HarmonyHeiTi") 130 .fontWeight(FontWeight.Medium) 131 .fontSize($r("sys.float.ohos_id_text_size_body1")) 132 } 133 .alignItems(HorizontalAlign.Start) 134 135 Blank() 136 137 Row() { 138 Text(this.AnimationText) 139 .margin({ right: $r("app.float.distance_4") }) 140 .fontSize($r("sys.float.ohos_id_text_size_body2")) 141 .fontColor($r('sys.color.ohos_fa_text_secondary')) 142 143 Image('/res/image/ic_settings_arrow.svg') 144 .width($r('app.float.wh_value_12')) 145 .height($r('app.float.wh_value_24')) 146 .fillColor($r("sys.color.ohos_id_color_primary")) 147 .opacity($r("app.float.opacity_0_2")) 148 } 149 .onClick(() => { 150 this.AnimationScalingDialog?.open(); 151 }) 152 } 153 .padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('app.float.distance_8') }) 154 .alignItems(VerticalAlign.Center) 155 .width(ConfigData.WH_100_100) 156 .height($r("app.float.wh_value_48")) 157 } 158 } 159 .width(ConfigData.WH_100_100) 160 .divider({ 161 strokeWidth: $r('app.float.divider_wh'), 162 color: $r('sys.color.ohos_id_color_list_separator'), 163 startMargin: $r('app.float.wh_value_15'), 164 endMargin: $r('app.float.wh_value_15') }) 165 } 166 .borderRadius($r("app.float.wh_value_24")) 167 .backgroundColor($r("app.color.white_bg_color")) 168 .width(ConfigData.WH_100_100) 169 .margin({ top: $r("app.float.distance_12") }) 170 .padding({ 171 top: $r("app.float.distance_4"), 172 bottom: $r("app.float.distance_4") 173 }) 174 175 SwitchComponent({ 176 title: $r("app.string.Debug_GPU_OverDraw"), 177 summary: "", 178 isOn: $controllerOverdrawIsOn, 179 controller: this.controllerOverdraw, 180 switchHeight: $r("app.float.wh_value_56") 181 }) 182 .margin({ top: $r("app.float.distance_12") }) 183 184 SubEntryComponent({ 185 targetPage: "pages/compatibilityAssessment", 186 title: $r("app.string.OpenHarmony_Compatibility_Assessment") 187 }) 188 .margin({ top: $r("app.float.distance_12") }) 189 } 190 .useSizeType({ 191 sm: { span: 4, offset: 0 }, 192 md: { span: 6, offset: 1 }, 193 lg: { span: 8, offset: 2 } 194 }) 195 } 196 .width(ConfigData.WH_100_100) 197 .height(ConfigData.WH_100_100) 198 } 199 .backgroundColor($r("sys.color.ohos_id_color_sub_background")) 200 .width(ConfigData.WH_100_100) 201 .height(ConfigData.WH_100_100) 202 } 203} 204 205@CustomDialog 206struct AnimationScalingInformation { 207 controller?: CustomDialogController; 208 private AnimationMultiplier: string[] = ["0", "0.5", "1", "1.5", "2", "5", "10"]; 209 @Link isPhoneOrRK : boolean ; 210 @Link AnimationText: Resource ; 211 @Link checked: string; 212 213 aboutToAppear() { 214 LogUtil.info(MODULE_TAG + "aboutToAppear deviceTypeInfo" + JSON.stringify(deviceTypeInfo)); 215 } 216 217 build() { 218 Column(){ 219 Column() { 220 Text($r("app.string.Excessive_animation_scaling")) 221 .fontFamily("HarmonyHeiTi") 222 .fontSize($r("sys.float.ohos_id_text_size_headline8")) 223 .fontWeight(FontWeight.Medium) 224 .height($r("app.float.wh_value_56")) 225 .alignSelf(ItemAlign.Start) 226 227 List() { 228 ForEach(this.AnimationMultiplier, (item: string, index) => { 229 ListItem() { 230 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 231 Text(item === "0" ? $r("app.string.Close_Animation") : $r("app.string.Animation_Multiplier", item)) 232 .fontFamily("HarmonyHeiTi") 233 .fontSize($r("sys.float.ohos_id_text_size_body1")) 234 .fontWeight(FontWeight.Medium) 235 236 Radio({ value: "", group: 'radioGroup' }) 237 .checked(this.checked === item ? true : false) 238 .height($r("app.float.wh_value_24")) 239 .width($r("app.float.wh_value_24")) 240 .onChange((value: boolean) => { 241 if(value) { 242 this.controller?.close(); 243 if (item === "0") { 244 this.AnimationText = $r("app.string.Close_Animation"); 245 parameter.set(GRAPHIC_ANIMATION_SCALE_NAME, "0"); 246 parameter.set(ARKUI_ANIMATION_SCALE_NAME, "0"); 247 LogUtil.info(MODULE_TAG + "close animation success"); 248 } else { 249 this.AnimationText = $r("app.string.Animation_Multiplier", item); 250 parameter.set(GRAPHIC_ANIMATION_SCALE_NAME, item) 251 .then(() => { 252 LogUtil.info(MODULE_TAG + "set graphic parameter success"); 253 }) 254 .catch((err: BusinessError) => { 255 LogUtil.info(MODULE_TAG + "catch graphic parameter error" + JSON.stringify(err)); 256 }) 257 258 parameter.set(ARKUI_ANIMATION_SCALE_NAME, item) 259 .then(() => { 260 LogUtil.info(MODULE_TAG + "set arkui parameter success"); 261 }) 262 .catch((err: BusinessError) => { 263 LogUtil.info(MODULE_TAG + "catch arkui parameter error" + JSON.stringify(err)); 264 }) 265 } 266 this.checked = item; 267 } 268 }) 269 } 270 .height($r("app.float.wh_value_48")) 271 } 272 .height($r("app.float.wh_value_48")) 273 }) 274 } 275 276 Text($r("app.string.Cancel_Animation")) 277 .fontSize($r("sys.float.ohos_id_text_size_button1")) 278 .fontColor($r("sys.color.ohos_id_color_text_primary_activated")) 279 .alignSelf(ItemAlign.Center) 280 .width($r("app.float.cancel_animation_button_w_value")) 281 .height($r("app.float.wh_value_40")) 282 .margin({ top: $r("app.float.distance_8") }) 283 .onClick(() => { 284 this.controller?.close(); 285 }) 286 } 287 .padding({ 288 left: $r("app.float.padding_24"), 289 right: $r("app.float.padding_24") 290 }) 291 .height($r("app.float.animationScalingInformation_h_value")) 292 .alignItems(HorizontalAlign.Center) 293 .backgroundColor($r("app.color.white_bg_color")) 294 .borderRadius($r("app.float.radius_24")) 295 } 296 .width(this.isPhoneOrRK ? ConfigData.WH_100_100 : $r("app.float.wh_value_410")) 297 .padding(this.isPhoneOrRK ? { left: $r("app.float.distance_12"), right: $r("app.float.distance_12")} : {}) 298 } 299} 300