1048147e0Sopenharmony_ci/** 2048147e0Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3048147e0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4048147e0Sopenharmony_ci * you may not use this file except in compliance with the License. 5048147e0Sopenharmony_ci * You may obtain a copy of the License at 6048147e0Sopenharmony_ci * 7048147e0Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8048147e0Sopenharmony_ci * 9048147e0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10048147e0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11048147e0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12048147e0Sopenharmony_ci * See the License for the specific language governing permissions and 13048147e0Sopenharmony_ci * limitations under the License. 14048147e0Sopenharmony_ci */ 15048147e0Sopenharmony_ciimport MmsBoolean from '../data/MmsBoolean'; 16048147e0Sopenharmony_ci 17048147e0Sopenharmony_ci/** 18048147e0Sopenharmony_ci * Options: dual title, 1 switch 19048147e0Sopenharmony_ci */ 20048147e0Sopenharmony_ci@Component 21048147e0Sopenharmony_ciexport struct SettingItemSwitch { 22048147e0Sopenharmony_ci primaryTitle: string | Resource; 23048147e0Sopenharmony_ci secondaryTitle?: string | Resource; 24048147e0Sopenharmony_ci @ObjectLink isEnable: MmsBoolean; 25048147e0Sopenharmony_ci showBottomDivider ?: boolean = false; 26048147e0Sopenharmony_ci visibilityShow ?: Visibility = Visibility.Visible; 27048147e0Sopenharmony_ci onChange: (isOn: boolean) => void; 28048147e0Sopenharmony_ci 29048147e0Sopenharmony_ci build() { 30048147e0Sopenharmony_ci Column() { 31048147e0Sopenharmony_ci Flex({ 32048147e0Sopenharmony_ci direction: FlexDirection.Row, 33048147e0Sopenharmony_ci justifyContent: FlexAlign.SpaceBetween, 34048147e0Sopenharmony_ci alignItems: ItemAlign.Center 35048147e0Sopenharmony_ci }) { 36048147e0Sopenharmony_ci Flex({ 37048147e0Sopenharmony_ci direction: FlexDirection.Column, 38048147e0Sopenharmony_ci justifyContent: FlexAlign.Center, 39048147e0Sopenharmony_ci alignItems: ItemAlign.Start 40048147e0Sopenharmony_ci }) { 41048147e0Sopenharmony_ci Text(this.primaryTitle) 42048147e0Sopenharmony_ci .height($r('app.float.settings_item_primary_title_height')) 43048147e0Sopenharmony_ci .fontWeight(FontWeight.Medium) 44048147e0Sopenharmony_ci .fontSize($r('app.float.settings_item_primary_title_font_size')) 45048147e0Sopenharmony_ci .fontColor($r('sys.color.ohos_id_color_text_primary')) 46048147e0Sopenharmony_ci 47048147e0Sopenharmony_ci if (this.secondaryTitle != undefined) { 48048147e0Sopenharmony_ci Text(this.secondaryTitle) 49048147e0Sopenharmony_ci .height($r('app.float.settings_item_secondary_title_height')) 50048147e0Sopenharmony_ci .margin({ top: $r('app.float.settings_item_title_space') }) 51048147e0Sopenharmony_ci .fontWeight(FontWeight.Regular) 52048147e0Sopenharmony_ci .fontSize($r('app.float.settings_item_secondary_title_font_size')) 53048147e0Sopenharmony_ci .fontColor($r('sys.color.ohos_id_color_text_tertiary')) 54048147e0Sopenharmony_ci } 55048147e0Sopenharmony_ci } 56048147e0Sopenharmony_ci .layoutWeight(1) 57048147e0Sopenharmony_ci 58048147e0Sopenharmony_ci Toggle({ type: ToggleType.Switch, isOn: this.isEnable.value }) 59048147e0Sopenharmony_ci .width($r('app.float.settings_item_switch_width')) 60048147e0Sopenharmony_ci .offset({ x: 4, y: 0 }) 61048147e0Sopenharmony_ci .selectedColor($r('sys.color.ohos_id_color_activated')) 62048147e0Sopenharmony_ci .onChange((isOn: boolean) => { 63048147e0Sopenharmony_ci if (typeof isOn === 'number') { 64048147e0Sopenharmony_ci let newIsOn: number = isOn; 65048147e0Sopenharmony_ci switch (newIsOn) { 66048147e0Sopenharmony_ci case 1: 67048147e0Sopenharmony_ci isOn = true; 68048147e0Sopenharmony_ci break; 69048147e0Sopenharmony_ci case 0: 70048147e0Sopenharmony_ci isOn = false; 71048147e0Sopenharmony_ci break; 72048147e0Sopenharmony_ci default: 73048147e0Sopenharmony_ci break; 74048147e0Sopenharmony_ci } 75048147e0Sopenharmony_ci } 76048147e0Sopenharmony_ci this.onChange(isOn); 77048147e0Sopenharmony_ci }) 78048147e0Sopenharmony_ci } 79048147e0Sopenharmony_ci .layoutWeight(1) 80048147e0Sopenharmony_ci 81048147e0Sopenharmony_ci if (this.showBottomDivider) { 82048147e0Sopenharmony_ci Divider() 83048147e0Sopenharmony_ci .vertical(false) 84048147e0Sopenharmony_ci .strokeWidth(1) 85048147e0Sopenharmony_ci .color($r('sys.color.ohos_id_color_list_separator')) 86048147e0Sopenharmony_ci .lineCap(LineCapStyle.Round) 87048147e0Sopenharmony_ci } 88048147e0Sopenharmony_ci } 89048147e0Sopenharmony_ci .width('100%') 90048147e0Sopenharmony_ci .height(this.secondaryTitle != undefined ? $r('app.float.settings_item_height_2') : 91048147e0Sopenharmony_ci $r('app.float.settings_item_height_1')) 92048147e0Sopenharmony_ci .visibility(this.visibilityShow) 93048147e0Sopenharmony_ci } 94048147e0Sopenharmony_ci} 95048147e0Sopenharmony_ci 96048147e0Sopenharmony_ci/** 97048147e0Sopenharmony_ci * Setting items: double title, one status, and one next icon 98048147e0Sopenharmony_ci */ 99048147e0Sopenharmony_ci@Component 100048147e0Sopenharmony_ciexport struct SettingItemJump { 101048147e0Sopenharmony_ci primaryTitle: string | Resource; 102048147e0Sopenharmony_ci secondaryTitle ?: string | Resource; 103048147e0Sopenharmony_ci @Consume statusTitle: Resource; 104048147e0Sopenharmony_ci showBottomDivider ?: boolean = false; 105048147e0Sopenharmony_ci visibilityShow ?: Visibility = Visibility.Visible; 106048147e0Sopenharmony_ci OnClick: (event?: ClickEvent) => void; 107048147e0Sopenharmony_ci 108048147e0Sopenharmony_ci build() { 109048147e0Sopenharmony_ci Column() { 110048147e0Sopenharmony_ci Flex({ 111048147e0Sopenharmony_ci direction: FlexDirection.Row, 112048147e0Sopenharmony_ci justifyContent: FlexAlign.SpaceBetween, 113048147e0Sopenharmony_ci alignItems: ItemAlign.Center 114048147e0Sopenharmony_ci }) { 115048147e0Sopenharmony_ci Flex({ 116048147e0Sopenharmony_ci direction: FlexDirection.Column, 117048147e0Sopenharmony_ci justifyContent: FlexAlign.Center, 118048147e0Sopenharmony_ci alignItems: ItemAlign.Start 119048147e0Sopenharmony_ci }) { 120048147e0Sopenharmony_ci Text(this.primaryTitle) 121048147e0Sopenharmony_ci .height($r('app.float.settings_item_primary_title_height')) 122048147e0Sopenharmony_ci .fontWeight(FontWeight.Medium) 123048147e0Sopenharmony_ci .fontSize($r('app.float.settings_item_primary_title_font_size')) 124048147e0Sopenharmony_ci .fontColor($r('sys.color.ohos_id_color_text_primary')) 125048147e0Sopenharmony_ci 126048147e0Sopenharmony_ci if (this.secondaryTitle != undefined) { 127048147e0Sopenharmony_ci Text(this.secondaryTitle) 128048147e0Sopenharmony_ci .height($r('app.float.settings_item_secondary_title_height')) 129048147e0Sopenharmony_ci .margin({ top: $r('app.float.settings_item_title_space') }) 130048147e0Sopenharmony_ci .fontWeight(FontWeight.Regular) 131048147e0Sopenharmony_ci .fontSize($r('app.float.settings_item_secondary_title_font_size')) 132048147e0Sopenharmony_ci .fontColor($r('sys.color.ohos_id_color_text_tertiary')) 133048147e0Sopenharmony_ci } 134048147e0Sopenharmony_ci } 135048147e0Sopenharmony_ci .layoutWeight(1) 136048147e0Sopenharmony_ci 137048147e0Sopenharmony_ci Row() { 138048147e0Sopenharmony_ci if (this.statusTitle != undefined) { 139048147e0Sopenharmony_ci Text(this.statusTitle) 140048147e0Sopenharmony_ci .height($r('app.float.settings_item_secondary_title_height')) 141048147e0Sopenharmony_ci .margin({ right: $r('app.float.settings_item_status_title_margin_right') }) 142048147e0Sopenharmony_ci .fontWeight(FontWeight.Regular) 143048147e0Sopenharmony_ci .fontSize($r('app.float.settings_item_secondary_title_font_size')) 144048147e0Sopenharmony_ci .fontColor($r('sys.color.ohos_id_color_text_secondary')) 145048147e0Sopenharmony_ci } 146048147e0Sopenharmony_ci 147048147e0Sopenharmony_ci Image($rawfile('icon/ic_next.svg')) 148048147e0Sopenharmony_ci .width($r('app.float.settings_item_next_image_width')) 149048147e0Sopenharmony_ci .height($r('app.float.settings_item_next_image_height')) 150048147e0Sopenharmony_ci } 151048147e0Sopenharmony_ci } 152048147e0Sopenharmony_ci .layoutWeight(1) 153048147e0Sopenharmony_ci .onClick(this.OnClick) 154048147e0Sopenharmony_ci 155048147e0Sopenharmony_ci if (this.showBottomDivider) { 156048147e0Sopenharmony_ci Divider() 157048147e0Sopenharmony_ci .vertical(false) 158048147e0Sopenharmony_ci .strokeWidth(1) 159048147e0Sopenharmony_ci .color($r('sys.color.ohos_id_color_list_separator')) 160048147e0Sopenharmony_ci .lineCap(LineCapStyle.Round) 161048147e0Sopenharmony_ci } 162048147e0Sopenharmony_ci } 163048147e0Sopenharmony_ci .width('100%') 164048147e0Sopenharmony_ci .height(this.secondaryTitle != undefined ? $r('app.float.settings_item_height_2') : 165048147e0Sopenharmony_ci $r('app.float.settings_item_height_1')) 166048147e0Sopenharmony_ci .visibility(this.visibilityShow) 167048147e0Sopenharmony_ci } 168048147e0Sopenharmony_ci}