2017-08-15 17:54:02 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
|
|
|
local ButtonTable = require("ui/widget/buttontable")
|
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
|
|
|
local CloseButton = require("ui/widget/closebutton")
|
|
|
|
local Device = require("device")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
local Font = require("ui/font")
|
|
|
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local LineWidget = require("ui/widget/linewidget")
|
|
|
|
local OverlapGroup = require("ui/widget/overlapgroup")
|
2017-09-17 14:41:54 +00:00
|
|
|
local NumberPickerWidget = require("ui/widget/numberpickerwidget")
|
2017-09-13 14:56:20 +00:00
|
|
|
local Size = require("ui/size")
|
2017-08-15 17:54:02 +00:00
|
|
|
local TextBoxWidget = require("ui/widget/textboxwidget")
|
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
|
|
|
local _ = require("gettext")
|
|
|
|
local Screen = Device.screen
|
|
|
|
|
|
|
|
local TimeWidget = InputContainer:new{
|
|
|
|
title_face = Font:getFace("x_smalltfont"),
|
|
|
|
width = nil,
|
|
|
|
height = nil,
|
|
|
|
hour = 0,
|
2017-09-24 11:03:14 +00:00
|
|
|
hour_max = 23,
|
2017-08-15 17:54:02 +00:00
|
|
|
min = 0,
|
|
|
|
ok_text = _("OK"),
|
|
|
|
cancel_text = _("Cancel"),
|
|
|
|
}
|
|
|
|
|
|
|
|
function TimeWidget:init()
|
|
|
|
self.medium_font_face = Font:getFace("ffont")
|
|
|
|
self.light_bar = {}
|
2017-09-13 14:56:20 +00:00
|
|
|
self.screen_width = Screen:getWidth()
|
|
|
|
self.screen_height = Screen:getHeight()
|
2020-06-12 23:56:36 +00:00
|
|
|
self.width = math.floor(self.screen_width * 0.95)
|
2017-08-15 17:54:02 +00:00
|
|
|
if Device:hasKeys() then
|
|
|
|
self.key_events = {
|
2018-02-07 17:45:46 +00:00
|
|
|
Close = { {"Back"}, doc = "close time widget" }
|
2017-08-15 17:54:02 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events = {
|
2018-02-07 17:45:46 +00:00
|
|
|
TapClose = {
|
2017-08-15 17:54:02 +00:00
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = Geom:new{
|
|
|
|
w = self.screen_width,
|
|
|
|
h = self.screen_height,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
self:update()
|
|
|
|
end
|
|
|
|
|
2017-09-17 14:41:54 +00:00
|
|
|
function TimeWidget:update()
|
|
|
|
local hour_widget = NumberPickerWidget:new{
|
2017-08-15 17:54:02 +00:00
|
|
|
show_parent = self,
|
2020-06-12 23:56:36 +00:00
|
|
|
width = math.floor(self.screen_width * 0.2),
|
2017-09-17 14:41:54 +00:00
|
|
|
value = self.hour,
|
|
|
|
value_min = 0,
|
2017-09-24 11:03:14 +00:00
|
|
|
value_max = self.hour_max,
|
2017-09-17 14:41:54 +00:00
|
|
|
value_step = 1,
|
|
|
|
value_hold_step = 4,
|
|
|
|
}
|
|
|
|
local min_widget = NumberPickerWidget:new{
|
2017-08-15 17:54:02 +00:00
|
|
|
show_parent = self,
|
2020-06-12 23:56:36 +00:00
|
|
|
width = math.floor(self.screen_width * 0.2),
|
2017-09-17 14:41:54 +00:00
|
|
|
value = self.min,
|
|
|
|
value_min = 0,
|
|
|
|
value_max = 59,
|
|
|
|
value_step = 1,
|
|
|
|
value_hold_step = 10,
|
2017-08-15 17:54:02 +00:00
|
|
|
}
|
|
|
|
local colon_space = TextBoxWidget:new{
|
|
|
|
text = ":",
|
|
|
|
alignment = "center",
|
|
|
|
face = self.title_face,
|
|
|
|
bold = true,
|
2020-06-12 23:56:36 +00:00
|
|
|
width = math.floor(self.screen_width * 0.2),
|
2017-08-15 17:54:02 +00:00
|
|
|
}
|
2017-09-17 14:41:54 +00:00
|
|
|
local time_group = HorizontalGroup:new{
|
2017-08-15 17:54:02 +00:00
|
|
|
align = "center",
|
2017-09-17 14:41:54 +00:00
|
|
|
hour_widget,
|
2017-08-15 17:54:02 +00:00
|
|
|
colon_space,
|
2017-09-17 14:41:54 +00:00
|
|
|
min_widget,
|
2017-08-15 17:54:02 +00:00
|
|
|
}
|
|
|
|
|
2019-10-27 17:30:39 +00:00
|
|
|
local closebutton = CloseButton:new{ window = self, padding_top = Size.margin.title, }
|
2017-08-15 17:54:02 +00:00
|
|
|
local time_title = FrameContainer:new{
|
2017-10-16 15:51:56 +00:00
|
|
|
padding = Size.padding.default,
|
|
|
|
margin = Size.margin.title,
|
2017-08-15 17:54:02 +00:00
|
|
|
bordersize = 0,
|
|
|
|
TextWidget:new{
|
|
|
|
text = self.title_text,
|
|
|
|
face = self.title_face,
|
|
|
|
bold = true,
|
2020-06-12 23:56:36 +00:00
|
|
|
max_width = math.floor(self.screen_width * 0.95) - closebutton:getSize().w,
|
2017-08-15 17:54:02 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
local time_line = LineWidget:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width,
|
2017-09-13 14:56:20 +00:00
|
|
|
h = Size.line.thick,
|
2017-08-15 17:54:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
local time_bar = OverlapGroup:new{
|
|
|
|
dimen = {
|
|
|
|
w = self.width,
|
|
|
|
h = time_title:getSize().h
|
|
|
|
},
|
|
|
|
time_title,
|
2019-10-27 17:30:39 +00:00
|
|
|
closebutton,
|
2017-08-15 17:54:02 +00:00
|
|
|
}
|
|
|
|
local buttons = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = self.cancel_text,
|
|
|
|
callback = function()
|
|
|
|
self:onClose()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = self.ok_text,
|
|
|
|
callback = function()
|
|
|
|
if self.callback then
|
2017-09-17 14:41:54 +00:00
|
|
|
self.hour = hour_widget:getValue()
|
|
|
|
self.min = min_widget:getValue()
|
2017-08-15 17:54:02 +00:00
|
|
|
self:callback(self)
|
|
|
|
end
|
|
|
|
self:onClose()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
local ok_cancel_buttons = ButtonTable:new{
|
2017-10-08 15:53:25 +00:00
|
|
|
width = self.width - 2*Size.padding.default,
|
2017-08-15 17:54:02 +00:00
|
|
|
buttons = buttons,
|
2017-10-08 15:53:25 +00:00
|
|
|
zero_sep = true,
|
2017-08-15 17:54:02 +00:00
|
|
|
show_parent = self,
|
|
|
|
}
|
|
|
|
|
|
|
|
self.time_frame = FrameContainer:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
radius = Size.radius.window,
|
2017-08-15 17:54:02 +00:00
|
|
|
padding = 0,
|
|
|
|
margin = 0,
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
|
|
VerticalGroup:new{
|
|
|
|
align = "left",
|
|
|
|
time_bar,
|
|
|
|
time_line,
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
2020-06-12 23:56:36 +00:00
|
|
|
w = math.floor(self.screen_width * 0.95),
|
|
|
|
h = math.floor(time_group:getSize().h * 1.2),
|
2017-08-15 17:54:02 +00:00
|
|
|
},
|
2017-09-17 14:41:54 +00:00
|
|
|
time_group
|
2017-08-15 17:54:02 +00:00
|
|
|
},
|
2017-10-08 15:53:25 +00:00
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width,
|
|
|
|
h = ok_cancel_buttons:getSize().h,
|
|
|
|
},
|
|
|
|
ok_cancel_buttons
|
|
|
|
}
|
2017-08-15 17:54:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
self[1] = WidgetContainer:new{
|
|
|
|
align = "center",
|
2018-02-07 17:45:46 +00:00
|
|
|
dimen = Geom:new{
|
2017-08-15 17:54:02 +00:00
|
|
|
x = 0, y = 0,
|
|
|
|
w = self.screen_width,
|
|
|
|
h = self.screen_height,
|
|
|
|
},
|
|
|
|
FrameContainer:new{
|
|
|
|
bordersize = 0,
|
|
|
|
self.time_frame,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "ui", self.time_frame.dimen
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
function TimeWidget:onCloseWidget()
|
|
|
|
UIManager:setDirty(nil, function()
|
|
|
|
return "partial", self.time_frame.dimen
|
|
|
|
end)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function TimeWidget:onShow()
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "ui", self.time_frame.dimen
|
|
|
|
end)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function TimeWidget:onAnyKeyPressed()
|
|
|
|
UIManager:close(self)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2018-02-07 17:45:46 +00:00
|
|
|
function TimeWidget:onTapClose(arg, ges_ev)
|
2017-08-15 17:54:02 +00:00
|
|
|
if ges_ev.pos:notIntersectWith(self.time_frame.dimen) then
|
|
|
|
self:onClose()
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function TimeWidget:onClose()
|
|
|
|
UIManager:close(self)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
return TimeWidget
|