• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_MULTILINE_CONTENT_H
17 #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_MULTILINE_CONTENT_H
18 
19 #include "notification_basic_content.h"
20 #include "parcel.h"
21 
22 namespace OHOS {
23 namespace Notification {
24 class NotificationMultiLineContent : public NotificationBasicContent {
25 public:
26     /**
27      * Default constructor used to create a NotificationMultiLineContent instance.
28      */
29     NotificationMultiLineContent() = default;
30 
31     /**
32      * Default deconstructor used to deconstruct.
33      */
34     ~NotificationMultiLineContent() = default;
35 
36     /**
37      * Sets the title to be displayed when this multi-line notification is expanded.
38      * After this title is set, the title set by setTitle(string) will be displayed only
39      * when this notification is in the collapsed state.
40      * @param exTitle Indicates the title to be displayed when this notification is expanded.
41      */
42     void SetExpandedTitle(const std::string &exTitle);
43 
44     /**
45      * Obtains the title that will be displayed for this multi-line notification when it is expanded.
46      * @return the title to be displayed when this notification is expanded.
47      */
48     std::string GetExpandedTitle() const;
49 
50     /**
51      * Sets the brief text to be included in a multi-line notification.
52      * The brief text is a summary of this multi-line notification and is displayed in the first line of
53      * the notification. Similar to setAdditionalText(string), the font of the brief text is also
54      * smaller than the notification text set by calling setText(string).
55      * The positions where the brief text and additional text will display may conflict.
56      * If both texts are set, only the additional text will be displayed.
57      * @param briefText Indicates the brief text to be included.
58      */
59     void SetBriefText(const std::string &briefText);
60 
61     /**
62      * Obtains the brief text that has been set by calling setBriefText(string) for this multi-line notification.
63      * @return the brief text of this notification.
64      */
65     std::string GetBriefText() const;
66 
67     /**
68      * Adds a single line of text to this notification.
69      * You can call this method up to seven times to add seven lines to a notification.
70      * @param oneLine Indicates the single line of text to be included.
71      */
72     void AddSingleLine(const std::string &oneLine);
73 
74     /**
75      * Obtains the list of lines included in this multi-line notification.
76      * @return the list of lines included in this notification.
77      */
78     std::vector<std::string> GetAllLines() const;
79 
80     /**
81      * Returns a string representation of the object.
82      * @return a string representation of the object.
83      */
84     std::string Dump() override;
85 
86     /**
87      * Converts a NotificationMultiLineContent object into a Json.
88      * @param jsonObject Indicates the Json object.
89      */
90     virtual bool ToJson(nlohmann::json &jsonObject) const override;
91 
92     /**
93      * Creates a NotificationMultiLineContent object from a Json.
94      * @param jsonObject Indicates the Json object.
95      * @return the NotificationMultiLineContent.
96      */
97     static NotificationMultiLineContent *FromJson(const nlohmann::json &jsonObject);
98 
99     /**
100      * Marshal a object into a Parcel.
101      * @param parcel the object into the parcel
102      */
103     virtual bool Marshalling(Parcel &parcel) const override;
104 
105     /**
106      * Unmarshal object from a Parcel.
107      * @return the NotificationMultiLineContent
108      */
109     static NotificationMultiLineContent *Unmarshalling(Parcel &parcel);
110 
111 protected:
112     /**
113      * Read a NotificationMultiLineContent object from a Parcel.
114      * @param parcel the parcel
115      */
116     bool ReadFromParcel(Parcel &parcel) override;
117 
118 private:
119     /**
120      * the maximum size of vector is 7.
121      */
122     static const std::vector<std::string>::size_type MAX_LINES;
123 
124 private:
125     std::string expandedTitle_ {};
126     std::string briefText_ {};
127     std::vector<std::string> allLines_ {};
128 };
129 }  // namespace Notification
130 }  // namespace OHOS
131 
132 #endif  // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_MULTILINE_CONTENT_H