2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
|
|
|
local TextBoxWidget = require("ui/widget/textboxwidget")
|
|
|
|
local Font = require("ui/font")
|
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local Device = require("ui/device")
|
|
|
|
local UIManager = require("ui/uimanager")
|
2013-10-22 15:11:31 +00:00
|
|
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
|
|
|
local Input = require("ui/input")
|
|
|
|
local Screen = require("ui/screen")
|
2013-01-01 23:08:19 +00:00
|
|
|
|
|
|
|
--[[
|
|
|
|
Widget that displays a tiny notification on top of screen
|
|
|
|
--]]
|
2013-10-18 20:38:07 +00:00
|
|
|
local Notification = InputContainer:new{
|
2013-01-01 23:08:19 +00:00
|
|
|
face = Font:getFace("infofont", 20),
|
|
|
|
text = "Null Message",
|
|
|
|
timeout = nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
function Notification:init()
|
2013-02-02 06:36:29 +00:00
|
|
|
if Device:hasKeyboard() then
|
2013-10-16 12:56:18 +00:00
|
|
|
self.key_events = {
|
2013-02-02 06:36:29 +00:00
|
|
|
AnyKeyPressed = { { Input.group.Any }, seqtext = "any key", doc = "close dialog" }
|
|
|
|
}
|
|
|
|
end
|
2013-01-01 23:08:19 +00:00
|
|
|
-- we construct the actual content here because self.text is only available now
|
|
|
|
self[1] = CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight()/10,
|
|
|
|
},
|
|
|
|
ignore = "height",
|
|
|
|
FrameContainer:new{
|
|
|
|
background = 0,
|
|
|
|
radius = 0,
|
|
|
|
HorizontalGroup:new{
|
|
|
|
align = "center",
|
|
|
|
TextBoxWidget:new{
|
|
|
|
text = self.text,
|
|
|
|
face = self.face,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function Notification:onShow()
|
|
|
|
-- triggered by the UIManager after we got successfully shown (not yet painted)
|
|
|
|
if self.timeout then
|
|
|
|
UIManager:scheduleIn(self.timeout, function() UIManager:close(self) end)
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function Notification:onAnyKeyPressed()
|
|
|
|
-- triggered by our defined key events
|
|
|
|
UIManager:close(self)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return Notification
|