Difference between revisions of "Notification"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(2 intermediate revisions by the same user not shown)
Line 10: Line 10:
 
=== <translate>Examples</translate> ===
 
=== <translate>Examples</translate> ===
 
'''Create new notification and dispatch right away'''<br/>
 
'''Create new notification and dispatch right away'''<br/>
<source lang="lua">local note = Notification.new(1)
+
<syntaxhighlight lang="lua">local note = Notification.new(1)
 
note:setTitle("Notification app")
 
note:setTitle("Notification app")
 
note:setMessage("Do you see me?")
 
note:setMessage("Do you see me?")
 
note:setSound("./some_sound.wav")
 
note:setSound("./some_sound.wav")
note:dispatchNow()</source>
+
note:dispatchNow()</syntaxhighlight>
<br/>'''Create new notification and dispatch after one hour with repeating period of one day'''<br/>
+
'''Create new notification and dispatch after one hour with repeating period of one day'''<br/>
<source lang="lua">local note = Notification.new(2)
+
<syntaxhighlight lang="lua">local note = Notification.new(2)
 
note:setTitle("Notification app")
 
note:setTitle("Notification app")
 
note:setMessage("I will bother you each day")
 
note:setMessage("I will bother you each day")
note:dispatchAfter({hour = 1}, {day = 1})</source>
+
note:dispatchAfter({hour = 1}, {day = 1})</syntaxhighlight>
<br/>'''Create new notification and dispatch on specific date in specific time'''<br/>
+
'''Create new notification and dispatch on specific date in specific time'''<br/>
<source lang="lua">local note = Notification.new(3)
+
<syntaxhighlight lang="lua">local note = Notification.new(3)
 
note:setTitle("Notification app")
 
note:setTitle("Notification app")
 
note:setMessage("Happy Birthday")
 
note:setMessage("Happy Birthday")
note:dispatchOn({year = 2013, month = 8, day = 1, hour = 9, min = 0, sec = 0})</source>
+
note:dispatchOn({year = 2013, month = 8, day = 1, hour = 9, min = 0, sec = 0})</syntaxhighlight>
<br/>'''Modifying existing scheduled notification'''<br/>
+
'''Modifying existing scheduled notification'''<br/>
<source lang="lua">--id of notification to modify
+
<syntaxhighlight lang="lua">--id of notification to modify
 
local id = 1
 
local id = 1
  
Line 37: Line 37:
 
--check if id is in it
 
--check if id is in it
 
if t[id] then
 
if t[id] then
  --notification is still scheduled
+
--notification is still scheduled
  --let's modify it by creating new instance with same id
+
--let's modify it by creating new instance with same id
  local note = Notification.new(id)
+
local note = Notification.new(id)
  note:setTitle("New title")
+
note:setTitle("New title")
  note:setMessage("New message")
+
note:setMessage("New message")
  --if we want to modify dispatch time we need to redispatch it
+
--if we want to modify dispatch time we need to redispatch it
  note:dispatchAfter({day = 1})
+
note:dispatchAfter({day = 1})
end</source>
+
end</syntaxhighlight>
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
 
 
=== <translate>Methods</translate> ===
 
=== <translate>Methods</translate> ===
 
[[Special:MyLanguage/Notification.new|Notification.new]] ''<translate>creates new notification</translate>''<br/><!-- GIDEROSMTD:Notification.new() creates new notification -->
 
[[Special:MyLanguage/Notification.new|Notification.new]] ''<translate>creates new notification</translate>''<br/><!-- GIDEROSMTD:Notification.new() creates new notification -->

Latest revision as of 14:32, 13 July 2023


Supported platforms:
Available since: Gideros 2011.6

Description

Notification class is used to compose and schedule new local notifications. You need to provide an ID of notification to constructor. Using same provided ID you can create a new instance of Notification class and modify existing notification with that ID. Additionally the ID allows you to identify local notification in the table of scheduled local notifications retrieved from NotificationManager:getScheduledNotifications, or table of local notifications that were already displayed using NotificationManager:getLocalNotifications

Notification consists of notification message, title, sound and number. Only message is the mandatory one. You can combine others as you wish.

Examples

Create new notification and dispatch right away

local note = Notification.new(1)
note:setTitle("Notification app")
note:setMessage("Do you see me?")
note:setSound("./some_sound.wav")
note:dispatchNow()

Create new notification and dispatch after one hour with repeating period of one day

local note = Notification.new(2)
note:setTitle("Notification app")
note:setMessage("I will bother you each day")
note:dispatchAfter({hour = 1}, {day = 1})

Create new notification and dispatch on specific date in specific time

local note = Notification.new(3)
note:setTitle("Notification app")
note:setMessage("Happy Birthday")
note:dispatchOn({year = 2013, month = 8, day = 1, hour = 9, min = 0, sec = 0})

Modifying existing scheduled notification

--id of notification to modify
local id = 1

--retrieve shared instance
local mngr = NotificationManager.getSharedInstance()

--retrieve table with scheduled notifications
local t = mngr:getScheduledNotifications()

--check if id is in it
if t[id] then
	--notification is still scheduled
	--let's modify it by creating new instance with same id
	local note = Notification.new(id)
	note:setTitle("New title")
	note:setMessage("New message")
	--if we want to modify dispatch time we need to redispatch it
	note:dispatchAfter({day = 1})
end

Methods

Notification.new creates new notification
Notification:cancel cancel notification
Notification:dispatchAfter Dispatch notification after specified time
Notification:dispatchNow dispatch notification now
Notification:dispatchOn dispatch on specified date
Notification:getId get id of notification
Notification:getMessage get message of notification
Notification:getNumber get notification number
Notification:getSound get sound of notification
Notification:getTitle get title of notification
Notification:setNumber set notification number
Notification:setSound set notification sound
Notification:setTitle set the title of notification

Events

Constants

Notification.DEFAULT_SOUND