diff --git a/frontend/apps/cloudstorage/dropbox.lua b/frontend/apps/cloudstorage/dropbox.lua index 168374c2c..62fed5354 100644 --- a/frontend/apps/cloudstorage/dropbox.lua +++ b/frontend/apps/cloudstorage/dropbox.lua @@ -111,8 +111,8 @@ function DropBox:config(item, callback) height = Screen:getHeight() * 0.2, input_type = "text", } - self.settings_dialog:onShowKeyboard() UIManager:show(self.settings_dialog) + self.settings_dialog:onShowKeyboard() end function DropBox:info(token) diff --git a/frontend/apps/cloudstorage/ftp.lua b/frontend/apps/cloudstorage/ftp.lua index db03bd0d4..fe66c9210 100644 --- a/frontend/apps/cloudstorage/ftp.lua +++ b/frontend/apps/cloudstorage/ftp.lua @@ -140,8 +140,8 @@ function Ftp:config(item, callback) height = Screen:getHeight() * 0.2, input_type = "text", } - self.settings_dialog:onShowKeyboard() UIManager:show(self.settings_dialog) + self.settings_dialog:onShowKeyboard() end function Ftp:info(item) diff --git a/frontend/apps/filemanager/filemanager.lua b/frontend/apps/filemanager/filemanager.lua index f8254981f..993b00077 100644 --- a/frontend/apps/filemanager/filemanager.lua +++ b/frontend/apps/filemanager/filemanager.lua @@ -264,8 +264,8 @@ function FileManager:init() }, }}, } - fileManager.rename_dialog:onShowKeyboard() UIManager:show(fileManager.rename_dialog) + fileManager.rename_dialog:onShowKeyboard() end, } }, @@ -404,8 +404,8 @@ function FileManager:tapPlus() } }, } - self.input_dialog:onShowKeyboard() UIManager:show(self.input_dialog) + self.input_dialog:onShowKeyboard() end, }, }, diff --git a/frontend/apps/filemanager/filemanagerfilesearcher.lua b/frontend/apps/filemanager/filemanagerfilesearcher.lua index 3d622bc37..83455d8c0 100644 --- a/frontend/apps/filemanager/filemanagerfilesearcher.lua +++ b/frontend/apps/filemanager/filemanagerfilesearcher.lua @@ -138,8 +138,8 @@ function FileSearcher:showSearch() }, }, } - self.search_dialog:onShowKeyboard() UIManager:show(self.search_dialog) + self.search_dialog:onShowKeyboard() end function FileSearcher:showSearchResults() diff --git a/frontend/apps/filemanager/filemanagersearch.lua b/frontend/apps/filemanager/filemanagersearch.lua index 69d5f07e9..1ba0a8b5f 100644 --- a/frontend/apps/filemanager/filemanagersearch.lua +++ b/frontend/apps/filemanager/filemanagersearch.lua @@ -205,8 +205,8 @@ function Search:ShowSearch() width = Screen:getWidth() * 0.8, height = Screen:getHeight() * 0.2, } - self.search_dialog:onShowKeyboard() UIManager:show(self.search_dialog) + self.search_dialog:onShowKeyboard() else if self.error then UIManager:show(InfoMessage:new{ diff --git a/frontend/apps/filemanager/filemanagersetdefaults.lua b/frontend/apps/filemanager/filemanagersetdefaults.lua index d668a5424..f50a9c234 100644 --- a/frontend/apps/filemanager/filemanagersetdefaults.lua +++ b/frontend/apps/filemanager/filemanagersetdefaults.lua @@ -154,8 +154,8 @@ function SetDefaults:init() input_type = setting_type, width = Screen:getWidth() * 0.95, } - self.set_dialog:onShowKeyboard() UIManager:show(self.set_dialog) + self.set_dialog:onShowKeyboard() end table.insert(self.results, { @@ -205,8 +205,8 @@ function SetDefaults:init() width = Screen:getWidth() * 0.95, height = Screen:getHeight() * 0.2, } - self.set_dialog:onShowKeyboard() UIManager:show(self.set_dialog) + self.set_dialog:onShowKeyboard() end table.insert(self.results, { @@ -244,8 +244,8 @@ function SetDefaults:init() input_type = setting_type, width = Screen:getWidth() * 0.95, } - self.set_dialog:onShowKeyboard() UIManager:show(self.set_dialog) + self.set_dialog:onShowKeyboard() end table.insert(self.results, { diff --git a/frontend/apps/reader/modules/readerbookmark.lua b/frontend/apps/reader/modules/readerbookmark.lua index bd70f6a14..f0414b2e7 100644 --- a/frontend/apps/reader/modules/readerbookmark.lua +++ b/frontend/apps/reader/modules/readerbookmark.lua @@ -482,8 +482,8 @@ function ReaderBookmark:renameBookmark(item, from_highlight) } }, } - self.input:onShowKeyboard() UIManager:show(self.input) + self.input:onShowKeyboard() end function ReaderBookmark:toggleBookmark(pn_or_xp) diff --git a/frontend/apps/reader/modules/readergoto.lua b/frontend/apps/reader/modules/readergoto.lua index a6a12d743..f6b90fb69 100644 --- a/frontend/apps/reader/modules/readergoto.lua +++ b/frontend/apps/reader/modules/readergoto.lua @@ -84,8 +84,8 @@ function ReaderGoto:onShowGotoDialog() }, input_type = "number", } - self.goto_dialog:onShowKeyboard() UIManager:show(self.goto_dialog) + self.goto_dialog:onShowKeyboard() end function ReaderGoto:onShowSkimtoDialog() diff --git a/frontend/apps/reader/modules/readerwikipedia.lua b/frontend/apps/reader/modules/readerwikipedia.lua index 1fad3189c..7b7d16b13 100644 --- a/frontend/apps/reader/modules/readerwikipedia.lua +++ b/frontend/apps/reader/modules/readerwikipedia.lua @@ -58,8 +58,8 @@ function ReaderWikipedia:lookupInput() } }, } - self.input_dialog:onShowKeyboard() UIManager:show(self.input_dialog) + self.input_dialog:onShowKeyboard() end function ReaderWikipedia:addToMainMenu(menu_items) @@ -165,8 +165,8 @@ function ReaderWikipedia:addToMainMenu(menu_items) } }, } - wikilang_input:onShowKeyboard() UIManager:show(wikilang_input) + wikilang_input:onShowKeyboard() end, }, { -- setting used by dictquicklookup diff --git a/frontend/apps/reader/readerui.lua b/frontend/apps/reader/readerui.lua index 967986add..2964d39ec 100644 --- a/frontend/apps/reader/readerui.lua +++ b/frontend/apps/reader/readerui.lua @@ -521,8 +521,8 @@ function ReaderUI:unlockDocumentWithPassword(document, try_again) }, text_type = "password", } - self.password_dialog:onShowKeyboard() UIManager:show(self.password_dialog) + self.password_dialog:onShowKeyboard() end function ReaderUI:onVerifyPassword(document) diff --git a/frontend/ui/screensaver.lua b/frontend/ui/screensaver.lua index ea2f455ed..6d25d6c22 100644 --- a/frontend/ui/screensaver.lua +++ b/frontend/ui/screensaver.lua @@ -130,8 +130,8 @@ function Screensaver:setMessage() }, }, } - self.input_dialog:onShowKeyboard() UIManager:show(self.input_dialog) + self.input_dialog:onShowKeyboard() end function Screensaver:show(event, fallback_message) diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index 3312d4afb..93f1d4d9a 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -476,8 +476,8 @@ function UIManager:sendEvent(event) end if widget.widget.is_always_active then -- active widgets will handle this event - -- Note: is_always_active widgets currently are vitualkeyboard and - -- readerconfig + -- Note: is_always_active widgets currently are widgets that want to show a keyboard + -- and readerconfig checked_widgets[widget] = true if widget.widget:handleEvent(event) then return end end diff --git a/frontend/ui/widget/bookstatuswidget.lua b/frontend/ui/widget/bookstatuswidget.lua index d553a5fa8..7422b4578 100644 --- a/frontend/ui/widget/bookstatuswidget.lua +++ b/frontend/ui/widget/bookstatuswidget.lua @@ -575,8 +575,8 @@ function BookStatusWidget:onSwitchFocus(inputbox) }, }, } - self.note_dialog:onShowKeyboard() UIManager:show(self.note_dialog) + self.note_dialog:onShowKeyboard() end function BookStatusWidget:closeInputDialog() diff --git a/frontend/ui/widget/buttontable.lua b/frontend/ui/widget/buttontable.lua index 860531327..d0b96d6d7 100644 --- a/frontend/ui/widget/buttontable.lua +++ b/frontend/ui/widget/buttontable.lua @@ -85,7 +85,7 @@ function ButtonTable:init() end end -- end for each button line self:addHorizontalSep(true, false, false) - if Device:hasDPad() or Device:hasKeyboard() then + if Device:hasKeys() then self.layout = self.buttons_layout self.layout[1][1]:onFocus() self.key_events.SelectByKeyPress = { {{"Press", "Enter"}} } diff --git a/frontend/ui/widget/container/inputcontainer.lua b/frontend/ui/widget/container/inputcontainer.lua index fc40a371d..8e69fc238 100644 --- a/frontend/ui/widget/container/inputcontainer.lua +++ b/frontend/ui/widget/container/inputcontainer.lua @@ -236,8 +236,8 @@ function InputContainer:onInput(input) }, }, } - self.input_dialog:onShowKeyboard() UIManager:show(self.input_dialog) + self.input_dialog:onShowKeyboard() end function InputContainer:closeInputDialog() diff --git a/frontend/ui/widget/dictquicklookup.lua b/frontend/ui/widget/dictquicklookup.lua index a8a641515..b20b10c6a 100644 --- a/frontend/ui/widget/dictquicklookup.lua +++ b/frontend/ui/widget/dictquicklookup.lua @@ -860,8 +860,8 @@ function DictQuickLookup:lookupInputWord(hint) } }, } - self.input_dialog:onShowKeyboard() UIManager:show(self.input_dialog) + self.input_dialog:onShowKeyboard() end function DictQuickLookup:inputLookup() diff --git a/frontend/ui/widget/focusmanager.lua b/frontend/ui/widget/focusmanager.lua index 31dc3db5f..41dd51cc9 100644 --- a/frontend/ui/widget/focusmanager.lua +++ b/frontend/ui/widget/focusmanager.lua @@ -1,3 +1,4 @@ +local Device = require("device") local Event = require("ui/event") local InputContainer = require("ui/widget/container/inputcontainer") local logger = require("logger") @@ -33,13 +34,15 @@ function FocusManager:init() if not self.selected then self.selected = { x = 1, y = 1 } end - self.key_events = { - -- these will all generate the same event, just with different arguments - FocusUp = { {"Up"}, doc = "move focus up", event = "FocusMove", args = {0, -1} }, - FocusDown = { {"Down"}, doc = "move focus down", event = "FocusMove", args = {0, 1} }, - FocusLeft = { {"Left"}, doc = "move focus left", event = "FocusMove", args = {-1, 0} }, - FocusRight = { {"Right"}, doc = "move focus right", event = "FocusMove", args = {1, 0} }, - } + if Device:hasKeys() then + self.key_events = { + -- these will all generate the same event, just with different arguments + FocusUp = { {"Up"}, doc = "move focus up", event = "FocusMove", args = {0, -1} }, + FocusDown = { {"Down"}, doc = "move focus down", event = "FocusMove", args = {0, 1} }, + FocusLeft = { {"Left"}, doc = "move focus left", event = "FocusMove", args = {-1, 0} }, + FocusRight = { {"Right"}, doc = "move focus right", event = "FocusMove", args = {1, 0} }, + } + end end function FocusManager:onFocusMove(args) @@ -62,7 +65,9 @@ function FocusManager:onFocusMove(args) end elseif not self.layout[self.selected.y + dy][self.selected.x] then --inner horizontal border, trying to be clever and step down - self:_verticalStep(dy) + if not self:_verticalStep(dy) then + break + end elseif not self.layout[self.selected.y + dy][self.selected.x + dx] then --vertical border, no wraparound break @@ -97,7 +102,7 @@ function FocusManager:_wrapAround(dy) self.selected.y = y if not self.layout[self.selected.y][self.selected.x] then --call verticalStep on the current line to perform the search - self:_verticalStep(0) + return self:_verticalStep(0) end return true else @@ -107,6 +112,10 @@ end function FocusManager:_verticalStep(dy) local x = self.selected.x + if type(self.layout[self.selected.y + dy]) ~= "table" or self.layout[self.selected.y + dy] == {} then + logger.err("[FocusManager] : Malformed layout") + return false + end --looking for the item on the line below, the closest on the left side while not self.layout[self.selected.y + dy][x] do x = x - 1 @@ -120,6 +129,7 @@ function FocusManager:_verticalStep(dy) end self.selected.x = x self.selected.y = self.selected.y + dy + return true end function FocusManager:getFocusItem() diff --git a/frontend/ui/widget/infomessage.lua b/frontend/ui/widget/infomessage.lua index 6523b19a0..b573f863c 100644 --- a/frontend/ui/widget/infomessage.lua +++ b/frontend/ui/widget/infomessage.lua @@ -18,8 +18,8 @@ Example: show_icon = false, timeout = 5, -- This widget will vanish in 5 seconds. } - sample_input:onShowKeyboard() UIManager:show(sample_input) + sample_input:onShowKeyboard() ]] local Blitbuffer = require("ffi/blitbuffer") diff --git a/frontend/ui/widget/inputdialog.lua b/frontend/ui/widget/inputdialog.lua index 720749e81..103792235 100644 --- a/frontend/ui/widget/inputdialog.lua +++ b/frontend/ui/widget/inputdialog.lua @@ -34,8 +34,8 @@ Example: } }, } - sample_input:onShowKeyboard() UIManager:show(sample_input) + sample_input:onShowKeyboard() If it would take the user more than half a minute to recover from a mistake, a "Cancel" button must be added to the dialog. The cancellation button @@ -50,6 +50,7 @@ longer than three words it should just read "OK". local Blitbuffer = require("ffi/blitbuffer") local ButtonTable = require("ui/widget/buttontable") local CenterContainer = require("ui/widget/container/centercontainer") +local Device = require("device") local Font = require("ui/font") local FrameContainer = require("ui/widget/container/framecontainer") local Geom = require("ui/geometry") @@ -64,9 +65,10 @@ local TextWidget = require("ui/widget/textwidget") local UIManager = require("ui/uimanager") local VerticalGroup = require("ui/widget/verticalgroup") local VerticalSpan = require("ui/widget/verticalspan") -local Screen = require("device").screen +local Screen = Device.screen local InputDialog = InputContainer:new{ + is_always_active = true, title = "", input = "", input_hint = "", @@ -195,6 +197,10 @@ function InputDialog:init() } } } + if Device:hasKeys() then + --little hack to piggyback on the layout of the button_table to handle the new InputText + table.insert(self.button_table.layout, 1, {self._input_widget}) + end self[1] = CenterContainer:new{ dimen = Geom:new{ diff --git a/frontend/ui/widget/inputtext.lua b/frontend/ui/widget/inputtext.lua index 5b0262c61..f5179832f 100644 --- a/frontend/ui/widget/inputtext.lua +++ b/frontend/ui/widget/inputtext.lua @@ -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) + 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 - 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) + + 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 end end + if Device.hasKeys() then + if not InputText.initEventListener then + function InputText:initEventListener() end + end - function InputText:onHoldTextBox(arg, ges) - if self.parent.onSwitchFocus then - self.parent:onSwitchFocus(self) + function InputText:onFocus() + --Event called by the focusmanager + self.key_events.ShowKeyboard = { {"Press"}, doc = "show keyboard" } + self:focus() + return true 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) + + function InputText:onUnfocus() + --Event called by the focusmanager + self.key_events = {} + self:unfocus() + return true end end -elseif not Device.hasKeyboard() then - Keyboard = require("ui/widget/virtualkeyboard") - function InputText:initEventListener() end --do nothing but doesn't crash for now 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() diff --git a/frontend/ui/widget/multiinputdialog.lua b/frontend/ui/widget/multiinputdialog.lua index 70df5e9b4..5433d2df7 100644 --- a/frontend/ui/widget/multiinputdialog.lua +++ b/frontend/ui/widget/multiinputdialog.lua @@ -48,6 +48,10 @@ function MultiInputDialog:init() scroll = false, parent = self, } + if Device:hasKeys() then + --little hack to piggyback on the layout of the button_table to handle the new InputText + table.insert(self.button_table.layout, #self.button_table.layout, {input_field[k]}) + end if field.description then input_description[k] = FrameContainer:new{ padding = self.description_padding, @@ -76,6 +80,10 @@ function MultiInputDialog:init() }) end + if Device:hasKeys() then + --remove the not needed hack in inputdialog + table.remove(self.button_table.layout, 1) + end -- Add same vertical space after than before InputText table.insert(VerticalGroupData,CenterContainer:new{ dimen = Geom:new{ @@ -131,8 +139,6 @@ function MultiInputDialog:onSwitchFocus(inputbox) self._input_widget = inputbox self._input_widget:focus() self._input_widget:onShowKeyboard() - - UIManager:show(self) end return MultiInputDialog diff --git a/frontend/ui/widget/networksetting.lua b/frontend/ui/widget/networksetting.lua index 07948432f..4227b3927 100644 --- a/frontend/ui/widget/networksetting.lua +++ b/frontend/ui/widget/networksetting.lua @@ -300,8 +300,8 @@ function NetworkItem:onEditNetwork() }, }, } - password_input:onShowKeyboard() UIManager:show(password_input) + password_input:onShowKeyboard() return true end @@ -331,8 +331,8 @@ function NetworkItem:onAddNetwork() }, }, } - password_input:onShowKeyboard() UIManager:show(password_input) + password_input:onShowKeyboard() return true end diff --git a/frontend/ui/widget/numberpickerwidget.lua b/frontend/ui/widget/numberpickerwidget.lua index cf9b047d5..a12722d36 100644 --- a/frontend/ui/widget/numberpickerwidget.lua +++ b/frontend/ui/widget/numberpickerwidget.lua @@ -139,8 +139,8 @@ function NumberPickerWidget:paintWidget() }, }, } - input:onShowKeyboard() UIManager:show(input) + input:onShowKeyboard() end end diff --git a/frontend/ui/widget/opdsbrowser.lua b/frontend/ui/widget/opdsbrowser.lua index 642296538..650255b30 100644 --- a/frontend/ui/widget/opdsbrowser.lua +++ b/frontend/ui/widget/opdsbrowser.lua @@ -146,8 +146,8 @@ function OPDSBrowser:addNewCatalog() width = Screen:getWidth() * 0.95, height = Screen:getHeight() * 0.2, } - self.add_server_dialog:onShowKeyboard() UIManager:show(self.add_server_dialog) + self.add_server_dialog:onShowKeyboard() end function OPDSBrowser:editCalibreServer() @@ -187,8 +187,8 @@ function OPDSBrowser:editCalibreServer() width = Screen:getWidth() * 0.95, height = Screen:getHeight() * 0.2, } - self.add_server_dialog:onShowKeyboard() UIManager:show(self.add_server_dialog) + self.add_server_dialog:onShowKeyboard() end function OPDSBrowser:genItemTableFromRoot() @@ -322,8 +322,8 @@ function OPDSBrowser:fetchWithLogin(host, callback) height = Screen:getHeight() * 0.4, } - self.login_dialog:onShowKeyboard() UIManager:show(self.login_dialog) + self.login_dialog:onShowKeyboard() end function OPDSBrowser:closeDialog() @@ -679,8 +679,8 @@ function OPDSBrowser:editOPDSServer(item) width = Screen:getWidth() * 0.95, height = Screen:getHeight() * 0.2, } - self.edit_server_dialog:onShowKeyboard() UIManager:show(self.edit_server_dialog) + self.edit_server_dialog:onShowKeyboard() end function OPDSBrowser:deleteOPDSServer(item) diff --git a/frontend/ui/widget/virtualkeyboard.lua b/frontend/ui/widget/virtualkeyboard.lua index 00db9508e..faabcdc93 100644 --- a/frontend/ui/widget/virtualkeyboard.lua +++ b/frontend/ui/widget/virtualkeyboard.lua @@ -2,6 +2,8 @@ local Blitbuffer = require("ffi/blitbuffer") local BottomContainer = require("ui/widget/container/bottomcontainer") local CenterContainer = require("ui/widget/container/centercontainer") local Device = require("device") +local Event = require("ui/event") +local FocusManager = require("ui/widget/focusmanager") local Font = require("ui/font") local FrameContainer = require("ui/widget/container/framecontainer") local Geom = require("ui/geometry") @@ -112,6 +114,14 @@ function VirtualKey:update_keyboard() end) end +function VirtualKey:onFocus() + self[1].invert = true +end + +function VirtualKey:onUnfocus() + self[1].invert = false +end + function VirtualKey:onTapSelect() if self.flash_keyboard then self[1].invert = true @@ -149,8 +159,8 @@ function VirtualKey:invert(invert) self:update_keyboard() end -local VirtualKeyboard = InputContainer:new{ - is_always_active = true, +local VirtualKeyboard = FocusManager:new{ + modal = true, disable_double_tap = true, inputbox = nil, KEYS = {}, -- table to store layouts @@ -160,11 +170,12 @@ local VirtualKeyboard = InputContainer:new{ umlautmode_keys = {}, min_layout = 2, max_layout = 12, - layout = 2, + keyboard_layout = 2, shiftmode = false, symbolmode = false, utf8mode = false, umlautmode = false, + layout = {}, width = Screen:scaleBySize(600), height = nil, @@ -191,7 +202,21 @@ function VirtualKeyboard:init() self.utf8mode_keys = keyboard.utf8mode_keys self.umlautmode_keys = keyboard.umlautmode_keys self.height = Screen:scaleBySize(64 * #self.KEYS) - self:initLayout(self.layout) + self:initLayout(self.keyboard_layout) + if Device:hasKeys() then + self.key_events.PressKey = { {"Press"}, doc = "select key" } + self.key_events.Close = { {"Back"}, doc = "close keyboard" } + end +end + +function VirtualKeyboard:onClose() + UIManager:close(self) + return true +end + +function VirtualKeyboard:onPressKey() + self:getFocusItem():handleEvent(Event:new("TapSelect")) + return true end function VirtualKeyboard:_refresh() @@ -223,19 +248,20 @@ function VirtualKeyboard:initLayout(layout) -- to be sure layout is selected properly layout = math.max(layout, self.min_layout) layout = math.min(layout, self.max_layout) - self.layout = layout + self.keyboard_layout = layout -- fill the layout modes self.shiftmode = (layout == 1 or layout == 3 or layout == 5 or layout == 7 or layout == 9 or layout == 11) self.symbolmode = (layout == 3 or layout == 4 or layout == 7 or layout == 8 or layout == 11 or layout == 12) self.utf8mode = (layout == 5 or layout == 6 or layout == 7 or layout == 8) self.umlautmode = (layout == 9 or layout == 10 or layout == 11 or layout == 12) else -- or, without input parameter, restore layout from current layout modes - self.layout = VKLayout(self.shiftmode, self.symbolmode, self.utf8mode, self.umlautmode) + self.keyboard_layout = VKLayout(self.shiftmode, self.symbolmode, self.utf8mode, self.umlautmode) end self:addKeys() end function VirtualKeyboard:addKeys() + self.layout = {} local base_key_width = math.floor((self.width - (#self.KEYS[1] + 1)*self.key_padding - 2*self.padding)/#self.KEYS[1]) local base_key_height = math.floor((self.height - (#self.KEYS + 1)*self.key_padding - 2*self.padding)/#self.KEYS) local h_key_padding = HorizontalSpan:new{width = self.key_padding} @@ -243,14 +269,15 @@ function VirtualKeyboard:addKeys() local vertical_group = VerticalGroup:new{} for i = 1, #self.KEYS do local horizontal_group = HorizontalGroup:new{} + local layout_horizontal = {} for j = 1, #self.KEYS[i] do local width_factor = self.KEYS[i][j].width or 1.0 local key_width = math.floor((base_key_width + self.key_padding) * width_factor) - self.key_padding local key_height = base_key_height - local label = self.KEYS[i][j].label or self.KEYS[i][j][self.layout] + local label = self.KEYS[i][j].label or self.KEYS[i][j][self.keyboard_layout] local key = VirtualKey:new{ - key = self.KEYS[i][j][self.layout], + key = self.KEYS[i][j][self.keyboard_layout], icon = self.KEYS[i][j].icon, label = label, keyboard = self, @@ -258,11 +285,13 @@ function VirtualKeyboard:addKeys() height = key_height, } table.insert(horizontal_group, key) + table.insert(layout_horizontal, key) if j ~= #self.KEYS[i] then table.insert(horizontal_group, h_key_padding) end end table.insert(vertical_group, horizontal_group) + table.insert(self.layout, layout_horizontal) if i ~= #self.KEYS then table.insert(vertical_group, v_key_padding) end diff --git a/plugins/evernote.koplugin/main.lua b/plugins/evernote.koplugin/main.lua index 95f68417b..25478ddff 100644 --- a/plugins/evernote.koplugin/main.lua +++ b/plugins/evernote.koplugin/main.lua @@ -216,8 +216,8 @@ function EvernoteExporter:login() height = Screen:getHeight() * 0.4, } - self.login_dialog:onShowKeyboard() UIManager:show(self.login_dialog) + self.login_dialog:onShowKeyboard() end function EvernoteExporter:closeDialog() diff --git a/plugins/goodreads.koplugin/main.lua b/plugins/goodreads.koplugin/main.lua index 2ee7bbc29..0efa979c7 100644 --- a/plugins/goodreads.koplugin/main.lua +++ b/plugins/goodreads.koplugin/main.lua @@ -143,8 +143,8 @@ How to generate a key and a secret key: height = Screen:getHeight() * 0.2, input_type = "text", } - self.settings_dialog:onShowKeyboard() UIManager:show(self.settings_dialog) + self.settings_dialog:onShowKeyboard() end function Goodreads:saveSettings(fields) @@ -227,8 +227,8 @@ function Goodreads:search(search_type) } }, } - search_input:onShowKeyboard() UIManager:show(search_input) + search_input:onShowKeyboard() end return Goodreads diff --git a/plugins/kosync.koplugin/main.lua b/plugins/kosync.koplugin/main.lua index 4b90aae50..d71ad6642 100644 --- a/plugins/kosync.koplugin/main.lua +++ b/plugins/kosync.koplugin/main.lua @@ -290,8 +290,8 @@ function KOSync:login() height = Screen:getHeight() * 0.4, } - self.login_dialog:onShowKeyboard() UIManager:show(self.login_dialog) + self.login_dialog:onShowKeyboard() end function KOSync:closeDialog() diff --git a/plugins/perceptionexpander.koplugin/main.lua b/plugins/perceptionexpander.koplugin/main.lua index 7f1870c75..4d8224e87 100755 --- a/plugins/perceptionexpander.koplugin/main.lua +++ b/plugins/perceptionexpander.koplugin/main.lua @@ -153,8 +153,8 @@ function PerceptionExpander:showSettingsDialog() width = Screen:getWidth() * 0.8, height = Screen:getHeight() * 0.3, } - self.settings_dialog:onShowKeyboard() UIManager:show(self.settings_dialog) + self.settings_dialog:onShowKeyboard() end function PerceptionExpander:addToMainMenu(menu_items) diff --git a/plugins/statistics.koplugin/main.lua b/plugins/statistics.koplugin/main.lua index a5ecc41cd..e265d27e2 100755 --- a/plugins/statistics.koplugin/main.lua +++ b/plugins/statistics.koplugin/main.lua @@ -662,8 +662,8 @@ function ReaderStatistics:updateSettings() height = Screen:getHeight() * 0.2, input_type = "number", } - self.settings_dialog:onShowKeyboard() UIManager:show(self.settings_dialog) + self.settings_dialog:onShowKeyboard() end function ReaderStatistics:addToMainMenu(menu_items) diff --git a/plugins/terminal.koplugin/main.lua b/plugins/terminal.koplugin/main.lua index 3ea8668dc..d3f6f2834 100644 --- a/plugins/terminal.koplugin/main.lua +++ b/plugins/terminal.koplugin/main.lua @@ -39,8 +39,8 @@ function Terminal:start() end, }}}, } - self.input:onShowKeyboard() UIManager:show(self.input) + self.input:onShowKeyboard() end function Terminal:execute()