2013-07-24 06:14:12 +00:00
|
|
|
require "ui/widget/container"
|
2013-08-05 21:06:26 +00:00
|
|
|
require "ui/widget/inputdialog"
|
2013-04-14 13:17:52 +00:00
|
|
|
require "ui/device"
|
|
|
|
|
|
|
|
ReaderFrontLight = InputContainer:new{
|
|
|
|
steps = {0,1,2,3,4,5,6,7,8,9,10},
|
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderFrontLight:init()
|
2013-08-12 05:11:54 +00:00
|
|
|
if Device:getFrontlight() ~= nil then
|
2013-07-23 17:40:26 +00:00
|
|
|
self.ges_events = {
|
|
|
|
Adjust = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "two_finger_pan",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
},
|
|
|
|
rate = 2.0,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
2013-08-12 05:11:54 +00:00
|
|
|
self.ui.menu:registerToMainMenu(self)
|
2013-04-14 13:17:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFrontLight:onAdjust(arg, ges)
|
2013-08-12 12:37:41 +00:00
|
|
|
local fl = Device:getFrontlight()
|
2013-08-12 05:11:54 +00:00
|
|
|
if fl.intensity ~= nil then
|
2013-04-14 13:17:52 +00:00
|
|
|
local rel_proportion = ges.distance / Screen:getWidth()
|
2013-07-22 12:23:58 +00:00
|
|
|
local delta_int = self.steps[math.ceil(#self.steps*rel_proportion)] or self.steps[#self.steps]
|
2013-08-12 05:11:54 +00:00
|
|
|
local msg = nil
|
2013-04-14 13:17:52 +00:00
|
|
|
if ges.direction == "north" then
|
|
|
|
msg = _("Increase front light intensity to ")
|
2013-08-12 05:11:54 +00:00
|
|
|
fl:setIntensity(fl.intensity + delta_int)
|
2013-04-14 13:17:52 +00:00
|
|
|
elseif ges.direction == "south" then
|
|
|
|
msg = _("Decrease front light intensity to ")
|
2013-08-12 05:11:54 +00:00
|
|
|
fl:setIntensity(fl.intensity - delta_int)
|
2013-04-14 13:17:52 +00:00
|
|
|
end
|
2013-08-12 05:11:54 +00:00
|
|
|
if msg ~= nil then
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = msg..fl.intensity,
|
|
|
|
timeout = 1
|
|
|
|
})
|
2013-07-23 17:40:26 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-08-05 21:06:26 +00:00
|
|
|
function ReaderFrontLight:addToMainMenu(tab_item_table)
|
|
|
|
-- insert fldial command to main reader menu
|
|
|
|
table.insert(tab_item_table.main, {
|
2013-08-12 05:11:54 +00:00
|
|
|
text = _("Frontlight settings"),
|
2013-08-05 21:06:26 +00:00
|
|
|
callback = function()
|
|
|
|
self:onShowFlDialog()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFrontLight:onShowFlDialog()
|
2013-08-12 12:37:41 +00:00
|
|
|
local fl = Device:getFrontlight()
|
2013-08-05 21:06:26 +00:00
|
|
|
self.fl_dialog = InputDialog:new{
|
2013-08-12 05:11:54 +00:00
|
|
|
title = _("Frontlight Level"),
|
2013-08-12 12:37:41 +00:00
|
|
|
input_hint = ("(%d - %d)"):format(fl.min, fl.max),
|
2013-08-05 21:06:26 +00:00
|
|
|
buttons = {
|
|
|
|
{
|
2013-08-12 05:11:54 +00:00
|
|
|
{
|
|
|
|
text = _("Toggle"),
|
|
|
|
enabled = true,
|
|
|
|
callback = function()
|
2013-08-12 12:37:41 +00:00
|
|
|
fl:toggle()
|
2013-08-12 05:11:54 +00:00
|
|
|
end,
|
|
|
|
},
|
2013-08-05 21:06:26 +00:00
|
|
|
{
|
|
|
|
text = _("Apply"),
|
|
|
|
enabled = true,
|
|
|
|
callback = function()
|
|
|
|
self:fldialIntensity()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("OK"),
|
|
|
|
enabled = true,
|
|
|
|
callback = function()
|
|
|
|
self:fldialIntensity()
|
|
|
|
self:close()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
input_type = "number",
|
|
|
|
width = Screen:getWidth() * 0.8,
|
|
|
|
height = Screen:getHeight() * 0.2,
|
|
|
|
}
|
|
|
|
self.fl_dialog:onShowKeyboard()
|
|
|
|
UIManager:show(self.fl_dialog)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFrontLight:close()
|
|
|
|
self.fl_dialog:onClose()
|
2013-08-12 12:37:41 +00:00
|
|
|
G_reader_settings:saveSetting("frontlight_intensity", Device:getFrontlight().intensity)
|
2013-08-05 21:06:26 +00:00
|
|
|
UIManager:close(self.fl_dialog)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFrontLight:fldialIntensity()
|
|
|
|
local number = tonumber(self.fl_dialog:getInputText())
|
2013-08-12 05:11:54 +00:00
|
|
|
if number ~= nil then
|
2013-08-12 12:37:41 +00:00
|
|
|
Device:getFrontlight():setIntensity(number)
|
2013-08-05 21:06:26 +00:00
|
|
|
end
|
|
|
|
end
|