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 brightness from '@ohos.brightness'; 17import mBrightnessManager from '../brightnessManager'; 18import StyleConfiguration, { BrightnessComponentStyle } from '../common/StyleConfiguration'; 19import Log from '../../../../../../../common/src/main/ets/default/Log'; 20 21const TAG = 'Control-brightnessComponent'; 22 23class brightnessItemData { 24 min:number; 25 max:number; 26 value:number 27} 28 29@Component 30export default struct MyBrightness { 31 @StorageLink('BrightnessValue') brightnessValue: number = 0; 32 @State style: BrightnessComponentStyle = StyleConfiguration.getBrightnessComponentStyle(); 33 @State brightnessItem: brightnessItemData = { 34 min: mBrightnessManager.getMin(), 35 max: mBrightnessManager.getMax(), 36 value: mBrightnessManager.getDefault() 37 }; 38 39 aboutToAppear() { 40 Log.showDebug(TAG, `Brightness aboutToAppear ${JSON.stringify(this.brightnessItem)}`); 41 } 42 43 aboutToDisappear() { 44 Log.showDebug(TAG, 'aboutToDisappear'); 45 } 46 47 build() { 48 Row() { 49 Image($r('app.media.ic_brightness_reduce')) 50 .width(this.style.brightnessPlusWidth) 51 .height('100%') 52 .margin({left: this.style.marginLeft, right: this.style.componentGap}) 53 .size({ width: this.style.brightnessReduceWidth, 54 height: this.style.brightnessReduceHeight }) 55 .fillColor(this.style.brightnessIconColor) 56 .layoutWeight(0) 57 58 Slider({ 59 value: this.brightnessValue, 60 min: this.brightnessItem.min, 61 max: this.brightnessItem.max, 62 step: 1, 63 style: SliderStyle.InSet 64 65 }) 66 .width('100%') 67 .height('100%') 68 .layoutWeight(1) 69 .trackThickness(this.style.sliderHeight) 70 .blockColor(this.style.sliderBlockColor) 71 .trackColor(this.style.sliderTrackColor) 72 .selectedColor(this.style.sliderSelectedColor) 73 .onChange((value: number, mode: SliderChangeMode) => { 74 mBrightnessManager.setValue(value, mode); 75 this.brightnessValue = value 76 }) 77 78 Image($r('app.media.ic_brightness_plus')) 79 .width(this.style.brightnessPlusWidth) 80 .height('100%') 81 .margin({left: this.style.componentGap, right: this.style.marginRight}) 82 .size({ width: this.style.brightnessPlusWidth, 83 height: this.style.brightnessPlusHeight }) 84 .fillColor(this.style.brightnessIconColor) 85 .layoutWeight(0) 86 }.width('100%') 87 .height(this.style.brightnessHeight) 88 } 89}