2013-10-18 22:38:07 +02:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2014-03-11 23:40:00 +08:00
|
|
|
local Notification = require("ui/widget/notification")
|
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
|
local UIManager = require("ui/uimanager")
|
2014-10-30 19:42:18 +01:00
|
|
|
local Screen = require("device").screen
|
|
|
|
|
local Device = require("device")
|
2016-12-29 00:10:38 -08:00
|
|
|
local logger = require("logger")
|
2014-11-29 15:45:18 +01:00
|
|
|
local T = require("ffi/util").template
|
2014-03-11 23:40:00 +08:00
|
|
|
local _ = require("gettext")
|
2013-04-14 21:17:52 +08:00
|
|
|
|
2014-03-11 23:40:00 +08:00
|
|
|
local ReaderFrontLight = InputContainer:new{
|
2014-03-17 19:36:18 +01:00
|
|
|
steps = {0,1,1,1,1,2,2,2,3,4,5,6,7,8,9,10},
|
2014-06-11 20:50:38 +02:00
|
|
|
gestureScale = Screen:getWidth() * FRONTLIGHT_SENSITIVITY_DECREASE,
|
2014-03-11 23:40:00 +08:00
|
|
|
}
|
2014-06-11 20:52:45 +02:00
|
|
|
|
2013-04-14 21:17:52 +08:00
|
|
|
function ReaderFrontLight:init()
|
2014-03-11 23:40:00 +08:00
|
|
|
if Device:isTouchDevice() then
|
|
|
|
|
self.ges_events = {
|
|
|
|
|
Adjust = {
|
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "two_finger_pan",
|
2014-10-30 19:42:18 +01:00
|
|
|
rate = Device.model ~= 'Kobo_phoenix' and 3.0 or nil,
|
2014-03-11 23:40:00 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
PanRelease= {
|
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "two_finger_pan_release",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Swipe = {
|
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "two_finger_swipe",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
end
|
2014-04-07 00:25:10 +08:00
|
|
|
|
2013-04-14 21:17:52 +08:00
|
|
|
end
|
|
|
|
|
|
2014-03-11 23:40:00 +08:00
|
|
|
function ReaderFrontLight:onAdjust(arg, ges)
|
2017-06-14 10:32:16 -07:00
|
|
|
if not Device.hasFrontlight() then return true end
|
2014-03-11 23:40:00 +08:00
|
|
|
local powerd = Device:getPowerDevice()
|
2017-06-14 10:32:16 -07:00
|
|
|
logger.dbg("frontlight intensity", powerd:frontlightIntensity())
|
|
|
|
|
local step = math.ceil(#self.steps * ges.distance / self.gestureScale)
|
|
|
|
|
logger.dbg("step = ", step)
|
|
|
|
|
local delta_int = self.steps[step] or self.steps[#self.steps]
|
|
|
|
|
logger.dbg("delta_int = ", delta_int)
|
|
|
|
|
local new_intensity
|
|
|
|
|
if ges.direction == "north" then
|
|
|
|
|
new_intensity = powerd:frontlightIntensity() + delta_int
|
|
|
|
|
elseif ges.direction == "south" then
|
|
|
|
|
new_intensity = powerd:frontlightIntensity() - delta_int
|
|
|
|
|
end
|
|
|
|
|
if new_intensity == nil then return true end
|
|
|
|
|
-- when new_intensity <=0, toggle light off
|
|
|
|
|
if new_intensity <= 0 then
|
|
|
|
|
powerd:turnOffFrontlight()
|
|
|
|
|
else
|
|
|
|
|
powerd:setIntensity(new_intensity)
|
|
|
|
|
end
|
|
|
|
|
if self.view.footer_visible and self.view.footer.settings.frontlight then
|
|
|
|
|
self.view.footer:updateFooter()
|
2014-03-11 23:40:00 +08:00
|
|
|
end
|
|
|
|
|
return true
|
2013-07-23 19:40:26 +02:00
|
|
|
end
|
|
|
|
|
|
2014-03-11 23:40:00 +08:00
|
|
|
function ReaderFrontLight:onShowIntensity()
|
2017-06-14 10:32:16 -07:00
|
|
|
if not Device.hasFrontlight() then return true end
|
2014-03-11 23:40:00 +08:00
|
|
|
local powerd = Device:getPowerDevice()
|
2017-06-14 10:32:16 -07:00
|
|
|
local new_text
|
|
|
|
|
if powerd:isFrontlightOff() then
|
|
|
|
|
new_text = _("Frontlight is off.")
|
|
|
|
|
else
|
|
|
|
|
new_text = T(_("Frontlight intensity is set to %1."), powerd:frontlightIntensity())
|
2014-03-11 23:40:00 +08:00
|
|
|
end
|
2017-06-14 10:32:16 -07:00
|
|
|
UIManager:show(Notification:new{
|
|
|
|
|
text = new_text,
|
2018-05-19 14:01:20 +02:00
|
|
|
timeout = 2,
|
2017-06-14 10:32:16 -07:00
|
|
|
})
|
2014-03-12 17:05:38 +08:00
|
|
|
return true
|
2014-03-11 23:40:00 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderFrontLight:onSwipe(arg, ges)
|
|
|
|
|
if ges.direction == "north" or ges.direction == "south" then
|
2016-12-29 00:10:38 -08:00
|
|
|
logger.dbg("onSwipe activated")
|
2014-03-11 23:40:00 +08:00
|
|
|
return self:onShowIntensity()
|
|
|
|
|
end
|
2014-03-11 15:04:01 +01:00
|
|
|
end
|
|
|
|
|
|
2014-03-11 23:40:00 +08:00
|
|
|
function ReaderFrontLight:onPanRelease(arg, ges)
|
2016-12-29 00:10:38 -08:00
|
|
|
logger.dbg("onPanRelease activated")
|
2014-03-11 23:40:00 +08:00
|
|
|
return self:onShowIntensity()
|
|
|
|
|
end
|
2014-03-11 15:04:01 +01:00
|
|
|
|
2013-08-05 23:06:26 +02:00
|
|
|
function ReaderFrontLight:onShowFlDialog()
|
2016-12-01 18:58:06 +01:00
|
|
|
local FrontLightWidget = require("ui/widget/frontlightwidget")
|
2016-12-24 23:43:58 -08:00
|
|
|
UIManager:show(FrontLightWidget:new{})
|
2013-08-05 23:06:26 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderFrontLight:close()
|
2014-03-12 17:05:38 +08:00
|
|
|
self.fl_dialog:onClose()
|
|
|
|
|
UIManager:close(self.fl_dialog)
|
2013-08-05 23:06:26 +02:00
|
|
|
end
|
|
|
|
|
|
2013-10-18 22:38:07 +02:00
|
|
|
return ReaderFrontLight
|