2017-04-29 08:38:09 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2016-01-31 22:56:05 +00:00
|
|
|
local BottomContainer = require("ui/widget/container/bottomcontainer")
|
2017-04-29 08:38:09 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
|
|
|
local Device = require("device")
|
|
|
|
local Font = require("ui/font")
|
2016-01-31 22:56:05 +00:00
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
2017-04-29 08:38:09 +00:00
|
|
|
local Geom = require("ui/geometry")
|
2016-01-31 22:56:05 +00:00
|
|
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
|
|
|
local HorizontalSpan = require("ui/widget/horizontalspan")
|
2017-04-29 08:38:09 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2017-09-13 14:56:20 +00:00
|
|
|
local Size = require("ui/size")
|
2016-01-31 22:56:05 +00:00
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
2017-04-29 08:38:09 +00:00
|
|
|
local TopContainer = require("ui/widget/container/topcontainer")
|
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
2016-12-29 08:10:38 +00:00
|
|
|
local logger = require("logger")
|
2017-04-29 08:38:09 +00:00
|
|
|
local util = require("util")
|
|
|
|
local Screen = Device.screen
|
2016-01-31 22:56:05 +00:00
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
local PhysicalNumericKey = WidgetContainer:extend{
|
2016-01-31 22:56:05 +00:00
|
|
|
key = nil,
|
|
|
|
label = nil,
|
|
|
|
physical_key_label = nil,
|
|
|
|
|
|
|
|
keyboard = nil,
|
|
|
|
callback = nil,
|
|
|
|
mapping = nil,
|
|
|
|
|
|
|
|
width = nil,
|
|
|
|
height = nil,
|
2017-09-13 14:56:20 +00:00
|
|
|
bordersize = Size.border.button,
|
2017-04-29 08:38:09 +00:00
|
|
|
face = Font:getFace("infont"),
|
2016-01-31 22:56:05 +00:00
|
|
|
pkey_face = Font:getFace("infont", 14),
|
|
|
|
}
|
|
|
|
|
|
|
|
function PhysicalNumericKey:init()
|
|
|
|
local label_widget = TextWidget:new{
|
|
|
|
text = self.label,
|
|
|
|
face = self.face,
|
|
|
|
}
|
|
|
|
self[1] = FrameContainer:new{
|
|
|
|
margin = 0,
|
|
|
|
bordersize = self.bordersize,
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2017-09-13 14:56:20 +00:00
|
|
|
radius = Size.radius.default,
|
2016-01-31 22:56:05 +00:00
|
|
|
padding = 0,
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width - 2*self.bordersize,
|
|
|
|
h = self.height - 2*self.bordersize,
|
|
|
|
},
|
|
|
|
VerticalGroup:new{
|
|
|
|
label_widget,
|
|
|
|
TextWidget:new{
|
2019-03-14 19:58:45 +00:00
|
|
|
fgcolor = Blitbuffer.COLOR_DARK_GRAY,
|
2016-01-31 22:56:05 +00:00
|
|
|
text = self.physical_key_label,
|
|
|
|
face = self.pkey_face,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
self.dimen = Geom:new{
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
x = 0,
|
|
|
|
y = 0,
|
2016-01-31 22:56:05 +00:00
|
|
|
w = self.width,
|
|
|
|
h = self.height,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
-- start of PhysicalKeyboard
|
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
local PhysicalKeyboard = InputContainer:extend{
|
2016-01-31 22:56:05 +00:00
|
|
|
is_always_active = true,
|
|
|
|
inputbox = nil, -- expect ui/widget/inputtext instance
|
2017-09-13 14:56:20 +00:00
|
|
|
bordersize = Size.border.button,
|
|
|
|
padding = Size.padding.button,
|
2016-01-31 22:56:05 +00:00
|
|
|
height = math.max(Screen:getWidth(), Screen:getHeight())*0.33,
|
2017-09-13 14:56:20 +00:00
|
|
|
key_padding = Size.padding.default,
|
2016-01-31 22:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function PhysicalKeyboard:init()
|
|
|
|
local all_keys = {}
|
|
|
|
for _,row in ipairs(Device.keyboard_layout) do
|
|
|
|
util.arrayAppend(all_keys, row)
|
|
|
|
end
|
2022-10-27 00:01:51 +00:00
|
|
|
self.key_events.KeyPress = { { all_keys } }
|
2016-01-31 22:56:05 +00:00
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
self.dimen = Geom:new{ x = 0, y = 0, w = 0, h = 0 }
|
2016-01-31 22:56:05 +00:00
|
|
|
|
|
|
|
self:setType(self.inputbox.input_type)
|
|
|
|
end
|
|
|
|
|
|
|
|
function PhysicalKeyboard:setType(t)
|
|
|
|
if t == "number" then
|
|
|
|
self.mapping = {
|
|
|
|
{"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
|
|
|
|
}
|
|
|
|
self.key_transformer = {}
|
|
|
|
for i,row in ipairs(self.mapping) do
|
|
|
|
for j,key in ipairs(row) do
|
|
|
|
local pkey = Device.keyboard_layout[i][j]
|
|
|
|
self.key_transformer[pkey] = self.mapping[i][j]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self:setupNumericMappingUI()
|
|
|
|
else
|
|
|
|
-- default mapping
|
|
|
|
self.mapping = Device.keyboard_layout
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function PhysicalKeyboard:onKeyPress(ev)
|
|
|
|
local key = ev.key
|
|
|
|
if key == "Back" then
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.warn("TODO: exit keyboard")
|
2016-01-31 22:56:05 +00:00
|
|
|
elseif key == "Del" then
|
|
|
|
self.inputbox:delChar()
|
|
|
|
else
|
|
|
|
if self.key_transformer then
|
|
|
|
key = self.key_transformer[key]
|
|
|
|
end
|
2018-03-07 09:22:49 +00:00
|
|
|
self.inputbox:addChars(key)
|
2016-01-31 22:56:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function PhysicalKeyboard:setupNumericMappingUI()
|
|
|
|
local key_rows = VerticalGroup:new{}
|
2017-09-13 14:56:20 +00:00
|
|
|
local key_margin = Size.margin.tiny
|
2016-01-31 22:56:05 +00:00
|
|
|
local row_len = #self.mapping[1]
|
|
|
|
local base_key_width = math.floor((self.width - row_len*(self.key_padding+2*key_margin) - 2*self.padding)/10)
|
|
|
|
local base_key_height = math.floor((self.height - self.key_padding - 2*self.padding)/4)
|
|
|
|
local key_width = math.floor(base_key_width + self.key_padding)
|
|
|
|
|
|
|
|
for i, kb_row in ipairs(self.mapping) do
|
|
|
|
local row = HorizontalGroup:new{}
|
|
|
|
for j, key in ipairs(kb_row) do
|
|
|
|
if j > 1 then
|
|
|
|
table.insert(row, HorizontalSpan:new{width=key_margin*2})
|
|
|
|
end
|
|
|
|
table.insert(row, PhysicalNumericKey:new{
|
|
|
|
label = key,
|
|
|
|
physical_key_label = Device.keyboard_layout[i][j],
|
|
|
|
width = key_width,
|
|
|
|
height = base_key_height,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
table.insert(key_rows, row)
|
|
|
|
end
|
|
|
|
|
|
|
|
local keyboard_frame = FrameContainer:new{
|
|
|
|
margin = 0,
|
|
|
|
bordersize = 0,
|
|
|
|
radius = 0,
|
|
|
|
padding = self.padding,
|
|
|
|
TopContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width - 2*self.bordersize -2*self.padding,
|
|
|
|
h = self.height - 2*self.bordersize -2*self.padding,
|
|
|
|
},
|
|
|
|
key_rows,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self[1] = BottomContainer:new{
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
keyboard_frame,
|
|
|
|
}
|
|
|
|
|
|
|
|
self.dimen = keyboard_frame:getSize()
|
|
|
|
end
|
|
|
|
|
2023-09-01 20:51:41 +00:00
|
|
|
-- Match VirtualKeyboard's API to ease caller's life
|
|
|
|
function PhysicalKeyboard:lockVisibility() end
|
|
|
|
function PhysicalKeyboard:setVisibility() end
|
|
|
|
function PhysicalKeyboard:isVisible() return true end
|
|
|
|
function PhysicalKeyboard:showKeyboard() end
|
|
|
|
function PhysicalKeyboard:hideKeyboard() end
|
|
|
|
|
2016-01-31 22:56:05 +00:00
|
|
|
return PhysicalKeyboard
|