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