@@ -300,17 +300,107 @@ internal long When(AndroidJavaObject notification)
300
300
}
301
301
}
302
302
303
+ struct NotificationBuilderJni
304
+ {
305
+ JniMethodID getExtras ;
306
+ JniMethodID setContentTitle ;
307
+ JniMethodID setContentText ;
308
+ JniMethodID setAutoCancel ;
309
+ JniMethodID setNumber ;
310
+ JniMethodID setStyle ;
311
+ JniMethodID setWhen ;
312
+ JniMethodID setGroup ;
313
+ JniMethodID setGroupSummary ;
314
+ JniMethodID setSortKey ;
315
+ JniMethodID setShowWhen ;
316
+
317
+ public void CollectJni ( )
318
+ {
319
+ using ( var clazz = new AndroidJavaClass ( "android.app.Notification$Builder" ) )
320
+ {
321
+ getExtras = JniApi . FindMethod ( clazz , "getExtras" , "()Landroid/os/Bundle;" , false ) ;
322
+ setContentTitle = JniApi . FindMethod ( clazz , "setContentTitle" , "(Ljava/lang/CharSequence;)Landroid/app/Notification$Builder;" , false ) ;
323
+ setContentText = JniApi . FindMethod ( clazz , "setContentText" , "(Ljava/lang/CharSequence;)Landroid/app/Notification$Builder;" , false ) ;
324
+ setAutoCancel = JniApi . FindMethod ( clazz , "setAutoCancel" , "(Z)Landroid/app/Notification$Builder;" , false ) ;
325
+ setNumber = JniApi . FindMethod ( clazz , "setNumber" , "(I)Landroid/app/Notification$Builder;" , false ) ;
326
+ setStyle = JniApi . FindMethod ( clazz , "setStyle" , "(Landroid/app/Notification$Style;)Landroid/app/Notification$Builder;" , false ) ;
327
+ setWhen = JniApi . FindMethod ( clazz , "setWhen" , "(J)Landroid/app/Notification$Builder;" , false ) ;
328
+ setGroup = JniApi . FindMethod ( clazz , "setGroup" , "(Ljava/lang/String;)Landroid/app/Notification$Builder;" , false ) ;
329
+ setGroupSummary = JniApi . FindMethod ( clazz , "setGroupSummary" , "(Z)Landroid/app/Notification$Builder;" , false ) ;
330
+ setSortKey = JniApi . FindMethod ( clazz , "setSortKey" , "(Ljava/lang/String;)Landroid/app/Notification$Builder;" , false ) ;
331
+ setShowWhen = JniApi . FindMethod ( clazz , "setShowWhen" , "(Z)Landroid/app/Notification$Builder;" , false ) ;
332
+ }
333
+ }
334
+
335
+ public AndroidJavaObject GetExtras ( AndroidJavaObject builder )
336
+ {
337
+ return builder . Call < AndroidJavaObject > ( getExtras ) ;
338
+ }
339
+
340
+ public void SetContentTitle ( AndroidJavaObject builder , string title )
341
+ {
342
+ builder . Call < AndroidJavaObject > ( setContentTitle , title ) . Dispose ( ) ;
343
+ }
344
+
345
+ public void SetContentText ( AndroidJavaObject builder , string text )
346
+ {
347
+ builder . Call < AndroidJavaObject > ( setContentText , text ) . Dispose ( ) ;
348
+ }
349
+
350
+ public void SetAutoCancel ( AndroidJavaObject builder , bool shouldAutoCancel )
351
+ {
352
+ builder . Call < AndroidJavaObject > ( setAutoCancel , shouldAutoCancel ) . Dispose ( ) ;
353
+ }
354
+
355
+ public void SetNumber ( AndroidJavaObject builder , int number )
356
+ {
357
+ builder . Call < AndroidJavaObject > ( setNumber , number ) . Dispose ( ) ;
358
+ }
359
+
360
+ public void SetStyle ( AndroidJavaObject builder , AndroidJavaObject style )
361
+ {
362
+ builder . Call < AndroidJavaObject > ( setStyle , style ) . Dispose ( ) ;
363
+ }
364
+
365
+ public void SetWhen ( AndroidJavaObject builder , long timestamp )
366
+ {
367
+ builder . Call < AndroidJavaObject > ( setWhen , timestamp ) . Dispose ( ) ;
368
+ }
369
+
370
+ public void SetGroup ( AndroidJavaObject builder , string group )
371
+ {
372
+ builder . Call < AndroidJavaObject > ( setGroup , group ) . Dispose ( ) ;
373
+ }
374
+
375
+ public void SetGroupSummary ( AndroidJavaObject builder , bool groupSummary )
376
+ {
377
+ builder . Call < AndroidJavaObject > ( setGroupSummary , groupSummary ) . Dispose ( ) ;
378
+ }
379
+
380
+ public void SetSortKey ( AndroidJavaObject builder , string sortKey )
381
+ {
382
+ builder . Call < AndroidJavaObject > ( setSortKey , sortKey ) . Dispose ( ) ;
383
+ }
384
+
385
+ public void SetShowWhen ( AndroidJavaObject builder , bool showTimestamp )
386
+ {
387
+ builder . Call < AndroidJavaObject > ( setShowWhen , showTimestamp ) . Dispose ( ) ;
388
+ }
389
+ }
390
+
303
391
struct JniApi
304
392
{
305
393
public NotificationManagerJni NotificationManager ;
306
394
public NotificationJni Notification ;
395
+ public NotificationBuilderJni NotificationBuilder ;
307
396
308
397
public JniApi ( AndroidJavaClass notificationManagerClass , AndroidJavaObject notificationManager )
309
398
{
310
399
NotificationManager = new NotificationManagerJni ( notificationManagerClass , notificationManager ) ;
311
400
Notification = default ;
312
401
Notification . CollectJni ( ) ;
313
- JniApi . NotificationBuilder . CollectJni ( ) ;
402
+ NotificationBuilder = default ;
403
+ NotificationBuilder . CollectJni ( ) ;
314
404
JniApi . Bundle . CollectJni ( ) ;
315
405
}
316
406
@@ -326,94 +416,6 @@ public static JniMethodID FindMethod(AndroidJavaClass clazz, string name, string
326
416
#endif
327
417
}
328
418
329
- public static class NotificationBuilder
330
- {
331
- static JniMethodID getExtras ;
332
- static JniMethodID setContentTitle ;
333
- static JniMethodID setContentText ;
334
- static JniMethodID setAutoCancel ;
335
- static JniMethodID setNumber ;
336
- static JniMethodID setStyle ;
337
- static JniMethodID setWhen ;
338
- static JniMethodID setGroup ;
339
- static JniMethodID setGroupSummary ;
340
- static JniMethodID setSortKey ;
341
- static JniMethodID setShowWhen ;
342
-
343
- public static void CollectJni ( )
344
- {
345
- using ( var clazz = new AndroidJavaClass ( "android.app.Notification$Builder" ) )
346
- {
347
- getExtras = JniApi . FindMethod ( clazz , "getExtras" , "()Landroid/os/Bundle;" , false ) ;
348
- setContentTitle = JniApi . FindMethod ( clazz , "setContentTitle" , "(Ljava/lang/CharSequence;)Landroid/app/Notification$Builder;" , false ) ;
349
- setContentText = JniApi . FindMethod ( clazz , "setContentText" , "(Ljava/lang/CharSequence;)Landroid/app/Notification$Builder;" , false ) ;
350
- setAutoCancel = JniApi . FindMethod ( clazz , "setAutoCancel" , "(Z)Landroid/app/Notification$Builder;" , false ) ;
351
- setNumber = JniApi . FindMethod ( clazz , "setNumber" , "(I)Landroid/app/Notification$Builder;" , false ) ;
352
- setStyle = JniApi . FindMethod ( clazz , "setStyle" , "(Landroid/app/Notification$Style;)Landroid/app/Notification$Builder;" , false ) ;
353
- setWhen = JniApi . FindMethod ( clazz , "setWhen" , "(J)Landroid/app/Notification$Builder;" , false ) ;
354
- setGroup = JniApi . FindMethod ( clazz , "setGroup" , "(Ljava/lang/String;)Landroid/app/Notification$Builder;" , false ) ;
355
- setGroupSummary = JniApi . FindMethod ( clazz , "setGroupSummary" , "(Z)Landroid/app/Notification$Builder;" , false ) ;
356
- setSortKey = JniApi . FindMethod ( clazz , "setSortKey" , "(Ljava/lang/String;)Landroid/app/Notification$Builder;" , false ) ;
357
- setShowWhen = JniApi . FindMethod ( clazz , "setShowWhen" , "(Z)Landroid/app/Notification$Builder;" , false ) ;
358
- }
359
- }
360
-
361
- public static AndroidJavaObject GetExtras ( AndroidJavaObject builder )
362
- {
363
- return builder . Call < AndroidJavaObject > ( getExtras ) ;
364
- }
365
-
366
- public static void SetContentTitle ( AndroidJavaObject builder , string title )
367
- {
368
- builder . Call < AndroidJavaObject > ( setContentTitle , title ) . Dispose ( ) ;
369
- }
370
-
371
- public static void SetContentText ( AndroidJavaObject builder , string text )
372
- {
373
- builder . Call < AndroidJavaObject > ( setContentText , text ) . Dispose ( ) ;
374
- }
375
-
376
- public static void SetAutoCancel ( AndroidJavaObject builder , bool shouldAutoCancel )
377
- {
378
- builder . Call < AndroidJavaObject > ( setAutoCancel , shouldAutoCancel ) . Dispose ( ) ;
379
- }
380
-
381
- public static void SetNumber ( AndroidJavaObject builder , int number )
382
- {
383
- builder . Call < AndroidJavaObject > ( setNumber , number ) . Dispose ( ) ;
384
- }
385
-
386
- public static void SetStyle ( AndroidJavaObject builder , AndroidJavaObject style )
387
- {
388
- builder . Call < AndroidJavaObject > ( setStyle , style ) . Dispose ( ) ;
389
- }
390
-
391
- public static void SetWhen ( AndroidJavaObject builder , long timestamp )
392
- {
393
- builder . Call < AndroidJavaObject > ( setWhen , timestamp ) . Dispose ( ) ;
394
- }
395
-
396
- public static void SetGroup ( AndroidJavaObject builder , string group )
397
- {
398
- builder . Call < AndroidJavaObject > ( setGroup , group ) . Dispose ( ) ;
399
- }
400
-
401
- public static void SetGroupSummary ( AndroidJavaObject builder , bool groupSummary )
402
- {
403
- builder . Call < AndroidJavaObject > ( setGroupSummary , groupSummary ) . Dispose ( ) ;
404
- }
405
-
406
- public static void SetSortKey ( AndroidJavaObject builder , string sortKey )
407
- {
408
- builder . Call < AndroidJavaObject > ( setSortKey , sortKey ) . Dispose ( ) ;
409
- }
410
-
411
- public static void SetShowWhen ( AndroidJavaObject builder , bool showTimestamp )
412
- {
413
- builder . Call < AndroidJavaObject > ( setShowWhen , showTimestamp ) . Dispose ( ) ;
414
- }
415
- }
416
-
417
419
public static class Bundle
418
420
{
419
421
static JniMethodID containsKey ;
@@ -836,35 +838,35 @@ public static AndroidJavaObject CreateNotificationBuilder(int id, AndroidNotific
836
838
s_Jni . NotificationManager . SetNotificationIcon ( notificationBuilder , s_Jni . NotificationManager . KEY_SMALL_ICON , notification . SmallIcon ) ;
837
839
if ( ! string . IsNullOrEmpty ( notification . LargeIcon ) )
838
840
s_Jni . NotificationManager . SetNotificationIcon ( notificationBuilder , s_Jni . NotificationManager . KEY_LARGE_ICON , notification . LargeIcon ) ;
839
- JniApi . NotificationBuilder . SetContentTitle ( notificationBuilder , notification . Title ) ;
840
- JniApi . NotificationBuilder . SetContentText ( notificationBuilder , notification . Text ) ;
841
- JniApi . NotificationBuilder . SetAutoCancel ( notificationBuilder , notification . ShouldAutoCancel ) ;
841
+ s_Jni . NotificationBuilder . SetContentTitle ( notificationBuilder , notification . Title ) ;
842
+ s_Jni . NotificationBuilder . SetContentText ( notificationBuilder , notification . Text ) ;
843
+ s_Jni . NotificationBuilder . SetAutoCancel ( notificationBuilder , notification . ShouldAutoCancel ) ;
842
844
if ( notification . Number >= 0 )
843
- JniApi . NotificationBuilder . SetNumber ( notificationBuilder , notification . Number ) ;
845
+ s_Jni . NotificationBuilder . SetNumber ( notificationBuilder , notification . Number ) ;
844
846
if ( notification . Style == NotificationStyle . BigTextStyle )
845
847
{
846
848
using ( var style = new AndroidJavaObject ( "android.app.Notification$BigTextStyle" ) )
847
849
{
848
850
style . Call < AndroidJavaObject > ( "bigText" , notification . Text ) . Dispose ( ) ;
849
- JniApi . NotificationBuilder . SetStyle ( notificationBuilder , style ) ;
851
+ s_Jni . NotificationBuilder . SetStyle ( notificationBuilder , style ) ;
850
852
}
851
853
}
852
854
long timestampValue = notification . ShowCustomTimestamp ? notification . CustomTimestamp . ToLong ( ) : fireTime ;
853
- JniApi . NotificationBuilder . SetWhen ( notificationBuilder , timestampValue ) ;
855
+ s_Jni . NotificationBuilder . SetWhen ( notificationBuilder , timestampValue ) ;
854
856
if ( ! string . IsNullOrEmpty ( notification . Group ) )
855
- JniApi . NotificationBuilder . SetGroup ( notificationBuilder , notification . Group ) ;
857
+ s_Jni . NotificationBuilder . SetGroup ( notificationBuilder , notification . Group ) ;
856
858
if ( notification . GroupSummary )
857
- JniApi . NotificationBuilder . SetGroupSummary ( notificationBuilder , notification . GroupSummary ) ;
859
+ s_Jni . NotificationBuilder . SetGroupSummary ( notificationBuilder , notification . GroupSummary ) ;
858
860
if ( ! string . IsNullOrEmpty ( notification . SortKey ) )
859
- JniApi . NotificationBuilder . SetSortKey ( notificationBuilder , notification . SortKey ) ;
860
- JniApi . NotificationBuilder . SetShowWhen ( notificationBuilder , notification . ShowTimestamp ) ;
861
+ s_Jni . NotificationBuilder . SetSortKey ( notificationBuilder , notification . SortKey ) ;
862
+ s_Jni . NotificationBuilder . SetShowWhen ( notificationBuilder , notification . ShowTimestamp ) ;
861
863
int color = notification . Color . ToInt ( ) ;
862
864
if ( color != 0 )
863
865
s_Jni . NotificationManager . SetNotificationColor ( notificationBuilder , color ) ;
864
866
s_Jni . NotificationManager . SetNotificationUsesChronometer ( notificationBuilder , notification . UsesStopwatch ) ;
865
867
s_Jni . NotificationManager . SetNotificationGroupAlertBehavior ( notificationBuilder , ( int ) notification . GroupAlertBehaviour ) ;
866
868
867
- using ( var extras = JniApi . NotificationBuilder . GetExtras ( notificationBuilder ) )
869
+ using ( var extras = s_Jni . NotificationBuilder . GetExtras ( notificationBuilder ) )
868
870
{
869
871
JniApi . Bundle . PutInt ( extras , s_Jni . NotificationManager . KEY_ID , id ) ;
870
872
JniApi . Bundle . PutLong ( extras , s_Jni . NotificationManager . KEY_REPEAT_INTERVAL , notification . RepeatInterval . ToLong ( ) ) ;
0 commit comments