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