Skip to content

Instantly share code, notes, and snippets.

@marc-an-be
Created February 2, 2012 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marc-an-be/1723300 to your computer and use it in GitHub Desktop.
Save marc-an-be/1723300 to your computer and use it in GitHub Desktop.
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