Created
February 2, 2012 12:47
-
-
Save marc-an-be/1723300 to your computer and use it in GitHub Desktop.
Sample Activity for a Ruboto Article
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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