• 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 */
15
16import image from '@ohos.multimedia.image'
17import notification from '@ohos.notificationManager'
18
19class NotificationContentUtil {
20  /**
21   * init basic notification content
22   * @param basicContent
23   * @return return the created NotificationContent
24   */
25  initBasicNotificationContent(basicContent: notification.NotificationBasicContent) {
26    return {
27      contentType: notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, // 通知内容类型
28      normal: basicContent // 基本类型通知内容
29    }
30  }
31
32  /**
33   *  init longText notification content
34   *
35   * @param basicContent
36   * @param notificationLongText
37   * @param notificationBriefText
38   * @param notificationExpandedTitle
39   * @return return the created NotificationContent
40   */
41  initNotificationLongTextContent(basicContent: notification.NotificationBasicContent, notificationLongText: string, notificationBriefText: string, notificationExpandedTitle: string) {
42    return {
43      contentType: notification.ContentType.NOTIFICATION_CONTENT_LONG_TEXT, // 通知内容类型
44      longText: {
45        title: basicContent.title, // 通知标题
46        text: basicContent.text, // 通知内容
47        additionalText: basicContent.additionalText ? basicContent.additionalText : '', // 通知次要内容
48        longText: notificationLongText, // 通知的长文本
49        briefText: notificationBriefText, // 通知概要内容,是对通知内容的总结
50        expandedTitle: notificationExpandedTitle // 通知展开时的标题
51      }
52    }
53  }
54
55  /**
56   * init multiline notification content
57   * @param basicContent
58   * @param notificationBriefText
59   * @param notificationLongTitle
60   * @param notificationLines
61   * @return return the created NotificationContent
62   */
63  initNotificationMultiLineContent(basicContent: notification.NotificationBasicContent, notificationBriefText: string, notificationLongTitle: string, notificationLines: Array<string>) {
64    return {
65      contentType: notification.ContentType.NOTIFICATION_CONTENT_MULTILINE, // 通知内容类型
66      multiLine: {
67        title: basicContent.title, // 通知标题
68        text: basicContent.text, // 通知内容
69        additionalText: basicContent.additionalText ? basicContent.additionalText : '', // 通知次要内容,是对通知内容的补充
70        briefText: notificationBriefText, // 通知概要内容,是对通知内容的总结
71        longTitle: notificationLongTitle, // 通知展开时的标题
72        lines: notificationLines // 通知的多行文本
73      }
74    }
75  }
76
77  /**
78   * init picture notification content
79   * @param basicContent
80   * @param notificationBriefText
81   * @param notificationExpandedTitle
82   * @param notificationPicture
83   * @return return the created NotificationContent
84   */
85  initNotificationPictureContent(basicContent: notification.NotificationBasicContent, notificationBriefText: string, notificationExpandedTitle: string, notificationPicture: image.PixelMap) {
86    return {
87      contentType: notification.ContentType.NOTIFICATION_CONTENT_PICTURE,  // 通知内容类型
88      picture: {
89        title: basicContent.title, // 通知标题
90        text: basicContent.text, // 通知内容
91        additionalText: basicContent.additionalText ? basicContent.additionalText : '', // 通知次要内容,是对通知内容的补充
92        briefText: notificationBriefText, // 通知概要内容,是对通知内容的总结
93        expandedTitle: notificationExpandedTitle, // 通知展开时的标题
94        picture: notificationPicture // 通知的图片
95      }
96    }
97  }
98}
99
100export let notificationContentUtil = new NotificationContentUtil()