2017-04-29 08:38:09 +00:00
|
|
|
--[[--
|
|
|
|
Widget that displays a tiny notification at the top of the screen.
|
|
|
|
--]]
|
|
|
|
|
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2013-10-18 20:38:07 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
2017-04-29 08:38:09 +00:00
|
|
|
local Device = require("device")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Font = require("ui/font")
|
2017-04-29 08:38:09 +00:00
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Geom = require("ui/geometry")
|
2018-05-19 12:01:20 +00:00
|
|
|
local GestureRange = require("ui/gesturerange")
|
2017-04-29 08:38:09 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2017-09-13 14:56:20 +00:00
|
|
|
local Size = require("ui/size")
|
2017-04-29 08:38:09 +00:00
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
2013-10-18 20:38:07 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2017-04-29 08:38:09 +00:00
|
|
|
local Input = Device.input
|
|
|
|
local Screen = Device.screen
|
2013-01-01 23:08:19 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local Notification = InputContainer:new{
|
2017-04-29 08:38:09 +00:00
|
|
|
face = Font:getFace("x_smallinfofont"),
|
2014-03-13 13:52:43 +00:00
|
|
|
text = "Null Message",
|
|
|
|
timeout = nil,
|
2017-09-13 14:56:20 +00:00
|
|
|
margin = Size.margin.default,
|
|
|
|
padding = Size.padding.default,
|
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 = {
|
2018-05-19 12:01:20 +00:00
|
|
|
AnyKeyPressed = { { Input.group.Any },
|
|
|
|
seqtext = "any key", doc = "close dialog" }
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
end
|
2018-05-19 12:01:20 +00:00
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events.TapClose = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
-- 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,
|
2018-05-19 12:01:20 +00:00
|
|
|
face = self.face,
|
2014-05-02 04:47:40 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
|
2014-12-01 14:39:41 +00:00
|
|
|
function Notification:onCloseWidget()
|
|
|
|
UIManager:setDirty(nil, function()
|
2018-06-02 16:10:55 +00:00
|
|
|
return "ui", self[1][1].dimen
|
2014-12-01 14:39:41 +00:00
|
|
|
end)
|
|
|
|
return true
|
2014-11-30 22:25:23 +00:00
|
|
|
end
|
|
|
|
|
2013-01-01 23:08:19 +00:00
|
|
|
function Notification:onShow()
|
2014-03-13 13:52:43 +00:00
|
|
|
-- triggered by the UIManager after we got successfully shown (not yet painted)
|
2014-12-01 14:39:41 +00:00
|
|
|
UIManager:setDirty(self, function()
|
2015-04-26 18:07:17 +00:00
|
|
|
return "ui", self[1][1].dimen
|
2014-12-01 14:39:41 +00:00
|
|
|
end)
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.timeout then
|
2014-12-01 14:39:41 +00:00
|
|
|
UIManager:scheduleIn(self.timeout, function() UIManager:close(self) end)
|
2014-03-13 13:52:43 +00:00
|
|
|
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
|
2014-12-01 14:39:41 +00:00
|
|
|
UIManager:close(self)
|
2018-05-19 12:01:20 +00:00
|
|
|
if self.readonly ~= true then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Notification:onTapClose()
|
|
|
|
UIManager:close(self)
|
|
|
|
if self.readonly ~= true then
|
|
|
|
return true
|
|
|
|
end
|
2013-01-01 23:08:19 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return Notification
|