InputDialog, InputText: a bunch of updates (#7896)

- New way to hide the VirtualKeyboard: to hide the keyboard
  tap any point of the screen outside the inputbox and above
  the keyboard; to show the keyboard tap the inputbox.
  (Removed hacky "holding the arrow-down key" which is no
  longer needed).
- InputDialog windows are movable/translucent by default
- Redesign of the Clipboard dialog
reviewable/pr7903/r1
hius07 3 years ago committed by GitHub
parent db60ba48b7
commit 5e2d83965b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -101,6 +101,7 @@ local Device = require("device")
local Font = require("ui/font")
local FrameContainer = require("ui/widget/container/framecontainer")
local Geom = require("ui/geometry")
local GestureRange = require("ui/gesturerange")
local InfoMessage = require("ui/widget/infomessage")
local InputContainer = require("ui/widget/container/inputcontainer")
local InputText = require("ui/widget/inputtext")
@ -159,11 +160,8 @@ local InputDialog = InputContainer:new{
view_pos_callback = nil, -- Called with no arg to get initial top_line_num/charpos,
-- called with (top_line_num, charpos) to give back position on close.
-- movable = true, -- set to false if movable gestures conflicts with subwidgets gestures
-- for now, too much conflicts between InputText and MovableContainer, and
-- there's the keyboard to exclude from move area (the InputDialog could
-- be moved under the keyboard, and the user would be locked)
movable = false,
-- Set to false if movable gestures conflicts with subwidgets gestures
is_movable = true,
width = nil,
@ -203,7 +201,7 @@ local InputDialog = InputContainer:new{
function InputDialog:init()
if self.fullscreen then
self.movable = false
self.is_movable = false
self.border_size = 0
self.width = Screen:getWidth() - 2*self.border_size
self.covers_fullscreen = true -- hint for UIManager:_repaint()
@ -391,7 +389,6 @@ function InputDialog:init()
scroll_callback = self._buttons_scroll_callback, -- nil if no Nav or Scroll buttons
scroll = true,
scroll_by_pan = self.scroll_by_pan,
has_nav_bar = self.add_nav_bar,
cursor_at_end = self.cursor_at_end,
readonly = self.readonly,
parent = self,
@ -441,10 +438,11 @@ function InputDialog:init()
}
}
local frame = self.dialog_frame
if self.movable then
frame = MovableContainer:new{
if self.is_movable then
self.movable = MovableContainer:new{ -- (UIManager expects this as 'self.movable')
self.dialog_frame,
}
frame = self.movable
end
local keyboard_height = self.keyboard_hidden and 0
or self._input_widget:getKeyboardDimen().h
@ -455,6 +453,23 @@ function InputDialog:init()
},
frame
}
if Device:isTouchDevice() then -- is used to hide the keyboard with a tap outside of inputbox
self.ges_events = {
Tap = {
GestureRange:new{
ges = "tap",
range = self[1].dimen, -- screen above the keyboard
},
},
}
end
end
function InputDialog:onTap()
if self.fullscreen or self.add_nav_bar then
return
end
self._input_widget:onCloseKeyboard()
end
function InputDialog:getInputText()

