Initial light control widget; final fixes for kobo light

This commit is contained in:
Giorgio Micotti
2013-08-05 23:06:26 +02:00
parent 68af46f495
commit cea353323e
5 changed files with 86 additions and 5 deletions

View File

@@ -1,7 +1,10 @@
require "ui/widget/container"
require "ui/widget/inputdialog"
require "ui/device"
ReaderFrontLight = InputContainer:new{
fldial_menu_title = ("Frontlight Settings"),
fl_dialog_title = ("Frontlight Level"),
steps = {0,1,2,3,4,5,6,7,8,9,10},
intensity = nil,
fl = nil,
@@ -31,7 +34,11 @@ function ReaderFrontLight:init()
end
if Device:isKobo() then
self.fl = kobolight.open()
self.intensity = 20
self.intensity = G_reader_settings:readSetting("frontlight_intensity")
if not self.intensity then
self.intensity = 20
end
self:setIntensity(self.intensity, "Set intensity")
end
end
@@ -54,7 +61,7 @@ function ReaderFrontLight:onAdjust(arg, ges)
end
function ReaderFrontLight:setIntensity(intensity, msg)
if self.lipc_handle then
if self.lipc_handle then
intensity = intensity < 0 and 0 or intensity
intensity = intensity > 24 and 24 or intensity
self.intensity = intensity
@@ -65,6 +72,8 @@ function ReaderFrontLight:setIntensity(intensity, msg)
})
end
if Device:isKobo() then
intensity = intensity < 1 and 1 or intensity
intensity = intensity > 100 and 100 or intensity
if self.fl == nil then
ReaderFrontLight:init()
end
@@ -87,3 +96,60 @@ function ReaderFrontLight:toggle()
end
return true
end
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,
input_hint = "(1 - 100)",
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
self:setIntensity(number, "Set intensity")
end
return true
end