• 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 { dataUriUtils } from '@kit.AbilityKit';
17import { hilog } from '@kit.PerformanceAnalysisKit';
18import { promptAction } from '@kit.ArkUI';
19
20const TAG: string = 'DataUriUtils';
21const DOMAIN: number = 0xFF00;
22const ID = 1122;
23
24@Entry
25@Component
26struct DataUriUtils {
27  private promptDuration: number = 2000;
28  @State loopObserverRegistered: boolean = false;
29  @State unhandledRejectionRegistered: boolean = false;
30
31  build() {
32    Column() {
33      Row() {
34        Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) {
35          Text($r('app.string.DataUriUtils'))
36            .fontSize(30)
37            .fontWeight(700)
38            .textAlign(TextAlign.Start)
39            .margin({
40              top: 8,
41              bottom: 8,
42              left: 12
43            })
44        }
45      }
46      .width('100%')
47      .height('14.36%')
48      .justifyContent(FlexAlign.Start)
49      .backgroundColor($r('app.color.backGrounding'))
50
51      List({ initialIndex: 0 }) {
52        ListItem() {
53          Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
54            Text($r('app.string.getId'))
55              .textAlign(TextAlign.Start)
56              .fontWeight(500)
57              .margin({
58                top: 17,
59                bottom: 17,
60                left: 12
61              })
62              .fontSize(16)
63              .width('77.87%')
64              .height('39.29%')
65              .fontColor($r('app.color.text_color'))
66          }
67          .id('getId')
68          .onClick(() => {
69            ((): void => {
70              try {
71                let id = dataUriUtils.getId('com.example.dataUriUtils/1221');
72                hilog.info(DOMAIN, TAG, `dataUriUtils.getId() called. id: ${id}`);
73                promptAction.showToast({
74                  message: `dataUriUtils.getId() called. id: ${id}`,
75                  duration: this.promptDuration
76                });
77              } catch (err) {
78                hilog.info(DOMAIN, TAG, `dataUriUtils.getId() error: ${err}`);
79                promptAction.showToast({
80                  message: `dataUriUtils.getId() error: ${err}`,
81                  duration: this.promptDuration
82                });
83              }
84            })()
85          })
86        }
87        .height('8.45%')
88        .backgroundColor($r('app.color.start_window_background'))
89        .borderRadius(24)
90        .margin({ top: 12, right: 12, left: 12 })
91
92        ListItem() {
93          Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
94            Text($r('app.string.attachId'))
95              .textAlign(TextAlign.Start)
96              .fontWeight(500)
97              .margin({
98                top: 17,
99                bottom: 17,
100                left: 12
101              })
102              .fontSize(16)
103              .width('77.87%')
104              .height('39.29%')
105              .fontColor($r('app.color.text_color'))
106          }
107          .id('attachId')
108          .onClick(() => {
109            ((): void => {
110              let id = 1122;
111              let uri = dataUriUtils.attachId(
112                'com.example.dataUriUtils',
113                id,
114              );
115              promptAction.showToast({
116                message: `dataUriUtils.attachId() called. uri: ${JSON.stringify(uri)}`,
117                duration: this.promptDuration
118              });
119            })()
120          })
121        }
122        .height('8.45%')
123        .backgroundColor($r('app.color.start_window_background'))
124        .borderRadius(24)
125        .margin({ top: 12, right: 12, left: 12 })
126
127        ListItem() {
128          Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
129            Text($r('app.string.deleteId'))
130              .textAlign(TextAlign.Start)
131              .fontWeight(500)
132              .margin({
133                top: 17,
134                bottom: 17,
135                left: 12
136              })
137              .fontSize(16)
138              .width('77.87%')
139              .height('39.29%')
140              .fontColor($r('app.color.text_color'))
141          }
142          .id('deleteId')
143          .onClick(() => {
144            ((): void => {
145              let uri = dataUriUtils.deleteId('com.example.dataUriUtils/1221');
146              promptAction.showToast({
147                message: `dataUriUtils.deleteId() called. uri: ${JSON.stringify(uri)}`,
148                duration: this.promptDuration
149              });
150            })()
151          })
152        }
153        .height('8.45%')
154        .backgroundColor($r('app.color.start_window_background'))
155        .borderRadius(24)
156        .margin({ top: 12, right: 12, left: 12 })
157
158        ListItem() {
159          Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
160            Text($r('app.string.updateId'))
161              .textAlign(TextAlign.Start)
162              .fontWeight(500)
163              .margin({
164                top: 17,
165                bottom: 17,
166                left: 12
167              })
168              .fontSize(16)
169              .width('77.87%')
170              .height('39.29%')
171              .fontColor($r('app.color.text_color'))
172          }
173          .id('updateId')
174          .onClick(() => {
175            ((): void => {
176              let uri = dataUriUtils.updateId(
177                'com.example.dataUriUtils/1221',
178                ID
179              );
180              promptAction.showToast({
181                message: `dataUriUtils.updateId() called. uri: ${JSON.stringify(uri)}`,
182                duration: this.promptDuration
183              });
184            })()
185          })
186        }
187        .height('8.45%')
188        .backgroundColor($r('app.color.start_window_background'))
189        .borderRadius(24)
190        .margin({ top: 12, right: 12, left: 12 })
191      }
192      .height('86%')
193      .backgroundColor($r('app.color.backGrounding'))
194    }
195    .height('100%')
196    .width('100%')
197  }
198}