2
0
mirror of https://github.com/koreader/koreader synced 2024-11-10 01:10:34 +00:00
koreader/frontend/apps/reader/modules/readerfrontlight.lua

106 lines
3.2 KiB
Lua
Raw Normal View History

2013-10-18 20:38:07 +00:00
local InputContainer = require("ui/widget/container/inputcontainer")
2014-03-11 15:40:00 +00:00
local Notification = require("ui/widget/notification")
local GestureRange = require("ui/gesturerange")
local UIManager = require("ui/uimanager")
local Screen = require("device").screen
local Device = require("device")
local logger = require("logger")
local T = require("ffi/util").template
2014-03-11 15:40:00 +00:00
local _ = require("gettext")
2014-03-11 15:40:00 +00:00
local ReaderFrontLight = InputContainer:new{
steps = {0,1,1,1,1,2,2,2,3,4,5,6,7,8,9,10},
gestureScale = Screen:getWidth() * FRONTLIGHT_SENSITIVITY_DECREASE,
2014-03-11 15:40:00 +00:00
}
function ReaderFrontLight:init()
2014-03-11 15:40:00 +00:00
if Device:isTouchDevice() then
self.ges_events = {
Adjust = {
GestureRange:new{
ges = "two_finger_pan",
rate = Device.model ~= 'Kobo_phoenix' and 3.0 or nil,
2014-03-11 15:40:00 +00:00
}
},
PanRelease= {
GestureRange:new{
ges = "two_finger_pan_release",
}
},
Swipe = {
GestureRange:new{
ges = "two_finger_swipe",
}
},
}
end
2014-04-06 16:25:10 +00:00
end
2014-03-11 15:40:00 +00:00
function ReaderFrontLight:onAdjust(arg, ges)
if not Device.hasFrontlight() then return true end
2014-03-11 15:40:00 +00:00
local powerd = Device:getPowerDevice()
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 15:40:00 +00:00
end
return true
end
2014-03-11 15:40:00 +00:00
function ReaderFrontLight:onShowIntensity()
if not Device.hasFrontlight() then return true end
2014-03-11 15:40:00 +00:00
local powerd = Device:getPowerDevice()
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 15:40:00 +00:00
end
UIManager:show(Notification:new{
text = new_text,
timeout = 2,
})
2014-03-12 09:05:38 +00:00
return true
2014-03-11 15:40:00 +00:00
end
function ReaderFrontLight:onSwipe(arg, ges)
if ges.direction == "north" or ges.direction == "south" then
logger.dbg("onSwipe activated")
2014-03-11 15:40:00 +00:00
return self:onShowIntensity()
end
end
2014-03-11 15:40:00 +00:00
function ReaderFrontLight:onPanRelease(arg, ges)
logger.dbg("onPanRelease activated")
2014-03-11 15:40:00 +00:00
return self:onShowIntensity()
end
function ReaderFrontLight:onShowFlDialog()
2016-12-01 17:58:06 +00:00
local FrontLightWidget = require("ui/widget/frontlightwidget")
2016-12-25 07:43:58 +00:00
UIManager:show(FrontLightWidget:new{})
end
function ReaderFrontLight:close()
2014-03-12 09:05:38 +00:00
self.fl_dialog:onClose()
UIManager:close(self.fl_dialog)
end
2013-10-18 20:38:07 +00:00
return ReaderFrontLight