• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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
16// Flash page
17import cameraDemo from 'libentry.so';
18
19interface FlashPic {
20  iconOff: Resource;
21  iconOn: Resource;
22  iconAuto: Resource;
23  iconAlwaysOn: Resource;
24}
25
26@Component
27export struct FlashingLightPage {
28  // Page judgment
29  @State flashingBol: boolean = true;
30  // Flash mode
31  @State flashingNum: number = 0;
32  private flashIcon: FlashPic = {
33    iconOff: $r('app.media.ic_camera_public_flash_off'),
34    iconOn: $r('app.media.ic_camera_public_flash_on'),
35    iconAuto: $r('app.media.ic_camera_public_flash_auto'),
36    iconAlwaysOn: $r('app.media.flash_always_on')
37  };
38
39  // Return to selected image
40  getImageDefault() {
41    if (this.flashingNum == 0) {
42      return this.flashIcon.iconOff;
43    }
44    if (this.flashingNum == 1) {
45      return this.flashIcon.iconOn;
46    }
47    if (this.flashingNum == 2) {
48      return this.flashIcon.iconAuto;
49    }
50    if (this.flashingNum == 3) {
51      return this.flashIcon.iconAlwaysOn;
52    }
53    return;
54  }
55
56  build() {
57    Row() {
58      if (this.flashingBol) {
59        Row() {
60          Button() {
61            Image(this.getImageDefault())
62              .width('60px').height('60px').fillColor('#FFFFFF');
63          }
64          .width('80px')
65          .height('80px')
66          .backgroundColor('rgba(255,255,255,0.20)')
67          .borderRadius('40px')
68          .onClick(() => {
69            this.flashingBol = false;
70          })
71        }
72      } else {
73        Flex({ justifyContent: FlexAlign.SpaceEvenly, alignItems: ItemAlign.Center }) {
74          Image($r('app.media.ic_camera_public_flash_auto'))
75            .width('60px')
76            .height('60px')
77            .fillColor(this.flashingNum == 2 ? $r('app.color.theme_color') : '')
78            .onClick(() => {
79              this.flashingNum = 2;
80              this.flashingBol = true;
81              cameraDemo.hasFlash(this.flashingNum);
82            });
83          Image($r('app.media.ic_camera_public_flash_off'))
84            .width('60px')
85            .height('60px')
86            .fillColor(this.flashingNum == 0 ? $r('app.color.theme_color') : '')
87            .onClick(() => {
88              this.flashingNum = 0;
89              this.flashingBol = true;
90              cameraDemo.hasFlash(this.flashingNum);
91            });
92          Image($r('app.media.ic_camera_public_flash_on'))
93            .width('60px')
94            .height('60px')
95            .fillColor(this.flashingNum == 1 ? $r('app.color.theme_color') : '')
96            .onClick(() => {
97              this.flashingNum = 1;
98              this.flashingBol = true;
99              cameraDemo.hasFlash(this.flashingNum);
100            });
101          Image($r('app.media.flash_always_on'))
102            .width('50px')
103            .height('50px')
104            .fillColor(this.flashingNum == 3 ? $r('app.color.theme_color') : '')
105            .onClick(() => {
106              this.flashingNum = 3;
107              this.flashingBol = true;
108              cameraDemo.hasFlash(this.flashingNum);
109            });
110        }
111        .backgroundColor('#FFFFFF')
112        .borderRadius('40px')
113        .width('300px')
114        .height('80px')
115        .zIndex(999)
116      }
117    }
118    .position({ x: 30, y: 408 })
119    .id('FlashLightButton')
120  }
121}