• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2022 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 */
15import DeviceUtil from "../utils/DeviceUtil";
16
17/**
18 * Type of the dialog box: No title, 1 message, and 2 buttons
19 */
20@CustomDialog
21export struct DeleteDialog {
22    controller: CustomDialogController;
23    /**
24     * Cancel Event
25     */
26    cancel: () => void;
27    /**
28     * Acknowledge Event
29     */
30    confirm: () => void;
31    /**
32     * Message content
33     */
34    msg: string | Resource;
35    /**
36     * Check whether the deleted information contains locked information.
37     */
38    hasLockMsg: boolean;
39    setSelectLock?: () => void;
40    /**
41     * Whether to delete lock information synchronously
42     */
43    isSelectLockMsg?: boolean;
44    setSelectLockChange?: (isOn: boolean) => void;
45
46    build() {
47        Column() {
48            Text(this.msg)
49                .width("100%")
50                .margin({ bottom: 8 })
51                .textAlign(TextAlign.Center)
52                .fontSize(16)
53                .fontColor($r("sys.color.ohos_id_color_text_primary"))
54                .lineHeight(22)
55                .fontWeight(FontWeight.Regular)
56                .fontFamily("HarmonyHeiTi")
57            if (this.hasLockMsg) {
58                Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
59                    Toggle({ type: ToggleType.Checkbox, isOn: this.isSelectLockMsg })
60                        .width("20vp")
61                        .height("20vp")
62                        .onChange((isOn: boolean) => {
63                            this.setSelectLockChange(isOn)
64                        })
65                    Text($r("app.string.msg_delete_dialog_cb_tip")).height("100%")
66                }
67                .width("100%")
68                .height("32vp")
69                .onClick((event?: ClickEvent) => {
70                    this.setSelectLock();
71                })
72            }
73            Flex({
74                direction: FlexDirection.Row,
75                justifyContent: FlexAlign.SpaceEvenly,
76                alignItems: ItemAlign.Center
77            }) {
78                Button() {
79                    Text($r("app.string.cancel"))
80                        .textAlign(TextAlign.Center)
81                        .fontSize(16)
82                        .fontColor($r("sys.color.ohos_id_color_floating_button_bg_normal"))
83                        .fontWeight(FontWeight.Medium)
84                        .fontFamily("HarmonyHeiTi")
85                        .lineHeight(22)
86                }
87                .backgroundColor($r("sys.color.ohos_id_color_background_transparent"))
88                .layoutWeight(1)
89                .onClick(() => {
90                    this.controller.close();
91                    this.cancel();
92                })
93
94                Divider()
95                    .vertical(true)
96                    .strokeWidth("1px")
97                    .height("20vp")
98                    .color($r("sys.color.ohos_id_color_list_separator"))
99                Button() {
100                    Text($r("app.string.delete"))
101                        .textAlign(TextAlign.Center)
102                        .fontSize(16)
103                        .fontColor($r("sys.color.ohos_id_color_warning"))
104                        .fontWeight(FontWeight.Medium)
105                        .fontFamily("HarmonyHeiTi")
106                        .lineHeight(22)
107                }
108                .backgroundColor($r("sys.color.ohos_id_color_background_transparent"))
109                .layoutWeight(1)
110                .onClick(() => {
111                    this.controller.close();
112                    this.confirm();
113                })
114            }
115            .width("100%")
116            .height(40)
117        }
118        .width("100%")
119        .padding({ left: 24, right: 24, top: 24, bottom: 16 })
120    }
121}
122
123@CustomDialog
124export struct DelConversionDialog {
125    controller: CustomDialogController;
126    /**
127     * Cancel Event
128     */
129    cancel: () => void;
130    /**
131     * Acknowledge Event
132     */
133    confirm: () => void;
134    /**
135     * Message content
136     */
137    msg: string | Resource;
138
139    build() {
140        Column() {
141            Text(this.msg)
142                .width("100%")
143                .margin({ bottom: 8 })
144                .textAlign(TextAlign.Center)
145                .fontSize(16)
146                .fontColor($r("sys.color.ohos_id_color_text_primary"))
147                .lineHeight(22)
148                .fontWeight(FontWeight.Regular)
149                .fontFamily("HarmonyHeiTi")
150            Flex({
151                direction: FlexDirection.Row,
152                justifyContent: FlexAlign.SpaceEvenly,
153                alignItems: ItemAlign.Center
154            }) {
155                Button() {
156                    Text($r("app.string.cancel"))
157                        .textAlign(TextAlign.Center)
158                        .fontSize(16)
159                        .fontColor($r("sys.color.ohos_id_color_floating_button_bg_normal"))
160                        .fontWeight(FontWeight.Medium)
161                        .fontFamily("HarmonyHeiTi")
162                        .lineHeight(22)
163                }
164                .backgroundColor($r("sys.color.ohos_id_color_background_transparent"))
165                .layoutWeight(1)
166                .onClick(() => {
167                    this.controller.close();
168                    this.cancel();
169                })
170
171                Divider()
172                    .vertical(true)
173                    .strokeWidth("1px")
174                    .height("20vp")
175                    .color($r("sys.color.ohos_id_color_list_separator"))
176                Button() {
177                    Text($r("app.string.delete"))
178                        .textAlign(TextAlign.Center)
179                        .fontSize(16)
180                        .fontColor($r("sys.color.ohos_id_color_warning"))
181                        .fontWeight(FontWeight.Medium)
182                        .fontFamily("HarmonyHeiTi")
183                        .lineHeight(22)
184                }
185                .backgroundColor($r("sys.color.ohos_id_color_background_transparent"))
186                .layoutWeight(1)
187                .onClick(() => {
188                    this.controller.close();
189                    this.confirm();
190                })
191            }
192            .width("100%")
193            .height(40)
194        }
195        .width("100%")
196        .padding({ left: 24, right: 24, top: 24, bottom: 16 })
197    }
198}
199
200export class MmsSimpleDialog {
201    value: AlertDialogParamWithMms;
202    private dialogGridCount: number = 4;
203    private dialogAlignment: DialogAlignment = DeviceUtil.isTablet() ? DialogAlignment.Center : DialogAlignment.Bottom;
204    private dialogOffset: Offset = DeviceUtil.isTablet() ? { dx: 0, dy: 0 } : { dx: 0, dy: -12 };
205    constructor(value: AlertDialogParamWithMms) {
206        this.value = value;
207    }
208
209    show() {
210        AlertDialog.show(
211            {
212                message: this.value.message,
213                autoCancel: false,
214                alignment: this.dialogAlignment,
215                offset: this.dialogOffset,
216                gridCount: this.dialogGridCount,
217                primaryButton: {
218                    value: this.value.primaryButton.value,
219                    action: this.value.primaryButton.action,
220                    fontColor: $r("sys.color.ohos_id_color_activated")
221                },
222                secondaryButton: {
223                    value: this.value.secondaryButton.value,
224                    action: this.value.secondaryButton.action,
225                    fontColor: $r("sys.color.ohos_id_color_warning")
226                }
227            }
228        )
229    }
230}
231
232
233@CustomDialog
234export struct SysSimpleExample {
235    controller: CustomDialogController
236    cancel: () => void
237    confirm: () => void
238
239    value: AlertDialogParamWithMms;
240    private dialogAlignment: DialogAlignment = DeviceUtil.isTablet() ? DialogAlignment.Center : DialogAlignment.Bottom;
241    private dialogOffset: Offset = DeviceUtil.isTablet() ? { dx: 0, dy: 0 } : { dx: 0, dy: -12 };
242
243    build() {
244        Column() {
245            Text(this.value.message)
246                .fontSize(16)
247                .fontWeight(FontWeight.Regular)
248                .margin({ top: 24, bottom: 8 })
249            Flex({ justifyContent: FlexAlign.SpaceAround ,alignItems: ItemAlign.Center}) {
250                Button($r("app.string.cancel"))
251                    .onClick(() => {
252                        this.controller.close()
253                        this.cancel()
254                    })
255                    .backgroundColor(0xffffff)
256                    .fontColor($r("sys.color.ohos_id_color_activated"))
257                    .fontWeight(FontWeight.Medium)
258                    .layoutWeight(1)
259                Text("|").fontSize(16).fontColor(Color.Gray)
260                Button($r("app.string.restore"))
261                    .onClick(() => {
262                        this.controller.close()
263                        this.confirm()
264                    })
265                    .backgroundColor(0xffffff)
266                    .fontColor($r("sys.color.ohos_id_color_warning"))
267                    .fontWeight(FontWeight.Medium)
268                    .layoutWeight(1)
269            }.margin({ bottom: 12 ,top:12})
270        }.borderRadius(24)
271    }
272}
273
274declare interface AlertDialogParamWithMms {
275    message: ResourceStr;
276    primaryButton: {
277        value: ResourceStr;
278        action: () => void;
279    };
280    secondaryButton: {
281        value: ResourceStr;
282        action: () => void;
283    };
284}
285
286export interface CheckBoxItem {
287    title: string | Resource;
288    isOn: boolean;
289    onClick: (event?: ClickEvent) => void;
290}
291
292/**
293 * Type of the dialog box: 1 title, 2 options, and 2 buttons
294 */
295@CustomDialog
296export struct CheckBoxDialog {
297    controller: CustomDialogController;
298    /**
299     * Cancel Event
300     */
301    cancel: () => void;
302    /**
303     * Acknowledge Event
304     */
305    confirm: () => void;
306    /**
307     * Title
308     */
309    title: string | Resource;
310
311    /**
312     * Option Collection
313     */
314    @State itemList: Array<CheckBoxItem> = [];
315
316    build() {
317        Column() {
318            // dialog title
319            Text(this.title)
320                .width("100%")
321                .margin({ bottom: 8 })
322                .fontSize(16)
323                .fontColor($r("sys.color.ohos_id_color_text_primary"))
324                .lineHeight(22)
325                .fontWeight(FontWeight.Regular)
326                .fontFamily("HarmonyHeiTi")
327            // item Checklist
328            ForEach(this.itemList, (item, index) => {
329                Flex({
330                    direction: FlexDirection.Row,
331                    justifyContent: FlexAlign.SpaceBetween,
332                    alignItems: ItemAlign.Center
333                }) {
334                    Text(item.title)
335                    Toggle({ type: ToggleType.Checkbox, isOn: item.isOn })
336                        .width("20vp")
337                        .height("20vp")
338                        .enabled(false)
339                }
340                .width("100%")
341                .height("32vp")
342                .onClick(item.onClick)
343            }, (item, index) => index.toString())
344            // OK and Cancel Buttons
345            Flex({
346                direction: FlexDirection.Row,
347                justifyContent: FlexAlign.SpaceEvenly,
348                alignItems: ItemAlign.Center
349            }) {
350                Button() {
351                    Text($r("app.string.cancel"))
352                        .textAlign(TextAlign.Center)
353                        .fontSize(16)
354                        .fontColor($r("sys.color.ohos_id_color_floating_button_bg_normal"))
355                        .fontWeight(FontWeight.Medium)
356                        .fontFamily("HarmonyHeiTi")
357                        .lineHeight(22)
358                        .onClick(() => {
359                            this.controller.close();
360                            this.cancel();
361                        })
362                }.backgroundColor($r("sys.color.ohos_id_color_background_transparent")).layoutWeight(1)
363
364                Divider()
365                    .vertical(true)
366                    .strokeWidth("1px")
367                    .height("20vp")
368                    .color($r("sys.color.ohos_id_color_list_separator"))
369                Button() {
370                    Text($r("app.string.ok"))
371                        .textAlign(TextAlign.Center)
372                        .fontSize(16)
373                        .fontColor($r("sys.color.ohos_id_color_floating_button_bg_normal"))
374                        .fontWeight(FontWeight.Medium)
375                        .fontFamily("HarmonyHeiTi")
376                        .lineHeight(22)
377                        .onClick(() => {
378                            this.controller.close();
379                            this.confirm();
380                        })
381                }.backgroundColor($r("sys.color.ohos_id_color_background_transparent")).layoutWeight(1)
382            }
383            .width("100%")
384            .height(40)
385        }
386        .width("100%")
387        .padding({ left: 24, right: 24, top: 24, bottom: 16 })
388    }
389}
390
391@CustomDialog
392export struct TransmitMsgDialog {
393    scroller: Scroller = new Scroller()
394    controller: CustomDialogController;
395    /**
396     * Cancel an event
397     */
398    cancel: () => void;
399    /**
400     * Acknowledgment Events
401     */
402    confirm: () => void;
403    /**
404     * Message content
405     */
406    msg: object | Resource | any;
407
408    isChecked: boolean = true;
409
410    changeValue?: () => void;
411
412    clickChecked?: () => void;
413
414    build() {
415        Column() {
416            Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) {
417                Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }){
418                    // Title
419                    Column() {
420                        if(this.msg.contactsParam.contactsNum > 1) {
421                            Text() {
422                                Span($r("app.string.contentSentTo"))
423                                    .fontSize(20)
424                                    .fontColor($r("sys.color.ohos_id_color_text_primary"))
425                                    .fontWeight(FontWeight.Bold)
426                                Span(this.msg.contactsParam.contactName == "" ?
427                                this.msg.contactsParam.telephoneFormatSplit :
428                                this.msg.contactsParam.contactNameSplit)
429                                    .fontSize(20)
430                                    .fontColor($r("sys.color.ohos_id_color_text_primary"))
431                                    .fontWeight(FontWeight.Bold)
432                                Span($r('app.string.including'))
433                                    .fontSize(20)
434                                    .fontColor($r("sys.color.ohos_id_color_text_primary"))
435                                    .fontWeight(FontWeight.Bold)
436                                Span(this.msg.contactsParam.contactsNum)
437                                    .fontSize(20)
438                                    .fontColor($r("sys.color.ohos_id_color_text_primary"))
439                                    .fontWeight(FontWeight.Bold)
440                                Span($r('app.string.people'))
441                                    .fontSize(20)
442                                    .fontColor($r("sys.color.ohos_id_color_text_primary"))
443                                    .fontWeight(FontWeight.Bold)
444                            }
445                        } else {
446                            Text() {
447                                Span($r("app.string.contentSentTo"))
448                                    .fontSize(20)
449                                    .fontColor($r("sys.color.ohos_id_color_text_primary"))
450                                    .fontWeight(FontWeight.Bold)
451                                Span(this.msg.contactsParam.contactName == '' ?
452                                this.msg.contactsParam.telephoneFormat :
453                                this.msg.contactsParam.contactName)
454                                    .fontSize(20)
455                                    .fontColor($r("sys.color.ohos_id_color_text_primary"))
456                                    .fontWeight(FontWeight.Bold)
457                            }
458                        }
459                    }
460                    .alignItems(HorizontalAlign.Start)
461                    .width("100%")
462
463                    // Forwarded content
464                    Column(){
465                        List() {
466                            ForEach(this.msg.transmitContentList, item => {
467                                ListItem() {
468                                    if( item.msgShowType == 0 || item.msgShowType == 4){
469                                        Flex() {
470                                            if( item.msgUriPath != '' && (item.msgType==1 || item.msgType == 2)) {
471                                                Image($rawfile(item.msgUriPath))
472                                                    .width('100%')
473                                                    .height(150)
474                                            } else if( item.msgUriPath != '' && item.msgType == 5) {
475                                                Image($rawfile("icon/msg_contacts.svg"))
476                                                    .height(48)
477                                                    .width(48)
478                                                    .margin({left: 10, right: 10})
479                                                Flex() {
480                                                    Text(item.msgUriPath)
481                                                        .align(Alignment.Center)
482                                                    if(item.audioTime != '') {
483                                                        Text(item.audioTime)
484                                                            .align(Alignment.Center)
485                                                    }
486                                                }
487                                                .padding(5)
488                                                .margin({right: 40})
489                                            } else if(item.content != '') {
490                                                if(this.isChecked || (!this.isChecked && item.isMsm)) {
491                                                    Column() {
492                                                        Column() {
493                                                            Text(this.msg.transmitContent)
494                                                            Text(item.contentInfo)
495                                                        }
496                                                        Column() {
497                                                            Text(item.content)
498                                                                .fontSize(16)
499                                                                .margin({ top: 5})
500                                                        }
501                                                    }
502                                                    .padding({ top: 20 })
503                                                    .width('100%')
504                                                    .alignItems(HorizontalAlign.Start)
505
506                                                } else if(!this.isChecked && !item.isMsm) {
507                                                    TextArea({
508                                                        text: item.content
509                                                    })
510                                                        .onChange((item) => {
511                                                            this.changeValue()
512                                                        })
513                                                }
514                                            }
515                                        }
516                                    } else if(item.msgShowType == 1 || item.msgShowType == 2) {
517                                        Flex() {
518                                            Image($rawfile("icon/ppt.svg"))
519                                                .width('100%')
520                                                .height(150)
521                                            if(item.content != '') {
522                                                Text(item.content)
523                                            }
524                                        }
525                                        .padding(20)
526                                        .backgroundColor('#20A9A9A9')
527                                        .borderRadius(15)
528                                    } else {
529                                        Flex() {
530                                            if(item.content != '') {
531                                                Text(item.content)
532                                                    .margin({ top: 10, left: 30, bottom: 10})
533                                            }
534                                        }
535                                    }
536
537                                }
538                            }, item => item.msgType.toString())
539                        }
540                    }
541                    .alignItems(HorizontalAlign.Start)
542                    .width("100%")
543                }
544            }
545
546            Flex({ justifyContent: FlexAlign.SpaceAround }) {
547                Button() {
548                    Text($r("app.string.cancel"))
549                        .textAlign(TextAlign.Center)
550                        .fontSize(16)
551                        .fontColor($r("sys.color.ohos_id_color_floating_button_bg_normal"))
552                        .fontWeight(FontWeight.Medium)
553                        .fontFamily("HarmonyHeiTi")
554                        .lineHeight(22)
555                }
556                .backgroundColor($r("sys.color.ohos_id_color_background_transparent"))
557                .layoutWeight(1)
558                .onClick(() => {
559                    this.controller.close();
560                    this.cancel();
561                })
562
563                Divider().vertical(true).strokeWidth("1px").height("20vp").color($r("sys.color.ohos_id_color_list_separator"))
564                Button() {
565                    Text($r("app.string.msg_transmit"))
566                        .textAlign(TextAlign.Center)
567                        .fontSize(16)
568                        .fontColor($r("sys.color.ohos_id_color_warning"))
569                        .fontWeight(FontWeight.Medium)
570                        .fontFamily("HarmonyHeiTi")
571                        .lineHeight(22)
572                }
573                .backgroundColor($r("sys.color.ohos_id_color_background_transparent"))
574                .layoutWeight(1)
575                .onClick(() => {
576                    this.controller.close();
577                    this.confirm();
578                })
579            }
580        }
581        .width("100%")
582        .height(200)
583        .padding({ left: 24, right: 24, top: 24, bottom:40 })
584    }
585}