|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | 3 | // found in the LICENSE file. |
4 | 4 |
|
5 | | -// ignore_for_file: public_member_api_docs |
| 5 | +import 'package:tizen_app_control/tizen_app_control.dart'; |
6 | 6 |
|
7 | | -import 'enums.dart'; |
| 7 | +export 'package:tizen_app_control/tizen_app_control.dart'; |
8 | 8 |
|
9 | | -/// Properties that configure how the system handles notification at |
10 | | -/// certain scenarios. |
11 | | -class Property { |
12 | | - /// Display only SIM card inserted. |
13 | | - static const int displayOnlySimMode = 1 << 0; |
| 9 | +/// How the system handles the notification in certain scenarios. |
| 10 | +class NotificationProperty { |
| 11 | + // The constants below are originally defined in notification_type.h as |
| 12 | + // the enum type _notification_property. |
| 13 | + NotificationProperty._(); |
14 | 14 |
|
15 | | - /// Disable application launch when notification is selected. |
16 | | - static const int disableAppLaunch = 1 << 1; |
| 15 | + /// Display only if a SIM card is inserted. |
| 16 | + static const int onlySimMode = 0x00000001; |
17 | 17 |
|
18 | | - /// Disable auto delete when notification is selected. |
19 | | - static const int disableAutoDelete = 1 << 2; |
| 18 | + /// Do not perform any operation when the notification is clicked. |
| 19 | + static const int disableAppLaunch = 0x00000002; |
20 | 20 |
|
21 | | - /// Delete notification when device is rebooted. |
22 | | - static const int volatileDisplay = 1 << 8; |
| 21 | + /// Do not dismiss the notification when clicked. |
| 22 | + static const int disableAutoDelete = 0x00000004; |
| 23 | + |
| 24 | + /// Dismiss the notification when the device is rebooted. |
| 25 | + static const int volatile = 0x00000100; |
23 | 26 | } |
24 | 27 |
|
25 | | -/// The destination app that displays notification. |
26 | | -class DisplayApplist { |
27 | | - /// Notification Tray(Quickpanel). |
28 | | - static const int tray = 1 << 0; |
| 28 | +/// Where and how the notification should be presented. |
| 29 | +class NotificationStyle { |
| 30 | + // The constants below are originally defined in notification_type.h as |
| 31 | + // the enum type _notification_display_applist. |
| 32 | + NotificationStyle._(); |
29 | 33 |
|
30 | | - /// Ticker notification. |
31 | | - static const int ticker = 1 << 1; |
| 34 | + /// Display in the notification area of the quick panel. |
| 35 | + static const int tray = 0x00000001; |
32 | 36 |
|
33 | | - /// Lock screen. |
34 | | - static const int lock = 1 << 2; |
| 37 | + /// Display in the lock screen. |
| 38 | + static const int lock = 0x00000004; |
35 | 39 |
|
36 | | - /// Indicator. |
37 | | - static const int indicator = 1 << 3; |
| 40 | + /// Display in the indicator area (the top of the screen). |
| 41 | + static const int indicator = 0x00000002 | 0x00000008; |
38 | 42 |
|
39 | | - /// All display application. |
40 | | - static const int all = (1 << 4) - 1; |
| 43 | + /// All of the above. |
| 44 | + static const int all = tray | lock | indicator; |
41 | 45 | } |
42 | 46 |
|
43 | | -class NotificationImage { |
44 | | - /// [NotificationImage] specifies image options for notifications. |
45 | | - NotificationImage({ |
46 | | - this.iconPath, |
47 | | - this.indicatorPath, |
48 | | - this.lockPath, |
| 47 | +/// A set of icons to be shown in the notification layouts. |
| 48 | +class NotificationIcons { |
| 49 | + /// Creates a [NotificationIcons] with the given icon paths. |
| 50 | + NotificationIcons({ |
| 51 | + this.icon, |
| 52 | + this.indicatorIcon, |
| 53 | + this.lockIcon, |
49 | 54 | }); |
50 | 55 |
|
51 | | - /// The path of icon. |
52 | | - final String? iconPath; |
| 56 | + /// The path to the icon file. |
| 57 | + String? icon; |
53 | 58 |
|
54 | | - /// The path of indicator icon. |
55 | | - final String? indicatorPath; |
| 59 | + /// The path to the indicator icon file. |
| 60 | + String? indicatorIcon; |
56 | 61 |
|
57 | | - /// The path of lock screen icon. |
58 | | - final String? lockPath; |
| 62 | + /// The path to the lock screen icon file. |
| 63 | + String? lockIcon; |
59 | 64 |
|
60 | | - /// Returns [NotificationImage] member fields in a map format. |
61 | | - Map<String, dynamic> toMap() => <String, dynamic>{ |
62 | | - 'icon': iconPath, |
63 | | - 'iconForIndicator': indicatorPath, |
64 | | - 'iconForLock': lockPath, |
| 65 | + /// Converts to a map. |
| 66 | + Map<String, String?> toMap() => <String, String?>{ |
| 67 | + 'icon': icon, |
| 68 | + 'iconForIndicator': indicatorIcon, |
| 69 | + 'iconForLock': lockIcon, |
65 | 70 | }; |
66 | 71 | } |
67 | 72 |
|
| 73 | +/// The type of sound. |
| 74 | +enum SoundType { |
| 75 | + /// No sound. |
| 76 | + none, |
| 77 | + |
| 78 | + /// Default sound. |
| 79 | + builtIn, |
| 80 | + |
| 81 | + /// User sound data. |
| 82 | + userData, |
| 83 | +} |
| 84 | + |
| 85 | +/// The sound to play when the notification is presented. |
68 | 86 | class NotificationSound { |
69 | | - /// [NotificationSound] specifies sound options for notifications. |
70 | | - /// |
71 | | - /// [path] refers to a file path to custom sound data played on notification, |
72 | | - /// this value is ignored When [type] is not [SoundType.userData]. |
73 | | - NotificationSound({ |
74 | | - required this.type, |
75 | | - this.path, |
76 | | - }); |
| 87 | + /// Creates a [NotificationSound] with the given [type] and [path]. |
| 88 | + NotificationSound({required this.type, this.path}); |
| 89 | + |
| 90 | + /// The type of sound. |
| 91 | + SoundType type; |
77 | 92 |
|
78 | | - final SoundType type; |
| 93 | + /// The path to the user sound data file. |
| 94 | + /// |
| 95 | + /// Only applicable if the [type] is [SoundType.userData]. |
79 | 96 | String? path; |
80 | 97 |
|
81 | | - /// Returns [NotificationSound] member fields in a map format. |
82 | | - Map<String, dynamic> toMap() => <String, dynamic>{ |
| 98 | + /// Converts to a map. |
| 99 | + Map<String, String?> toMap() => <String, String?>{ |
83 | 100 | 'type': type.name, |
84 | 101 | 'path': path, |
85 | 102 | }; |
86 | 103 | } |
87 | 104 |
|
| 105 | +/// The type of vibration. |
| 106 | +enum VibrationType { |
| 107 | + /// No vibration. |
| 108 | + none, |
| 109 | + |
| 110 | + /// Default vibration pattern. |
| 111 | + builtIn, |
| 112 | + |
| 113 | + /// User vibration data. |
| 114 | + userData, |
| 115 | +} |
| 116 | + |
| 117 | +/// The notification vibration options. |
88 | 118 | class NotificationVibration { |
89 | | - /// [NotificationVibration] specifies vibration options for notifications. |
90 | | - NotificationVibration({ |
91 | | - required this.type, |
92 | | - this.path, |
93 | | - }); |
| 119 | + /// Creates a [NotificationVibration] with the given [type] and [path]. |
| 120 | + NotificationVibration({required this.type, this.path}); |
94 | 121 |
|
95 | | - final VibrationType type; |
| 122 | + /// The type of vibration. |
| 123 | + VibrationType type; |
| 124 | + |
| 125 | + /// The path to the user vibration data file. |
| 126 | + /// |
| 127 | + /// Only applicable if the [type] is [VibrationType.userData]. |
96 | 128 | String? path; |
97 | 129 |
|
98 | | - /// Returns [NotificationVibration] member fields in a map format. |
99 | | - Map<String, dynamic> toMap() => <String, dynamic>{ |
| 130 | + /// Converts to a map. |
| 131 | + Map<String, String?> toMap() => <String, String?>{ |
100 | 132 | 'type': type.name, |
101 | 133 | 'path': path, |
102 | 134 | }; |
103 | 135 | } |
| 136 | + |
| 137 | +extension _AppControlToMap on AppControl { |
| 138 | + /// Converts to a map. |
| 139 | + Map<String, Object?> toMap() => <String, Object?>{ |
| 140 | + 'appId': appId, |
| 141 | + 'operation': operation, |
| 142 | + 'uri': uri, |
| 143 | + 'mime': mime, |
| 144 | + 'extraData': extraData, |
| 145 | + }; |
| 146 | +} |
| 147 | + |
| 148 | +/// The notification details. |
| 149 | +class TizenNotificationDetails { |
| 150 | + /// Constructs a [TizenNotificationDetails] from the given properties. |
| 151 | + TizenNotificationDetails({ |
| 152 | + this.icons, |
| 153 | + this.sound, |
| 154 | + this.vibration, |
| 155 | + this.properties = 0, |
| 156 | + this.style = NotificationStyle.all, |
| 157 | + this.ongoing = false, |
| 158 | + this.appControl, |
| 159 | + }); |
| 160 | + |
| 161 | + /// A set of icons to be shown in the notification layouts. |
| 162 | + NotificationIcons? icons; |
| 163 | + |
| 164 | + /// The sound to play when the notification is presented. |
| 165 | + NotificationSound? sound; |
| 166 | + |
| 167 | + /// The notification vibration options. |
| 168 | + NotificationVibration? vibration; |
| 169 | + |
| 170 | + /// Specifies how the system handles the notification in certain scenarios. |
| 171 | + /// |
| 172 | + /// Multiple [NotificationProperty] values can be set using the bitwise OR |
| 173 | + /// operator (|). |
| 174 | + int properties; |
| 175 | + |
| 176 | + /// Specifies where and how the notification should be presented. |
| 177 | + /// |
| 178 | + /// Multiple [NotificationStyle] values can be set using the bitwise OR |
| 179 | + /// operator (|). |
| 180 | + int style; |
| 181 | + |
| 182 | + /// Whether the notification can be dismissed by user. |
| 183 | + /// |
| 184 | + /// Only supported on Raspberry Pi (common profile) devices. |
| 185 | + bool ongoing; |
| 186 | + |
| 187 | + /// A control message to be sent when the notification is clicked. |
| 188 | + AppControl? appControl; |
| 189 | + |
| 190 | + /// Converts to a map. |
| 191 | + Map<String, Object?> toMap() => <String, Object?>{ |
| 192 | + 'image': icons?.toMap(), |
| 193 | + 'sound': sound?.toMap(), |
| 194 | + 'vibration': vibration?.toMap(), |
| 195 | + 'properties': properties, |
| 196 | + 'displayApplist': style, |
| 197 | + 'ongoing': ongoing, |
| 198 | + 'appControl': appControl?.toMap(), |
| 199 | + }; |
| 200 | +} |
0 commit comments