lib/android: intro the `notifications` module
[nit.git] / lib / android / notification / native_notification.nit
1 # This file is part of NIT (http://www.nitlanguage.org).
2 #
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Native Java classes for notifications
18 module native_notification is min_api_version 11
19
20 import android::assets_and_resources
21
22 in "Java" `{
23 import android.content.Context;
24 import android.app.NotificationManager;
25 import android.app.Notification;
26 `}
27
28 redef class NativeActivity
29 fun notification_manager: NativeNotificationManager in "Java" `{
30 return (NotificationManager)recv.getSystemService(Context.NOTIFICATION_SERVICE);
31 `}
32 end
33
34 extern class NativeNotificationManager in "Java" `{ android.app.NotificationManager `}
35
36 fun notify(tag: JavaString, id: Int, notif: NativeNotification) in "Java" `{
37 recv.notify(tag, (int)id, notif);
38 `}
39
40 fun cancel(tag: JavaString, id: Int) in "Java" `{ recv.cancel(tag, (int)id); `}
41
42 fun cancel_all in "Java" `{ recv.cancelAll(); `}
43 end
44
45 extern class NativeNotification in "Java" `{ android.app.Notification `}
46 end
47
48 extern class NativeNotificationBuilder in "Java" `{ android.app.Notification$Builder `}
49
50 new (context: NativeActivity) in "Java" `{ return new Notification.Builder(context); `}
51
52 fun create: NativeNotification in "Java" `{
53 // Deprecated since API 16, which introduces `build`,
54 // refinement and global compilation should prevent warnings.
55 return recv.getNotification();
56 `}
57
58 fun title=(value: JavaString) in "Java" `{ recv.setContentTitle(value); `}
59
60 fun text=(value: JavaString) in "Java" `{ recv.setContentText(value); `}
61
62 fun ticker=(value: JavaString) in "Java" `{ recv.setTicker(value); `}
63
64 fun small_icon=(value: Int) in "Java" `{ recv.setSmallIcon((int)value); `}
65
66 fun auto_cancel=(value: Bool) in "Java" `{ recv.setAutoCancel(value); `}
67
68 fun number=(value: Int) in "Java" `{ recv.setNumber((int)value); `}
69
70 fun ongoing=(value: Bool) in "Java" `{ recv.setOngoing(value); `}
71 end