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