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 { Action } from '../../../../../../common/src/main/ets/default/redux/actions/Action' 17import { Log } from '../../../../../../common/src/main/ets/default/utils/Log' 18import getStore, { OhCombinedState } from '../../../../../../common/src/main/ets/default/redux/store' 19import { SettingItem 20} from '../../../../../../common/src/main/ets/default/featurecommon/settingview/tablet/SettingItem' 21import SettingListModel from '../../../../../../common/src/main/ets/default/featurecommon/settingview/model/SettingListModel' 22import { SettingManager } from '../../../../../../common/src/main/ets/default/setting/SettingManager' 23import EventBusManager from '../../../../../../common/src/main/ets/default/worker/eventbus/EventBusManager'; 24import { EventBus } from '../../../../../../common/src/main/ets/default/worker/eventbus/EventBus'; 25 26let localState = (state: OhCombinedState) => { 27 return { 28 isCloseFlag: state.SettingReducer.isCloseFlag, 29 mode: state.ModeReducer.mode, 30 } 31} 32 33let localDispatcher = (dispatch) => { 34 return { 35 closeDialog: (isCloseFlag: boolean) => { 36 dispatch(Action.closeDialog(isCloseFlag)) 37 }, 38 hideSettingView: () => { 39 dispatch(Action.showSettingView(false)) 40 }, 41 changeXComponentSize: (xComponentWidth: number, xComponentHeight: number) => { 42 dispatch(Action.changeXComponentSize(xComponentWidth, xComponentHeight)) 43 }, 44 assistiveGridView: (isViewShow) => { 45 dispatch(Action.assistiveGridView(isViewShow)) 46 }, 47 reStartPreview: () => { 48 dispatch(Action.reStartPreview()) 49 }, 50 showBlur:() => { 51 dispatch(Action.uiState(false)) 52 }, 53 resetZoomRatio: () => { 54 dispatch(Action.changeZoomRatio(1)) 55 }, 56 } 57} 58 59@Component 60export struct SettingView { 61 private TAG: string = '[SettingView]:' 62 private settingManager = SettingManager.getInstance() 63 private scroller: Scroller = new Scroller(); 64 @State checkNameList: Array<string> = ["4:3", "[16:9] 720p"] 65 @State closeFlag: boolean = false 66 @State tempGutter: number = 12; //列间距 67 @State tempMargin: number = 12; //两侧间距 68 @State settingsList: any[] = SettingListModel.getSettingList() 69 @State state: any = {} 70 @State localStyle: any = { "columns": 12, "offset": 2, "span": 8 } 71 private WH_100_100: string = "100%"; 72 private mEventBus: EventBus = EventBusManager.getInstance().getEventBus() 73 74 aboutToAppear(): void{ 75 Log.info(`${this.TAG} aboutToAppear invoke E`) 76 getStore().connect(localState, localDispatcher)(this.state) 77 this.mEventBus.on("windowSize", this.windowSizeChange.bind(this)) 78 this.mEventBus.on("AspectRatio", this.aspectRatioChange.bind(this)) 79 this.mEventBus.on("Resolution", this.resolutionChange.bind(this)) 80 this.mEventBus.on("AssistiveGrid", this.assistiveGridChange.bind(this)) 81 Log.info(`${this.TAG} aboutToAppear invoke X`) 82 } 83 84 aboutToDisappear(): void { 85 Log.info(`${this.TAG} aboutToDisappear E`) 86 this.mEventBus.off("AspectRatio", this.aspectRatioChange.bind(this)) 87 this.mEventBus.off("Resolution", this.resolutionChange.bind(this)) 88 this.mEventBus.off("AssistiveGrid", this.assistiveGridChange.bind(this)) 89 } 90 91 onBackPress(): boolean { 92 Log.info(`${this.TAG} onBackPress invoke X`) 93 if (this.state.isCloseFlag){ 94 this.closeFlag = !this.closeFlag 95 } else { 96 this.state.hideSettingView() 97 } 98 return true; 99 } 100 101 private windowSizeChange(data) { 102 this.localStyle = (data.width >= px2vp(1280)) ? { "columns": 12, "offset": 2, "span": 8 } : 103 { "columns": 8, "offset": 1, "span": 6 } 104 } 105 private aspectRatioChange(xComponentSize) { 106 if (this.state.mode != 'VIDEO') { 107 this.state.changeXComponentSize(xComponentSize.width, xComponentSize.height) 108 this.state.reStartPreview() 109 } 110 } 111 private resolutionChange(xComponentSize) { 112 if (this.state.mode == 'VIDEO') { 113 this.state.changeXComponentSize(xComponentSize.width, xComponentSize.height) 114 this.state.reStartPreview() 115 } 116 } 117 private assistiveGridChange(mAssistiveGrid) { 118 this.state.assistiveGridView(mAssistiveGrid) 119 } 120 121 build() { 122 Column() { 123 Row() { 124 Image($r("app.media.ic_public_back")) 125 .width(24) 126 .height(24) 127 .fillColor($r('app.color.settings_ic_public_back_FFFFFF')) 128 .onClick(() => { 129 this.state.hideSettingView() 130 }) 131 Text($r('app.string.settings')) 132 .margin({ left: $r("sys.float.ohos_id_elements_margin_horizontal_l") }) 133 .fontColor($r('app.color.settings_ic_public_back_FFFFFF')) 134 .fontSize($r('sys.float.ohos_id_text_size_headline8')) 135 .fontWeight(FontWeight.Medium) 136 } 137 .width(this.WH_100_100) 138 .height(56) 139 .margin({ left: 48 }) 140 141 Scroll(this.scroller) { 142 Column() { 143 GridContainer({ columns: this.localStyle.columns, gutter: this.tempGutter, margin: this.tempMargin }) { 144 Row() { 145 Column() { 146 List() { 147 ForEach(this.settingsList, (item, index) => { 148 ListItem() { 149 SettingItem({ 150 settingsList: $settingsList, 151 closeFlag: $closeFlag, 152 item: item, 153 index: index 154 }) 155 } 156 }) 157 } 158 }.useSizeType({ 159 xs: { span: this.localStyle.span, offset: this.localStyle.offset }, 160 sm: { span: this.localStyle.span, offset: this.localStyle.offset }, 161 md: { span: this.localStyle.span, offset: this.localStyle.offset }, 162 lg: { span: this.localStyle.span, offset: this.localStyle.offset } 163 }) 164 } 165 } 166 167 GridContainer({ columns: 12, gutter: this.tempGutter, margin: this.tempMargin }) { 168 Row() { 169 Button({ type: ButtonType.Normal, stateEffect: true }) { 170 Text($r('app.string.restore_defaults')) 171 .fontSize($r('sys.float.ohos_id_text_size_button1')) 172 .fontColor($r('app.color.font_color_FFFFFF')) 173 .fontWeight(FontWeight.Regular) 174 .textAlign(TextAlign.Center) 175 } 176 .borderRadius(30) 177 .backgroundColor($r('app.color.background_color_333333')) 178 .height(40) 179 .useSizeType({ 180 xs: { span: 4, offset: 4 }, 181 sm: { span: 4, offset: 4 }, 182 md: { span: 4, offset: 4 }, 183 lg: { span: 4, offset: 4 } 184 }) 185 .onClick(() => { 186 this.state.showBlur() 187 this.settingManager.restoreValues(this.state.mode) 188 this.state.resetZoomRatio() 189 this.state.hideSettingView() 190 }) 191 }.margin({ top: $r("sys.float.ohos_id_text_paragraph_margin_l") , bottom: 70 }) 192 } 193 } 194 } 195 .scrollable(ScrollDirection.Vertical) 196 .scrollBar(BarState.Off) 197 } 198 .height(this.WH_100_100) 199 .backgroundColor(Color.Black) 200 } 201}