1/* 2 * Copyright (c) 2023 Hunan OpenValley Digital Industry Development 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 Constants from '../Constants'; 17import ComponentSingletonTimer from '../components/ComponentSingletonTimer'; 18import common from '@ohos.app.ability.common'; 19 20/** 21 * 悬浮窗UI 22 */ 23@Entry 24@Component 25struct Float { 26 @StorageLink('UI_EVENT') mUIEvent: number = -1; 27 28 build() { 29 Column() { 30 if (this.mUIEvent === Constants.EVENT_UI_CALL) { //请求通话页面 31 FloatComponent({ res: $r('app.media.icon_openvalley_call_green'), tips: $r('app.string.tips_call') }) 32 } else if (this.mUIEvent === Constants.EVENT_UI_ANSWER) { // 来电页面 33 FloatComponent({ res: $r('app.media.icon_openvalley_call_green'), tips: $r('app.string.tips_answer') }) 34 } else if (this.mUIEvent === Constants.EVENT_UI_VOICE) { //通话页面 35 FloatComponent({ res: $r('app.media.icon_openvalley_call_green') }) 36 } 37 } 38 .id('switch_window_to_index') 39 .backgroundColor($r('app.color.color_transparent')) 40 .width('100%') 41 .height('100%') 42 .onClick(() => { 43 let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext 44 context.startAbility({ 45 bundleName: context.abilityInfo.bundleName, 46 abilityName: context.abilityInfo.name 47 }) 48 }) 49 } 50} 51 52@Component 53struct FloatComponent { 54 private res?: Resource; 55 private tips?: Resource; 56 57 build() { 58 59 Column() { 60 if (this.res) { 61 Image(this.res) 62 .objectFit(ImageFit.Contain) 63 .width('40%') 64 .height('40%') 65 } 66 67 if (this.tips) { 68 Text(this.tips) 69 .fontSize(14) 70 .fontColor($r('app.color.color_green')) 71 .fontWeight(FontWeight.Regular) 72 .fontFamily('HarmonyOS Sans SC') 73 } else { 74 ComponentSingletonTimer({ mTextColor: $r('app.color.color_green'), mTextSize: 14 }) 75 } 76 } 77 .backgroundColor($r('app.color.color_fff')) 78 .borderRadius(16) 79 .justifyContent(FlexAlign.SpaceAround) 80 .width('100%') 81 .height('100%') 82 } 83}