2017-09-13 14:56:20 +00:00
|
|
|
--[[--
|
|
|
|
This widget displays a login dialog with a username and password.
|
|
|
|
]]
|
|
|
|
|
2017-09-11 08:32:39 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2014-04-23 14:19:29 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
2017-09-11 08:32:39 +00:00
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local Geom = require("ui/geometry")
|
2014-04-23 14:19:29 +00:00
|
|
|
local InputDialog = require("ui/widget/inputdialog")
|
|
|
|
local InputText = require("ui/widget/inputtext")
|
2017-09-13 14:56:20 +00:00
|
|
|
local Size = require("ui/size")
|
2014-04-23 14:19:29 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2017-09-11 08:32:39 +00:00
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
2014-04-23 14:19:29 +00:00
|
|
|
local _ = require("gettext")
|
2017-09-11 08:32:39 +00:00
|
|
|
local Screen = require("device").screen
|
2014-04-23 14:19:29 +00:00
|
|
|
|
|
|
|
local LoginDialog = InputDialog:extend{
|
|
|
|
username = "",
|
|
|
|
username_hint = "username",
|
|
|
|
password = "",
|
|
|
|
password_hint = "password",
|
|
|
|
}
|
|
|
|
|
|
|
|
function LoginDialog:init()
|
|
|
|
-- init title and buttons in base class
|
|
|
|
InputDialog.init(self)
|
|
|
|
self.input_username = InputText:new{
|
|
|
|
text = self.username,
|
|
|
|
hint = self.username_hint,
|
|
|
|
face = self.input_face,
|
|
|
|
width = self.width * 0.9,
|
|
|
|
focused = true,
|
|
|
|
scroll = false,
|
|
|
|
parent = self,
|
|
|
|
}
|
|
|
|
|
|
|
|
self.input_password = InputText:new{
|
|
|
|
text = self.password,
|
|
|
|
hint = self.password_hint,
|
|
|
|
face = self.input_face,
|
|
|
|
width = self.width * 0.9,
|
|
|
|
text_type = "password",
|
|
|
|
focused = false,
|
|
|
|
scroll = false,
|
|
|
|
parent = self,
|
|
|
|
}
|
|
|
|
|
|
|
|
self.dialog_frame = FrameContainer:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
radius = Size.radius.window,
|
2014-04-23 14:19:29 +00:00
|
|
|
padding = 0,
|
|
|
|
margin = 0,
|
2014-10-22 13:34:11 +00:00
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2014-04-23 14:19:29 +00:00
|
|
|
VerticalGroup:new{
|
|
|
|
align = "left",
|
2018-08-06 19:16:30 +00:00
|
|
|
self.title_widget,
|
2014-04-23 14:19:29 +00:00
|
|
|
self.title_bar,
|
|
|
|
-- username input
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.title_bar:getSize().w,
|
|
|
|
h = self.input_username:getSize().h,
|
|
|
|
},
|
|
|
|
self.input_username,
|
|
|
|
},
|
|
|
|
-- password input
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.title_bar:getSize().w,
|
|
|
|
h = self.input_password:getSize().h,
|
|
|
|
},
|
|
|
|
self.input_password,
|
|
|
|
},
|
|
|
|
-- buttons
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.title_bar:getSize().w,
|
|
|
|
h = self.button_table:getSize().h,
|
|
|
|
},
|
|
|
|
self.button_table,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-21 15:30:06 +00:00
|
|
|
self._input_widget = self.input_username
|
2014-04-23 14:19:29 +00:00
|
|
|
|
|
|
|
self[1] = CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = Screen:getWidth(),
|
2016-02-21 15:30:06 +00:00
|
|
|
h = Screen:getHeight() - self._input_widget:getKeyboardDimen().h,
|
2014-04-23 14:19:29 +00:00
|
|
|
},
|
|
|
|
self.dialog_frame,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function LoginDialog:getCredential()
|
|
|
|
local username = self.input_username:getText()
|
|
|
|
local password = self.input_password:getText()
|
|
|
|
return username, password
|
|
|
|
end
|
|
|
|
|
|
|
|
function LoginDialog:onSwitchFocus(inputbox)
|
|
|
|
-- unfocus current inputbox
|
2016-02-21 15:30:06 +00:00
|
|
|
self._input_widget:unfocus()
|
|
|
|
self._input_widget:onCloseKeyboard()
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
UIManager:close(self)
|
2014-04-23 14:19:29 +00:00
|
|
|
|
|
|
|
-- focus new inputbox
|
2016-02-21 15:30:06 +00:00
|
|
|
self._input_widget = inputbox
|
|
|
|
self._input_widget:focus()
|
|
|
|
self._input_widget:onShowKeyboard()
|
2014-04-23 14:19:29 +00:00
|
|
|
|
|
|
|
UIManager:show(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
return LoginDialog
|
|
|
|
|