• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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      Image(this.res)
61        .objectFit(ImageFit.Contain)
62        .width('40%')
63        .height('40%')
64
65      if (this.tips) {
66        Text(this.tips)
67          .fontSize(14)
68          .fontColor($r('app.color.color_green'))
69          .fontWeight(FontWeight.Regular)
70          .fontFamily('HarmonyOS Sans SC')
71      } else {
72        ComponentSingletonTimer({ mTextColor: $r('app.color.color_green'), mTextSize: 14 })
73      }
74    }
75    .backgroundColor($r('app.color.color_fff'))
76    .borderRadius(16)
77    .justifyContent(FlexAlign.SpaceAround)
78    .width('100%')
79    .height('100%')
80  }
81}