|
|
|
@ -1,84 +1,39 @@
|
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
|
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
|
|
|
|
|
local _ = require("gettext")
|
|
|
|
|
|
|
|
|
|
local ReaderFrontLight = InputContainer:new{
|
|
|
|
|
steps = {0,1,1,1,1,2,2,2,3,4,5,6,7,8,9,10},
|
|
|
|
|
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, },
|
|
|
|
|
gestureScale = Screen:getWidth() * FRONTLIGHT_SENSITIVITY_DECREASE,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ReaderFrontLight:init()
|
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
|
self.ges_events = {
|
|
|
|
|
Adjust = {
|
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "two_finger_pan",
|
|
|
|
|
rate = Device.model ~= 'Kobo_phoenix' and 3.0 or nil,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
PanRelease= {
|
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "two_finger_pan_release",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Swipe = {
|
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "two_finger_swipe",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderFrontLight:onAdjust(arg, ges)
|
|
|
|
|
if not Device:hasFrontlight() then return true end
|
|
|
|
|
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()
|
|
|
|
|
end
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- direction +1 - increase frontlight
|
|
|
|
|
-- direction -1 - decrease frontlight
|
|
|
|
|
function ReaderFrontLight:onChangeFlIntensity(ges, direction)
|
|
|
|
|
local powerd = Device:getPowerDevice()
|
|
|
|
|
local gestureScale
|
|
|
|
|
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
|
|
|
|
|
if ges.direction == "south" or ges.direction == "north" then
|
|
|
|
|
gestureScale = Screen:getHeight() * 0.8
|
|
|
|
|
gestureScale = Screen:getHeight() * scale_multiplier
|
|
|
|
|
elseif ges.direction == "west" or ges.direction == "east" then
|
|
|
|
|
gestureScale = Screen:getWidth() * 0.8
|
|
|
|
|
gestureScale = Screen:getWidth() * scale_multiplier
|
|
|
|
|
else
|
|
|
|
|
local width = Screen:getWidth()
|
|
|
|
|
local height = Screen:getHeight()
|
|
|
|
|
-- diagonal
|
|
|
|
|
gestureScale = math.sqrt(width * width + height * height) * 0.8
|
|
|
|
|
gestureScale = math.sqrt(width * width + height * height) * scale_multiplier
|
|
|
|
|
end
|
|
|
|
|
if powerd.fl_intensity == nil then return false end
|
|
|
|
|
|
|
|
|
@ -129,15 +84,25 @@ function ReaderFrontLight:onChangeFlWarmth(ges, direction)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local gestureScale
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
if ges.direction == "south" or ges.direction == "north" then
|
|
|
|
|
gestureScale = Screen:getHeight() * 0.8
|
|
|
|
|
gestureScale = Screen:getHeight() * scale_multiplier
|
|
|
|
|
elseif ges.direction == "west" or ges.direction == "east" then
|
|
|
|
|
gestureScale = Screen:getWidth() * 0.8
|
|
|
|
|
gestureScale = Screen:getWidth() * scale_multiplier
|
|
|
|
|
else
|
|
|
|
|
local width = Screen:getWidth()
|
|
|
|
|
local height = Screen:getHeight()
|
|
|
|
|
-- diagonal
|
|
|
|
|
gestureScale = math.sqrt(width * width + height * height) * 0.8
|
|
|
|
|
gestureScale = math.sqrt(width * width + height * height) * scale_multiplier
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local steps_tbl = {}
|
|
|
|
@ -212,18 +177,6 @@ function ReaderFrontLight:onShowWarmth(value)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderFrontLight:onSwipe(arg, ges)
|
|
|
|
|
if ges.direction == "north" or ges.direction == "south" then
|
|
|
|
|
logger.dbg("onSwipe activated")
|
|
|
|
|
return self:onShowIntensity()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderFrontLight:onPanRelease(arg, ges)
|
|
|
|
|
logger.dbg("onPanRelease activated")
|
|
|
|
|
return self:onShowIntensity()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderFrontLight:onShowFlDialog()
|
|
|
|
|
local FrontLightWidget = require("ui/widget/frontlightwidget")
|
|
|
|
|
UIManager:show(FrontLightWidget:new{})
|
|
|
|
|