Create a gist now

Instantly share code, notes, and snippets.

Sample Activity for a Ruboto Article
require 'ruboto/activity'
require 'ruboto/widget'
require 'ruboto/util/toast'
require 'socket'
ruboto_import_widgets :Button, :LinearLayout, :EditText
$activity.start_ruboto_activity "$sample_activity" do
setTitle 'Funky TestApp'
def on_create(bundle)
self.content_view =
linear_layout(:orientation => :vertical) do
@host = edit_text(:single_line => true, :hint => "Hostname[:port]",
:layout => {:width= => :fill_parent, :height= => :wrap_content, :weight= => 1.0})
@message = edit_text(:single_line => true, :hint => "Message",
:layout => {:width= => :fill_parent, :height= => :wrap_content, :weight= => 1.0})
button :text => 'Send message!', :width => :wrap_content, :on_click_listener => @handle_click
end
end
@handle_click = proc do |view|
begin
host, port = @host.getText.to_s.split(':')
@sock = TCPSocket.open(host, port || 1234) if !@sock || @sock.closed?
@sock.puts @message.getText.to_s
rescue
toast "#{$!}"
@sock.close rescue nil
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment