GestureDetector: add Tap interval on keyboard setting

Follow up to b90f6db8: allow specifying an other
value for tap interval when the keyboard is shown
(a good value for tap interval on reader and UI
elements might be too long on the keyboard, and
prevent typing fast).
reviewable/pr6840/r1
poire-z 4 years ago
parent 8f2bdf959d
commit 74c1813a82

@ -154,12 +154,12 @@ end
--[[
tap2 is the later tap
--]]
function GestureDetector:isTapBounce(tap1, tap2)
function GestureDetector:isTapBounce(tap1, tap2, interval)
local tv_diff = tap2.timev - tap1.timev
return (
math.abs(tap1.x - tap2.x) < self.SINGLE_TAP_BOUNCE_DISTANCE and
math.abs(tap1.y - tap2.y) < self.SINGLE_TAP_BOUNCE_DISTANCE and
(tv_diff.sec == 0 and (tv_diff.usec) < ges_tap_interval)
(tv_diff.sec == 0 and (tv_diff.usec) < interval)
)
end
@ -393,9 +393,11 @@ function GestureDetector:handleDoubleTap(tev)
timev = tev.timev,
}
-- Tap interval / bounce detection may be tweaked by widget (i.e. VirtualKeyboard)
local tap_interval = self.input.tap_interval_override or ges_tap_interval
-- We do tap bounce detection even when double tap is enabled (so, double tap
-- is triggered when: ges_tap_interval <= delay < ges_double_tap_interval)
if ges_tap_interval > 0 and self.last_taps[slot] ~= nil and self:isTapBounce(self.last_taps[slot], cur_tap) then
if tap_interval > 0 and self.last_taps[slot] ~= nil and self:isTapBounce(self.last_taps[slot], cur_tap, tap_interval) then
logger.dbg("tap bounce detected in slot", slot, ": ignored")
-- Simply ignore it, and clear state as this is the end of a touch event
-- (this doesn't clear self.last_taps[slot], so a 3rd tap can be detected

@ -126,6 +126,7 @@ local Input = {
timer_callbacks = {},
disable_double_tap = true,
tap_interval_override = nil,
-- keyboard state:
modifiers = {

@ -399,6 +399,8 @@ function UIManager:show(widget, refreshtype, refreshregion, x, y, refreshdither)
else
Input.disable_double_tap = true
end
-- a widget may override tap interval (when it doesn't, nil restores the default)
Input.tap_interval_override = widget.tap_interval_override
end
--[[--
@ -460,6 +462,10 @@ function UIManager:close(widget, refreshtype, refreshregion, refreshdither)
if requested_disable_double_tap ~= nil then
Input.disable_double_tap = requested_disable_double_tap
end
if #self._window_stack > 0 then
-- set tap interval override to what the topmost widget specifies (when it doesn't, nil restores the default)
Input.tap_interval_override = self._window_stack[#self._window_stack].widget.tap_interval_override
end
if dirty and not widget.invisible then
-- schedule the remaining visible (i.e., uncovered) widgets to be painted
for i = start_idx, #self._window_stack do

@ -587,6 +587,7 @@ function VirtualKeyPopup:init()
}
},
}
self.tap_interval_override = G_reader_settings:readSetting("ges_tap_interval_on_keyboard") or 0
if Device:hasDPad() then
self.key_events.PressKey = { {"Press"}, doc = "select key" }
@ -693,6 +694,7 @@ function VirtualKeyboard:init()
self.min_layer = keyboard.min_layer
self.max_layer = keyboard.max_layer
self:initLayer(self.keyboard_layer)
self.tap_interval_override = G_reader_settings:readSetting("ges_tap_interval_on_keyboard") or 0
if Device:hasDPad() then
self.key_events.PressKey = { {"Press"}, doc = "select key" }
end

@ -497,6 +497,33 @@ Default value: %1]]), GestureDetector.TAP_INTERVAL/1000),
UIManager:show(items)
end,
},
{
text = _("Tap interval on keyboard"),
keep_menu_open = true,
callback = function()
local SpinWidget = require("ui/widget/spinwidget")
local items = SpinWidget:new{
title_text = _("Tap interval on keyboard"),
info_text = _([[
Any other taps made within this interval after a first tap will be considered accidental and ignored.
The interval value is in milliseconds and can range from 0 (0 second) to 2000 (2 seconds).
Default value: 0]]),
width = math.floor(Screen:getWidth() * 0.75),
value = (G_reader_settings:readSetting("ges_tap_interval_on_keyboard") or 0)/1000,
value_min = 0,
value_max = 2000,
value_step = 50,
value_hold_step = 200,
ok_text = _("Set interval"),
default_value = 0,
callback = function(spin)
G_reader_settings:saveSetting("ges_tap_interval_on_keyboard", spin.value*1000)
end
}
UIManager:show(items)
end,
},
{
text = _("Double tap interval"),
keep_menu_open = true,

Loading…
Cancel
Save