-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNotificationManager.bbj
343 lines (308 loc) · 14.3 KB
/
NotificationManager.bbj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
REM /**
REM * 2019-09-29 ; RVDHofDAGOCAR ; Requirement to display the notificaion in the top right corner in order to avoid a display conflict with an already existing solutions showing notifications at the lower right edge.
REM */
use ::BBjNotificationManager/src/Notification.bbj::Notification
use java.util.ArrayList
use ::BBjWidget/BBjWidget.bbj::BBjWidget
use ::BBjNotificationManager/src/NotificationButton.bbj::NotificationButton
use ::BBjNotificationManager/src/NotificationEvent.bbj::NotificationEvent
rem /** <br>
rem * -------------------------- <br>
rem * Manual <br>
rem * -------------------------- <br>
rem * The plugin will use the BBjAPI-IDs as follows for each respective Notification (only mind if you´re working on the NotificationControlls themselves) <br>
rem * IDS WILL NOT BE BLOCKED OUTSIDE OF A NOTIFICATIONS CONTEXT!!! <br>
rem * 1100+ = IDs for the notificationwindows itself and its respective titles <br>
rem * 11100+ = IDs for the notifications respective dismissbutton <br>
rem * 51100+ = IDs for the notifications respective textfields <br>
rem * 101100+ = IDs for the notifications respective timer (only if a timer was given) <br>
rem * 175000+ = IDs for custom Buttons on the Notification <br>
rem * 1000000 = ID for the Icon on the Notification <br>
rem * ---------------------------------------------------------------------------- <br>
rem * simple usage guide: <br>
rem * initialize an instance of the NotificationManager i.e. mng! = new NotificationManager(1) <br>
rem * create a Notification with the addNotification method i.e. mng!.addNotification(text,timeout,title,eventhandle,color,image,List<Buttons>,link) <br>
rem * change the animationmode with setAnimate(true/false) , it is false by default <br>
rem * ---------------------------------------------------------------------------- <br>
rem * optional values are : text, dismiss, title, handle, color, image, buttons, link <br>
rem * these can be passed null() if not required and will be left out <br>
rem * <br>
rem * if an eventhandle was given to the Notification it will push the event 17 which can be caught by processing event onclick: <br>
rem * (A Notification has to be cleared manually if it was clicked, which can be performed using the eventhandle delivered by the event and the deletehandle(String handle) method <br>
rem * <br>
rem * if a timeout was given the Notification will be dismissed on the timeout count (in seconds) <br>
rem * <br>
rem * if a color (BBjColor) is given it will change the BackgroundColor of the Notification <br>
rem * <br>
rem * if an image (only BBj-conform formats can be used) is passed it will appear on the left hand side of the Notification as an Icon <br>
rem * <br>
rem * if Buttons are passed every Item in the List will be added as a Button in the Notification. <br>
rem * to pass buttons simply create a java.util.ArrayList and fill it with NotificationButton Objects, provided in the Plugin <br>
rem * to create an object call the constructor with new NotificationButton(String text, String eventhandle,int width) and put it in to the List <br>
rem * <br>
rem * if a link is passed, the Notification will get a little button which will redirect the user to given links <br>
rem * ---------------------------------------------------------------------------- <br>
rem * <br>
rem * (This System was reworked in version 1.2)
rem * <br>
rem * You can catch Events related to the Notifications by giving the Manager a Callback on Event id 17 and reading the eventdata passed <br>
rem * <br>
rem * The Events structures are structured as follows: <br>
rem * An Event of the Type "NotificationEvent" (needs to be imported) will be passed <br>
rem * Every Event thrown will contain 3 fields: <br>
rem * Notification : this is the Handle of the Notification the Event was sent from.<br>
rem * You can use this field to identify the source of the event in your data or use it to delete the Notification. <br>
rem * Eventtype : This will contain the event that triggered this data to be thrown <br>
rem * At this version it can contain :"CLOSE" "TIMEOUT" "BTN_PUSH" or "WINDOW_PUSH" with the Event displaying what caused the event to be thrown <br>
rem * Event : This is the exact eventhandle thrown, could be a handle to the Notification or a Button on such <br>
rem */
class public NotificationManager extends BBjWidget
field private BBjSysGui SysGui!
field private ArrayList notifications!
field private ArrayList buffer!
rem settings
rem maximal number of notifications displayed
field private int displayMax!
rem buffer to the bottom of the screen
field private int bottombuffer!
rem buffer to the right of the screen
field private int xbuffer!
rem animation mode
field private Boolean animate!
rem default orientation where notifications appear : '' | 'TOPRIGHT'
field private BBjString orientation! = ""
rem /**
rem * Constructor for the Manager
rem */
method public NotificationManager()
rem Getting Sysgui
#SysGui! = BBjAPI().openSysGui("X0")
rem initializing required fields
#notifications! = new ArrayList()
#buffer! = new ArrayList()
rem init settings
#displayMax! = 5
#bottombuffer! = 50
#xbuffer! = 30
#animate! = false
methodend
REM /**
REM * Sets the starting appearance of the notification to the top right corner of the display.
REM */
method public void setInitialOrientationTopRight()
if #orientation!=""
#orientation!="TOPRIGHT"
fi
methodend
rem /**
rem * reposition the entirety of displayed notifications
rem */
method public void reposition ()
declare auto Notification not!
if #notifications!.size() > 0 then
rem cycling through the notifications object to reposition all notifications to their respective new position
for i=0 to #notifications!.size()-1
not! = #notifications!.get(i)
newYPos=#getNextYPOS(i-1,not!.getheight())
not!.setPosition(not!.getx(),newYPos,#animate!)
next i
fi
methodend
rem /**
rem * change the animate property which controlls if the animationfeature is used or not
rem *
rem * @param animate! Variable to toggle animated mode
rem */
method public void setAnimate(Boolean animate!)
#animate! = animate!
declare auto Notification not!
rem cycling through displayed notifications
if #notifications!.size() > 0 then
for i = 0 to #notifications!.size()-1
not! = #notifications!.get(i)
not!.setanimate(#animate!)
next i
fi
rem cycling through buffered notifications
if #buffer!.size() > 0 then
for i = 0 to #buffer!.size()-1
not! = #buffer!.get(i)
not!.setanimate(#animate!)
next i
fi
methodend
rem /**
rem * delete the ID of an active notification
rem *
rem * @param ID! ID of the Notification to be deleted
rem */
method public void deleteID(int ID!)
declare auto Notification not!
if #notifications!.size() > 0 then
rem cycling the active notifications
for i=0 to #notifications!.size()-1
not! = #notifications!.get(i)
rem if the id was found it will be deleted with an optional animation
if not!.getID() = ID! then
not!.dismiss(#animate!)
#notifications!.remove(i)
break
fi
next i
fi
methodend
rem /**
rem * gets called when the notifications change, it will fire a new notification from the buffer
rem * to the displayed notifications if it reaches an amount of less than 5
rem *
rem */
method public void fireNextFromBuffer()
if #notifications!.size() < #displayMax! AND #buffer!.size()>0 then
declare auto Notification not!
not! = #buffer!.get(0)
#notifications!.add(not!)
not!.display(#animate!)
#buffer!.remove(0)
fi
methodend
rem /**
rem * add a new notification to the system with given properties
rem *
rem * @param text! Text to be displayed in the body of the Notification
rem * @param dismiss! Time in seconds until the Notification will be dismissed automatically
rem * @param title! Title to be displayed on the upper section of the Notification
rem * @param EventHandle! Handle to be thrown out when a Notification itself is clicked
rem * @param color! Backgroundcolor of the Notification
rem * @param image! Icon to be displayed on the left hand side of the Notification
rem * @param buttons! List of ButtonsMetadata to be displayed on the Bottom of the Notification
rem * @param redirect! Link to be linked with the redirect button on the upper right corner (only valid links in Format https://www.examplesite.com)
rem */
method public void addNotification(String text!,int dismiss!,String title!, String EventHandle!,BBjColor color!,BBjImage image!,ArrayList buttons!,String redirect!)
declare int height!
declare int width!
declare int y!
ID! = #getFreeID()
screenBounds! = #SysGui!.getSystemMetrics().getScreenBounds()
rem height of the notifications is correspodning to 10% of the screen size
height! = int(screenBounds!.height*0.1)
rem width of the notification is corresponding to 20% of the screen size
width! = int(screenBounds!.width*0.2)
rem giving the notification a little buffer to the right side of the screen
rem to change the buffersize , change the content of the variable xbuffer! to any value you´d like
x! = screenBounds!.width - (width!+#xbuffer!)
declare Notification not!
y!=0
not! = new Notification(ID!,height!,width!,text!,dismiss!,x!,y!,"Notification",#this!,title!,#animate!,EventHandle!,color!,image!,buttons!,redirect!)
rem only displaying the given amount of notifications, if the notification would exceed the given amount
rem it will be put into a buffer and displayed if enough slots are open
if #notifications!.size() < #displayMax! then
#notifications!.add(not!)
not!.sety(0)
not!.display(#animate!)
else
#buffer!.add(not!)
endif
methodend
rem /**
rem * find the next avaiable ypos open on the screen to display a notification at
rem *
rem * @param run! Position of the Notification wihtin the Array
rem * @param ownheight! height of the Notification
rem *
rem * @return returns the next found free ypos
rem */
method private int getNextYPOS(int run!,int ownheight!)
declare int ypos!
declare int height!
declare auto Notification not!
screenBounds! = #SysGui!.getSystemMetrics().getScreenBounds()
height! = ownheight!+20
rem cycling through the notifications and adding all the heights including a bottombuffer together to find a ypos thats open at the top
if run! < #notifications!.size() AND run! >= 0 then
if #notifications!.size() > 0 then
for i = 0 to run!
not! = #notifications!.get(i)
height! = height! + not!.getheight()+10
next i
fi
endif
if #orientation!="TOPRIGHT"
ypos! = screenBounds!.y + height! + #bottombuffer! - ownheight!
else
ypos! = screenBounds!.height - (height!+#bottombuffer!)
fi
methodret ypos!
methodend
rem /**
rem * find a unused display-id within the range of all active and inactive notifications that are in the notifications list and the buffer
rem *
rem * @return returns the next ID that is free calculated up from 1100 , recycling IDs that are not used anymore
rem */
method private int getFreeID()
declare int ID!
declare Boolean contained!
ID!=1100
contained! = 1
rem cycling through the buffer and the notifications to find an open id via brute force
if #notifications!.size() > 0 then
while contained!
contained! = 0
declare auto Notification not!
for i= 0 to #notifications!.size()-1
not! = #notifications!.get(i)
if not!.getID() = ID! then
contained! = 1
fi
next i
if #buffer!.size() > 0 then
for i = 0 to #buffer!.size()-1
not! = #buffer!.get(i)
if not!.getID() = ID! then
contained! = 1
fi
next i
fi
if contained! then
ID! = ID! + 1
fi
wend
fi
methodret ID!
methodend
rem /**
rem * delete a specific notification by its eventhandle which has to be given to it when creating it
rem * only safe method to delete a notification from outside!
rem *
rem * @param eventhandle! Handle of the Notification to be deleted
rem */
method public void deleteNotification(String eventhandle!)
declare auto Notification not!
if #notifications!.size() > 0 then
for i = 0 to #notifications!.size()-1
not! = #notifications!.get(i)
if not!.getEventHandle() = eventhandle! then
#deleteID(not!.getID())
break
fi
next i
fi
if #buffer!.size() > 0 then
for i = 0 to #buffer!.size()-1
not! = #notifications!.get(i)
if not!.getEventHandle() = eventhandle! then
#deleteID(not!.getID())
break
fi
next i
fi
#reposition()
methodend
rem /**
rem * fireevent when a notification is clicked
rem *
rem * @param id! String to be thrown as an Event
rem */
method public void firePush(NotificationEvent id!)
#super!.fireEvent(17,id!)
methodend
classend