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