2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
|
|
|
local RightContainer = require("ui/widget/container/rightcontainer")
|
|
|
|
local BottomContainer = require("ui/widget/container/bottomcontainer")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local ProgressWidget = require("ui/widget/progresswidget")
|
2013-12-15 12:19:06 +00:00
|
|
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
2013-10-18 20:38:07 +00:00
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
2013-12-15 12:19:06 +00:00
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local Device = require("ui/device")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Screen = require("ui/screen")
|
|
|
|
local Geom = require("ui/geometry")
|
2013-12-17 14:42:25 +00:00
|
|
|
local Event = require("ui/event")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Font = require("ui/font")
|
2013-12-15 12:19:06 +00:00
|
|
|
local DEBUG = require("dbg")
|
2013-02-23 18:25:57 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local ReaderFooter = InputContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
visible = true,
|
|
|
|
pageno = nil,
|
|
|
|
pages = nil,
|
|
|
|
progress_percentage = 0.0,
|
|
|
|
progress_text = "0 / 0",
|
|
|
|
show_time = false,
|
|
|
|
bar_width = 0.85,
|
|
|
|
text_width = 0.15,
|
|
|
|
text_font_face = "ffont",
|
|
|
|
text_font_size = 14,
|
|
|
|
height = 19,
|
2013-02-23 18:25:57 +00:00
|
|
|
}
|
|
|
|
|
2013-02-24 07:25:08 +00:00
|
|
|
function ReaderFooter:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.progress_bar = ProgressWidget:new{
|
|
|
|
width = math.floor(Screen:getWidth()*(self.bar_width-0.02)),
|
|
|
|
height = 7,
|
|
|
|
percentage = self.progress_percentage,
|
|
|
|
}
|
|
|
|
self.progress_text = TextWidget:new{
|
|
|
|
text = self.progress_text,
|
|
|
|
face = Font:getFace(self.text_font_face, self.text_font_size),
|
|
|
|
}
|
|
|
|
local _, text_height = self.progress_text:getSize()
|
|
|
|
local horizontal_group = HorizontalGroup:new{}
|
|
|
|
local bar_container = RightContainer:new{
|
|
|
|
dimen = Geom:new{w = Screen:getWidth()*self.bar_width, h = self.height},
|
|
|
|
self.progress_bar,
|
|
|
|
}
|
|
|
|
local text_container = CenterContainer:new{
|
|
|
|
dimen = Geom:new{w = Screen:getWidth()*self.text_width, h = self.height},
|
|
|
|
self.progress_text,
|
|
|
|
}
|
|
|
|
table.insert(horizontal_group, bar_container)
|
|
|
|
table.insert(horizontal_group, text_container)
|
|
|
|
self[1] = BottomContainer:new{
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
FrameContainer:new{
|
|
|
|
horizontal_group,
|
|
|
|
background = 0,
|
|
|
|
bordersize = 0,
|
|
|
|
padding = 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.dimen = self[1]:getSize()
|
|
|
|
self.pageno = self.view.state.page
|
|
|
|
self.pages = self.view.document.info.number_of_pages
|
|
|
|
self:updateFooterPage()
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events = {
|
|
|
|
TapFooter = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = self[1]:contentRange(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
HoldFooter = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold",
|
|
|
|
range = self[1]:contentRange(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
2013-02-23 18:25:57 +00:00
|
|
|
end
|
|
|
|
|
2014-02-12 07:26:56 +00:00
|
|
|
function ReaderFooter:updateFooterPage()
|
2014-03-13 13:52:43 +00:00
|
|
|
if type(self.pageno) ~= "number" then return end
|
|
|
|
self.progress_bar.percentage = self.pageno / self.pages
|
|
|
|
|
|
|
|
if self.show_time then
|
|
|
|
self.progress_text.text = os.date("%H:%M")
|
|
|
|
else
|
|
|
|
self.progress_text.text = string.format("%d / %d", self.pageno, self.pages)
|
|
|
|
end
|
2013-02-23 18:25:57 +00:00
|
|
|
end
|
|
|
|
|
2014-02-12 07:26:56 +00:00
|
|
|
function ReaderFooter:updateFooterPos()
|
2014-03-13 13:52:43 +00:00
|
|
|
if type(self.position) ~= "number" then return end
|
|
|
|
self.progress_bar.percentage = self.position / self.doc_height
|
|
|
|
|
|
|
|
if self.show_time then
|
|
|
|
self.progress_text.text = os.date("%H:%M")
|
|
|
|
else
|
|
|
|
self.progress_text.text = string.format("%1.f", self.progress_bar.percentage*100).."%"
|
|
|
|
end
|
2014-02-12 07:26:56 +00:00
|
|
|
end
|
|
|
|
|
2013-02-24 07:25:08 +00:00
|
|
|
function ReaderFooter:onPageUpdate(pageno)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.pageno = pageno
|
|
|
|
self.pages = self.view.document.info.number_of_pages
|
|
|
|
self:updateFooterPage()
|
2014-02-12 07:26:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFooter:onPosUpdate(pos)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.position = pos
|
|
|
|
self.doc_height = self.view.document.info.doc_height
|
|
|
|
self:updateFooterPos()
|
2013-02-23 18:25:57 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
2013-12-17 14:42:25 +00:00
|
|
|
function ReaderFooter:onTapFooter(arg, ges)
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.view.flipping_visible then
|
|
|
|
local pos = ges.pos
|
|
|
|
local dimen = self.progress_bar.dimen
|
|
|
|
local percentage = (pos.x - dimen.x)/dimen.w
|
|
|
|
self.ui:handleEvent(Event:new("GotoPercentage", percentage))
|
|
|
|
else
|
|
|
|
self.show_time = not self.show_time
|
|
|
|
end
|
|
|
|
if self.pageno then
|
|
|
|
self:updateFooterPage()
|
|
|
|
else
|
|
|
|
self:updateFooterPos()
|
|
|
|
end
|
|
|
|
UIManager:setDirty(self.view.dialog, "partial")
|
|
|
|
-- consume this tap when footer is visible
|
|
|
|
if self.view.footer_visible then
|
|
|
|
return true
|
|
|
|
end
|
2013-12-15 12:19:06 +00:00
|
|
|
end
|
|
|
|
|
2014-02-12 12:41:16 +00:00
|
|
|
function ReaderFooter:onHoldFooter(arg, ges)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui:handleEvent(Event:new("ShowGotoDialog"))
|
|
|
|
return true
|
2014-02-12 12:41:16 +00:00
|
|
|
end
|
|
|
|
|
2014-02-12 07:26:56 +00:00
|
|
|
function ReaderFooter:onSetStatusLine(status_line)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.view.footer_visible = status_line == 1 and true or false
|
|
|
|
self.ui.document:setStatusLineProp(status_line)
|
|
|
|
self.ui:handleEvent(Event:new("UpdatePos"))
|
2014-02-12 07:26:56 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return ReaderFooter
|