use "std" use "forms" use "http" use "android" chatLog = newTextView("Чат с самоботом\n") chatText = newEditText() chatText.setHint("Введите сообщение") sendButton = newButton("Отправить") sendButton.onClick(::onSend) def onSend() { text = chatText.getText() if (length(text) == 0) { chatText.setError("Вы не ввели текст!") return 0 } chatText.setError("") chatText.setText("") chatLog.setText(chatLog.getText() + "\nyou > " + text) thread(::http, "http://annimon.com/json/bot.php", "POST", {"text": text}, def(answer) { uithread(def() { chatLog.setText(chatLog.getText() + "\nbot > " + answer) }) }) } messageLayoutId = 3228 messageLayout = newLinearLayout() messageLayout.setId(messageLayoutId) messageLayout.setOrientation(LinearLayout.HORIZONTAL) messageLayout.addView(chatText, { "layout_width" : WRAP_CONTENT, "layout_height" : MATCH_PARENT, "layout_weight" : 8 }) messageLayout.addView(sendButton, { "layout_width" : WRAP_CONTENT, "layout_height" : MATCH_PARENT, "layout_weight" : 1 }) root = newRelativeLayout() root.addView(chatLog, { "layout_width" : MATCH_PARENT, "layout_height" : MATCH_PARENT, "layout_above" : messageLayoutId, "layout_centerHorizontal" : true }) root.addView(messageLayout, { "layout_width" : MATCH_PARENT, "layout_height" : WRAP_CONTENT, "layout_alignParentBottom" : true }) showForm(root, { "layout_width" : MATCH_PARENT, "layout_height" : MATCH_PARENT })