2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2014-03-11 15:40:00 +00:00
|
|
|
local InputDialog = require("ui/widget/inputdialog")
|
|
|
|
local Notification = require("ui/widget/notification")
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
local UIManager = require("ui/uimanager")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Screen = require("device").screen
|
|
|
|
local Device = require("device")
|
2014-03-11 14:04:01 +00:00
|
|
|
local DEBUG = require("dbg")
|
2014-11-29 14:45:18 +00:00
|
|
|
local T = require("ffi/util").template
|
2014-03-11 15:40:00 +00:00
|
|
|
local _ = require("gettext")
|
2013-04-14 13:17:52 +00:00
|
|
|
|
2014-03-11 15:40:00 +00:00
|
|
|
local ReaderFrontLight = InputContainer:new{
|
2014-03-17 18:36:18 +00:00
|
|
|
steps = {0,1,1,1,1,2,2,2,3,4,5,6,7,8,9,10},
|
2014-06-11 18:50:38 +00:00
|
|
|
gestureScale = Screen:getWidth() * FRONTLIGHT_SENSITIVITY_DECREASE,
|
2014-03-11 15:40:00 +00:00
|
|
|
}
|
2014-06-11 18:52:45 +00:00
|
|
|
|
2013-04-14 13:17:52 +00:00
|
|
|
function ReaderFrontLight:init()
|
2014-03-11 15:40:00 +00:00
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events = {
|
|
|
|
Adjust = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "two_finger_pan",
|
2014-10-30 18:42:18 +00:00
|
|
|
rate = Device.model ~= 'Kobo_phoenix' and 3.0 or nil,
|
2014-03-11 15:40:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
PanRelease= {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "two_finger_pan_release",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Swipe = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "two_finger_swipe",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
2014-04-06 16:25:10 +00:00
|
|
|
|
2013-04-14 13:17:52 +00:00
|
|
|
end
|
|
|
|
|
2014-03-11 15:40:00 +00:00
|
|
|
function ReaderFrontLight:onAdjust(arg, ges)
|
|
|
|
local powerd = Device:getPowerDevice()
|
|
|
|
if powerd.flIntensity ~= nil then
|
|
|
|
DEBUG("frontlight intensity", powerd.flIntensity)
|
2014-06-11 18:50:38 +00:00
|
|
|
local step = math.ceil(#self.steps * ges.distance / self.gestureScale)
|
2014-04-06 16:25:10 +00:00
|
|
|
DEBUG("step = ", step)
|
2014-03-17 18:36:18 +00:00
|
|
|
local delta_int = self.steps[step] or self.steps[#self.steps]
|
2014-04-06 16:25:10 +00:00
|
|
|
DEBUG("delta_int = ", delta_int)
|
2016-01-07 14:30:28 +00:00
|
|
|
local new_intensity
|
2014-03-11 15:40:00 +00:00
|
|
|
if ges.direction == "north" then
|
2016-01-07 14:30:28 +00:00
|
|
|
new_intensity = powerd.flIntensity + delta_int
|
2014-03-11 15:40:00 +00:00
|
|
|
elseif ges.direction == "south" then
|
2016-01-07 14:30:28 +00:00
|
|
|
new_intensity = powerd.flIntensity - delta_int
|
|
|
|
end
|
|
|
|
if new_intensity ~= nil then
|
|
|
|
powerd:setIntensity(new_intensity)
|
2014-03-11 15:40:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
2013-07-23 17:40:26 +00:00
|
|
|
end
|
|
|
|
|
2014-03-11 15:40:00 +00:00
|
|
|
function ReaderFrontLight:onShowIntensity()
|
|
|
|
local powerd = Device:getPowerDevice()
|
|
|
|
if powerd.flIntensity ~= nil then
|
|
|
|
UIManager:show(Notification:new{
|
2014-11-28 13:10:37 +00:00
|
|
|
text = T( _("Frontlight intensity is set to %1."), powerd.flIntensity),
|
2014-03-11 15:40:00 +00:00
|
|
|
timeout = 1.0,
|
|
|
|
})
|
|
|
|
end
|
2014-03-12 09:05:38 +00:00
|
|
|
return true
|
2014-03-11 15:40:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFrontLight:onSwipe(arg, ges)
|
|
|
|
if ges.direction == "north" or ges.direction == "south" then
|
2014-04-06 16:25:10 +00:00
|
|
|
DEBUG("onSwipe activated")
|
2014-03-11 15:40:00 +00:00
|
|
|
return self:onShowIntensity()
|
|
|
|
end
|
2014-03-11 14:04:01 +00:00
|
|
|
end
|
|
|
|
|
2014-03-11 15:40:00 +00:00
|
|
|
function ReaderFrontLight:onPanRelease(arg, ges)
|
2014-04-06 16:25:10 +00:00
|
|
|
DEBUG("onPanRelease activated")
|
2014-03-11 15:40:00 +00:00
|
|
|
return self:onShowIntensity()
|
|
|
|
end
|
2014-03-11 14:04:01 +00:00
|
|
|
|
2013-08-05 21:06:26 +00:00
|
|
|
function ReaderFrontLight:onShowFlDialog()
|
2014-03-12 09:05:38 +00:00
|
|
|
local powerd = Device:getPowerDevice()
|
|
|
|
self.fl_dialog = InputDialog:new{
|
2014-11-21 14:41:14 +00:00
|
|
|
title = _("Frontlight level"),
|
2014-03-12 09:05:38 +00:00
|
|
|
input_hint = ("(%d - %d)"):format(powerd.fl_min, powerd.fl_max),
|
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Toggle"),
|
|
|
|
enabled = true,
|
|
|
|
callback = function()
|
|
|
|
self.fl_dialog.input:setText("")
|
|
|
|
powerd:toggleFrontlight()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Apply"),
|
|
|
|
enabled = true,
|
|
|
|
callback = function()
|
|
|
|
self:fldialIntensity()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("OK"),
|
|
|
|
enabled = true,
|
|
|
|
callback = function()
|
|
|
|
self:fldialIntensity()
|
|
|
|
self:close()
|
|
|
|
end,
|
|
|
|
},
|
2013-08-05 21:06:26 +00:00
|
|
|
|
2014-03-12 09:05:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
input_type = "number",
|
|
|
|
width = Screen:getWidth() * 0.8,
|
|
|
|
height = Screen:getHeight() * 0.2,
|
|
|
|
}
|
|
|
|
self.fl_dialog:onShowKeyboard()
|
|
|
|
UIManager:show(self.fl_dialog)
|
2013-08-05 21:06:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFrontLight:close()
|
2014-03-12 09:05:38 +00:00
|
|
|
self.fl_dialog:onClose()
|
|
|
|
UIManager:close(self.fl_dialog)
|
2013-08-05 21:06:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFrontLight:fldialIntensity()
|
2014-03-12 09:05:38 +00:00
|
|
|
local number = tonumber(self.fl_dialog:getInputText())
|
|
|
|
if number ~= nil then
|
|
|
|
Device:getPowerDevice():setIntensity(number)
|
|
|
|
end
|
2013-08-05 21:06:26 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
return ReaderFrontLight
|