using System; using UnityEngine; namespace Unity.Notifications.Android { /// /// Allows applying a rich notification style to a notification. /// public enum NotificationStyle { /// /// Use the default style. /// None = 0, //// todo currently disabled, bigpicture style requires additional logic that will be implemented in a future release ///// ///// generate a large-format notification. ///// //bigpicture = 1, /// /// Generate a large-format notification that includes a lot of text. /// BigTextStyle = 2 } /// /// Allows applying an alert behaviour to grouped notifications. /// public enum GroupAlertBehaviours { /// /// All notifications in a group with sound or vibration will make sound or vibrate, so this notification will not be muted when it is in a group. /// GroupAlertAll = 0, /// /// The summary notification in a group will be silenced (no sound or vibration) even if they would otherwise make sound or vibrate. /// Use this to mute this notification if this notification is a group summary. /// GroupAlertSummary = 1, /// /// All children notification in a group will be silenced (no sound or vibration) even if they would otherwise make sound or vibrate. /// Use this to mute this notification if this notification is a group child. This must be set on all children notifications you want to mute. /// GroupAlertChildren = 2, } /// /// The AndroidNotification is used schedule a local notification, which includes the content of the notification. /// public struct AndroidNotification { /// /// Notification title. /// Set the first line of text in the notification. /// public string Title { get; set; } /// /// Notification body. /// Set the second line of text in the notification. /// public string Text { get; set; } /// /// Notification small icon. /// It will be used to represent the notification in the status bar and content view (unless overridden there by a large icon) /// The icon PNG file has to be placed in the `/Assets/Plugins/Android/res/drawable` folder and it's name has to be specified without the extension. /// public string SmallIcon { get; set; } /// /// The date and time when the notification should be delivered. /// public DateTime FireTime { get; set; } /// /// The notification will be be repeated on every specified time interval. /// Do not set for one time notifications. /// public TimeSpan? RepeatInterval { get { return m_RepeatInterval; } set { m_RepeatInterval = value.HasValue ? value.Value : (-1L).ToTimeSpan(); } } /// /// Notification large icon. /// Add a large icon to the notification content view. This image will be shown on the left of the notification view in place of the small icon (which will be placed in a small badge atop the large icon). /// The icon PNG file has to be placed in the `/Assets/Plugins/Android/res/drawable folder` and it's name has to be specified without the extension. /// public string LargeIcon { get; set; } /// /// Apply a custom style to the notification. /// Currently only BigPicture and BigText styles are supported. /// public NotificationStyle Style { get; set; } /// /// Accent color to be applied by the standard style templates when presenting this notification. /// The template design constructs a colorful header image by overlaying the icon image (stenciled in white) atop a field of this color. Alpha components are ignored. /// public Color? Color { get { return m_Color; } set { m_Color = value.HasValue ? value.Value : new Color(0, 0, 0, 0); } } /// /// Sets the number of items this notification represents. /// Is displayed as a badge count on the notification icon if the launcher supports this behavior. /// public int Number { get; set; } /// /// This notification will automatically be dismissed when the user touches it. /// By default this behavior is turned off. /// public bool ShouldAutoCancel { get; set; } /// /// Show the notification time field as a stopwatch instead of a timestamp. /// public bool UsesStopwatch { get; set; } /// ///Set this property for the notification to be made part of a group of notifications sharing the same key. /// Grouped notifications may display in a cluster or stack on devices which support such rendering. /// Only available on Android 7.0 (API level 24) and above. /// public string Group { get; set; } /// /// Set this notification to be the group summary for a group of notifications. Requires the 'Group' property to also be set. /// Grouped notifications may display in a cluster or stack on devices which support such rendering. /// Only available on Android 7.0 (API level 24) and above. /// public bool GroupSummary { get; set; } /// /// Sets the group alert behavior for this notification. Set this property to mute this notification if alerts for this notification's group should be handled by a different notification. /// This is only applicable for notifications that belong to a group. This must be set on all notifications you want to mute. /// Only available on Android 8.0 (API level 26) and above. /// public GroupAlertBehaviours GroupAlertBehaviour { get; set; } /// /// The sort key will be used to order this notification among other notifications from the same package. /// Notifications will be sorted lexicographically using this value. /// public string SortKey { get; set; } /// /// Use this to save arbitrary string data related to the notification. /// public string IntentData { get; set; } /// /// Enable it to show a timestamp on the notification when it's delivered, unless the "CustomTimestamp" property is set "FireTime" will be shown. /// public bool ShowTimestamp { get; set; } /// /// Set this to show custom date instead of the notification's "FireTime" as the notification's timestamp'. /// public DateTime CustomTimestamp { get { return m_CustomTimestamp; } set { ShowCustomTimestamp = true; m_CustomTimestamp = value; } } /// /// Set this notification to be shown when app is in the foreground (default: true). /// public bool ShowInForeground { get => !m_SilentInForeground; set => m_SilentInForeground = !value; } internal bool ShowCustomTimestamp { get; set; } private Color m_Color; private TimeSpan m_RepeatInterval; private DateTime m_CustomTimestamp; private bool m_SilentInForeground; /// /// Create a notification struct with all optional fields set to default values. /// /// Notification title /// Text to show on notification /// Date and time when to show, can be DateTime.Now to show right away public AndroidNotification(string title, string text, DateTime fireTime) { Title = title; Text = text; FireTime = fireTime; SmallIcon = string.Empty; ShouldAutoCancel = false; LargeIcon = string.Empty; Style = NotificationStyle.None; Number = -1; UsesStopwatch = false; IntentData = string.Empty; Group = string.Empty; GroupSummary = false; SortKey = string.Empty; GroupAlertBehaviour = GroupAlertBehaviours.GroupAlertAll; ShowTimestamp = false; ShowCustomTimestamp = false; m_RepeatInterval = (-1L).ToTimeSpan(); m_Color = new Color(0, 0, 0, 0); m_CustomTimestamp = (-1L).ToDatetime(); m_SilentInForeground = false; } /// /// Create a repeatable notification struct with all optional fields set to default values. /// /// Notification title /// Text to show on notification /// Date and time when to show, can be DateTime.Now to show right away /// Makes notification repeatable with this time interval /// /// There is a minimum period of 1 minute for repeating notifications. /// public AndroidNotification(string title, string text, DateTime fireTime, TimeSpan repeatInterval) : this(title, text, fireTime) { RepeatInterval = repeatInterval; } /// /// Create a notification struct with a custom small icon and all optional fields set to default values. /// /// Notification title /// Text to show on notification /// Date and time when to show, can be DateTime.Now to show right away /// Makes notification repeatable with this time interval /// Name of the small icon to be shown on notification public AndroidNotification(string title, string text, DateTime fireTime, TimeSpan repeatInterval, string smallIcon) : this(title, text, fireTime, repeatInterval) { SmallIcon = smallIcon; } } }