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{
|
2013-08-11 00:00:13 +00:00
|
|
|
fldial_menu_title = _("Frontlight settings"),
|
|
|
|
fl_dialog_title = _("Frontlight Level"),
|
2013-04-14 13:17:52 +00:00
|
|
|
steps = {0,1,2,3,4,5,6,7,8,9,10},
|
|
|
|
intensity = nil,
|
2013-08-02 09:08:36 +00:00
|
|
|
fl = nil,
|
2013-04-14 13:17:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderFrontLight:init()
|
2013-08-11 00:00:13 +00:00
|
|
|
if not Device:hasFrontlight() then return end
|
2013-04-14 13:17:52 +00:00
|
|
|
local dev_mod = Device:getModel()
|
|
|
|
if dev_mod == "KindlePaperWhite" then
|
|
|
|
require "liblipclua"
|
|
|
|
self.lipc_handle = lipc.init("com.github.koreader")
|
2013-04-20 03:08:12 +00:00
|
|
|
if self.lipc_handle then
|
|
|
|
self.intensity = self.lipc_handle:get_int_property("com.lab126.powerd", "flIntensity")
|
|
|
|
end
|
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-11 00:00:13 +00:00
|
|
|
elseif Device:isKobo() then
|
2013-08-02 09:08:36 +00:00
|
|
|
self.fl = kobolight.open()
|
2013-08-05 21:06:26 +00:00
|
|
|
self.intensity = G_reader_settings:readSetting("frontlight_intensity")
|
|
|
|
if not self.intensity then
|
|
|
|
self.intensity = 20
|
|
|
|
end
|
2013-08-11 00:00:13 +00:00
|
|
|
self:setIntensity(self.intensity, _("Set intensity "))
|
|
|
|
self.key_events.Toggle = { {"Light"}, doc = _("Toggle light") }
|
2013-04-14 13:17:52 +00:00
|
|
|
end
|
2013-08-11 00:00:13 +00:00
|
|
|
self.ui.menu:registerToMainMenu(self)
|
2013-04-14 13:17:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFrontLight:onAdjust(arg, ges)
|
2013-04-20 03:08:12 +00:00
|
|
|
if self.lipc_handle and self.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-04-14 13:17:52 +00:00
|
|
|
local msg = ""
|
|
|
|
if ges.direction == "north" then
|
|
|
|
msg = _("Increase front light intensity to ")
|
|
|
|
self.intensity = self.intensity + delta_int
|
|
|
|
self:setIntensity(self.intensity, msg)
|
|
|
|
elseif ges.direction == "south" then
|
|
|
|
msg = _("Decrease front light intensity to ")
|
|
|
|
self.intensity = self.intensity - delta_int
|
|
|
|
self:setIntensity(self.intensity, msg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFrontLight:setIntensity(intensity, msg)
|
2013-08-05 21:06:26 +00:00
|
|
|
if self.lipc_handle then
|
2013-04-14 13:17:52 +00:00
|
|
|
intensity = intensity < 0 and 0 or intensity
|
|
|
|
intensity = intensity > 24 and 24 or intensity
|
2013-07-22 12:23:58 +00:00
|
|
|
self.intensity = intensity
|
2013-04-14 13:17:52 +00:00
|
|
|
self.lipc_handle:set_int_property("com.lab126.powerd", "flIntensity", intensity)
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = msg..intensity,
|
|
|
|
timeout = 1
|
|
|
|
})
|
2013-08-11 00:00:13 +00:00
|
|
|
elseif Device:isKobo() then
|
2013-08-05 21:06:26 +00:00
|
|
|
intensity = intensity < 1 and 1 or intensity
|
|
|
|
intensity = intensity > 100 and 100 or intensity
|
2013-08-02 09:08:36 +00:00
|
|
|
if self.fl ~= nil then
|
|
|
|
self.fl:setBrightness(intensity)
|
|
|
|
self.intensity = intensity
|
2013-07-23 17:40:26 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-08-11 00:00:13 +00:00
|
|
|
function ReaderFrontLight:onToggle()
|
|
|
|
if Device:isKobo() and self.fl ~= nil then
|
|
|
|
self.fl:toggle()
|
2013-07-23 17:40:26 +00:00
|
|
|
end
|
2013-04-14 13:17:52 +00:00
|
|
|
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, {
|
|
|
|
text = self.fldial_menu_title,
|
|
|
|
callback = function()
|
|
|
|
self:onShowFlDialog()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFrontLight:onShowFlDialog()
|
|
|
|
DEBUG("show fldial dialog")
|
|
|
|
self.fl_dialog = InputDialog:new{
|
|
|
|
title = self.fl_dialog_title,
|
2013-08-11 00:00:13 +00:00
|
|
|
input_hint = Device:isKobo() and "(1 - 100)" or "(0 - 24)",
|
2013-08-05 21:06:26 +00:00
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
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()
|
|
|
|
G_reader_settings:saveSetting("frontlight_intensity", self.intensity)
|
|
|
|
UIManager:close(self.fl_dialog)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFrontLight:fldialIntensity()
|
|
|
|
local number = tonumber(self.fl_dialog:getInputText())
|
|
|
|
if number then
|
2013-08-11 00:00:13 +00:00
|
|
|
self:setIntensity(number, _("Set intensity "))
|
2013-08-05 21:06:26 +00:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|