public
Created

Sample Activity for a Ruboto Article

  • Download Gist
quick_start_activity.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.