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 router from '@ohos.router' 17import VideoListLayout from '../component/VideoPreview' 18import RacingLayout from '../component/Racing' 19import BattleLayout from '../component/Battle' 20import ShootLayout from '../component/Shooting' 21import InstrumentLayout from '../component/Instrument' 22import RealisticLayout from '../component/Realistic' 23import FootstepLayout from '../component/Footstep' 24import EnvironmentLayout from '../component/Environment' 25import ExerciseLayout from '../component/Exercise' 26import InteractionLayout from '../component/Interaction' 27import Logger from './Logger' 28import TabBar from './TabBar' 29 30const TAG = '[DisplayModule]' 31 32export enum TabIndex { 33 RACING = 0, 34 BATTLE, 35 SHOOT, 36 INSTRUMENT, 37 REALISTIC, 38 FOOTSTEP, 39 ENVIRONMENT, 40 EXERCISE, 41 INTERACTION, 42} 43 44@Component 45export default struct DisplayModule { 46 @State titleArr: Resource[] = [ 47 $r("app.string.display_racing"), $r("app.string.display_battle"), $r("app.string.display_shoot"), 48 $r("app.string.display_instrument"), $r("app.string.display_realistic"), $r("app.string.display_footstep"), 49 $r("app.string.display_environment"), $r("app.string.display_exercise"), $r("app.string.display_interaction") 50 ] 51 @State currentIndex: number = 0 52 private swiperController: SwiperController = new SwiperController() 53 private tabHeight = 50 54 @State playDis: boolean = false 55 @Link vibrationIntensity: string 56 private controller: TabsController = new TabsController(); 57 58 build() { 59 Column({ space: 10 }) { 60 Row() { 61 Text($r("app.string.display_haptic_video")) 62 .width('50%') 63 .fontSize(24) 64 .fontColor('#ffffffff') 65 .fontWeight(FontWeight.Normal) 66 .textAlign(TextAlign.Start) 67 .layoutWeight(7) 68 .padding({ left: 10 }) 69 Button($r("app.string.display_show_more")) 70 .id('showMore') 71 .backgroundColor("#00d613ca") 72 .layoutWeight(3) 73 .height(35) 74 .fontColor('#919191') 75 .onClick(() => { 76 Logger.info(TAG, 'Show more pressed') 77 router.pushUrl({ 78 url: 'module/VideoListModule' 79 }) 80 }) 81 } 82 .padding({ top: 5 }) 83 84 VideoListLayout() 85 86 Text($r("app.string.display_haptic_library")) 87 .width('100%') 88 .fontSize(24) 89 .fontColor('#ffffffff') 90 .fontWeight(FontWeight.Normal) 91 .textAlign(TextAlign.Start) 92 .padding({ left: 10 }) 93 94 Row() { 95 TabBar({ 96 titleArr: $titleArr, 97 currentIndex: $currentIndex, 98 tabSelected: (position: number, title: string) => { 99 this.currentIndex = position 100 Logger.info(TAG, 'onTabSelected position = ' + position + ', title = ' + title) 101 this.swiperController.showNext() 102 }, 103 }) 104 } 105 .width('100%') 106 .height(this.tabHeight) 107 .zIndex(10) 108 109 Scroll() { 110 Column() { 111 Swiper(this.swiperController) { 112 ForEach(this.titleArr, (item: string) => { 113 Column() { 114 if (this.currentIndex === TabIndex.RACING) { 115 RacingLayout({ 116 vibrationIntensity: $vibrationIntensity 117 }) 118 } else if (this.currentIndex === TabIndex.BATTLE) { 119 BattleLayout({ 120 vibrationIntensity: $vibrationIntensity 121 }) 122 } else if (this.currentIndex === TabIndex.SHOOT) { 123 ShootLayout({ 124 vibrationIntensity: $vibrationIntensity 125 }) 126 } else if (this.currentIndex === TabIndex.INSTRUMENT) { 127 InstrumentLayout({ 128 vibrationIntensity: $vibrationIntensity 129 }) 130 } else if (this.currentIndex === TabIndex.REALISTIC) { 131 RealisticLayout({ 132 vibrationIntensity: $vibrationIntensity 133 }) 134 } else if (this.currentIndex === TabIndex.FOOTSTEP) { 135 FootstepLayout({ 136 vibrationIntensity: $vibrationIntensity 137 }) 138 } else if (this.currentIndex === TabIndex.ENVIRONMENT) { 139 EnvironmentLayout({ 140 vibrationIntensity: $vibrationIntensity 141 }) 142 } else if (this.currentIndex === TabIndex.EXERCISE) { 143 ExerciseLayout({ 144 vibrationIntensity: $vibrationIntensity 145 }) 146 } else if (this.currentIndex === TabIndex.INTERACTION) { 147 InteractionLayout() 148 } else { 149 Text('Please Waiting!') 150 .fontSize(48) 151 .fontColor(Color.Black) 152 .width("100%") 153 .height("100%") 154 } 155 } 156 }, (item: string) => item) 157 } 158 .index(0) 159 .autoPlay(false) 160 .indicator(false) 161 .loop(false) 162 .vertical(false) 163 .itemSpace(0) 164 .index(this.currentIndex) 165 .flexGrow(1) 166 .width('100%') 167 .onChange((index: number) => { 168 Logger.info(TAG, index.toString()) 169 this.currentIndex = index 170 }) 171 } 172 } 173 .scrollBar(BarState.Off) 174 } 175 .width('100%') 176 .height('100%') 177 .backgroundColor('#f2191a32') 178 } 179} 180