Merge pull request #527 from koreader/Frontlight

UPDATE readerfrontlight.lua
pull/528/head
Huang Xin 10 years ago
commit 6ae771a7f4

@ -1,57 +1,76 @@
local InputContainer = require("ui/widget/container/inputcontainer") local InputContainer = require("ui/widget/container/inputcontainer")
local InputDialog = require("ui/widget/inputdialog")
local Notification = require("ui/widget/notification")
local GestureRange = require("ui/gesturerange")
local UIManager = require("ui/uimanager")
local Geom = require("ui/geometry") local Geom = require("ui/geometry")
local Screen = require("ui/screen") local Screen = require("ui/screen")
local Device = require("ui/device") local Device = require("ui/device")
local GestureRange = require("ui/gesturerange") local DEBUG = require("dbg")
local InputDialog = require("ui/widget/inputdialog")
local UIManager = require("ui/uimanager")
local Notification = require("ui/widget/notification")
local _ = require("gettext") local _ = require("gettext")
local ReaderFrontLight = InputContainer:new{ local ReaderFrontLight = InputContainer:new{
steps = {0,1,2,3,4,5,6,7,8,9,10}, steps = {0,1,2,3,4,5,6,7,8,9,10},
} }
function ReaderFrontLight:init() function ReaderFrontLight:init()
if Device:isTouchDevice() then if Device:isTouchDevice() then
self.ges_events = { self.ges_events = {
Adjust = { Adjust = {
GestureRange:new{ GestureRange:new{
ges = "two_finger_pan", ges = "two_finger_pan",
range = Geom:new{ rate = Device:getModel() == 'Kobo_phoenix' and nil or 3.0,
x = 0, y = 0, }
w = Screen:getWidth(), },
h = Screen:getHeight(), PanRelease= {
}, GestureRange:new{
rate = 2.0, ges = "two_finger_pan_release",
} }
}, },
} Swipe = {
self.ui.menu:registerToMainMenu(self) GestureRange:new{
end ges = "two_finger_swipe",
}
},
}
self.ui.menu:registerToMainMenu(self)
end
end end
function ReaderFrontLight:onAdjust(arg, ges) function ReaderFrontLight:onAdjust(arg, ges)
local powerd = Device:getPowerDevice() local powerd = Device:getPowerDevice()
if powerd.flIntensity ~= nil then if powerd.flIntensity ~= nil then
local rel_proportion = ges.distance / Screen:getWidth() DEBUG("frontlight intensity", powerd.flIntensity)
local delta_int = self.steps[math.ceil(#self.steps*rel_proportion)] or self.steps[#self.steps] local rel_proportion = ges.distance / Screen:getWidth()
local msg = nil local delta_int = self.steps[math.ceil(#self.steps*rel_proportion)] or self.steps[#self.steps]
if ges.direction == "north" then local msg = nil
msg = _("Increase front light intensity to ") if ges.direction == "north" then
powerd:setIntensity(powerd.flIntensity + delta_int) powerd:setIntensity(powerd.flIntensity + delta_int)
elseif ges.direction == "south" then elseif ges.direction == "south" then
msg = _("Decrease front light intensity to ") powerd:setIntensity(powerd.flIntensity - delta_int)
powerd:setIntensity(powerd.flIntensity - delta_int) end
end end
if msg ~= nil then return true
UIManager:show(Notification:new{ end
text = msg..powerd.flIntensity,
timeout = 1 function ReaderFrontLight:onShowIntensity()
}) local powerd = Device:getPowerDevice()
end if powerd.flIntensity ~= nil then
end UIManager:show(Notification:new{
return true text = _("Frontlight intensity is set to ")..powerd.flIntensity,
timeout = 1.0,
})
end
end
function ReaderFrontLight:onSwipe(arg, ges)
if ges.direction == "north" or ges.direction == "south" then
return self:onShowIntensity()
end
end
function ReaderFrontLight:onPanRelease(arg, ges)
return self:onShowIntensity()
end end
function ReaderFrontLight:addToMainMenu(tab_item_table) function ReaderFrontLight:addToMainMenu(tab_item_table)

Loading…
Cancel
Save