Created
November 1, 2012 22:49
-
-
Save mixflame/3997243 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/widget' | |
require 'ruboto/util/toast' | |
require 'server_list_controller' | |
ruboto_import_widgets :Button, :LinearLayout, :TextView, :ListView, :EditText | |
class ServerList | |
# def self.load_preferences | |
# e = getPreferences(Context::MODE_PRIVATE) | |
# handle = e.getString("Handle", "") | |
# port = e.getString("Port", "") | |
# host = e.getString("Host", "") | |
# { :handle => handle, :port => port, :host => host } | |
# end | |
# def self.save_preferences(options) | |
# e = getPreferences(Context::MODE_PRIVATE).edit | |
# e.putString("handle", options[:handle]) | |
# e.putString("host", options[:host]) | |
# e.putString("port", options[:port]) | |
# e.commit | |
# end | |
def on_stop | |
puts "saving preferences" | |
ServerList.save_preferences(:handle => $handle.getText.toString, :host => $host.getText.toString, :port => $port.getText.toString) | |
end | |
def on_create(bundle) | |
super | |
set_title 'Server List' | |
$sl = self | |
refresh_me | |
rescue | |
puts "Exception creating activity: #{$!}" | |
puts $!.backtrace.join("\n") | |
end | |
def refresh_me | |
Thread.new { | |
require 'net/http' | |
$server_list_hash = Net::HTTP.get('nexusnet.herokuapp.com', '/msl'). | |
split("\n"). | |
collect do |s| | |
par = s.split("-!!!-") | |
{:host => par[1], :name => par[0], :port => par[2]} | |
end | |
$names = $server_list_hash.map { |i| i[:name] } | |
$activity.run_on_ui_thread do | |
$sl.content_view = | |
linear_layout :orientation => :vertical do | |
$server_list = list_view(:list => $names, :on_item_click_listener => proc { | |
|av, v, p, i| | |
host = $server_list_hash[p][:host] | |
port = $server_list_hash[p][:port] | |
$host.setText host | |
$port.setText port | |
}) | |
text_view :text => "Handle" | |
$handle = edit_text | |
text_view :text => "Host" | |
$host = edit_text | |
text_view :text => "Port" | |
$port = edit_text | |
text_view :text => "Password" | |
$password = edit_text | |
button :text => "Connect", :on_click_listener => proc { connect } | |
button :text => "Refresh", :on_click_listener => proc { refresh_me } | |
end | |
end | |
} | |
end | |
def connect | |
puts "connecting" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment