Permalink
Browse files

* added support for spinner views

  • Loading branch information...
1 parent 51530c3 commit 8daf8e56090da1192e5a2dadc6511ae628536893 @donv donv committed Apr 8, 2011
Showing with 46 additions and 5 deletions.
  1. +11 −0 .project
  2. +32 −2 assets/assets/scripts/ruboto.rb
  3. +2 −2 lib/ruboto/commands/base.rb
  4. +1 −1 lib/ruboto/util/build.rb
View
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>ruboto-core</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ </natures>
+</projectDescription>
@@ -278,6 +278,7 @@ def #{(class_name.to_s.gsub(/([A-Z])/) {'_' + $1.downcase})[1..-1]}(params={})
"
setup_list_view if class_name == :ListView
+ setup_spinner if class_name == :Spinner
setup_button if class_name == :Button
setup_linear_layout if class_name == :LinearLayout
setup_relative_layout if class_name == :RelativeLayout
@@ -369,7 +370,8 @@ def configure(context, params = {})
if params.has_key? :list
@adapter_list = Java::java.util.ArrayList.new
@adapter_list.addAll(params[:list])
- @adapter = Java::android.widget.ArrayAdapter.new(context, R::layout::simple_list_item_1, @adapter_list)
+ item_layout = params.delete(:item_layout) || R::layout::simple_list_item_1
+ @adapter = Java::android.widget.ArrayAdapter.new(context, item_layout, @adapter_list)
setAdapter @adapter
params.delete :list
end
@@ -378,7 +380,7 @@ def configure(context, params = {})
end
def reload_list(list)
- @adapter_list.clear();
+ @adapter_list.clear
@adapter_list.addAll(list)
@adapter.notifyDataSetChanged
invalidate
@@ -388,6 +390,34 @@ def reload_list(list)
ruboto_register_handler("org.ruboto.callbacks.RubotoOnItemClickListener", "item_click", ListView, "setOnItemClickListener")
end
+def setup_spinner
+ Spinner.class_eval do
+ attr_reader :adapter, :adapter_list
+
+ def configure(context, params = {})
+ if params.has_key? :list
+ @adapter_list = Java::java.util.ArrayList.new
+ @adapter_list.addAll(params[:list])
+ item_layout = params.delete(:item_layout) || R::layout::simple_spinner_item
+ @adapter = Java::android.widget.ArrayAdapter.new(context, item_layout, @adapter_list)
+ setAdapter @adapter
+ params.delete :list
+ end
+ setOnItemSelectedListener(context)
+ super(context, params)
+ end
+
+ def reload_list(list)
+ @adapter.clear
+ @adapter.addAll(list)
+ @adapter.notifyDataSetChanged
+ invalidate
+ end
+ end
+
+ ruboto_register_handler("org.ruboto.callbacks.RubotoOnItemSelectedListener", "item_selected", Spinner, "setOnItemSelectedListener")
+end
+
#############################################################################
#
# Import a class and set it up for handlers
@@ -268,8 +268,8 @@ def run
argument("class"){
required
- validate {|i| %w(Activity Service BroadcastReceiver View PreferenceActivity TabActivity OnClickListener OnItemClickListener all).include?(i)}
- description "Activity, Service, BroadcastReceiver, View, OnClickListener, OnItemClickListener, or all (default = all); Other activities not included in 'all': PreferenceActivity, TabActivity"
+ validate {|i| %w(Activity Service BroadcastReceiver View PreferenceActivity TabActivity OnClickListener OnItemClickListener OnItemSelectedListener all).include?(i)}
+ description "Activity, Service, BroadcastReceiver, View, OnClickListener, OnItemClickListener, OnItemSelectedListener, or all (default = all); Other activities not included in 'all': PreferenceActivity, TabActivity"
}
option("method_base"){
View
@@ -125,7 +125,7 @@ def generate_subclass_or_interface(params)
# on the API specifications.
#
def generate_core_classes(params)
- %w(android.view.View.OnClickListener android.widget.AdapterView.OnItemClickListener).each do |i|
+ %w(android.view.View.OnClickListener android.widget.AdapterView.OnItemClickListener android.widget.AdapterView.OnItemSelectedListener).each do |i|
name = i.split(".")[-1]
if(params[:class] == name or params[:class] == "all")
generate_subclass_or_interface({:package => "org.ruboto.callbacks", :class => i, :name => "Ruboto#{name}"})

0 comments on commit 8daf8e5

Please sign in to comment.