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")
|
2014-05-02 04:47:40 +00:00
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Font = require("ui/font")
|
|
|
|
local Geom = require("ui/geometry")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Device = require("device")
|
2013-10-18 20:38:07 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2013-10-22 15:11:31 +00:00
|
|
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Input = require("device").input
|
|
|
|
local Screen = require("device").screen
|
2014-10-22 13:34:11 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
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{
|
2014-03-13 13:52:43 +00:00
|
|
|
face = Font:getFace("infofont", 20),
|
|
|
|
text = "Null Message",
|
|
|
|
timeout = nil,
|
2014-05-02 04:47:40 +00:00
|
|
|
margin = 5,
|
|
|
|
padding = 5,
|
2013-01-01 23:08:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function Notification:init()
|
2014-06-10 07:57:10 +00:00
|
|
|
if Device:hasKeys() then
|
2014-03-13 13:52:43 +00:00
|
|
|
self.key_events = {
|
|
|
|
AnyKeyPressed = { { Input.group.Any }, seqtext = "any key", doc = "close dialog" }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
-- we construct the actual content here because self.text is only available now
|
2014-05-02 04:47:40 +00:00
|
|
|
local text_widget = TextWidget:new{
|
|
|
|
text = self.text,
|
|
|
|
face = self.face
|
|
|
|
}
|
|
|
|
local widget_size = text_widget:getSize()
|
2014-03-13 13:52:43 +00:00
|
|
|
self[1] = CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight()/10,
|
|
|
|
},
|
|
|
|
FrameContainer:new{
|
2014-10-22 13:34:11 +00:00
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2014-03-13 13:52:43 +00:00
|
|
|
radius = 0,
|
2014-05-02 04:47:40 +00:00
|
|
|
margin = self.margin,
|
|
|
|
padding = self.padding,
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = widget_size.w,
|
|
|
|
h = widget_size.h
|
|
|
|
},
|
|
|
|
text_widget,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-01 23:08:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Notification:onShow()
|
2014-03-13 13:52:43 +00:00
|
|
|
-- 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
|
2013-01-01 23:08:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Notification:onAnyKeyPressed()
|
2014-03-13 13:52:43 +00:00
|
|
|
-- triggered by our defined key events
|
|
|
|
UIManager:close(self)
|
|
|
|
return true
|
2013-01-01 23:08:19 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return Notification
|