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 UIManager = require("ui/uimanager")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Screen = require("device").screen
|
|
|
|
local Device = require("device")
|
2014-11-29 14:45:18 +00:00
|
|
|
local T = require("ffi/util").template
|
2014-03-11 15:40:00 +00:00
|
|
|
local _ = require("gettext")
|
2013-04-14 13:17:52 +00:00
|
|
|
|
2014-03-11 15:40:00 +00:00
|
|
|
local ReaderFrontLight = InputContainer:new{
|
2019-08-01 17:08:09 +00:00
|
|
|
steps_fl = { 0.1, 0.1, 0.2, 0.4, 0.7, 1.1, 1.6, 2.2, 2.9, 3.7, 4.6, 5.6, 6.7, 7.9, 9.2, 10.6, },
|
2014-06-11 18:50:38 +00:00
|
|
|
gestureScale = Screen:getWidth() * FRONTLIGHT_SENSITIVITY_DECREASE,
|
2014-03-11 15:40:00 +00:00
|
|
|
}
|
2014-06-11 18:52:45 +00:00
|
|
|
|
2019-08-01 17:08:09 +00:00
|
|
|
-- direction +1 - increase frontlight
|
|
|
|
-- direction -1 - decrease frontlight
|
|
|
|
function ReaderFrontLight:onChangeFlIntensity(ges, direction)
|
|
|
|
local powerd = Device:getPowerDevice()
|
|
|
|
local gestureScale
|
2019-08-06 17:54:09 +00:00
|
|
|
local scale_multiplier
|
|
|
|
if ges.ges == "two_finger_swipe" then
|
|
|
|
-- for backward compatibility
|
|
|
|
scale_multiplier = FRONTLIGHT_SENSITIVITY_DECREASE * 0.8
|
|
|
|
elseif ges.ges == "swipe" then
|
|
|
|
scale_multiplier = 0.8
|
|
|
|
else
|
|
|
|
scale_multiplier = 1
|
|
|
|
end
|
2019-08-01 17:08:09 +00:00
|
|
|
if ges.direction == "south" or ges.direction == "north" then
|
2019-08-06 17:54:09 +00:00
|
|
|
gestureScale = Screen:getHeight() * scale_multiplier
|
2019-08-01 17:08:09 +00:00
|
|
|
elseif ges.direction == "west" or ges.direction == "east" then
|
2019-08-06 17:54:09 +00:00
|
|
|
gestureScale = Screen:getWidth() * scale_multiplier
|
2019-08-01 17:08:09 +00:00
|
|
|
else
|
|
|
|
local width = Screen:getWidth()
|
|
|
|
local height = Screen:getHeight()
|
|
|
|
-- diagonal
|
2019-08-06 17:54:09 +00:00
|
|
|
gestureScale = math.sqrt(width * width + height * height) * scale_multiplier
|
2019-08-01 17:08:09 +00:00
|
|
|
end
|
|
|
|
if powerd.fl_intensity == nil then return false end
|
|
|
|
|
|
|
|
local steps_tbl = {}
|
|
|
|
local scale = (powerd.fl_max - powerd.fl_min) / 2 / 10.6
|
|
|
|
for i = 1, #self.steps_fl, 1
|
|
|
|
do
|
|
|
|
steps_tbl[i] = math.ceil(self.steps_fl[i] * scale)
|
|
|
|
end
|
|
|
|
|
|
|
|
if ges.distance == nil then
|
|
|
|
ges.distance = 1
|
|
|
|
end
|
|
|
|
local step = math.ceil(#steps_tbl * ges.distance / gestureScale)
|
|
|
|
local delta_int = steps_tbl[step] or steps_tbl[#steps_tbl]
|
|
|
|
if direction ~= -1 and direction ~= 1 then
|
|
|
|
-- set default value (increase frontlight)
|
|
|
|
direction = 1
|
|
|
|
end
|
|
|
|
local new_intensity = powerd.fl_intensity + direction * delta_int
|
|
|
|
|
|
|
|
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
|
|
|
|
self:onShowIntensity()
|
|
|
|
if self.view and self.view.footer_visible and self.view.footer.settings.frontlight then
|
|
|
|
self.view.footer:updateFooter()
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
-- direction +1 - increase frontlight warmth
|
|
|
|
-- direction -1 - decrease frontlight warmth
|
|
|
|
function ReaderFrontLight:onChangeFlWarmth(ges, direction)
|
|
|
|
local powerd = Device:getPowerDevice()
|
|
|
|
if powerd.fl_warmth == nil then return false end
|
|
|
|
|
|
|
|
if powerd.auto_warmth then
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = _("Warmth is handled automatically."),
|
|
|
|
timeout = 1.0,
|
|
|
|
})
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
local gestureScale
|
2019-08-06 17:54:09 +00:00
|
|
|
local scale_multiplier
|
|
|
|
if ges.ges == "two_finger_swipe" then
|
|
|
|
-- for backward compatibility
|
|
|
|
scale_multiplier = FRONTLIGHT_SENSITIVITY_DECREASE * 0.8
|
|
|
|
elseif ges.ges == "swipe" then
|
|
|
|
scale_multiplier = 0.8
|
|
|
|
else
|
|
|
|
scale_multiplier = 1
|
|
|
|
end
|
|
|
|
|
2019-08-01 17:08:09 +00:00
|
|
|
if ges.direction == "south" or ges.direction == "north" then
|
2019-08-06 17:54:09 +00:00
|
|
|
gestureScale = Screen:getHeight() * scale_multiplier
|
2019-08-01 17:08:09 +00:00
|
|
|
elseif ges.direction == "west" or ges.direction == "east" then
|
2019-08-06 17:54:09 +00:00
|
|
|
gestureScale = Screen:getWidth() * scale_multiplier
|
2019-08-01 17:08:09 +00:00
|
|
|
else
|
|
|
|
local width = Screen:getWidth()
|
|
|
|
local height = Screen:getHeight()
|
|
|
|
-- diagonal
|
2019-08-06 17:54:09 +00:00
|
|
|
gestureScale = math.sqrt(width * width + height * height) * scale_multiplier
|
2019-08-01 17:08:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local steps_tbl = {}
|
|
|
|
local scale = (powerd.fl_max - powerd.fl_min) / 2 / 10.6
|
|
|
|
for i = 1, #self.steps_fl, 1
|
|
|
|
do
|
|
|
|
steps_tbl[i] = math.ceil(self.steps_fl[i] * scale)
|
|
|
|
end
|
|
|
|
|
|
|
|
if ges.distance == nil then
|
|
|
|
ges.distance = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
local step = math.ceil(#steps_tbl * ges.distance / gestureScale)
|
|
|
|
local delta_int = steps_tbl[step] or steps_tbl[#steps_tbl]
|
|
|
|
local warmth
|
|
|
|
if direction ~= -1 and direction ~= 1 then
|
|
|
|
-- set default value (increase frontlight)
|
|
|
|
direction = 1
|
|
|
|
end
|
|
|
|
warmth = powerd.fl_warmth + direction * delta_int
|
|
|
|
if warmth > 100 then
|
|
|
|
warmth = 100
|
|
|
|
elseif warmth < 0 then
|
|
|
|
warmth = 0
|
|
|
|
end
|
|
|
|
powerd:setWarmth(warmth)
|
|
|
|
self:onShowWarmth()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function ReaderFrontLight:onShowOnOff()
|
|
|
|
local powerd = Device:getPowerDevice()
|
|
|
|
local new_text
|
|
|
|
if powerd.is_fl_on then
|
|
|
|
new_text = _("Frontlight enabled.")
|
|
|
|
else
|
|
|
|
new_text = _("Frontlight disabled.")
|
|
|
|
end
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = new_text,
|
|
|
|
timeout = 1.0,
|
|
|
|
})
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2014-03-11 15:40:00 +00:00
|
|
|
function ReaderFrontLight:onShowIntensity()
|
2019-04-08 21:05:08 +00:00
|
|
|
if not Device:hasFrontlight() then return true end
|
2014-03-11 15:40:00 +00:00
|
|
|
local powerd = Device:getPowerDevice()
|
2017-06-14 17:32:16 +00:00
|
|
|
local new_text
|
|
|
|
if powerd:isFrontlightOff() then
|
2019-08-01 17:08:09 +00:00
|
|
|
new_text = _("Frontlight disabled.")
|
2017-06-14 17:32:16 +00:00
|
|
|
else
|
2019-08-24 07:25:38 +00:00
|
|
|
new_text = T(_("Frontlight intensity set to %1."), powerd:frontlightIntensity())
|
2014-03-11 15:40:00 +00:00
|
|
|
end
|
2017-06-14 17:32:16 +00:00
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = new_text,
|
2019-08-01 17:08:09 +00:00
|
|
|
timeout = 1,
|
2017-06-14 17:32:16 +00:00
|
|
|
})
|
2014-03-12 09:05:38 +00:00
|
|
|
return true
|
2014-03-11 15:40:00 +00:00
|
|
|
end
|
|
|
|
|
2019-08-01 17:08:09 +00:00
|
|
|
function ReaderFrontLight:onShowWarmth(value)
|
|
|
|
local powerd = Device:getPowerDevice()
|
|
|
|
if powerd.fl_warmth ~= nil then
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = T(_("Warmth set to %1."), powerd.fl_warmth),
|
|
|
|
timeout = 1.0,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-08-05 21:06:26 +00:00
|
|
|
function ReaderFrontLight:onShowFlDialog()
|
2016-12-01 17:58:06 +00:00
|
|
|
local FrontLightWidget = require("ui/widget/frontlightwidget")
|
2019-09-04 18:52:24 +00:00
|
|
|
UIManager:show(FrontLightWidget:new{
|
|
|
|
use_system_fl = Device:hasLightLevelFallback()
|
|
|
|
})
|
2013-08-05 21:06:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFrontLight:close()
|
2014-03-12 09:05:38 +00:00
|
|
|
self.fl_dialog:onClose()
|
|
|
|
UIManager:close(self.fl_dialog)
|
2013-08-05 21:06:26 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return ReaderFrontLight
|