Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function _M.newTextField(params)
- local group = params.group
- local back = display.newImageRect(group, 'images/login_field.png', 281, 36)
- game:setRP(back, 'TopCenter')
- local x = params.x or 0
- back.x, back.y = x, params.y
- local text = params.text or ''
- --local title = _M.newLabel{text = text, x = x + -132, y = params.y + 14, font = native.systemFont, size = 22, color = _COLORS.black, align = 'CenterLeft', flat = true}
- local title = _M.newLabel{text = text, x = x + -132, y = params.y + 20, font = _FONTNAME_HEAVY_CONDENSED, size = 22, color = _COLORS.black, align = 'CenterLeft', flat = true}
- group:insert(title)
- back.title = title
- function back:touch(event)
- if event.phase == 'began' then
- if type(params.onclick) == 'function' then
- params.onclick(self, 'up')
- else
- self:showTextField()
- end
- end
- return true
- end
- back:addEventListener('touch', back)
- function back:showTextField()
- if self.title.isVisible then
- self.title.isVisible = false
- local w, h = 260, 28
- local x, y = back:localToContent(0, 0)
- self.textField = native.newTextField(x - 132, y - 13, w, h)
- if self.current_text and self.current_text ~= params.title then
- self.textField.text = self.current_text
- end
- if params.password then
- self.textField.isSecure = params.password
- end
- self.textField.hasBackground = false
- self.textField.size = 22--math.floor(22 * display.pixelWidth / (_R - _L))
- self.textField.font = native.newFont(_FONTNAME_HEAVY_CONDENSED, 22)
- if params.mode then
- self.textField.inputType = params.mode
- end
- if params.userInput then
- self.textField:addEventListener('userInput', params.userInput)
- end
- native.setKeyboardFocus(self.textField)
- end
- end
- function back:hideTextField()
- if not self.title.isVisible then
- self.title.isVisible = true
- self.current_text = self.textField.text:sub(1, 45)
- self.title:setText(self.textField.text:sub(1, 45))
- self.title:setTextColor(0, 0, 0)
- if params.password then
- local s = string.gsub(self.title.text, '.', '●')
- self.title:setText(s)
- end
- native.setKeyboardFocus(nil)
- if params.userInput then
- self.textField:removeEventListener('userInput', params.userInput)
- end
- display.remove(self.textField)
- end
- end
- function back:checkEmpty()
- if (self.textField and self.textField.text) or self.current_text then
- local text = (self.textField and self.textField.text) or self.current_text
- if text:len() > 5 then
- if params.mode == 'email' then
- if text:match("[A-Za-z0-9%.%%%+%-]+@[A-Za-z0-9%.%%%+%-]+%.%w%w%w?%w?") then
- return true
- else
- native.showAlert(_APP_NAME, params.title .. ' is not valid.', {'OK'})
- end
- else
- return true
- end
- else
- native.showAlert(_APP_NAME, params.title .. ' must be at least 6 characters long.', {'OK'})
- end
- else
- native.showAlert(_APP_NAME, 'Please enter ' .. params.title, {'OK'})
- end
- return false
- end
- function back:getText()
- return (self.textField and self.textField.text) or self.current_text
- end
- return back
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement