• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { CameraService } from '../../camera/CameraService'
17import getStore from '../../redux/store'
18import { Log } from '../../utils/Log'
19
20let localState = (state) => {
21  return {
22    uiEnable: state.ContextReducer.uiEnable
23  }
24}
25
26let localDispatcher = (dispatch) => {
27  return {}
28}
29
30@Component
31export default struct EntryComponentForMulti {
32  private TAG: string = '[EntryComponentForMulti]:'
33  @State state: any = {}
34  @State isLocalDevice: boolean = false
35  @State switchCameraState: boolean = false
36  @State recCameraState: boolean = true
37  @State defaultChecked: boolean = false
38  @State curCameraName: string = ''
39  private localList: string
40  private item: string
41  private onChange: Function
42  private cameraService = CameraService.getInstance()
43  private deviceName: string
44  private cameraPositionRes: Resource
45  private cameraPositionName: string
46
47  aboutToAppear() {
48    getStore().connect(localState, localDispatcher)(this.state)
49    this.getShowName(this.item)
50    this.curCameraName = this.cameraService.getCameraName()
51    if (this.localList.split(",").length === 1 && this.curCameraName === 'BACK') {
52      this.curCameraName = 'FRONT'
53    }
54  }
55
56  private getShowName(item) {
57    let cameraMap
58    this.cameraPositionName = item.split('_').pop()
59    switch (this.cameraPositionName) {
60      case 'FRONT':
61        this.cameraPositionRes = $r("app.string.front")
62        break
63      case 'BACK':
64        this.cameraPositionRes = $r("app.string.back")
65        break
66      default:
67        break
68    }
69    if (item.split('_').length == 1) {
70      this.isLocalDevice = true
71    } else {
72      cameraMap = this.cameraService.getCameraMap()
73      this.deviceName = cameraMap.get(item).deviceName
74      this.isLocalDevice = false
75    }
76  }
77
78  build() {
79    Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
80      Row() {
81        if (this.isLocalDevice) {
82          Text($r("app.string.local"))
83            .fontColor('#E6000000')
84            .fontSize($r("sys.float.ohos_id_text_size_body1"))
85            .fontWeight(FontWeight.Medium)
86        } else {
87          Text(this.deviceName)
88            .fontColor('#E6000000')
89            .fontSize($r("sys.float.ohos_id_text_size_body1"))
90            .fontWeight(FontWeight.Medium)
91        }
92        Text(this.cameraPositionRes)
93          .fontColor('#E6000000')
94          .fontSize($r("sys.float.ohos_id_text_size_body1"))
95          .fontWeight(FontWeight.Medium)
96      }
97
98      Radio({ group: 'settingChildren', value: this.item.toString() })
99        .width(24)
100        .height(24)
101        .borderColor('#1095E8')
102        .checked(this.defaultChecked ? true : this.item === this.curCameraName)
103        .enabled(this.state.uiEnable)
104        .onClick(() => {
105          Log.info(`${this.TAG} onChange item: ${this.item}`)
106          if (this.item === this.curCameraName) {
107            Log.info(`${this.TAG} no Change curCameraName: ${this.curCameraName}`)
108          } else {
109            this.onChange(this.item)
110          }
111        })
112    }
113    .height(48)
114    .width('100%')
115  }
116}