• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 prompt from '@ohos.promptAction';
17import router from '@ohos.router';
18import { logger } from '../util/Logger';
19
20interface GroupModel {
21  title?: string;
22  list: ListItemModel[];
23}
24
25export interface ListItemModel {
26  text: Resource,
27  rType?: string,
28  callback?: () => void,
29}
30
31const TAG: string = 'HomeAbility';
32
33@Entry
34@Component
35struct SendSync {
36  private myProxy: (UIExtensionProxy | null) = null;
37  @State list: GroupModel[] = [
38    {
39      title: '1',
40      list: [
41        {
42          text: $r('app.string.sendSyncData'),
43          rType: '',
44          callback: () => {
45            if (this.myProxy === null) {
46              logger.error(`${TAG} myProxy null`);
47              return;
48            }
49            let params: Record<string, string> = { 'key': `data from ${TAG}` };
50            let result = this.myProxy.sendSync(params);
51            prompt.showToast({ message: (`${TAG} onReceive ${result['key']}`), duration: 3000, bottom: 150 });
52          }
53        }
54      ]
55    },
56  ]
57
58  build() {
59    Column() {
60      Column() {
61        Row() {
62          Image($r('app.media.ic_back'))
63            .size({ width: 20, height: 18 })
64            .margin({ right: 18 })
65            .onClick(() => {
66              router.back({
67                url: 'pages/Index'
68              });
69            })
70          Text($r('app.string.SendSyncUIExtAbility_label'))
71            .fontSize(20)
72            .fontWeight(FontWeight.Bold)
73        }.height(56)
74        .padding({ left: 24, right: 24 })
75        .width('100%')
76      }
77
78      Column() {
79        List({ space: 0, initialIndex: 0 }) {
80          ForEach(this.list, (groupItem: GroupModel, groupIndex: number) => {
81            ListItemGroup() {
82              ForEach(groupItem.list, (item: ListItemModel, index: number) => {
83                ListItem() {
84                  Column() {
85                    Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
86                      Text(item.text)
87                        .fontSize(16)
88                        .height(48)
89                        .fontColor($r('sys.color.ohos_id_color_toolbar_sub_bg_dark'))
90                    }.width('100%')
91                  }.width('100%')
92                }
93                .id('sendSync')
94                .align(Alignment.Start)
95                .onClick(item.callback)
96                .width('100%')
97                .padding({ left: 12, right: 12 })
98              })
99            }
100            .padding({ top: 4, bottom: 4 })
101            .borderRadius(24)
102            .width('100%')
103            .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary'))
104            .margin({ top: 10, bottom: 10 })
105          })
106          ListItemGroup() {
107            ListItem() {
108              UIExtensionComponent({
109                bundleName: 'com.samples.abilityFeatureSystem',
110                abilityName: 'SendSyncUIExtAbility',
111                parameters: {
112                  'ability.want.params.uiExtensionType': 'sys/commonUI',
113                }
114              }).size({ width: '100%', height: '90%' })
115                .onRemoteReady((pro: UIExtensionProxy) => {
116                  logger.info(`${TAG} onRemoteReady:`);
117                  this.myProxy = pro;
118                })
119            }
120          }
121          .borderRadius(24)
122          .width('100%')
123          .margin({ top: 10, bottom: 10 })
124        }
125        .scrollBar(BarState.Off)
126        .listDirection(Axis.Vertical)
127        .friction(0.6)
128        .edgeEffect(EdgeEffect.Spring)
129        .padding({ left: 12, right: 12 })
130        .width('100%')
131        .height('100%')
132      }.width('100%')
133    }.width('100%')
134    .height('100%')
135    .backgroundColor($r('sys.color.ohos_id_color_text_field_sub_bg'))
136    .padding({ top: 36, bottom: 106 })
137  }
138}