Merge pull request #2002 from koreader/houqp-master

Support page keys in dictionary window
pull/2004/head
Frans de Jonge 8 years ago
commit 19c4836166

@ -4,10 +4,11 @@ local VerticalScrollBar = require("ui/widget/verticalscrollbar")
local Geom = require("ui/geometry")
local GestureRange = require("ui/gesturerange")
local UIManager = require("ui/uimanager")
local Screen = require("device").screen
local Device = require("device")
local Screen = Device.screen
local Input = Device.input
local HorizontalGroup = require("ui/widget/horizontalgroup")
local HorizontalSpan = require("ui/widget/horizontalspan")
local Device = require("device")
local Blitbuffer = require("ffi/blitbuffer")
--[[
@ -57,6 +58,12 @@ function ScrollTextWidget:init()
},
}
end
if Device:hasKeyboard() or Device:hasKeys() then
self.key_events = {
ScrollDown = {{Input.group.PgFwd}, doc = "scroll down"},
ScrollUp = {{Input.group.PgBack}, doc = "scroll up"},
}
end
end
function ScrollTextWidget:updateScrollBar(text)
@ -69,17 +76,36 @@ function ScrollTextWidget:updateScrollBar(text)
)
end
function ScrollTextWidget:onScrollText(arg, ges)
if ges.direction == "north" then
function ScrollTextWidget:scrollText(direction)
if direction == 0 then return end
if direction > 0 then
self.text_widget:scrollDown()
self:updateScrollBar(self.text_widget)
elseif ges.direction == "south" then
else
self.text_widget:scrollUp()
self:updateScrollBar(self.text_widget)
end
self:updateScrollBar(self.text_widget)
UIManager:setDirty(self.dialog, function()
return "partial", self.dimen
end)
end
function ScrollTextWidget:onScrollText(arg, ges)
if ges.direction == "north" then
self:scrollText(1)
elseif ges.direction == "south" then
self:scrollText(-1)
end
return true
end
function ScrollTextWidget:onScrollDown()
self:scrollText(1)
return true
end
function ScrollTextWidget:onScrollUp()
self:scrollText(-1)
return true
end
return ScrollTextWidget

@ -95,4 +95,68 @@ describe("device module", function()
mock_input.open:revert()
end)
end)
describe("kindle", function()
it("should initialize voyager without error", function()
package.loaded['ffi/framebuffer_mxcfb'] = mock_fb
stub(io, "open")
io.open.returns({
read = function()
return "XX13XX"
end,
close = function() end
})
mock_input = require('device/input')
stub(mock_input, "open")
local kindle_dev = require("device/kindle/device")
assert.is.same(kindle_dev.model, "KindleVoyage")
kindle_dev:init()
assert.is.same(kindle_dev.input.event_map[104], "LPgBack")
assert.is.same(kindle_dev.input.event_map[109], "LPgFwd")
assert.is.same(kindle_dev.powerd.fl_min, 0)
assert.is.same(kindle_dev.powerd.fl_max, 24)
io.open:revert()
package.loaded['ffi/framebuffer_mxcfb'] = nil
mock_input.open:revert()
end)
it("should toggle frontlight", function()
package.loaded['ffi/framebuffer_mxcfb'] = mock_fb
stub(io, "open")
io.open.returns({
read = function()
return "12"
end,
close = function() end
})
mock_input = require('device/input')
stub(mock_input, "open")
stub(os, "execute")
local kindle_dev = require("device/kindle/device")
kindle_dev:init()
assert.is.same(kindle_dev.powerd.fl_intensity, 12)
kindle_dev.powerd:setIntensity(5)
assert.stub(os.execute).was_called_with(
"echo -n 5 > /sys/class/backlight/max77696-bl/brightness")
assert.is.same(kindle_dev.powerd.fl_intensity, 5)
kindle_dev.powerd:toggleFrontlight()
assert.stub(os.execute).was_called_with(
"echo -n 0 > /sys/class/backlight/max77696-bl/brightness")
assert.is.same(kindle_dev.powerd.fl_intensity, 5)
kindle_dev.powerd:toggleFrontlight()
assert.stub(os.execute).was_called_with(
"echo -n 5 > /sys/class/backlight/max77696-bl/brightness")
io.open:revert()
package.loaded['ffi/framebuffer_mxcfb'] = nil
mock_input.open:revert()
os.execute:revert()
end)
end)
end)

Loading…
Cancel
Save