@@ -23,6 +23,7 @@ public class AndroidTest : MonoBehaviour
23
23
private Button ButtonModifyExplicitID ;
24
24
private Button ButtonCancelExplicitID ;
25
25
private Button ButtonCheckStatusExplicitID ;
26
+ private AndroidNotificationTemplate [ ] AndroidNotificationsTemplates ;
26
27
27
28
public int notificationExplicitID
28
29
{
@@ -106,6 +107,32 @@ private void HandleLastNotificationIntent()
106
107
m_LOGGER . Red ( "Notification not found!" , 1 ) ;
107
108
}
108
109
}
110
+
111
+ private AndroidNotification parseNotificationTemplate ( AndroidNotificationTemplate template )
112
+ {
113
+ AndroidNotification newNotification = new AndroidNotification ( )
114
+ {
115
+ Title = template . Title ,
116
+ Text = template . Text ,
117
+
118
+ SmallIcon = template . SmallIcon ,
119
+ LargeIcon = template . LargeIcon ,
120
+ Style = template . NotificationStyle ,
121
+ FireTime = System . DateTime . Now . AddSeconds ( template . FireInSeconds ) ,
122
+ Color = template . Color ,
123
+ Number = template . Number ,
124
+ ShouldAutoCancel = template . ShouldAutoCancel ,
125
+ UsesStopwatch = template . UsesStopWatch ,
126
+ Group = template . Group ,
127
+ GroupSummary = template . GroupSummary ,
128
+ SortKey = template . SortKey ,
129
+ IntentData = template . IntentData ,
130
+ ShowTimestamp = template . ShowTimestamp ,
131
+ RepeatInterval = TimeSpan . FromSeconds ( template . RepeatInterval ) ,
132
+ //ShowInForeground = template.ShowInForeground
133
+ } ;
134
+ return newNotification ;
135
+ }
109
136
110
137
private void InstantiateAllTestButtons ( )
111
138
{
@@ -123,40 +150,16 @@ private void InstantiateAllTestButtons()
123
150
m_groups [ "Modify" ] [ "Modify pending Explicit notification" ] = new Action ( ( ) => { ModifyExplicitNotification ( ) ; } ) ;
124
151
m_groups [ "Modify" ] [ "Cancel pending Explicit notification" ] = new Action ( ( ) => { CancelExplicitNotification ( ) ; } ) ;
125
152
m_groups [ "Modify" ] [ "Check status of Explicit notification" ] = new Action ( ( ) => { CheckStatusOfExplicitNotification ( ) ; } ) ;
126
-
127
-
153
+ AndroidNotificationsTemplates = Resources . LoadAll < AndroidNotificationTemplate > ( "AndroidNotifications" ) ;
128
154
m_groups [ "Send" ] = new OrderedDictionary ( ) ;
129
- foreach ( AndroidNotificationTemplate template in Resources . LoadAll ( "AndroidNotifications" , typeof ( AndroidNotificationTemplate ) ) )
155
+ foreach ( AndroidNotificationTemplate template in AndroidNotificationsTemplates )
130
156
{
131
157
if ( template == null ) continue ;
132
- m_groups [ "Send" ] [ $ "[{ template . FireInSeconds } s] { template . ButtonName } "] = new Action ( ( ) => {
133
- SendNotification (
134
- new AndroidNotification ( )
135
- {
136
- Title = template . Title ,
137
- Text = template . Text ,
138
-
139
- SmallIcon = template . SmallIcon ,
140
- LargeIcon = template . LargeIcon ,
141
- Style = template . NotificationStyle ,
142
- FireTime = System . DateTime . Now . AddSeconds ( template . FireInSeconds ) ,
143
- Color = template . Color ,
144
- Number = template . Number ,
145
- ShouldAutoCancel = template . ShouldAutoCancel ,
146
- UsesStopwatch = template . UsesStopWatch ,
147
- Group = template . Group ,
148
- GroupSummary = template . GroupSummary ,
149
- SortKey = template . SortKey ,
150
- IntentData = template . IntentData ,
151
- ShowTimestamp = template . ShowTimestamp ,
152
- RepeatInterval = TimeSpan . FromSeconds ( template . RepeatInterval ) ,
153
- ShowInForeground = template . ShowInForeground ,
154
- } ,
155
- template . Channel , template . NotificationID
156
- ) ;
158
+ m_groups [ "Send" ] [ $ "[{ template . FireInSeconds } s] { template . ButtonName } "] = new Action ( ( ) =>
159
+ {
160
+ SendNotification ( parseNotificationTemplate ( template ) , template . Channel , template . NotificationID ) ;
157
161
} ) ;
158
162
}
159
-
160
163
m_groups [ "Cancellation" ] = new OrderedDictionary ( ) ;
161
164
m_groups [ "Cancellation" ] [ "Cancel all notifications" ] = new Action ( ( ) => { CancelAllNotifications ( ) ; } ) ;
162
165
m_groups [ "Cancellation" ] [ "Cancel pending notifications" ] = new Action ( ( ) => { CancelPendingNotifications ( ) ; } ) ;
@@ -209,7 +212,8 @@ private void InstantiateAllTestButtons()
209
212
AndroidNotificationCenter . OpenNotificationSettings ( "secondary_channel" ) ;
210
213
} ) ;
211
214
m_groups [ "Channels" ] [ "Delete All Channels" ] = new Action ( ( ) => { DeleteAllChannels ( ) ; } ) ;
212
-
215
+ m_groups [ "Custom sequences" ] = new OrderedDictionary ( ) ;
216
+ m_groups [ "Custom sequences" ] [ "Run custom sequence" ] = new Action ( ( ) => { StartCoroutine ( RunCustomSequence ( ) ) ; } ) ;
213
217
foreach ( KeyValuePair < string , OrderedDictionary > group in m_groups )
214
218
{
215
219
// Instantiate group
@@ -288,6 +292,7 @@ public void SendNotification(AndroidNotification notification, string channel =
288
292
}
289
293
if ( notificationID != 0 )
290
294
{
295
+ notification . Text = "ID: " + notificationID + " " + notification . Text ;
291
296
AndroidNotificationCenter . SendNotificationWithExplicitID ( notification , channel , notificationID ) ;
292
297
notificationExplicitID = notificationID ;
293
298
}
@@ -353,6 +358,25 @@ public void ScrollLogsToBottom()
353
358
Canvas . ForceUpdateCanvases ( ) ;
354
359
m_gameObjectReferences . LogsScrollRect . verticalNormalizedPosition = 0f ;
355
360
}
361
+
362
+ IEnumerator RunCustomSequence ( )
363
+ {
364
+ AndroidNotificationTemplate ant = AndroidNotificationsTemplates [ 4 ] ;
365
+ SendNotification ( parseNotificationTemplate ( ant ) , ant . Channel , 15 ) ;
366
+ SendNotification ( parseNotificationTemplate ( ant ) , ant . Channel , 20 ) ;
367
+ SendNotification ( parseNotificationTemplate ( ant ) , ant . Channel , 28 ) ;
368
+ SendNotification ( parseNotificationTemplate ( ant ) , ant . Channel , 14 ) ;
369
+ yield return new WaitForSeconds ( ant . FireInSeconds + 5 ) ;
370
+ AndroidNotificationCenter . CancelNotification ( 15 ) ;
371
+ yield return new WaitForSeconds ( 5 ) ;
372
+ AndroidNotificationCenter . CancelDisplayedNotification ( 20 ) ;
373
+ yield return new WaitForSeconds ( 5 ) ;
374
+ SendNotification ( parseNotificationTemplate ( ant ) , ant . Channel , 99 ) ;
375
+ SendNotification ( parseNotificationTemplate ( ant ) , ant . Channel , 99 ) ;
376
+ yield return new WaitForSeconds ( ant . FireInSeconds - 1 ) ;
377
+ SendNotification ( parseNotificationTemplate ( ant ) , ant . Channel , 99 ) ;
378
+ SendNotification ( parseNotificationTemplate ( ant ) , ant . Channel , 99 ) ;
379
+ }
356
380
357
381
#endif
358
382
}
0 commit comments