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 */ 15import DeviceUtil from '../../utils/DeviceUtil'; 16import { MmsSimpleDialog } from '../../views/MmsDialogs'; 17import { MoreMenu } from '../../views/MmsMenu'; 18import router from '@system.router'; 19import { SettingItemSwitch, SettingItemJump } from '../../views/SettingItem'; 20import SettingsController from './settingsController'; 21import HiLog from '../../utils/HiLog'; 22import WantUtil from '../../utils/WantUtil'; 23import AdvancedSettingsController from './advancedSettings/advancedSettingsController' 24 25const TAG = 'Settings'; 26@Entry 27@Component 28struct Settings { 29 @StorageLink('SettingsController') @Watch('changeSelectState') mSettingsCtrl: 30 SettingsController = SettingsController.getInstance() 31 @StorageLink('AdvancedSettingsController') @Watch('changeSelectState') mAdvancedSettingsCtrl: 32 AdvancedSettingsController = AdvancedSettingsController.getInstance(); 33 private gridColumns: GridRowColumnOption = { sm: 4, md: 8, lg: 12 }; 34 private girdSpan: GridColColumnOption = { sm: 4, md: 6, lg: 8 }; 35 private gridColOffset: GridColColumnOption = { md: 1, lg: 2 }; 36 private gridGutter: string = '12vp'; 37 isEnhanceShow: Visibility = DeviceUtil.isTablet() ? Visibility.None : Visibility.Visible; 38 private restoreDialog = new MmsSimpleDialog({ 39 message: $r('app.string.restore_all_default_settings'), 40 primaryButton: { 41 value: $r('app.string.cancel'), 42 action: () => { 43 } 44 }, 45 secondaryButton: { 46 value: $r('app.string.restore'), 47 action: () => { 48 this.mSettingsCtrl.restoreSettingsPageSwitchValue(); 49 this.mAdvancedSettingsCtrl.restoreSettingPageSwitchValue(); 50 } 51 } 52 }); 53 54 changeSelectState(){ 55 } 56 57 @Provide menuItems: Array<any> = [ 58 { 59 value: $r('app.string.restore_default_settings'), 60 action: () => { 61 this.restoreDialog.show(); 62 }, 63 enabled: true 64 } 65 ]; 66 @Provide statusTitle: Resource = null; 67 68 /** 69 * The function executes after a new instance of the custom component is created and before its build function 70 * is executed. 71 * Allows state variables to be changed in the aboutToAppear function, and these changes will take effect in 72 * subsequent executions of the build function. 73 */ 74 aboutToAppear() { 75 this.mSettingsCtrl.onInit() 76 } 77 78 /** 79 * Function executes before custom component destructor consumption. 80 * Changing state variables in the aboutToDisappear function is not allowed, especially changes to the @Link 81 * variable may cause unstable application behavior. 82 */ 83 aboutToDisappear() { 84 } 85 86 /** 87 * Triggers once when this page is displayed. In scenarios such as routing and application access to the foreground 88 * and background, only customized components modified by @Entry take effect. 89 */ 90 onPageShow() { 91 this.mSettingsCtrl.onShow(); 92 WantUtil.getWant(); 93 } 94 95 /** 96 * Triggers once when this page disappears. In scenarios such as routing and application access to the foreground 97 * and background, only customized components modified by @Entry take effect. 98 */ 99 onPageHide() { 100 } 101 102 /** 103 * Triggered when a user clicks the back button. Only the customized component modified by @Entry takes effect. 104 * If true is returned, the page processes the return logic and does not route the page. 105 * If false is returned, the default return logic is used. 106 * If no value is returned, the value is treated as false. 107 */ 108 onBackPress() { 109 } 110 111 build() { 112 Column() { 113 // Top Device Title 114 Row() { 115 Image($rawfile('icon/ic_message_back.svg')) 116 .width($r('app.float.icon_side_length_medium')) 117 .height($r('app.float.icon_side_length_medium')) 118 .margin({ 119 left: $r('app.float.action_bar_margin_left') 120 }) 121 .onClick(() => { 122 router.back() 123 }) 124 125 Row().width($r('app.float.space_16')) 126 127 Text($r('app.string.settings')) 128 .fontSize($r('app.float.action_bar_text_size')) 129 .fontColor(Color.Black) 130 .fontWeight(FontWeight.Bold) 131 132 Row().width('100%').flexShrink(1) 133 134 Column() { 135 MoreMenu() 136 } 137 .margin({ right: $r('app.float.action_bar_margin_right') }) 138 } 139 .width('100%') 140 .height($r('app.float.action_bar_height')) 141 142 Scroll() { 143 GridRow({ columns: this.gridColumns, gutter: this.gridGutter }) { 144 GridCol({ span: this.girdSpan, offset: this.gridColOffset }) { 145 // All settings 146 Column() { 147 // Setting items of the first group 148 Column() { 149 // Enhanced Information 150 SettingItemJump({ 151 primaryTitle: $r('app.string.enhanced_information'), 152 visibilityShow: this.isEnhanceShow, 153 OnClick: (event?: ClickEvent) => { 154 // The page for setting enhanced information is displayed. 155 } 156 }) 157 158 // Intelligent information 159 SettingItemJump({ 160 primaryTitle: $r('app.string.intelligent_information'), 161 OnClick: (event?: ClickEvent) => { 162 // The ringtone setting page is displayed. 163 } 164 }) 165 } 166 .width('100%') 167 .padding({ 168 top: $r('app.float.settings_item_padding_top'), 169 bottom: $r('app.float.settings_item_padding_bottom'), 170 left: $r('app.float.settings_item_padding_left'), 171 right: $r('app.float.settings_item_padding_right') 172 }) 173 .border({ 174 radius: $r('app.float.settings_items_radius'), 175 color: $r('sys.color.ohos_id_color_text_field_bg') 176 }) 177 .backgroundColor($r('sys.color.ohos_id_color_text_field_bg')) 178 .visibility(Visibility.None) 179 180 // Setting items of the second group 181 Column() { 182 // Notification information integration 183 SettingItemSwitch({ 184 primaryTitle: $r('app.string.archive_info_messages'), 185 secondaryTitle: $r('app.string.archive_info_messages_hint'), 186 isEnable: this.mSettingsCtrl.integrationSwitch, 187 showBottomDivider: false, 188 onChange: (isOn: boolean) => { 189 this.mSettingsCtrl.integration(isOn) 190 } 191 }) 192 } 193 .width('100%') 194 .padding({ 195 top: $r('app.float.settings_item_padding_top'), 196 bottom: $r('app.float.settings_item_padding_bottom'), 197 left: $r('app.float.settings_item_padding_left'), 198 right: $r('app.float.settings_item_padding_right') 199 }) 200 .border({ 201 radius: $r('app.float.settings_items_radius'), 202 color: $r('sys.color.ohos_id_color_text_field_bg') 203 }) 204 .backgroundColor($r('sys.color.ohos_id_color_text_field_bg')) 205 206 // Setting items of the third group 207 Column() { 208 // Message ringtone 209 SettingItemJump({ 210 primaryTitle: $r('app.string.message_tone'), 211 showBottomDivider: true, 212 visibilityShow: Visibility.None, 213 OnClick: (event?: ClickEvent) => { 214 // The ringtone setting page is displayed. 215 this.mSettingsCtrl.jumpToMessageTonePage() 216 } 217 }) 218 // Advanced 219 SettingItemJump({ 220 primaryTitle: $r('app.string.advanced'), 221 OnClick: (event?: ClickEvent) => { 222 // Go to the advanced settings screen. 223 this.mSettingsCtrl.advancedSetting() 224 } 225 }) 226 } 227 .width('100%') 228 .padding({ 229 top: $r('app.float.settings_item_padding_top'), 230 bottom: $r('app.float.settings_item_padding_bottom'), 231 left: $r('app.float.settings_item_padding_left'), 232 right: $r('app.float.settings_item_padding_right') 233 }) 234 .margin({ top: 12 }) 235 .border({ 236 radius: $r('app.float.settings_items_radius'), 237 color: $r('sys.color.ohos_id_color_text_field_bg') 238 }) 239 .backgroundColor($r('sys.color.ohos_id_color_text_field_bg')) 240 } 241 .margin({ 242 top: $r('app.float.settings_items_margin_top'), 243 bottom: $r('app.float.settings_items_margin_bottom') 244 }) 245 } 246 } 247 } 248 .layoutWeight(1) 249 .align(Alignment.Top) 250 } 251 .width('100%') 252 .height('100%') 253 .padding({ left: $r('app.float.page_padding_left'), right: $r('app.float.page_padding_right') }) 254 .backgroundColor($r('sys.color.ohos_id_color_sub_background')) 255 } 256}