Initial light control widget; final fixes for kobo light

pull/201/head
Giorgio Micotti 11 years ago
parent 68af46f495
commit cea353323e

@ -105,6 +105,13 @@ function Device:isTouchDevice()
return (self.model == "KindlePaperWhite") or (self.model == "KindleTouch") or self:isKobo() or util.isEmulated()
end
function Device:hasFrontlight()
if not self.model then
self.model = self:getModel()
end
return (self.model == "KindlePaperWhite") or (self.model == "Kobo_dragon") or (self.model == "Kobo_kraken") or (self.model == "Kobo_phoenix") or util.isEmulated()
end
function Device:setTouchInputDev(dev)
self.touch_dev = dev
end

@ -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

@ -56,7 +56,14 @@ function ReaderMenu:setUpdateItemTable()
for _, widget in pairs(self.registered_widgets) do
widget:addToMainMenu(self.tab_item_table)
end
if Device:hasFrontlight() then
table.insert(self.tab_item_table.main, {
text = _("Frontlight settings"),
callback = function()
ReaderFrontLight:onShowFlDialog()
end
})
end
table.insert(self.tab_item_table.main, {
text = _("Help"),
callback = function()

@ -129,14 +129,14 @@ function ReaderUI:init()
view = self[1],
ui = self
}
table.insert(self.active_widgets, reader_ss)
-- frontlight controller
local reader_fl = ReaderFrontLight:new{
dialog = self.dialog,
view = self[1],
ui = self
}
table.insert(self.active_widgets, reader_ss)
table.insert(self.active_widgets, reader_fl)
table.insert(self, reader_fl)
if self.document.info.has_pages then
-- for page specific controller

@ -1,6 +1,7 @@
require "ui/widget/container"
require "ui/widget/focusmanager"
require "ui/widget/infomessage"
require "ui/widget/frontlight"
require "ui/widget/button"
require "ui/widget/text"
require "ui/widget/group"

Loading…
Cancel
Save