Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* added support for spinner views

  • Loading branch information...
commit 8daf8e56090da1192e5a2dadc6511ae628536893 1 parent 51530c3
@donv donv authored
View
11 .project
@@ -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>
View
34 assets/assets/scripts/ruboto.rb
@@ -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
View
4 lib/ruboto/commands/base.rb
@@ -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
2  lib/ruboto/util/build.rb
@@ -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}"})
Please sign in to comment.
Something went wrong with that request. Please try again.