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