• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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 router from '@ohos.router';
17import taskpool from '@ohos.taskpool';
18import { IconItem } from './IconView';
19import { IconItemSource } from './IconItemSource';
20import Logger from '../util/Logger';
21
22const LOAD_SUCCESS: string = getContext().resourceManager.getStringSync($r('app.string.process_success'));
23
24@Concurrent
25function loadPicture(count: number): IconItemSource[] {
26  let iconItemSourceList: IconItemSource[] = [];
27  // 遍历添加count*6个IconItem的数据
28  for (let index = 0; index < count; index++) {
29    const numStart: number = index * 6;
30    // 此处循环使用6张图片资源
31    iconItemSourceList.push(new IconItemSource($r('app.media.nearby'), `item${numStart + 1}`));
32    iconItemSourceList.push(new IconItemSource($r('app.media.scan'), `item${numStart + 2}`));
33    iconItemSourceList.push(new IconItemSource($r('app.media.shop'), `item${numStart + 3}`));
34    iconItemSourceList.push(new IconItemSource($r('app.media.cards'), `item${numStart + 4}`));
35    iconItemSourceList.push(new IconItemSource($r('app.media.album'), `item${numStart + 5}`));
36    iconItemSourceList.push(new IconItemSource($r('app.media.applet'), `item${numStart + 6}`));
37  }
38  taskpool.Task.sendData(iconItemSourceList.length);
39  return iconItemSourceList;
40}
41
42function notice(data: number): void {
43  Logger.info(LOAD_SUCCESS + data);
44}
45
46@Component
47export struct TaskSendDataUsage {
48  @State iconItemSourceList: IconItemSource[] = [];
49
50  build() {
51    Column() {
52      // 顶部导航栏
53      Row() {
54        Image($r("app.media.back"))
55          .height(24)
56          .width(24)
57          .onClick(() => {
58            router.back();
59          })
60
61        Text($r('app.string.scenario_3'))
62          .fontSize(24)
63          .lineHeight(30)
64          .fontColor(Color.Black)
65          .fontWeight(FontWeight.Bold)
66          .textAlign(TextAlign.Start)
67          .margin({
68            left: 16
69          })
70      }
71      .width($r('app.string.percent_100'))
72      .height(50)
73      .justifyContent(FlexAlign.Start)
74      .padding({
75        left: 24
76      })
77
78      Button($r('app.string.load_image'), { type: ButtonType.Normal, stateEffect: true })
79        .fontSize(14)
80        .borderRadius(8)
81        .backgroundColor(Color.Blue)
82        .width(250)
83        .height(60)
84        .margin({
85          top: 30
86        })
87        .onClick(() => {
88          let lodePictureTask: taskpool.Task = new taskpool.Task(loadPicture, 30);
89          lodePictureTask.onReceiveData(notice);
90          taskpool.execute(lodePictureTask).then((res: Object) => {
91            this.iconItemSourceList = res as IconItemSource[];
92          })
93        })
94      if (this.iconItemSourceList.length > 0) {
95        List({ space: 20 }) {
96          ForEach(this.iconItemSourceList, (item: IconItemSource) => {
97            ListItem() {
98              IconItem({ image: item.image, text: item.text });
99            }
100          }, (item: IconItemSource, index) => index.toString())
101        }
102        .divider({ strokeWidth: 2, startMargin: 20, endMargin: 20 }) // 每行之间的分界线
103        .width($r('app.string.percent_100'))
104        .height($r('app.string.percent_100'))
105        .layoutWeight(1)
106      }
107    }
108    .width($r('app.string.percent_100'))
109    .height($r('app.string.percent_100'))
110    .alignItems(HorizontalAlign.Center)
111  }
112}