2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2014-06-05 06:58:53 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Font = require("ui/font")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Device = require("device")
|
2013-10-18 20:38:07 +00:00
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
|
|
|
local ImageWidget = require("ui/widget/imagewidget")
|
|
|
|
local TextBoxWidget = require("ui/widget/textboxwidget")
|
|
|
|
local HorizontalSpan = require("ui/widget/horizontalspan")
|
|
|
|
local UIManager = require("ui/uimanager")
|
2013-10-22 15:11:31 +00:00
|
|
|
local Geom = require("ui/geometry")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Input = require("device").input
|
|
|
|
local Screen = require("device").screen
|
2013-10-22 15:11:31 +00:00
|
|
|
local _ = require("gettext")
|
2014-10-22 13:34:11 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2012-06-10 15:52:09 +00:00
|
|
|
|
|
|
|
--[[
|
|
|
|
Widget that displays an informational message
|
|
|
|
|
|
|
|
it vanishes on key press or after a given timeout
|
|
|
|
]]
|
2013-10-18 20:38:07 +00:00
|
|
|
local InfoMessage = InputContainer:new{
|
2014-10-30 08:01:01 +00:00
|
|
|
modal = true,
|
2014-03-13 13:52:43 +00:00
|
|
|
face = Font:getFace("infofont", 25),
|
|
|
|
text = "",
|
|
|
|
timeout = nil, -- in seconds
|
2012-06-10 15:52:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function InfoMessage: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 },
|
2014-06-05 06:58:53 +00:00
|
|
|
seqtext = "any key", doc = "close dialog" }
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
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-08-27 03:07:25 +00:00
|
|
|
local image_widget = nil
|
|
|
|
if self.image then
|
|
|
|
image_widget = ImageWidget:new{
|
|
|
|
image = self.image,
|
|
|
|
width = self.image_width,
|
|
|
|
height = self.image_height,
|
|
|
|
}
|
|
|
|
else
|
|
|
|
image_widget = ImageWidget:new{
|
|
|
|
file = "resources/info-i.png",
|
|
|
|
}
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
-- we construct the actual content here because self.text is only available now
|
|
|
|
self[1] = CenterContainer:new{
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
FrameContainer:new{
|
|
|
|
margin = 2,
|
2014-10-22 13:34:11 +00:00
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2014-03-13 13:52:43 +00:00
|
|
|
HorizontalGroup:new{
|
|
|
|
align = "center",
|
2014-08-27 03:07:25 +00:00
|
|
|
image_widget,
|
2014-03-13 13:52:43 +00:00
|
|
|
HorizontalSpan:new{ width = 10 },
|
|
|
|
TextBoxWidget:new{
|
|
|
|
text = self.text,
|
2014-05-28 12:05:38 +00:00
|
|
|
face = self.face,
|
|
|
|
width = Screen:getWidth()*2/3,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-10 15:52:09 +00:00
|
|
|
end
|
|
|
|
|
2014-12-01 14:39:41 +00:00
|
|
|
function InfoMessage:onCloseWidget()
|
|
|
|
UIManager:setDirty(nil, function()
|
|
|
|
return "partial", self[1][1].dimen
|
|
|
|
end)
|
|
|
|
return true
|
2014-11-30 22:25:23 +00:00
|
|
|
end
|
|
|
|
|
2012-06-10 15:52:09 +00:00
|
|
|
function InfoMessage: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
|
2012-06-10 15:52:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function InfoMessage: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)
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2012-06-10 15:52:09 +00:00
|
|
|
end
|
|
|
|
|
2013-03-17 04:15:21 +00:00
|
|
|
function InfoMessage:onTapClose()
|
2014-12-01 14:39:41 +00:00
|
|
|
UIManager:close(self)
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2013-03-17 04:15:21 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
return InfoMessage
|