• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Hunan OpenValley Digital Industry Development 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 settings from '@ohos.settings';
18import { GlobalContext } from '../../../../../../entry/src/main/ets/pages/GlobalContext';
19
20@Preview
21@Component
22export struct BrightnessManager {
23  @State value: number = 0;
24
25  async aboutToAppear() {
26    let ctx: Context = GlobalContext.getContext().getValue('abilityContext') as Context;
27    let brightness = await settings.getValue(ctx, settings.display.SCREEN_BRIGHTNESS_STATUS);
28    this.value = Number(brightness);
29  }
30
31  build() {
32    Column() {
33      Text($r("app.string.brightness_manager"))
34        .fontSize(18)
35        .fontColor($r("app.color.list_content"))
36        .fontWeight(FontWeight.Medium)
37        .margin({
38          left: 16,
39          top: 48
40        })
41      Row() {
42        Image($r("app.media.ic_brightness_l"))
43          .objectFit(ImageFit.Contain)
44          .width(30)
45          .height(30)
46          .margin({
47            left: 16,
48            right: 16
49          })
50        Slider({
51          value: this.value,
52          min: 0,
53          max: 255,
54          style: SliderStyle.InSet
55        })
56          .layoutWeight(1)
57          .showTips(true)
58          .onChange((value: number, mode: SliderChangeMode) => {
59            this.value = value;
60            brightness.setValue(Math.round(value));
61          })
62        Image($r("app.media.ic_brightness_h"))
63          .objectFit(ImageFit.Contain)
64          .width(30)
65          .height(30)
66          .margin({
67            left: 16,
68            right: 16
69          })
70      }
71      .margin({
72        top: 12,
73        left: 4,
74        right: 4
75      })
76      .backgroundColor($r("app.color.white"))
77      .borderRadius(20)
78      .height(120)
79    }
80    .alignItems(HorizontalAlign.Start)
81  }
82}