[feat, UX] Support the virtualKeyboard on non touch-device (#3796)

* [VirtualKeyboard] Add support for keynaviguation

Also rename the variable "layout" to "keyboard_layout" because conflict
with the layout from the focusmanager

* Make the goto dialog compatible with key naviguation

My solution is to change the order of the widget. The last one will the
virtualkeybard so it catch all the keybinding, and below it, make the
dialog "is_always_active = true" so it can receive touch event.

* Correctly show the virtual keyboard on dpad devices

* change the order to call the virtualKeyboard so it end up on top

* Handle the multi input dialog

* Support reopening the virtualKeyboard by the Press key

* add check focusmanager

* Fix https://github.com/koreader/koreader/issues/3797

* MultiInputDialog : Now work on non touch-device

* Set the virtualkeyboard to be a modal widget

* Fix the layout in multiinputwidget

* Fix for the various combination of
hasKeys,hasDpad,isTouchDevice

* [Focusmanager] Better handling of malformed layout
This commit is contained in:
onde2rock
2018-03-30 12:46:36 +02:00
committed by Frans de Jonge
parent 6c3ace9940
commit e502bf04d3
31 changed files with 178 additions and 107 deletions

View File

@@ -39,58 +39,76 @@ local InputText = InputContainer:new{
}
-- only use PhysicalKeyboard if the device does not have touch screen
if Device.isTouchDevice() then
if Device.isTouchDevice() or Device.hasDPad() then
Keyboard = require("ui/widget/virtualkeyboard")
function InputText:initEventListener()
self.ges_events = {
TapTextBox = {
GestureRange:new{
ges = "tap",
range = self.dimen
}
},
HoldTextBox = {
GestureRange:new{
ges = "hold",
range = self.dimen
}
},
}
end
if Device.isTouchDevice() then
function InputText:initEventListener()
self.ges_events = {
TapTextBox = {
GestureRange:new{
ges = "tap",
range = self.dimen
}
},
HoldTextBox = {
GestureRange:new{
ges = "hold",
range = self.dimen
}
},
}
end
function InputText:onTapTextBox(arg, ges)
if self.parent.onSwitchFocus then
self.parent:onSwitchFocus(self)
end
local x = ges.pos.x - self._frame_textwidget.dimen.x - self.bordersize - self.padding
local y = ges.pos.y - self._frame_textwidget.dimen.y - self.bordersize - self.padding
if x > 0 and y > 0 then
self.charpos = self.text_widget:moveCursor(x, y)
UIManager:setDirty(self.parent, function()
return "ui", self.dimen
end)
end
end
function InputText:onHoldTextBox(arg, ges)
if self.parent.onSwitchFocus then
self.parent:onSwitchFocus(self)
end
local x = ges.pos.x - self._frame_textwidget.dimen.x - self.bordersize - self.padding
local y = ges.pos.y - self._frame_textwidget.dimen.y - self.bordersize - self.padding
if x > 0 and y > 0 then
self.charpos = self.text_widget:moveCursor(x, y)
if Device:hasClipboard() and Device.input.hasClipboardText() then
self:addChars(Device.input.getClipboardText())
function InputText:onTapTextBox(arg, ges)
if self.parent.onSwitchFocus then
self.parent:onSwitchFocus(self)
end
local x = ges.pos.x - self._frame_textwidget.dimen.x - self.bordersize - self.padding
local y = ges.pos.y - self._frame_textwidget.dimen.y - self.bordersize - self.padding
if x > 0 and y > 0 then
self.charpos = self.text_widget:moveCursor(x, y)
UIManager:setDirty(self.parent, function()
return "ui", self.dimen
end)
end
end
function InputText:onHoldTextBox(arg, ges)
if self.parent.onSwitchFocus then
self.parent:onSwitchFocus(self)
end
local x = ges.pos.x - self._frame_textwidget.dimen.x - self.bordersize - self.padding
local y = ges.pos.y - self._frame_textwidget.dimen.y - self.bordersize - self.padding
if x > 0 and y > 0 then
self.charpos = self.text_widget:moveCursor(x, y)
if Device:hasClipboard() and Device.input.hasClipboardText() then
self:addChars(Device.input.getClipboardText())
end
UIManager:setDirty(self.parent, function()
return "ui", self.dimen
end)
end
UIManager:setDirty(self.parent, function()
return "ui", self.dimen
end)
end
end
elseif not Device.hasKeyboard() then
Keyboard = require("ui/widget/virtualkeyboard")
function InputText:initEventListener() end --do nothing but doesn't crash for now
if Device.hasKeys() then
if not InputText.initEventListener then
function InputText:initEventListener() end
end
function InputText:onFocus()
--Event called by the focusmanager
self.key_events.ShowKeyboard = { {"Press"}, doc = "show keyboard" }
self:focus()
return true
end
function InputText:onUnfocus()
--Event called by the focusmanager
self.key_events = {}
self:unfocus()
return true
end
end
else
Keyboard = require("ui/widget/physicalkeyboard")
function InputText:initEventListener() end
@@ -219,8 +237,9 @@ function InputText:initKeyboard()
if self.input_type == "number" then
keyboard_layout = 4
end
self.key_events = nil
self.keyboard = Keyboard:new{
layout = keyboard_layout,
keyboard_layout = keyboard_layout,
inputbox = self,
width = Screen:getWidth(),
}
@@ -229,17 +248,18 @@ end
function InputText:unfocus()
self.focused = false
self.text_widget:unfocus()
self[1].color = Blitbuffer.COLOR_GREY
self._frame_textwidget.color = Blitbuffer.COLOR_GREY
end
function InputText:focus()
self.focused = true
self.text_widget:focus()
self[1].color = Blitbuffer.COLOR_BLACK
self._frame_textwidget.color = Blitbuffer.COLOR_BLACK
end
function InputText:onShowKeyboard()
UIManager:show(self.keyboard)
return true
end
function InputText:onCloseKeyboard()