• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-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
16/**
17 * @file Some notification types and content
18 * @kit NotificationKit
19 */
20
21import notification from '../@ohos.notification';
22import image from '../@ohos.multimedia.image';
23import { Resource } from '../global/resource';
24import type notificationManager from '../@ohos.notificationManager';
25
26/**
27 * Describes icon type.
28 *
29 * @typedef { Resource | image.PixelMap } IconType
30 * @syscap SystemCapability.Notification.Notification
31 * @systemapi
32 * @since 18
33 */
34type IconType = Resource | image.PixelMap;
35
36/**
37 * Describes a normal text notification.
38 *
39 * @typedef NotificationBasicContent
40 * @syscap SystemCapability.Notification.Notification
41 * @since 7
42 */
43/**
44 * Describes a normal text notification.
45 *
46 * @typedef NotificationBasicContent
47 * @syscap SystemCapability.Notification.Notification
48 * @crossplatform
49 * @since 12
50 */
51export interface NotificationBasicContent {
52  /**
53   * Title of the normal text notification.
54   *
55   * @type { string }
56   * @syscap SystemCapability.Notification.Notification
57   * @since 7
58   */
59  /**
60   * Title of the normal text notification.
61   *
62   * @type { string }
63   * @syscap SystemCapability.Notification.Notification
64   * @crossplatform
65   * @since 12
66   */
67  title: string;
68
69  /**
70   * Content of the normal text notification.
71   *
72   * @type { string }
73   * @syscap SystemCapability.Notification.Notification
74   * @since 7
75   */
76  /**
77   * Content of the normal text notification.
78   *
79   * @type { string }
80   * @syscap SystemCapability.Notification.Notification
81   * @crossplatform
82   * @since 12
83   */
84  text: string;
85
86  /**
87   * Additional information of the normal text notification.
88   *
89   * @type { ?string }
90   * @syscap SystemCapability.Notification.Notification
91   * @since 7
92   */
93  additionalText?: string;
94
95  /**
96   * Data image of the lock screen.
97   *
98   * @type { ?image.PixelMap }
99   * @syscap SystemCapability.Notification.Notification
100   * @since 12
101   */
102  lockscreenPicture?: image.PixelMap;
103}
104
105/**
106 * Describes a long text notification.
107 *
108 * @typedef NotificationLongTextContent
109 * @syscap SystemCapability.Notification.Notification
110 * @since 7
111 */
112/**
113 * Describes a long text notification.
114 *
115 * @extends NotificationBasicContent
116 * @typedef NotificationLongTextContent
117 * @syscap SystemCapability.Notification.Notification
118 * @crossplatform
119 * @since 12
120 */
121export interface NotificationLongTextContent extends NotificationBasicContent {
122  /**
123   * Long text content of the notification.
124   *
125   * @type { string }
126   * @syscap SystemCapability.Notification.Notification
127   * @since 7
128   */
129  /**
130   * Long text content of the notification.
131   *
132   * @type { string }
133   * @syscap SystemCapability.Notification.Notification
134   * @crossplatform
135   * @since 12
136   */
137  longText: string;
138
139  /**
140   * Brief text of the long text notification.
141   *
142   * @type { string }
143   * @syscap SystemCapability.Notification.Notification
144   * @since 7
145   */
146  /**
147   * Brief text of the long text notification.
148   *
149   * @type { string }
150   * @syscap SystemCapability.Notification.Notification
151   * @crossplatform
152   * @since 12
153   */
154  briefText: string;
155
156  /**
157   * Title that will be displayed for the long text notification when it is expanded.
158   *
159   * @type { string }
160   * @syscap SystemCapability.Notification.Notification
161   * @since 7
162   */
163  /**
164   * Title that will be displayed for the long text notification when it is expanded.
165   *
166   * @type { string }
167   * @syscap SystemCapability.Notification.Notification
168   * @crossplatform
169   * @since 12
170   */
171  expandedTitle: string;
172}
173
174/**
175   * Enum for live view notification option type.
176   *
177   * @enum { number }
178   * @syscap SystemCapability.Security.AccessToken
179   * @systemapi
180   * @since 11
181   */
182export enum LiveViewStatus {
183  /**
184   * Create the live view notification.
185   *
186   * @syscap SystemCapability.Security.AccessToken
187   * @systemapi
188   * @since 11
189   */
190  LIVE_VIEW_CREATE = 0,
191  /**
192   * Batch update the live view notification.
193   *
194   * @syscap SystemCapability.Security.AccessToken
195   * @systemapi
196   * @since 11
197   */
198  LIVE_VIEW_INCREMENTAL_UPDATE = 1,
199  /**
200   * Complete the live view notification.
201   *
202   * @syscap SystemCapability.Security.AccessToken
203   * @systemapi
204   * @since 11
205   */
206  LIVE_VIEW_END = 2,
207  /**
208   * Full update the live view notification.
209   *
210   * @syscap SystemCapability.Security.AccessToken
211   * @systemapi
212   * @since 11
213   */
214  LIVE_VIEW_FULL_UPDATE = 3
215}
216
217/**
218 * Enum for live view notification task type.
219 *
220 * @enum { number }
221 * @syscap SystemCapability.Notification.Notification
222 * @systemapi
223 * @since 18
224 */
225export enum LiveViewTypes {
226  /**
227   * Real-time activity live view Notification.
228   *
229   * @syscap SystemCapability.Notification.Notification
230   * @systemapi
231   * @since 18
232   */
233  LIVE_VIEW_ACTIVITY = 0,
234  /**
235   * Instant Task live view Notification.
236   *
237   * @syscap SystemCapability.Notification.Notification
238   * @systemapi
239   * @since 18
240   */
241  LIVE_VIEW_INSTANT = 1,
242  /**
243   * Long-term status task live view Notification.
244   *
245   * @syscap SystemCapability.Notification.Notification
246   * @systemapi
247   * @since 18
248   */
249  LIVE_VIEW_LONG_TERM = 2
250}
251
252/**
253 * Describes a live view notification.
254 *
255 * @extends NotificationBasicContent
256 * @typedef NotificationLiveViewContent
257 * @syscap SystemCapability.Notification.Notification
258 * @systemapi
259 * @since 11
260 */
261export interface NotificationLiveViewContent extends NotificationBasicContent {
262  /**
263   * Status of the live view (0: create, 1: batch update, 2: end, 3: full update).
264   *
265   * @type { LiveViewStatus }
266   * @syscap SystemCapability.Notification.Notification
267   * @systemapi
268   * @since 11
269   */
270  status: LiveViewStatus;
271
272  /**
273   * Version of the live view with the same id. (If the version number stored in the database is 0xffffffff,
274   * the version number is not verified at the current operation of update or end. Otherwise, the
275   * version number must be greater than the version number stored in the database.)
276   *
277   * @type { ?number }
278   * @syscap SystemCapability.Notification.Notification
279   * @systemapi
280   * @since 11
281   */
282  version?: number;
283
284  /**
285   * Additional information of the live view notification.
286   *
287   * @type { ?Record<string, Object>}
288   * @syscap SystemCapability.Notification.Notification
289   * @systemapi
290   * @since 11
291   */
292  extraInfo?: Record<string, Object>;
293
294  /**
295   * The picture information list of the live view notification.
296   *
297   * @type { ?Record<string, Array<image.PixelMap>> }
298   * @syscap SystemCapability.Notification.Notification
299   * @systemapi
300   * @since 11
301   */
302  pictureInfo?: Record<string, Array<image.PixelMap>>;
303
304  /**
305   * Whether to update locally.
306   *
307   * @type { ?boolean }
308   * @syscap SystemCapability.Notification.Notification
309   * @systemapi
310   * @since 12
311   */
312  isLocalUpdateOnly?: boolean;
313}
314
315/**
316 * Describes a multi-line text notification.
317 *
318 * @typedef NotificationMultiLineContent
319 * @syscap SystemCapability.Notification.Notification
320 * @since 7
321 */
322/**
323 * Describes a multi-line text notification.
324 *
325 * @extends NotificationBasicContent
326 * @typedef NotificationMultiLineContent
327 * @syscap SystemCapability.Notification.Notification
328 * @crossplatform
329 * @since 12
330 */
331export interface NotificationMultiLineContent extends NotificationBasicContent {
332  /**
333   * Brief text of the multi-line text notification.
334   *
335   * @type { string }
336   * @syscap SystemCapability.Notification.Notification
337   * @since 7
338   */
339  /**
340   * Brief text of the multi-line text notification.
341   *
342   * @type { string }
343   * @syscap SystemCapability.Notification.Notification
344   * @crossplatform
345   * @since 12
346   */
347  briefText: string;
348
349  /**
350   * Long title of the multi-line text notification.
351   *
352   * @type { string }
353   * @syscap SystemCapability.Notification.Notification
354   * @since 7
355   */
356  /**
357   * Long title of the multi-line text notification.
358   *
359   * @type { string }
360   * @syscap SystemCapability.Notification.Notification
361   * @crossplatform
362   * @since 12
363   */
364  longTitle: string;
365
366  /**
367   * Multi-line content of the multi-line text notification.
368   *
369   * @type { Array<string> }
370   * @syscap SystemCapability.Notification.Notification
371   * @since 7
372   */
373  /**
374   * Multi-line content of the multi-line text notification.
375   *
376   * @type { Array<string> }
377   * @syscap SystemCapability.Notification.Notification
378   * @crossplatform
379   * @since 12
380   */
381  lines: Array<string>;
382}
383
384/**
385 * Describes a picture-attached notification.
386 *
387 * @extends NotificationBasicContent
388 * @typedef NotificationPictureContent
389 * @syscap SystemCapability.Notification.Notification
390 * @since 7
391 */
392export interface NotificationPictureContent extends NotificationBasicContent {
393  /**
394   * Brief text of the multi-line text notification.
395   *
396   * @type { string }
397   * @syscap SystemCapability.Notification.Notification
398   * @since 7
399   */
400  briefText: string;
401
402  /**
403   * Title that will be displayed for the picture-attached notification when it is expanded.
404   *
405   * @type { string }
406   * @syscap SystemCapability.Notification.Notification
407   * @since 7
408   */
409  expandedTitle: string;
410
411  /**
412   * Picture to be included in a notification.
413   *
414   * @type { image.PixelMap }
415   * @syscap SystemCapability.Notification.Notification
416   * @since 7
417   */
418  picture: image.PixelMap;
419}
420
421/**
422 * Describes a system live view notification.
423 *
424 * @extends NotificationBasicContent
425 * @typedef NotificationSystemLiveViewContent
426 * @syscap SystemCapability.Notification.Notification
427 * @since 11
428 */
429export interface NotificationSystemLiveViewContent extends NotificationBasicContent {
430  /**
431   * type code of a system live view notification.
432   *
433   * @type { number }
434   * @syscap SystemCapability.Notification.Notification
435   * @since 11
436   */
437  typeCode: number;
438
439  /**
440   * capsule of a system live view notification.
441   *
442   * @type { ?NotificationCapsule }
443   * @syscap SystemCapability.Notification.Notification
444   * @since 11
445   */
446  capsule?: NotificationCapsule;
447
448  /**
449   * button of a system live view notification.
450   *
451   * @type { ?NotificationButton }
452   * @syscap SystemCapability.Notification.Notification
453   * @since 11
454   */
455  button?: NotificationButton;
456
457  /**
458   * card button of a system live view notification.
459   *
460   * @type { ?Array<NotificationIconButton> }
461   * @syscap SystemCapability.Notification.Notification
462   * @systemapi
463   * @since 18
464   */
465  cardButtons?: Array<NotificationIconButton>;
466
467  /**
468   * type of a system live view notification.
469   *
470   * @type { ?NotificationTime }
471   * @syscap SystemCapability.Notification.Notification
472   * @since 11
473   */
474  time?: NotificationTime;
475
476  /**
477   * progress of a system live view notification.
478   *
479   * @type { ?NotificationProgress }
480   * @syscap SystemCapability.Notification.Notification
481   * @since 11
482   */
483  progress?: NotificationProgress;
484
485  /**
486   * task type of a system live view notification.
487   *
488   * @type { number }
489   * @syscap SystemCapability.Notification.Notification
490   * @systemapi
491   * @since 18
492   */
493  liveViewType?: LiveViewTypes;
494}
495
496/**
497 * Describes a system live view capsule type.
498 *
499 * @typedef NotificationCapsule
500 * @syscap SystemCapability.Notification.Notification
501 * @since 11
502 */
503export interface NotificationCapsule {
504  /**
505   * Title displayed in this capsule.
506   *
507   * @type { ?string }
508   * @syscap SystemCapability.Notification.Notification
509   * @since 11
510   */
511  title?: string;
512
513  /**
514   * Icon displayed in this capsule.
515   *
516   * @type { ?image.PixelMap }
517   * @syscap SystemCapability.Notification.Notification
518   * @since 11
519   */
520  icon?: image.PixelMap;
521
522  /**
523   * Background color of this capsule.
524   *
525   * @type { ?string }
526   * @syscap SystemCapability.Notification.Notification
527   * @since 11
528   */
529  backgroundColor?: string;
530
531  /**
532   * Extended text of this capsule.
533   *
534   * @type { ?string }
535   * @syscap SystemCapability.Notification.Notification
536   * @systemapi
537   * @since 12
538   */
539  content?: string;
540
541  /**
542   * Display time of this capsule.
543   *
544   * @type { ?number }
545   * @syscap SystemCapability.Notification.Notification
546   * @systemapi
547   * @since 18
548   */
549  time?: number;
550
551  /**
552   * Extended button of this capsule.
553   *
554   * @type { ?Array<NotificationIconButton> }
555   * @syscap SystemCapability.Notification.Notification
556   * @systemapi
557   * @since 18
558   */
559  capsuleButtons?: Array<NotificationIconButton>;
560}
561
562/**
563 * Describes a system live view button with icon.
564 *
565 * @typedef NotificationIconButton
566 * @syscap SystemCapability.Notification.Notification
567 * @since 18
568 */
569export interface NotificationIconButton {
570
571  /**
572   * button unique name.
573   *
574   * @type { string }
575   * @syscap SystemCapability.Notification.Notification
576   * @systemapi
577   * @since 18
578   */
579  name: string;
580
581  /**
582   * button icon resource.
583   *
584   * @type { IconType }
585   * @syscap SystemCapability.Notification.Notification
586   * @systemapi
587   * @since 18
588   */
589  iconResource: IconType;
590
591  /**
592   * addition text of the icon buttion
593   *
594   * @type { ?string }
595   * @syscap SystemCapability.Notification.Notification
596   * @systemapi
597   * @since 18
598   */
599  text?: string;
600
601  /**
602   * hide the panel when click the icon button.
603   *
604   * @type { ?boolean }
605   * @syscap SystemCapability.Notification.Notification
606   * @systemapi
607   * @since 18
608   */
609  hidePanel?: boolean;
610}
611
612/**
613 * Describes a system live view button type.
614 *
615 * @typedef NotificationButton
616 * @syscap SystemCapability.Notification.Notification
617 * @since 11
618 */
619export interface NotificationButton {
620  /**
621   * array of button names.
622   *
623   * @type { ?Array<string> }
624   * @syscap SystemCapability.Notification.Notification
625   * @since 11
626   */
627  names?: Array<string>;
628
629  /**
630   * array of button icons.
631   *
632   * @type { ?Array<image.PixelMap> }
633   * @syscap SystemCapability.Notification.Notification
634   * @since 11
635   */
636  icons?: Array<image.PixelMap>;
637
638  /**
639   * array of button icons resource.
640   *
641   * @type { ?Array<Resource> }
642   * @syscap SystemCapability.Notification.Notification
643   * @since 12
644   */
645  iconsResource?: Array<Resource>;
646}
647
648/**
649 * Describes a system live view time type.
650 *
651 * @typedef NotificationTime
652 * @syscap SystemCapability.Notification.Notification
653 * @since 11
654 */
655export interface NotificationTime {
656  /**
657   * The initial time of this notification.
658   *
659   * @type { ?number }
660   * @syscap SystemCapability.Notification.Notification
661   * @since 11
662   */
663  initialTime?: number;
664
665  /**
666   *
667   * Count down the time.
668   *
669   * @type { ?boolean }
670   * @syscap SystemCapability.Notification.Notification
671   * @since 11
672   */
673  isCountDown?: boolean;
674
675  /**
676   * The time is paused.
677   *
678   * @type { ?boolean }
679   * @syscap SystemCapability.Notification.Notification
680   * @since 11
681   */
682  isPaused?: boolean;
683
684  /**
685   * The time should be displayed in title.
686   *
687   * @type { ?boolean }
688   * @syscap SystemCapability.Notification.Notification
689   * @since 11
690   */
691  isInTitle?: boolean;
692}
693
694/**
695 * Describes a system live view progress type.
696 *
697 * @typedef NotificationProgress
698 * @syscap SystemCapability.Notification.Notification
699 * @since 11
700 */
701export interface NotificationProgress {
702  /**
703   * Max value of this progress.
704   *
705   * @type { ?number }
706   * @syscap SystemCapability.Notification.Notification
707   * @since 11
708   */
709  maxValue?: number;
710
711  /**
712   * Current value of this progress.
713   *
714   * @type { ?number }
715   * @syscap SystemCapability.Notification.Notification
716   * @since 11
717   */
718  currentValue?: number;
719
720  /**
721   * Use percentage mode in this progress.
722   *
723   * @type { ?boolean }
724   * @syscap SystemCapability.Notification.Notification
725   * @since 11
726   */
727  isPercentage?: boolean;
728}
729
730/**
731 * Describes notification types.
732 *
733 * @typedef NotificationContent
734 * @syscap SystemCapability.Notification.Notification
735 * @since 7
736 */
737/**
738 * Describes notification types.
739 *
740 * @typedef NotificationContent
741 * @syscap SystemCapability.Notification.Notification
742 * @crossplatform
743 * @since 12
744 */
745export interface NotificationContent {
746  /**
747   * Notification content type.
748   *
749   * @type { ?notification.ContentType }
750   * @syscap SystemCapability.Notification.Notification
751   * @since 7
752   * @deprecated since 11
753   * @useinstead NotificationContent#notificationContentType
754   */
755  contentType?: notification.ContentType;
756
757  /**
758   * Notification content type.
759   *
760   * @type { ?notificationManager.ContentType }
761   * @syscap SystemCapability.Notification.Notification
762   * @since 11
763   */
764  /**
765   * Notification content type.
766   *
767   * @type { ?notificationManager.ContentType }
768   * @syscap SystemCapability.Notification.Notification
769   * @crossplatform
770   * @since 12
771   */
772  notificationContentType?: notificationManager.ContentType;
773
774  /**
775   * Normal text notification.
776   *
777   * @type { ?NotificationBasicContent }
778   * @syscap SystemCapability.Notification.Notification
779   * @since 7
780   */
781  /**
782   * Normal text notification.
783   *
784   * @type { ?NotificationBasicContent }
785   * @syscap SystemCapability.Notification.Notification
786   * @crossplatform
787   * @since 12
788   */
789  normal?: NotificationBasicContent;
790
791  /**
792   * Long text notification.
793   *
794   * @type { ?NotificationLongTextContent }
795   * @syscap SystemCapability.Notification.Notification
796   * @since 7
797   */
798  /**
799   * Long text notification.
800   *
801   * @type { ?NotificationLongTextContent }
802   * @syscap SystemCapability.Notification.Notification
803   * @crossplatform
804   * @since 12
805   */
806  longText?: NotificationLongTextContent;
807
808  /**
809   * Multi-line text notification.
810   *
811   * @type { ?NotificationMultiLineContent }
812   * @syscap SystemCapability.Notification.Notification
813   * @since 7
814   */
815  /**
816   * Multi-line text notification.
817   *
818   * @type { ?NotificationMultiLineContent }
819   * @syscap SystemCapability.Notification.Notification
820   * @crossplatform
821   * @since 12
822   */
823  multiLine?: NotificationMultiLineContent;
824
825  /**
826   * Picture-attached notification.
827   *
828   * @type { ?NotificationPictureContent }
829   * @syscap SystemCapability.Notification.Notification
830   * @since 7
831   */
832  picture?: NotificationPictureContent;
833
834  /**
835   * System-live-view notification.
836   *
837   * @type { ?NotificationSystemLiveViewContent }
838   * @syscap SystemCapability.Notification.Notification
839   * @since 11
840   */
841  systemLiveView?: NotificationSystemLiveViewContent;
842
843  /**
844   * live-view notification.
845   *
846   * @type { ?NotificationLiveViewContent }
847   * @syscap SystemCapability.Notification.Notification
848   * @systemapi
849   * @since 11
850   */
851  liveView?: NotificationLiveViewContent;
852}
853