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 brightness from '@ohos.brightness'; 17import { StartTestTitleComponent } from '../common/ui/StartTestTitleComponent'; 18import SPLogger from '../common/utils/SPLogger' 19/** 20 * 亮度调整 21 */ 22@Entry 23@Component 24struct LightAdjust { 25 @State outSetValue: number = 40 26 27 build() { 28 Column() { 29 30 StartTestTitleComponent({ title: '亮度调整' }) 31 32 Row() { 33 Slider({ 34 value: this.outSetValue, 35 min: 0, 36 max: 255, 37 step: 1, 38 style: SliderStyle.OutSet 39 }) 40 .blockColor(Color.Blue) 41 .trackColor(Color.Gray) 42 .selectedColor(Color.Blue) 43 .showSteps(true) 44 .onChange((value: number, mode: SliderChangeMode) => { 45 this.outSetValue = value 46 brightness.setValue(value) 47 console.info('value:' + value + 'mode:' + mode.toString()) 48 }) 49 }.padding({ top: 50 }) 50 .width('80%') 51 52 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 53 54 Text('+').fontSize('25fp').fontWeight(FontWeight.Bold).onClick(() => { 55 if (this.outSetValue == 255) { 56 return 57 } 58 ++this.outSetValue 59 brightness.setValue(this.outSetValue) 60 }) 61 62 Text(this.outSetValue.toFixed(0)).fontWeight(FontWeight.Bold).fontSize('25fp') 63 64 Text('-').fontSize('25fp').fontWeight(FontWeight.Bold).onClick(() => { 65 if (this.outSetValue == 0) { 66 return 67 } 68 --this.outSetValue 69 brightness.setValue(this.outSetValue) 70 }) 71 72 }.width('50%').padding({ top: 30 }) 73 74 Row() { 75 }.backgroundColor($r('app.color.color_fff')).width('50%').height('50%') 76 }.width('100%').height('100%') 77 } 78}