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 featureAbility from '@ohos.ability.featureAbility'; 17import common from '@ohos.app.ability.common'; 18import Want from '@ohos.app.ability.Want'; 19import { BusinessError } from '@ohos.base'; 20import Logger from '../../utils/Logger'; 21 22const TAG: string = 'PageInterflowFaAndStage'; 23 24@Entry 25@Component 26struct PageInterflowFaAndStage { 27 async startServiceAbility(): Promise<void> { 28 try { 29 let want: Want = { 30 bundleName: 'com.samples.famodelabilitydevelop', 31 abilityName: 'com.samples.famodelabilitydevelop.ServiceAbilityStartUIAbility' 32 }; 33 await featureAbility.startAbility({ want }); 34 Logger.info(TAG, `Start ServiceAbility succeed`); 35 } catch (error) { 36 Logger.error(TAG, 'Start ServiceAbility failed with ' + error); 37 } 38 } 39 40 build() { 41 Column() { 42 Row() { 43 Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { 44 Text($r('app.string.interflow_fa_and_stage_button')) 45 .fontSize(24) 46 .fontWeight(FontWeight.Bold) 47 .textAlign(TextAlign.Start) 48 .margin({ top: 12, bottom: 11, right: 24, left: 24 }) 49 } 50 } 51 .width('100%') 52 .height(56) 53 .justifyContent(FlexAlign.Start) 54 .backgroundColor($r('app.color.backGrounding')) 55 56 List({ initialIndex: 0 }) { 57 ListItem() { 58 Row() { 59 Row() { 60 Text($r('app.string.start_stage_noResult_button')) 61 .textAlign(TextAlign.Start) 62 .fontWeight(FontWeight.Medium) 63 .margin({ top: 13, bottom: 13, left: 0, right: 8 }) 64 .fontSize(16) 65 .height(22) 66 .fontColor($r('app.color.text_color')) 67 } 68 .height(48) 69 .width('100%') 70 .borderRadius(24) 71 .margin({ top: 4, bottom: 4, left: 12, right: 84 }) 72 } 73 .onClick(() => { 74 let want: Want = { 75 bundleName: 'ohos.samples.etsclock', 76 abilityName: 'MainAbility' 77 }; 78 featureAbility.startAbility({ want }).then((code) => { 79 Logger.info(TAG, 'Ability verify code: ' + JSON.stringify(code)); 80 }).catch((error: BusinessError) => { 81 Logger.error(TAG, 'Ability failed: ' + JSON.stringify(error)); 82 }); 83 84 let serviceWant: Want = { 85 bundleName: 'com.samples.stagemodelabilityinteraction', 86 abilityName: 'ServiceExtAbility' 87 }; 88 89 let faConnect: common.ConnectOptions = { 90 onConnect: (elementName, proxy) => { 91 Logger.info(TAG, "FaConnection onConnect called."); 92 }, 93 onDisconnect: (elementName) => { 94 Logger.info(TAG, "FaConnection onDisconnect called."); 95 }, 96 onFailed: (code) => { 97 Logger.info(TAG, "FaConnection onFailed code is: " + code); 98 } 99 }; 100 let connectionId = featureAbility.connectAbility(serviceWant, faConnect); 101 }) 102 } 103 .height(56) 104 .backgroundColor($r('app.color.start_window_background')) 105 .borderRadius(24) 106 .margin({ top: 8, right: 12, left: 12 }) 107 108 ListItem() { 109 Row() { 110 Row() { 111 Text($r('app.string.start_stage_withResult_button')) 112 .textAlign(TextAlign.Start) 113 .fontWeight(FontWeight.Medium) 114 .margin({ top: 13, bottom: 13, left: 0, right: 8 }) 115 .fontSize(16) 116 .height(22) 117 .fontColor($r('app.color.text_color')) 118 } 119 .height(48) 120 .width('100%') 121 .borderRadius(24) 122 .margin({ top: 4, bottom: 4, left: 12, right: 84 }) 123 } 124 .onClick(() => { 125 let want: Want = { 126 bundleName: 'ohos.samples.etsclock', 127 abilityName: 'MainAbility' 128 }; 129 featureAbility.startAbilityForResult({ want }).then((result) => { 130 Logger.info(TAG, 'Ability verify result: ' + JSON.stringify(result)); 131 }).catch((error: BusinessError) => { 132 Logger.error(TAG, 'Ability failed: ' + JSON.stringify(error)); 133 }); 134 }) 135 } 136 .height(56) 137 .backgroundColor($r('app.color.start_window_background')) 138 .borderRadius(24) 139 .margin({ top: 12, right: 12, left: 12 }) 140 141 ListItem() { 142 Row() { 143 Row() { 144 Text($r('app.string.start_stage_service_button')) 145 .textAlign(TextAlign.Start) 146 .fontWeight(FontWeight.Medium) 147 .margin({ top: 13, bottom: 13, left: 0, right: 8 }) 148 .fontSize(16) 149 .height(22) 150 .fontColor($r('app.color.text_color')) 151 } 152 .height(48) 153 .width('100%') 154 .borderRadius(24) 155 .margin({ top: 4, bottom: 4, left: 12, right: 84 }) 156 } 157 .onClick(() => { 158 this.startServiceAbility(); 159 }) 160 } 161 .height(56) 162 .backgroundColor($r('app.color.start_window_background')) 163 .borderRadius(24) 164 .margin({ top: 12, right: 12, left: 12 }) 165 } 166 .height('100%') 167 .backgroundColor($r('app.color.backGrounding')) 168 } 169 .width('100%') 170 .margin({ top: 8 }) 171 .backgroundColor($r('app.color.backGrounding')) 172 } 173}