@ -61,7 +61,7 @@ local InputText = InputContainer:new{
for_measurement_only = nil, -- When the widget is a one-off used to compute text height
do_select = false, -- to start text selection
selection_start_pos = nil, -- selection start position
is_keyboard_hidden = false, -- to be able to show the keyboard again when it was hidden (by VK itself)
is_keyboard_hidden = false, -- to be able to show the keyboard again when it was hidden
}
-- only use PhysicalKeyboard if the device does not have touch screen
@ -73,19 +73,19 @@ if Device:isTouchDevice() or Device:hasDPad() then
TapTextBox = {
GestureRange:new{
ges = "tap",
range = self.dimen
range = function() return self.dimen end
}
},
HoldTextBox = {
GestureRange:new{
ges = "hold",
range = self.dimen
range = function() return self.dimen end
}
},
SwipeTextBox = {
GestureRange:new{
ges = "swipe",
range = self.dimen
range = function() return self.dimen end
}
},
-- These are just to stop propagation of the event to
@ -166,18 +166,21 @@ if Device:isTouchDevice() or Device:hasDPad() then
return true
end
end
local input_dialog
input_dialog = require("ui/widget/inputdialog"):new{
title = _("Clipboard"),
local clipboard_value = Device.input.getClipboardText()
local clipboard_dialog
clipboard_dialog = require("ui/widget/textviewer"):new{
title = (clipboard_value == nil or clipboard_value == "") and _("Clipboard (empty)") or _("Clipboard"),
text = clipboard_value,
width = math.floor(Screen:getWidth() * 0.8),
height = math.floor(Screen:getHeight() * 0.4),
justified = false,
stop_events_propagation = true,
input_hint = _("empty"),
input = Device.input.getClipboardText(),
buttons = {
buttons_table = {
{
{
text = _("All"),
text = _("Copy all"),
callback = function()
UIManager:close(input_dialog)
UIManager:close(clipboard_dialog)
Device.input.setClipboardText(table.concat(self.charlist))
UIManager:show(Notification:new{
text = _("All text copied to clipboard."),
@ -185,9 +188,9 @@ if Device:isTouchDevice() or Device:hasDPad() then
end,
},
{
text = _("Line"),
text = _("Copy line"),
callback = function()
UIManager:close(input_dialog)
UIManager:close(clipboard_dialog)
local txt = table.concat(self.charlist, "", self:getStringPos({"\n", "\r"}, {"\n", "\r"}))
Device.input.setClipboardText(txt)
UIManager:show(Notification:new{
@ -196,9 +199,9 @@ if Device:isTouchDevice() or Device:hasDPad() then
end,
},
{
text = _("Word"),
text = _("Copy word"),
callback = function()
UIManager:close(input_dialog)
UIManager:close(clipboard_dialog)
local txt = table.concat(self.charlist, "", self:getStringPos({"\n", "\r", " "}, {"\n", "\r", " "}))
Device.input.setClipboardText(txt)
UIManager:show(Notification:new{
@ -211,13 +214,13 @@ if Device:isTouchDevice() or Device:hasDPad() then
{
text = _("Cancel"),
callback = function()
UIManager:close(input_dialog)
UIManager:close(clipboard_dialog)
end,
},
{
text = _("Select"),
callback = function()
UIManager:close(input_dialog)
UIManager:close(clipboard_dialog)
UIManager:show(Notification:new{
text = _("Set cursor to start of selection, then hold."),
})
@ -226,21 +229,17 @@ if Device:isTouchDevice() or Device:hasDPad() then
},
{
text = _("Paste"),
is_enter_default = true,
callback = function()
local paste_value = input_dialog:getInputText()
if paste_value ~= "" then
UIManager:close(input_dialog)
Device.input.setClipboardText(paste_value)
self:addChars(paste_value)
if clipboard_value ~= nil and clipboard_value ~= "" then
UIManager:close(clipboard_dialog)
self:addChars(clipboard_value)
end
end,
},
},
},
}
UIManager:show(input_dialog)
input_dialog:onShowKeyboard(true)
UIManager:show(clipboard_dialog)
end
return true
end
@ -574,19 +573,10 @@ function InputText:onShowKeyboard(ignore_first_hold_release)
return true
end
function InputText:onHideKeyboard()
if not self.has_nav_bar then
UIManager:close(self.keyboard)
Device:stopTextInput()
self.is_keyboard_hidden = true
end
return self.is_keyboard_hidden
end
function InputText:onCloseKeyboard()
UIManager:close(self.keyboard)
Device:stopTextInput()
self.is_keyboard_hidden = true
end
function InputText:onCloseWidget()

@ -127,13 +127,6 @@ function VirtualKey:init()
self.callback = function() self.keyboard:upLine() end
elseif self.label == "" then
self.callback = function() self.keyboard:downLine() end
self.hold_callback = function()
self.ignore_key_release = true
if not self.keyboard:onHideKeyboard() then
-- Keyboard was *not* actually hidden: refresh the key to clear the highlight
self:update_keyboard(false, true)
end
end
else
self.callback = function () self.keyboard:addChar(self.key) end
self.hold_callback = function()
@ -769,10 +762,6 @@ function VirtualKeyboard:onClose()
return true
end
function VirtualKeyboard:onHideKeyboard()
return self.inputbox:onHideKeyboard()
end
function VirtualKeyboard:onPressKey()
self:getFocusItem():handleEvent(Event:new("TapSelect"))
return true

Loading…
Cancel
Save