diff --git a/assets/src/InheritingBroadcastReceiver.java b/assets/src/InheritingBroadcastReceiver.java index 4478d4c5..2f8197a0 100644 --- a/assets/src/InheritingBroadcastReceiver.java +++ b/assets/src/InheritingBroadcastReceiver.java @@ -1,28 +1,9 @@ package THE_PACKAGE; import org.ruboto.JRubyAdapter; -import org.ruboto.ScriptLoader; public class InheritingBroadcastReceiver extends org.ruboto.RubotoBroadcastReceiver { - private boolean scriptLoaded = false; - public InheritingBroadcastReceiver() { super("sample_broadcast_receiver.rb"); - if (JRubyAdapter.isInitialized()) { - scriptLoaded = true; - } - } - - public void onReceive(android.content.Context context, android.content.Intent intent) { - if (!scriptLoaded) { - if (JRubyAdapter.setUpJRuby(context)) { - ScriptLoader.loadScript(this); - scriptLoaded = true; - } else { - // FIXME(uwe): What to do if the Ruboto Core platform is missing? - } - } - super.onReceive(context, intent); } - } diff --git a/assets/src/InheritingClass.java b/assets/src/InheritingClass.java index 096e6aa5..bfcc946f 100644 --- a/assets/src/InheritingClass.java +++ b/assets/src/InheritingClass.java @@ -9,9 +9,7 @@ import org.ruboto.ScriptLoader; public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS { -THE_CONSTANTS - - private final ScriptInfo scriptInfo = new ScriptInfo(CONSTANTS_COUNT); + private final ScriptInfo scriptInfo = new ScriptInfo(); { scriptInfo.setRubyClassName(getClass().getSimpleName()); ScriptLoader.loadScript(this); @@ -23,11 +21,6 @@ public ScriptInfo getScriptInfo() { return scriptInfo; } - // FIXME(uwe): Only used for block based primary activities. Remove if we remove support for such. - public void onCreateSuper() { - // Do nothing - } - THE_METHODS } diff --git a/assets/src/RubotoActivity.java b/assets/src/RubotoActivity.java index 1b314603..b6976613 100644 --- a/assets/src/RubotoActivity.java +++ b/assets/src/RubotoActivity.java @@ -8,9 +8,7 @@ import android.os.Bundle; public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS { -THE_CONSTANTS - - private final ScriptInfo scriptInfo = new ScriptInfo(CONSTANTS_COUNT); + private final ScriptInfo scriptInfo = new ScriptInfo(); private String remoteVariable = null; Bundle[] args; private Bundle configBundle = null; @@ -32,12 +30,6 @@ public ScriptInfo getScriptInfo() { * * Activity Lifecycle: onCreate */ - - // FIXME(uwe): Only used for block based primary activities. Remove if we remove support for such. - public void onCreateSuper() { - super.onCreate((Bundle) args[0]); - } - @Override public void onCreate(Bundle bundle) { System.out.println("THE_RUBOTO_CLASS onCreate(): " + getClass().getName()); diff --git a/assets/src/RubotoBroadcastReceiver.java b/assets/src/RubotoBroadcastReceiver.java index 2a41e24b..6e14027b 100644 --- a/assets/src/RubotoBroadcastReceiver.java +++ b/assets/src/RubotoBroadcastReceiver.java @@ -5,13 +5,9 @@ import org.ruboto.ScriptLoader; public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS { - private final ScriptInfo scriptInfo = new ScriptInfo(CONSTANTS_COUNT); + private final ScriptInfo scriptInfo = new ScriptInfo(); + private boolean scriptLoaded = false; - public void setCallbackProc(int id, Object obj) { - // Error: no callbacks - throw new RuntimeException("RubotoBroadcastReceiver does not accept callbacks"); - } - public ScriptInfo getScriptInfo() { return scriptInfo; } @@ -25,42 +21,34 @@ public THE_RUBOTO_CLASS(String name) { if (name != null) { scriptInfo.setScriptName(name); - if (JRubyAdapter.isInitialized()) { - // TODO(uwe): Only needed for non-class-based definitions - // Can be removed if we stop supporting non-class-based definitions - JRubyAdapter.put("$broadcast_receiver", this); - // TODO end - ScriptLoader.loadScript(this); + scriptLoaded = true; } } } - // FIXME(uwe): Only used for block based primary activities. Remove if we remove support for such. - public void onCreateSuper() { - // Do nothing - } - public void onReceive(android.content.Context context, android.content.Intent intent) { try { Log.d("onReceive: " + this); - - // FIXME(uwe): Only needed for older broadcast receiver using callbacks - // FIXME(uwe): Remove if we stop suppporting callbacks (to avoid global variables). - JRubyAdapter.put("$context", context); - JRubyAdapter.put("$intent", intent); - JRubyAdapter.put("$broadcast_receiver", this); - // FIXME end + if (!scriptLoaded) { + if (JRubyAdapter.setUpJRuby(context)) { + ScriptLoader.loadScript(this); + scriptLoaded = true; + } else { + // FIXME(uwe): What to do if the Ruboto Core platform is missing? + } + } // FIXME(uwe): Simplify when we stop supporting JRuby 1.6.x - if (JRubyAdapter.isJRubyPreOneSeven()) { - JRubyAdapter.runScriptlet("$broadcast_receiver.on_receive($context, $intent)"); - } else if (JRubyAdapter.isJRubyOneSeven()) { + // if (JRubyAdapter.isJRubyPreOneSeven()) { + // JRubyAdapter.put("$broadcast_receiver", this); + // JRubyAdapter.runScriptlet("$broadcast_receiver.on_receive($context, $intent)"); + // } else if (JRubyAdapter.isJRubyOneSeven()) { JRubyAdapter.runRubyMethod(this, "on_receive", new Object[]{context, intent}); - } else { - throw new RuntimeException("Unknown JRuby version: " + JRubyAdapter.get("JRUBY_VERSION")); - } + // } else { + // throw new RuntimeException("Unknown JRuby version: " + JRubyAdapter.get("JRUBY_VERSION")); + // } } catch(Exception e) { e.printStackTrace(); } diff --git a/assets/src/RubotoService.java b/assets/src/RubotoService.java index aebe49c0..bedab5c4 100644 --- a/assets/src/RubotoService.java +++ b/assets/src/RubotoService.java @@ -5,9 +5,7 @@ import java.io.IOException; public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS { -THE_CONSTANTS - - private final ScriptInfo scriptInfo = new ScriptInfo(CONSTANTS_COUNT); + private final ScriptInfo scriptInfo = new ScriptInfo(); public ScriptInfo getScriptInfo() { return scriptInfo; @@ -17,12 +15,6 @@ public ScriptInfo getScriptInfo() { * * Service Lifecycle: onCreate */ - - // FIXME(uwe): Only used for block based primary activities. Remove if we remove support for such. - public void onCreateSuper() { - super.onCreate(); - } - @Override public void onCreate() { if (ScriptLoader.isCalledFromJRuby()) { diff --git a/assets/src/org/ruboto/RubotoComponent.java b/assets/src/org/ruboto/RubotoComponent.java index 099ac1e6..be824e89 100644 --- a/assets/src/org/ruboto/RubotoComponent.java +++ b/assets/src/org/ruboto/RubotoComponent.java @@ -2,7 +2,4 @@ public interface RubotoComponent { ScriptInfo getScriptInfo(); - - // FIXME(uwe): Only used for block based primary activities. Remove if we remove support for such. - void onCreateSuper(); } diff --git a/assets/src/org/ruboto/ScriptInfo.java b/assets/src/org/ruboto/ScriptInfo.java index 614d372f..d67c6360 100644 --- a/assets/src/org/ruboto/ScriptInfo.java +++ b/assets/src/org/ruboto/ScriptInfo.java @@ -5,21 +5,6 @@ public class ScriptInfo { private String scriptName; private Object rubyInstance; - // FIXME(uwe): Only used for legacy handle_xxx callbacks. Remove when we stop supporting these. - private final Object[] callbackProcs; - - public ScriptInfo(int callbackSize) { - callbackProcs = new Object[callbackSize]; - } - - public Object[] getCallbackProcs() { - return callbackProcs; - } - - public void setCallbackProc(int id, Object obj) { - callbackProcs[id] = obj; - } - public String getRubyClassName() { if (rubyClassName == null && scriptName != null) { return Script.toCamelCase(scriptName); diff --git a/assets/src/org/ruboto/ScriptLoader.java b/assets/src/org/ruboto/ScriptLoader.java index 0002d8f0..062d1ec0 100644 --- a/assets/src/org/ruboto/ScriptLoader.java +++ b/assets/src/org/ruboto/ScriptLoader.java @@ -106,23 +106,8 @@ public void run() { if (component instanceof android.content.Context) { callOnCreate(rubyInstance, args); } - } else { - // FIXME(uwe): Remove when we stop supporting block based main activities. - component.onCreateSuper(); } component.getScriptInfo().setRubyInstance(rubyInstance); - } else { // if (configBundle != null) { - // FIXME(uwe): Simplify when we stop support for RubotoCore 0.4.7 - if (JRubyAdapter.isJRubyPreOneSeven()) { - JRubyAdapter.runScriptlet("$activity.initialize_ruboto"); - } else if (JRubyAdapter.isJRubyOneSeven()) { - JRubyAdapter.runRubyMethod(component, "initialize_ruboto"); - } else { - throw new RuntimeException("Unknown JRuby version: " + JRubyAdapter.get("JRUBY_VERSION")); - } - if (component instanceof android.content.Context) { - callOnCreate(component, args); - } } } catch(IOException e){ e.printStackTrace(); diff --git a/assets/src/ruboto.rb b/assets/src/ruboto.rb deleted file mode 100644 index b508e8a9..00000000 --- a/assets/src/ruboto.rb +++ /dev/null @@ -1,25 +0,0 @@ -####################################################### -# -# ruboto.rb -# -# - Wrapper for using RubotoActivity, RubotoService, and -# RubotoBroadcastReceiver. -# - Provides interface for generating UI elements. -# - Imports and configures callback classes. -# -# require this script for legacy support or require -# the individual script files. -# -####################################################### - -require 'ruboto/base' -require 'ruboto/package' -require 'ruboto/activity' -require 'ruboto/service' -require 'ruboto/broadcast_receiver' - -require 'ruboto/widget' -require 'ruboto/menu' -require 'ruboto/util/stack' -require 'ruboto/util/toast' -require 'ruboto/legacy' diff --git a/assets/src/ruboto/activity.rb b/assets/src/ruboto/activity.rb index 4e2de43f..6e30baea 100644 --- a/assets/src/ruboto/activity.rb +++ b/assets/src/ruboto/activity.rb @@ -5,33 +5,20 @@ # # ruboto/activity.rb # -# Basic activity set up and callback configuration. +# Basic activity set up. # ####################################################### # # Context # - module Ruboto module Context - def initialize_ruboto() - eval("#{$new_context_global} = self") - $new_context_global = nil - - instance_eval &$context_init_block if $context_init_block - $context_init_block = nil - setup_ruboto_callbacks - - @initialized = true - self - end - def start_ruboto_dialog(remote_variable, theme=Java::android.R.style::Theme_Dialog, &block) - ruboto_import "org.ruboto.RubotoDialog" + java_import "org.ruboto.RubotoDialog" start_ruboto_activity(remote_variable, RubotoDialog, theme, &block) end - + def start_ruboto_activity(global_variable_name = '$activity', klass=RubotoActivity, theme=nil, options = nil, &block) # FIXME(uwe): Translate old positional signature to new options-based signature. # FIXME(uwe): Remove when we stop supporting Ruboto 0.8.0 or older. @@ -44,31 +31,19 @@ def start_ruboto_activity(global_variable_name = '$activity', klass=RubotoActivi global_variable_name = nil end - # FIXME(uwe): Used for block-based definition of main activity. - # FIXME(uwe): Remove when we stop supporting Ruboto 0.8.0 or older. - puts "start_ruboto_activity self: #{self.inspect}" - if @ruboto_java_class and not @ruboto_java_class_initialized - @ruboto_java_class_initialized = true - puts "Block based main activity definition" - instance_eval &block if block - setup_ruboto_callbacks - on_create nil + class_name = options[:class_name] || "#{klass.name.split('::').last}_#{source_descriptor(block)[0].split("/").last.gsub(/[.-]+/, '_')}_#{source_descriptor(block)[1]}" + if !Object.const_defined?(class_name) + Object.const_set(class_name, Class.new(&block)) else - puts "Class based main activity definition" - class_name = options[:class_name] || "#{klass.name.split('::').last}_#{source_descriptor(block)[0].split("/").last.gsub(/[.-]+/, '_')}_#{source_descriptor(block)[1]}" - if !Object.const_defined?(class_name) - Object.const_set(class_name, Class.new(&block)) - else - Object.const_get(class_name).class_eval(&block) if block_given? - end - b = Java::android.os.Bundle.new - b.putInt("Theme", theme) if theme - b.putString("ClassName", class_name) - i = android.content.Intent.new - i.setClass self, klass.java_class - i.putExtra("RubotoActivity Config", b) - startActivity i + Object.const_get(class_name).class_eval(&block) if block_given? end + b = Java::android.os.Bundle.new + b.putInt("Theme", theme) if theme + b.putString("ClassName", class_name) + i = android.content.Intent.new + i.setClass self, klass.java_class + i.putExtra("RubotoActivity Config", b) + startActivity i self end @@ -110,6 +85,6 @@ def ruboto_configure_activity(klass) end java_import "android.app.Activity" -ruboto_import "org.ruboto.RubotoActivity" +java_import "org.ruboto.RubotoActivity" ruboto_configure_activity(RubotoActivity) diff --git a/assets/src/ruboto/base.rb b/assets/src/ruboto/base.rb index 03f45ac0..fd511212 100644 --- a/assets/src/ruboto/base.rb +++ b/assets/src/ruboto/base.rb @@ -6,15 +6,6 @@ # ####################################################### -# Only used needed for ruboto-core apps -require 'ruboto/version' -$RUBOTO_VERSION = 10 - -def confirm_ruboto_version(required_version, exact=true) - raise "requires $RUBOTO_VERSION=#{required_version} or greater, current version #{$RUBOTO_VERSION}" if $RUBOTO_VERSION < required_version and not exact - raise "requires $RUBOTO_VERSION=#{required_version}, current version #{$RUBOTO_VERSION}" if $RUBOTO_VERSION != required_version and exact -end - require 'java' # Create convenience method for top-level android package so we do not need to prefix with 'Java::'. @@ -32,64 +23,3 @@ def method_missing(method, *args, &block) java_import "android.R" AndroidIds = JavaUtilities.get_proxy_class("android.R$id") - -# -# Callbacks -# - -module Ruboto - module CallbackClass - def new_with_callbacks(*args, &block) - new(*args).initialize_ruboto_callbacks(&block) - end - end - - module Callbacks - def initialize_ruboto_callbacks &block - instance_eval &block - setup_ruboto_callbacks - self - end - - def ruboto_callback_methods - # FIXME(uwe): Remove to_sym conversion when we stop supporting Ruby 1.8 mode - (singleton_methods - ["on_create", "on_receive"]).select{|i| self.class.constants.map(&:to_sym).include?(i.to_s.sub(/^on_/, "CB_").upcase.to_sym) || self.class.constants.map(&:to_sym).include?("CB_#{i}".upcase.to_sym)} - end - - def setup_ruboto_callbacks - ruboto_callback_methods.each do |i| - begin - # FIXME(uwe): Remove to_sym conversion when we stop supporting Ruby 1.8 mode - scriptInfo.setCallbackProc((self.class.constants.map(&:to_sym).include?(i.to_s.sub(/^on_/, "CB_").upcase.to_sym) && self.class.const_get(i.to_s.sub(/^on_/, "CB_").upcase)) || (self.class.constants.map(&:to_sym).include?("CB_#{i}".upcase.to_sym) && self.class.const_get("CB_#{i}".upcase)), method(i)) - rescue - end - end - end - end -end - -# -# Import a class and set it up for handlers -# - -def ruboto_import(*package_classes) - already_classes = package_classes.select{|i| not i.is_a?(String) and not i.is_a?(Symbol)} - imported_classes = package_classes - already_classes - - unless imported_classes.empty? - # TODO(uwe): The first part of this "if" is only needed for JRuby 1.6.x. Simplify when we stop supporting JRuby 1.6.x - if imported_classes.size == 1 - imported_classes = [*(java_import(*imported_classes) || eval("Java::#{imported_classes[0]}"))] - else - imported_classes = java_import(imported_classes) - end - end - - (already_classes + imported_classes).each do |package_class| - package_class.class_eval do - extend Ruboto::CallbackClass - include Ruboto::Callbacks - end - end -end - diff --git a/assets/src/ruboto/broadcast_receiver.rb b/assets/src/ruboto/broadcast_receiver.rb index e48776cb..84b25987 100644 --- a/assets/src/ruboto/broadcast_receiver.rb +++ b/assets/src/ruboto/broadcast_receiver.rb @@ -2,33 +2,13 @@ # # ruboto/broadcast_receiver.rb # -# Basic broadcast_receiver set up and callback configuration. +# Basic broadcast_receiver set up. # ####################################################### require 'ruboto/base' -ruboto_import "org.ruboto.RubotoBroadcastReceiver" -RubotoBroadcastReceiver.class_eval do - def self.new_with_callbacks &block - (($broadcast_receiver.nil? || $broadcast_receiver.initialized) ? new : $broadcast_receiver).initialize_ruboto_callbacks &block - end - - def initialized - @initialized ||= false - end - - def initialize_ruboto_callbacks &block - instance_eval &block - setup_ruboto_callbacks - @initialized = true - self - end - - def on_receive(context, intent) - end -end - +java_import "org.ruboto.RubotoBroadcastReceiver" module Ruboto module BroadcastReceiver end diff --git a/assets/src/ruboto/legacy.rb b/assets/src/ruboto/legacy.rb deleted file mode 100644 index 1321a011..00000000 --- a/assets/src/ruboto/legacy.rb +++ /dev/null @@ -1,220 +0,0 @@ -require 'ruboto/activity' - -####################################################### -# -# ruboto/legacy.rb -# -# Required for backwards compatibility. The goal -# should be to run scripts without this. -# -####################################################### - -# -# Old handle methods -# - -module Ruboto - module Callbacks - def method_missing(name, *args, &block) - if name.to_s =~ /^handle_(.*)/ && self.class.respond_to?(:const_get) && (const = self.class.const_get("CB_#{$1.upcase}")) - scriptInfo.setCallbackProc(const, block) - self - else - super - end - end - - def respond_to?(name) - return true if name.to_s =~ /^handle_(.*)/ && self.class.respond_to?(:const_get) && self.class.const_get("CB_#{$1.upcase}") - super - end - - def initialize_handlers(&block) - instance_eval &block - self - end - end -end - -# -# Old handle_create for Activities -# - -module Ruboto - module Activity - def handle_finish_create &block - @finish_create_block = block - end - - def setup_content &block - @view_parent = nil - @content_view_block = block - end - - def handle_create(&block) - $new_context_global = "$activity" - instance_exec &block - initialize_ruboto - on_create nil - end - end -end - -RubotoActivity.class_eval do - def on_create(bundle) - @view_parent = nil - setContentView(instance_eval &@content_view_block) if @content_view_block - instance_eval { @finish_create_block.call } if @finish_create_block - end -end - -# -# Allow IRB legacy -# - -if $package_name == "org.ruboto.irb" - Java::org.ruboto.irb.IRB.class_eval do - def handle_create(&block) - start_ruboto_activity "$activity", RubotoActivity, nil, &block - end - end -end - -# -# Legacy Service Subclass Setup -# - -module Ruboto - module Service - def handle_create(&block) - $new_context_global = "$service" - instance_exec &block - initialize_ruboto - on_create - end - end -end - -# -# Legacy BroadcastReceiver Subclass Setup -# - -module Ruboto - module BroadcastReceiver - def handle_receive(&block) - instance_exec &block - on_receive($context, nil) - end - end -end - -# -# Allows RubotoActivity to handle callbacks covering Class based handlers -# - -def ruboto_register_handler(unique_name, for_class, method_name) - unless RubotoActivity.method_defined? "#{unique_name}_handler" - RubotoActivity.class_eval " - def #{unique_name}_handler - @#{unique_name}_handler - end - - def handle_#{unique_name}(&block) - @#{unique_name}_handler = block - self - end - " - end - - unless for_class.method_defined? "orig_#{method_name}" - for_class.class_eval " - alias_method :orig_#{method_name}, :#{method_name} - def #{method_name}(handler) - orig_#{method_name}(handler.kind_of?(RubotoActivity) ? handler.#{unique_name}_handler : handler) - end - " - end -end - -def setup_button - Button.class_eval do - def configure(context, params = {}) - setOnClickListener(context) - super(context, params) - end - end - - ruboto_register_handler("click", Button, "setOnClickListener") -end - -def setup_image_button - ImageButton.class_eval do - def configure(context, params = {}) - setOnClickListener(context) - super(context, params) - end - end - - ruboto_register_handler("click", ImageButton, "setOnClickListener") -end - -def setup_list_view - Java::android.widget.ListView.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_list_item_1 - @adapter = Java::android.widget.ArrayAdapter.new(context, item_layout, @adapter_list) - setAdapter @adapter - params.delete :list - end - if params.has_key? :adapter - @adapter = params[:adapter] - end - setOnItemClickListener(context) # legacy - super(context, params) - end - - def reload_list(list) - @adapter_list.clear - @adapter_list.addAll(list) - @adapter.notifyDataSetChanged - invalidate - end - end - - ruboto_register_handler("item_click", Java::android.widget.ListView, "setOnItemClickListener") # legacy -end - -def setup_spinner - Java::android.widget.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) - @adapter.setDropDownViewResource(params.delete(:dropdown_layout) || R::layout::simple_spinner_dropdown_item) - setAdapter @adapter - params.delete :list - end - setOnItemSelectedListener(context) # legacy - super(context, params) - end - - def reload_list(list) - @adapter.clear - @adapter.addAll(list) - @adapter.notifyDataSetChanged - invalidate - end - end - - ruboto_register_handler("item_selected", Java::android.widget.Spinner, "setOnItemSelectedListener") # legacy -end - diff --git a/assets/src/ruboto/menu.rb b/assets/src/ruboto/menu.rb deleted file mode 100644 index f29d7137..00000000 --- a/assets/src/ruboto/menu.rb +++ /dev/null @@ -1,88 +0,0 @@ -require 'ruboto/activity' - -####################################################### -# -# ruboto/menu.rb -# -# Make using menus a little easier. This is still using -# handle methods and may be moved into legacy code. -# -####################################################### - -module Ruboto - module Activity - # - # Option Menus - # - def add_menu title, icon=nil, &block - mi = @menu.add(title) - mi.setIcon(icon) if icon - mi.class.class_eval { attr_accessor :on_click } - mi.on_click = block - - # Seems to be needed or the block might get cleaned up - @all_menu_items = [] unless @all_menu_items - @all_menu_items << mi - end - - def handle_create_options_menu &block - p = Proc.new do |*args| - @menu = args[0] - instance_eval { block.call(*args) } if block - end - scriptInfo.setCallbackProc(self.class.const_get("CB_CREATE_OPTIONS_MENU"), p) - - p = Proc.new do |num, menu_item| - # handles a problem where this is called for context items - # TODO(uwe): Remove check for SDK version when we stop supporting api level < 11 - unless @just_processed_context_item == menu_item || (android.os.Build::VERSION::SDK_INT >= 11 && menu_item.item_id == AndroidIds.home) - instance_eval &(menu_item.on_click) - @just_processed_context_item = nil - true - else - false - end - end - scriptInfo.setCallbackProc(self.class.const_get("CB_MENU_ITEM_SELECTED"), p) - end - - # - # Context Menus - # - - def add_context_menu title, &block - mi = @context_menu.add(title) - mi.class.class_eval { attr_accessor :on_click } - mi.on_click = block - - # Seems to be needed or the block might get cleaned up - @all_menu_items = [] unless @all_menu_items - @all_menu_items << mi - end - - def handle_create_context_menu &block - p = Proc.new do |*args| - @context_menu = args[0] - instance_eval { block.call(*args) } if block - end - scriptInfo.setCallbackProc(self.class.const_get("CB_CREATE_CONTEXT_MENU"), p) - - p = Proc.new do |menu_item| - if menu_item.on_click - arg = menu_item - begin - arg = menu_item.getMenuInfo.position - rescue - end - instance_eval { menu_item.on_click.call(arg) } - @just_processed_context_item = menu_item - true - else - false - end - end - scriptInfo.setCallbackProc(self.class.const_get("CB_CONTEXT_ITEM_SELECTED"), p) - end - end -end - diff --git a/assets/src/ruboto/preference.rb b/assets/src/ruboto/preference.rb index 82ab6a06..bc360707 100644 --- a/assets/src/ruboto/preference.rb +++ b/assets/src/ruboto/preference.rb @@ -10,7 +10,7 @@ java_import "android.preference.PreferenceScreen" java_import "android.preference.Preference" -ruboto_import "org.ruboto.RubotoPreferenceActivity" +java_import "org.ruboto.RubotoPreferenceActivity" ruboto_configure_activity(RubotoPreferenceActivity) RubotoPreferenceActivity.class_eval do diff --git a/assets/src/ruboto/service.rb b/assets/src/ruboto/service.rb index 97cb77c3..6577e6d6 100644 --- a/assets/src/ruboto/service.rb +++ b/assets/src/ruboto/service.rb @@ -5,71 +5,34 @@ # # ruboto/service.rb # -# Basic service set up and callback configuration. +# Basic service set up. # ####################################################### -# -# Context -# +java_import "android.content.Context" +java_import "org.ruboto.RubotoService" module Ruboto module Context - def initialize_ruboto() - eval("#{$new_context_global} = self") - $new_context_global = nil - - instance_eval &$context_init_block if $context_init_block - $context_init_block = nil - setup_ruboto_callbacks - - @initialized = true - self - end - def start_ruboto_service(global_variable_name = '$service', klass=RubotoService, &block) - $context_init_block = block - $new_context_global = global_variable_name - - if @initialized or (self == $service) or ($service == nil) # FIx mix between activity and service - self.startService Java::android.content.Intent.new(self, klass.java_class) + class_name = options[:class_name] || "#{klass.name.split('::').last}_#{source_descriptor(block)[0].split("/").last.gsub(/[.-]+/, '_')}_#{source_descriptor(block)[1]}" + if !Object.const_defined?(class_name) + Object.const_set(class_name, Class.new(&block)) else - initialize_ruboto - on_create + Object.const_get(class_name).class_eval(&block) if block_given? end - + b = Java::android.os.Bundle.new + b.putInt("Theme", theme) if theme + b.putString("ClassName", class_name) + i = android.content.Intent.new + i.setClass self, klass.java_class + i.putExtra("RubotoActivity Config", b) + self.startService Java::android.content.Intent.new(self, klass.java_class) self end end end -java_import "android.content.Context" Context.class_eval do include Ruboto::Context end - -# -# Leave for legacy Service Subclass Setup -# - -module Ruboto - module Service - end -end - -# -# Basic Service Setup -# - -def ruboto_configure_service(klass) - klass.class_eval do - include Ruboto::Service - - def on_create - end - end -end - -ruboto_import "org.ruboto.RubotoService" -ruboto_configure_service(RubotoService) - diff --git a/assets/src/ruboto/widget.rb b/assets/src/ruboto/widget.rb index 7338a34a..6f39d49b 100644 --- a/assets/src/ruboto/widget.rb +++ b/assets/src/ruboto/widget.rb @@ -90,10 +90,10 @@ def ruboto_import_widgets(*widgets) def ruboto_import_widget(class_name, package_name="android.widget") if class_name.is_a?(String) or class_name.is_a?(Symbol) - klass = ruboto_import("#{package_name}.#{class_name}") || eval("Java::#{package_name}.#{class_name}") + klass = java_import("#{package_name}.#{class_name}") || eval("Java::#{package_name}.#{class_name}") else klass = class_name - ruboto_import klass + java_import klass class_name = klass.java_class.name.split('.')[-1] end diff --git a/examples/RubotoTestApp_0.6.0_tools_r19.tgz b/examples/RubotoTestApp_0.6.0_tools_r19.tgz deleted file mode 100644 index 2dd6d3d7..00000000 Binary files a/examples/RubotoTestApp_0.6.0_tools_r19.tgz and /dev/null differ diff --git a/lib/java_class_gen/InheritingClass.java.erb b/lib/java_class_gen/InheritingClass.java.erb deleted file mode 100644 index b08001b6..00000000 --- a/lib/java_class_gen/InheritingClass.java.erb +++ /dev/null @@ -1,10 +0,0 @@ -package THE_PACKAGE; - -public class Inheriting<%= @class %> extends org.ruboto.Ruboto<%= @class %> { -% v = @callbacks[@full_class][@first_method] - public <%= "#{v["return_type"]} #{v["interface_method"]}(#{v["args_with_types"] })" %> { - setScriptName("start.rb"); - super.<%= @first_method %>(<%= v["args_alone"].join(',') %>); - } - -} diff --git a/lib/ruboto/util/build.rb b/lib/ruboto/util/build.rb index 04bfd51e..25f152ab 100644 --- a/lib/ruboto/util/build.rb +++ b/lib/ruboto/util/build.rb @@ -112,9 +112,6 @@ def generate_subclass_or_interface(params) methods = check_methods(methods, params[:force]) puts "Done. Methods created: #{methods.count}" - # Remove any duplicate constants (use *args handle multiple parameter lists) - constants = methods.map(&:constant_string).uniq - params[:implements] = params[:implements].split(",").push('org.ruboto.RubotoComponent').join(",") action = class_desc.name == "class" ? "extends" : "implements" @@ -125,8 +122,6 @@ def generate_subclass_or_interface(params) "THE_ANDROID_CLASS" => (params[:class] || params[:interface]) + (params[:implements] == "" ? "" : ((action != 'implements' ? " implements " : ', ') + params[:implements].split(",").join(", "))), "THE_RUBOTO_CLASS" => params[:name], - "THE_CONSTANTS" => constants.map { |i| "public static final int #{i} = #{constants.index(i)};" }.indent.join("\n"), - "CONSTANTS_COUNT" => methods.count.to_s, "THE_CONSTRUCTORS" => class_desc.name == "class" ? class_desc.get_elements("constructor").map { |i| i.constructor_definition(params[:name]) }.join("\n\n") : "", "THE_METHODS" => methods.map { |i| i.method_definition(params[:name]) }.join("\n\n") diff --git a/lib/ruboto/util/update.rb b/lib/ruboto/util/update.rb index 659e2dda..144abd6c 100644 --- a/lib/ruboto/util/update.rb +++ b/lib/ruboto/util/update.rb @@ -10,7 +10,6 @@ module Update # # Updating components # - def update_android root = Dir.getwd build_xml_file = "#{root}/build.xml" @@ -122,15 +121,6 @@ def update_test(force = nil) ant_script.gsub!(/\s*.*?\s*/m, '') raise "Bad ANT script" unless ant_script.gsub!(/\s*(<\/project>)/, "\n\n#{run_tests_override}\n\n\\1") File.open('build.xml', 'w') { |f| f << ant_script } - - # FIXME(uwe): Remove when we stop supporting update from Ruboto < 0.5.3 - if File.directory? 'assets/scripts' - log_action 'Moving test scripts to the "src" directory.' do - FileUtils.mv Dir['assets/scripts/*'], 'src' - FileUtils.rm_rf 'assets/scripts' - end - end - # EMXIF end end @@ -208,13 +198,6 @@ def update_dx_jar(force=nil) def update_assets puts "\nCopying files:" - - # FIXME(uwe): Remove when we stop supporting updating from Ruboto < 0.6.0 - if File.exists?('Rakefile') && !File.exists?('rakelib/ruboto.rake') - FileUtils.rm 'Rakefile' - end - # EMXIF - weak_copier = Ruboto::Util::AssetCopier.new Ruboto::ASSETS, '.', false %w{.gitignore Rakefile}.each { |f| log_action(f) { weak_copier.copy f } } @@ -336,11 +319,6 @@ def update_manifest(min_sdk, target, force = false) end def update_core_classes(force = nil) - # FIXME(uwe): Remove when we stop supporting updating from Ruboto 0.5.5 and older. - FileUtils.rm_rf 'src/org/ruboto/callbacks' - FileUtils.rm_f 'src/org/ruboto/RubotoView.java' - # EMXIF - generate_core_classes(:class => "all", :method_base => "on", :method_include => "", :method_exclude => "", :force => force, :implements => "") end @@ -350,11 +328,6 @@ def read_ruboto_version end def update_ruboto(force=nil) - log_action("Copying ruboto.rb") do - from = File.expand_path(Ruboto::GEM_ROOT + "/assets/#{SCRIPTS_DIR}/ruboto.rb") - to = File.expand_path("./#{SCRIPTS_DIR}/ruboto.rb") - FileUtils.cp from, to - end log_action("Copying ruboto/version.rb") do from = File.expand_path(Ruboto::GEM_ROOT + "/lib/ruboto/version.rb") to = File.expand_path("./#{SCRIPTS_DIR}/ruboto/version.rb") diff --git a/lib/ruboto/util/xml_element.rb b/lib/ruboto/util/xml_element.rb index 7378129d..d77532bb 100644 --- a/lib/ruboto/util/xml_element.rb +++ b/lib/ruboto/util/xml_element.rb @@ -151,7 +151,7 @@ def super_return rv ? "return #{rv}" : default_return end - def ruby_call(on_ruby_instance = false, camelize = false) + def ruby_call(camelize = false) params = parameters args = "" if params.size > 1 @@ -175,7 +175,6 @@ def ruby_call(on_ruby_instance = false, camelize = false) convert_return = "#{return_class.sub(/<.*>$/, '')}.class, " end - if on_ruby_instance method_name = camelize ? attribute("name") : snake_case_attribute global_args = params.map{|i| "$arg_#{i[0]}"}.join(", ") ["// FIXME(uwe): Simplify when we stop support for RubotoCore 0.4.7"] + @@ -192,9 +191,6 @@ def ruby_call(on_ruby_instance = false, camelize = false) ['throw new RuntimeException("Unknown JRuby version: " + JRubyAdapter.get("JRUBY_VERSION"));'] ) ) - else - ["#{return_cast}JRubyAdapter.runRubyMethod(#{convert_return}scriptInfo.getCallbackProcs()[#{constant_string}], \"call\" #{args});"] - end end def snake_case_attribute @@ -209,22 +205,16 @@ def method_definition(class_name) ["if (ScriptLoader.isCalledFromJRuby()) #{super_return}", if_else( "JRubyAdapter.isInitialized()", - if_else( - "scriptInfo.getCallbackProcs() != null && scriptInfo.getCallbackProcs()[#{constant_string}] != null", - [super_string] + ruby_call, ['String rubyClassName = scriptInfo.getRubyClassName();'] + if_else( - # TODO(uwe): Remove defined?(rubyClassName) if we remove non-class-based class definitions - "(Boolean)JRubyAdapter.runScriptlet(\"defined?(\" + rubyClassName + \") == 'constant' && \" + rubyClassName + \".instance_methods(false).any?{|m| m.to_sym == :#{snake_case_attribute}}\")", - ruby_call(true), + "(Boolean)JRubyAdapter.runScriptlet(rubyClassName + \".instance_methods(false).any?{|m| m.to_sym == :#{snake_case_attribute}}\")", + ruby_call, if_else( - # TODO(uwe): Remove defined?(rubyClassName) if we remove non-class-based class definitions - "(Boolean)JRubyAdapter.runScriptlet(\"defined?(\" + rubyClassName + \") == 'constant' && \" + rubyClassName + \".instance_methods(false).any?{|m| m.to_sym == :#{attribute('name')}}\")", - ruby_call(true, true), + "(Boolean)JRubyAdapter.runScriptlet(rubyClassName + \".instance_methods(false).any?{|m| m.to_sym == :#{attribute('name')}}\")", + ruby_call(true), [super_return] ) - ) - ), + ), [ %Q{Log.i("Method called before JRuby runtime was initialized: #{class_name}##{attribute('name')}");}, super_return, diff --git a/lib/ruboto/version.rb b/lib/ruboto/version.rb index 99050440..44b32671 100644 --- a/lib/ruboto/version.rb +++ b/lib/ruboto/version.rb @@ -5,6 +5,6 @@ module Ruboto and generators for creating projects, classes, tests, and more. The complete APIs of Android, Java, and Ruby is available to you using the Ruby language. EOF - VERSION = '0.9.1.dev' - UPDATE_VERSION_LIMIT = '0.5.2' + VERSION = '0.10.0.dev' + UPDATE_VERSION_LIMIT = '0.7.0' end diff --git a/matrix_tests.sh b/matrix_tests.sh index 097b8442..b4732650 100755 --- a/matrix_tests.sh +++ b/matrix_tests.sh @@ -2,10 +2,10 @@ MASTER=1.7.1.dev PLATFORM_MODES="CURRENT FROM_GEM STANDALONE" -STANDALONE_JRUBY_VERSIONS="$MASTER 1.7.0 1.6.8" +STANDALONE_JRUBY_VERSIONS="$MASTER 1.7.0" +SKIP_RUBOTO_UPDATE_TEST=1 -export ANDROID_TARGET ANDROID_OS JRUBY_JARS_VERSION RUBOTO_PLATFORM -export SKIP_RUBOTO_UPDATE_TEST=1 +export ANDROID_TARGET ANDROID_OS RUBOTO_PLATFORM SKIP_RUBOTO_UPDATE_TEST EMULATOR_CMD=emulator64-arm @@ -71,15 +71,16 @@ for ANDROID_TARGET in 10 15 ; do killall -0 $EMULATOR_CMD 2> /dev/null if [ "$?" == "0" ] ; then - echo "Emulator started." + echo -n "Emulator started: " for i in 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 ; do sleep 1 if [ `adb get-state` == "device" ] ; then break fi - echo Waiting for device: $i + echo -n . done + echo if [ `adb get-state` == "device" ] ; then break fi @@ -119,8 +120,11 @@ for ANDROID_TARGET in 10 15 ; do for JRUBY_JARS_VERSION in $jruby_versions ; do if [ $RUBOTO_PLATFORM == "CURRENT" ] ; then unset JRUBY_JARS_VERSION - elif [ $RUBOTO_PLATFORM == "FROM_GEM" ] ; then - rake platform:clean + else + export JRUBY_JARS_VERSION + if [ $RUBOTO_PLATFORM == "FROM_GEM" ] ; then + rake platform:clean + fi fi echo "" echo "********************************************************************************" @@ -132,10 +136,7 @@ for ANDROID_TARGET in 10 15 ; do ./run_tests.sh # ruby test/minimal_app_test.rb # ruby test/ruboto_gen_test.rb -n test_new_apk_size_is_within_limits - # ACTIVITY_TEST_PATTERN=subclass ruby test/ruboto_gen_test.rb -n test_activity_tests - # ACTIVITY_TEST_PATTERN=mytest ruby test/ruboto_gen_test.rb -n test_activity_tests - # ruby test/ruboto_gen_test.rb -n test_handle_activity_tests - # ruby test/ruboto_gen_test.rb -n test_activity_with_first_letter_lower_case_in_name + # ACTIVITY_TEST_PATTERN=navigation ruby test/ruboto_gen_test.rb -n test_activity_tests done done done diff --git a/run_tests.sh b/run_tests.sh index aed96c20..d7688975 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,7 +1,7 @@ #!/bin/bash -el # BEGIN TIMEOUT # -TIMEOUT=14400 +TIMEOUT=14400 # 4 hours BOSSPID=$$ ( sleep $TIMEOUT diff --git a/test/app_test_methods.rb b/test/app_test_methods.rb index 1351e049..c796f943 100644 --- a/test/app_test_methods.rb +++ b/test/app_test_methods.rb @@ -22,18 +22,6 @@ def test_activity_tests run_activity_tests('activity') end - def test_block_def_activity_tests - run_activity_tests('block_def_activity') - end - - def test_handle_activity_tests - Dir.chdir APP_DIR do - FileUtils.rm "src/ruboto_test_app_activity.rb" - FileUtils.rm "test/src/ruboto_test_app_activity_test.rb" - end - run_activity_tests('handle_activity') - end - private def assert_code(activity_name, code) diff --git a/test/block_def_activity/image_button_activity.rb b/test/block_def_activity/image_button_activity.rb deleted file mode 100644 index fdb5d119..00000000 --- a/test/block_def_activity/image_button_activity.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'ruboto/activity' -require 'ruboto/widget' -require 'ruboto/util/toast' - -ruboto_import_widgets :ImageButton, :LinearLayout, :TextView - -$activity.start_ruboto_activity do - setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ') - - def on_create(bundle) - click_handler = proc do |view| - @text_view.setText 'What hath Matz wrought!' - toast 'Flipped a bit via butterfly' - end - - self.content_view = - linear_layout :orientation => LinearLayout::VERTICAL do - @text_view = text_view :text => 'What hath Matz wrought?', :id => 42 - image_button :image_resource => $package.R::drawable::get_ruboto_core, :width => :wrap_content, :id => 43, - :on_click_listener => click_handler - end - end -end diff --git a/test/block_def_activity/image_button_activity_test.rb b/test/block_def_activity/image_button_activity_test.rb deleted file mode 100644 index af2e3607..00000000 --- a/test/block_def_activity/image_button_activity_test.rb +++ /dev/null @@ -1,21 +0,0 @@ -activity Java::org.ruboto.test_app.ImageButtonActivity - -setup do |activity| - start = Time.now - loop do - @text_view = activity.findViewById(42) - break if @text_view || (Time.now - start > 60) - sleep 1 - end - assert @text_view -end - -test('initial setup') do |activity| - assert_equal "What hath Matz wrought?", @text_view.text -end - -test('button changes text') do |activity| - button = activity.findViewById(43) - button.performClick - assert_equal "What hath Matz wrought!", @text_view.text -end diff --git a/test/block_def_activity/image_button_and_button_activity.rb b/test/block_def_activity/image_button_and_button_activity.rb deleted file mode 100644 index 66ca556d..00000000 --- a/test/block_def_activity/image_button_and_button_activity.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'ruboto/activity' -require 'ruboto/widget' -require 'ruboto/util/toast' - -ruboto_import_widgets :Button, :ImageButton, :LinearLayout, :TextView - -$activity.start_ruboto_activity do - setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ') - - def on_create(bundle) - self.content_view = - linear_layout :orientation => LinearLayout::VERTICAL do - @text_view = text_view :text => 'What hath Matz wrought?', :id => 42 - button :text => 'Button', :width => :wrap_content, :id => 44, - :on_click_listener => proc { @text_view.text = 'Button pressed' } - image_button :image_resource => $package.R::drawable::get_ruboto_core, :width => :wrap_content, :id => 43, - :on_click_listener => proc { @text_view.text = 'Image button pressed' } - end - end -end diff --git a/test/block_def_activity/image_button_and_button_activity_test.rb b/test/block_def_activity/image_button_and_button_activity_test.rb deleted file mode 100644 index c392a592..00000000 --- a/test/block_def_activity/image_button_and_button_activity_test.rb +++ /dev/null @@ -1,27 +0,0 @@ -activity Java::org.ruboto.test_app.ImageButtonAndButtonActivity - -setup do |activity| - start = Time.now - loop do - @text_view = activity.find_view_by_id 42 - break if @text_view || (Time.now - start > 60) - sleep 1 - end - assert @text_view -end - -test('initial setup') do |activity| - assert_equal "What hath Matz wrought?", @text_view.text -end - -test('button changes text') do |activity| - button = activity.find_view_by_id 44 - button.perform_click - assert_equal 'Button pressed', @text_view.text -end - -test('image button changes text') do |activity| - image_button = activity.find_view_by_id 43 - image_button.perform_click - assert_equal 'Image button pressed', @text_view.text -end diff --git a/test/block_def_activity/margins_activity.rb b/test/block_def_activity/margins_activity.rb deleted file mode 100644 index a2c2cd75..00000000 --- a/test/block_def_activity/margins_activity.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'ruboto/activity' -require 'ruboto/widget' - -ruboto_import_widgets :LinearLayout, :TextView - -$activity.start_ruboto_activity do - setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ') - - def on_create(bundle) - self.content_view = - linear_layout :orientation => LinearLayout::VERTICAL do - @text_view_margins = text_view :text => 'What hath Matz wrought?', :id => 42, :margins => [100,0,0,0] - @text_view_layout = text_view :text => 'What hath Matz wrought?', :id => 43, :layout => {:set_margins => [100,0,0,0]} - @text_view_fieldset = text_view :text => 'What hath Matz wrought?', :id => 44, :layout => {:left_margin= => 100} - end - end -end - diff --git a/test/block_def_activity/margins_activity_test.rb b/test/block_def_activity/margins_activity_test.rb deleted file mode 100644 index 4ed96bc3..00000000 --- a/test/block_def_activity/margins_activity_test.rb +++ /dev/null @@ -1,25 +0,0 @@ -activity Java::org.ruboto.test_app.MarginsActivity - -setup do |activity| - start = Time.now - loop do - @text_view_margins = activity.findViewById(42) - @text_view_layout = activity.findViewById(43) - @text_view_fieldset = activity.findViewById(44) - break if @text_view_margins || @text_view_layout || @text_view_fieldset || (Time.now - start > 60) - sleep 1 - end - assert @text_view_margins - assert @text_view_layout - assert @text_view_fieldset -end - -def left_margin(view) - view.get_layout_params.leftMargin -end - -%w(margins layout fieldset).each do |view_type| - test("margins are set through #{view_type}") do |activity| - assert_equal 100, left_margin(instance_variable_get("@text_view_#{view_type}")) - end -end \ No newline at end of file diff --git a/test/block_def_activity/option_menu_activity.rb b/test/block_def_activity/option_menu_activity.rb deleted file mode 100644 index 02d8aa56..00000000 --- a/test/block_def_activity/option_menu_activity.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'ruboto/activity' -require 'ruboto/widget' -require 'ruboto/util/toast' - -ruboto_import_widgets :LinearLayout, :TextView - -$activity.start_ruboto_activity do - setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map{|s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ') - - def on_create(bundle) - self.content_view = - linear_layout :orientation => LinearLayout::VERTICAL do - @text_view = text_view :text => 'What hath Matz wrought?', :id => 42 - end - end - - def on_create_options_menu(menu) - mi = menu.add('Test') - mi.setIcon($package.R::drawable::get_ruboto_core) - mi.set_on_menu_item_click_listener do |menu_item| - @text_view.text = 'What hath Matz wrought!' - toast 'Flipped a bit via butterfly' - end - true - end -end diff --git a/test/block_def_activity/option_menu_activity_test.rb b/test/block_def_activity/option_menu_activity_test.rb deleted file mode 100644 index 80a7277b..00000000 --- a/test/block_def_activity/option_menu_activity_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -activity Java::org.ruboto.test_app.OptionMenuActivity - -setup do |activity| - start = Time.now - loop do - @text_view = activity.findViewById(42) - break if @text_view || (Time.now - start > 60) - sleep 1 - end - assert @text_view -end - -test('option_menu changes text') do |activity| - assert_equal "What hath Matz wrought?", @text_view.text - activity.window.performPanelIdentifierAction(android.view.Window::FEATURE_OPTIONS_PANEL, 0, 0) - assert_equal("What hath Matz wrought!", @text_view.text) -end diff --git a/test/block_def_activity/psych_activity.rb b/test/block_def_activity/psych_activity.rb deleted file mode 100644 index 4302794d..00000000 --- a/test/block_def_activity/psych_activity.rb +++ /dev/null @@ -1,35 +0,0 @@ -# TODO(uwe): Remove when we stop supporting psych with Ruby 1.8 mode -if RUBY_VERSION < '1.9' - require 'jruby' - require 'rbconfig' - org.jruby.ext.psych.PsychLibrary.new.load(JRuby.runtime, false) - $LOADED_FEATURES << 'psych.so' - $LOAD_PATH << File.join(Config::CONFIG['libdir'], 'ruby/1.9') -end -# ODOT - -require 'ruboto/activity' -require 'ruboto/widget' -require 'ruboto/util/stack' -require 'ruboto/util/toast' - -with_large_stack { require 'psych.rb' } - -Psych::Parser -Psych::Handler - -ruboto_import_widgets :Button, :LinearLayout, :TextView - -$activity.start_ruboto_activity do - setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ') - - def on_create(bundle) - self.content_view = - linear_layout :orientation => LinearLayout::VERTICAL do - @decoded_view = text_view :id => 42, :text => with_large_stack{Psych.load('--- foo')} - # TODO(uwe): Simplify when we stop supporting Psych in Ruby 1.8 mode - @encoded_view = text_view(:id => 43, :text => with_large_stack{Psych.dump('foo')}) unless RUBY_VERSION < '1.9' - end - end - -end diff --git a/test/block_def_activity/psych_activity_test.rb b/test/block_def_activity/psych_activity_test.rb deleted file mode 100644 index 71b13ba2..00000000 --- a/test/block_def_activity/psych_activity_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -activity org.ruboto.test_app.PsychActivity - -setup do |activity| - start = Time.now - loop do - @text_view = activity.findViewById(42) - break if @text_view || (Time.now - start > 60) - sleep 1 - end - assert @text_view -end - -test('psych_encode_decode') do |activity| - assert_equal 'foo', activity.find_view_by_id(42).text.to_s - #assert_equal "--- foo\n...\n", activity.find_view_by_id(43).text.to_s -end diff --git a/test/block_def_activity/stack_activity.rb b/test/block_def_activity/stack_activity.rb deleted file mode 100644 index 19784956..00000000 --- a/test/block_def_activity/stack_activity.rb +++ /dev/null @@ -1,25 +0,0 @@ -STACK_DEPTH_SCRIPT = java.lang.Thread.current_thread.stack_trace.length.to_s -require 'ruboto/activity' -require 'ruboto/widget' -require 'ruboto/util/toast' - -ruboto_import_widgets :Button, :LinearLayout, :TextView - -$activity.start_ruboto_activity do - STACK_DEPTH_START_RUBOTO_ACTIVITY = java.lang.Thread.current_thread.stack_trace.length.to_s - - def on_create(bundle) - stack_depth_on_create = java.lang.Thread.current_thread.stack_trace.length.to_s - setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ') - - self.content_view = - linear_layout :orientation => LinearLayout::VERTICAL do - stack_depth_linear_layout = java.lang.Thread.current_thread.stack_trace.length.to_s - text_view :id => 42, :text => STACK_DEPTH_SCRIPT - text_view :id => 43, :text => STACK_DEPTH_START_RUBOTO_ACTIVITY - text_view :id => 44, :text => stack_depth_on_create - text_view :id => 45, :text => stack_depth_linear_layout - end - end - -end diff --git a/test/block_def_activity/stack_activity_test.rb b/test/block_def_activity/stack_activity_test.rb deleted file mode 100644 index 1874045c..00000000 --- a/test/block_def_activity/stack_activity_test.rb +++ /dev/null @@ -1,39 +0,0 @@ -activity org.ruboto.test_app.StackActivity - -setup do |activity| - start = Time.now - loop do - @text_view = activity.findViewById(42) - break if @text_view || (Time.now - start > 60) - sleep 1 - end - assert @text_view -end - -# ANDROID: 15, PLATFORM: STANDALONE, JRuby: 1.7.0 '[44, 72, 62, 79]' expected, but got '[44, 71, 62, 79]' -test('stack depth') do |activity| - os_offset = {13 => 1, 15 => 1, 16 => 1}[android.os.Build::VERSION::SDK_INT].to_i - if org.ruboto.JRubyAdapter.uses_platform_apk? - jruby_offset = { - '0.4.7' => [0, 0, 0, 0], - '0.4.8.dev' => [0, -1, 0, 0], - '0.4.8' => [0, -1, 0, 0], - '0.4.9' => [0, -1, 0, 0], - }[org.ruboto.JRubyAdapter.platform_version_name] || [0, 0, 0, 0] - else # STANDALONE - jruby_offset = { - '1.7.0.preview1' => [0, -1, -1, -1], - '1.7.0.preview2' => [0, -1, 0, 0], - '1.7.0' => [0, -1, 0, 0], - '1.7.1.dev' => [0, -1, 0, 0], - }[org.jruby.runtime.Constants::VERSION] || [0, 0, 0, 0] - end - version_message ="ANDROID: #{android.os.Build::VERSION::SDK_INT}, PLATFORM: #{org.ruboto.JRubyAdapter.uses_platform_apk ? org.ruboto.JRubyAdapter.platform_version_name : 'STANDALONE'}, JRuby: #{org.jruby.runtime.Constants::VERSION}" - assert_equal [43 + os_offset + jruby_offset[0], - 71 + os_offset + jruby_offset[1], - 61 + os_offset + jruby_offset[2], - 78 + os_offset + jruby_offset[3]], [activity.find_view_by_id(42).text.to_i, - activity.find_view_by_id(43).text.to_i, - activity.find_view_by_id(44).text.to_i, - activity.find_view_by_id(45).text.to_i], version_message -end diff --git a/test/handle_activity/image_button_activity.rb b/test/handle_activity/image_button_activity.rb deleted file mode 100644 index 4398b277..00000000 --- a/test/handle_activity/image_button_activity.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'ruboto' - -ruboto_import_widgets :ImageButton, :LinearLayout, :TextView - -$activity.handle_create do |bundle| - setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map{|s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ') - - setup_content do - linear_layout :orientation => LinearLayout::VERTICAL do - @text_view = text_view :text => 'What hath Matz wrought?', :id => 42 - image_button :image_resource => $package.R::drawable::get_ruboto_core, :width => :wrap_content, :id => 43 - end - end - - handle_click do |view| - if view.id == 43 - @text_view.setText 'What hath Matz wrought!' - toast 'Flipped a bit via butterfly' - end - end -end diff --git a/test/handle_activity/image_button_activity_test.rb b/test/handle_activity/image_button_activity_test.rb deleted file mode 100644 index af2e3607..00000000 --- a/test/handle_activity/image_button_activity_test.rb +++ /dev/null @@ -1,21 +0,0 @@ -activity Java::org.ruboto.test_app.ImageButtonActivity - -setup do |activity| - start = Time.now - loop do - @text_view = activity.findViewById(42) - break if @text_view || (Time.now - start > 60) - sleep 1 - end - assert @text_view -end - -test('initial setup') do |activity| - assert_equal "What hath Matz wrought?", @text_view.text -end - -test('button changes text') do |activity| - button = activity.findViewById(43) - button.performClick - assert_equal "What hath Matz wrought!", @text_view.text -end diff --git a/test/handle_activity/image_button_and_button_activity.rb b/test/handle_activity/image_button_and_button_activity.rb deleted file mode 100644 index 381dc957..00000000 --- a/test/handle_activity/image_button_and_button_activity.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'ruboto' - -ruboto_import_widgets :Button, :ImageButton, :LinearLayout, :TextView - -$activity.handle_create do |bundle| - setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map{|s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ') - - setup_content do - linear_layout :orientation => LinearLayout::VERTICAL do - @text_view = text_view :text => 'What hath Matz wrought?', :id => 42 - button :text => 'Button', :width => :wrap_content, :id => 44 - image_button :image_resource => $package.R::drawable::get_ruboto_core, :width => :wrap_content, :id => 43 - end - end - - handle_click do |view| - if view.id == 43 - @text_view.text = 'Image button pressed' - elsif view.id == 44 - @text_view.text = 'Button pressed' - end - end - -end diff --git a/test/handle_activity/image_button_and_button_activity_test.rb b/test/handle_activity/image_button_and_button_activity_test.rb deleted file mode 100644 index c392a592..00000000 --- a/test/handle_activity/image_button_and_button_activity_test.rb +++ /dev/null @@ -1,27 +0,0 @@ -activity Java::org.ruboto.test_app.ImageButtonAndButtonActivity - -setup do |activity| - start = Time.now - loop do - @text_view = activity.find_view_by_id 42 - break if @text_view || (Time.now - start > 60) - sleep 1 - end - assert @text_view -end - -test('initial setup') do |activity| - assert_equal "What hath Matz wrought?", @text_view.text -end - -test('button changes text') do |activity| - button = activity.find_view_by_id 44 - button.perform_click - assert_equal 'Button pressed', @text_view.text -end - -test('image button changes text') do |activity| - image_button = activity.find_view_by_id 43 - image_button.perform_click - assert_equal 'Image button pressed', @text_view.text -end diff --git a/test/handle_activity/margins_activity.rb b/test/handle_activity/margins_activity.rb deleted file mode 100644 index c40142eb..00000000 --- a/test/handle_activity/margins_activity.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'ruboto' - -ruboto_import_widgets :LinearLayout, :TextView - -$activity.handle_create do |bundle| - setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map{|s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ') - - setup_content do - linear_layout :orientation => LinearLayout::VERTICAL do - @text_view_margins = text_view :text => 'What hath Matz wrought?', :id => 42, :margins => [100,0,0,0] - @text_view_layout = text_view :text => 'What hath Matz wrought?', :id => 43, :layout => {:set_margins => [100,0,0,0]} - @text_view_fieldset = text_view :text => 'What hath Matz wrought?', :id => 44, :layout => {:left_margin= => 100} - end - end -end diff --git a/test/handle_activity/margins_activity_test.rb b/test/handle_activity/margins_activity_test.rb deleted file mode 100644 index 4ed96bc3..00000000 --- a/test/handle_activity/margins_activity_test.rb +++ /dev/null @@ -1,25 +0,0 @@ -activity Java::org.ruboto.test_app.MarginsActivity - -setup do |activity| - start = Time.now - loop do - @text_view_margins = activity.findViewById(42) - @text_view_layout = activity.findViewById(43) - @text_view_fieldset = activity.findViewById(44) - break if @text_view_margins || @text_view_layout || @text_view_fieldset || (Time.now - start > 60) - sleep 1 - end - assert @text_view_margins - assert @text_view_layout - assert @text_view_fieldset -end - -def left_margin(view) - view.get_layout_params.leftMargin -end - -%w(margins layout fieldset).each do |view_type| - test("margins are set through #{view_type}") do |activity| - assert_equal 100, left_margin(instance_variable_get("@text_view_#{view_type}")) - end -end \ No newline at end of file diff --git a/test/handle_activity/option_menu_activity.rb b/test/handle_activity/option_menu_activity.rb deleted file mode 100644 index c81381d4..00000000 --- a/test/handle_activity/option_menu_activity.rb +++ /dev/null @@ -1,25 +0,0 @@ -STACK_DEPTH_SCRIPT = java.lang.Thread.current_thread.stack_trace.length.to_s - -raise "Stack level: #{STACK_DEPTH_SCRIPT}" rescue puts $!.message + "\n" + $!.backtrace.join("\n") - -require 'ruboto' - -ruboto_import_widgets :ImageButton, :LinearLayout, :TextView - -$activity.handle_create do |bundle| - setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map{|s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ') - - setup_content do - linear_layout :orientation => LinearLayout::VERTICAL do - @text_view = text_view :text => 'What hath Matz wrought?', :id => 42 - end - end - - handle_create_options_menu do |menu| - add_menu('Test') do - @text_view.setText 'What hath Matz wrought!' - toast 'Flipped a bit via butterfly' - end - true - end -end diff --git a/test/handle_activity/option_menu_activity_test.rb b/test/handle_activity/option_menu_activity_test.rb deleted file mode 100644 index 4314b0a9..00000000 --- a/test/handle_activity/option_menu_activity_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -activity Java::org.ruboto.test_app.OptionMenuActivity - -setup do |activity| - start = Time.now - loop do - @text_view = activity.findViewById(42) - break if @text_view || (Time.now - start > 60) - sleep 1 - end - assert @text_view -end - -test('initial setup') do |activity| - assert_equal "What hath Matz wrought?", @text_view.text -end - -test('option_menu changes text') do |activity| - activity.window.performPanelIdentifierAction(android.view.Window::FEATURE_OPTIONS_PANEL, 0, 0) - assert_equal "What hath Matz wrought!", @text_view.text -end diff --git a/test/handle_activity/psych_activity.rb b/test/handle_activity/psych_activity.rb deleted file mode 100644 index 21676176..00000000 --- a/test/handle_activity/psych_activity.rb +++ /dev/null @@ -1,31 +0,0 @@ -# TODO(uwe): Remove when we stop supporting psych with Ruby 1.8 mode -if RUBY_VERSION < '1.9' - require 'jruby' - require 'rbconfig' - org.jruby.ext.psych.PsychLibrary.new.load(JRuby.runtime, false) - $LOADED_FEATURES << 'psych.so' - $LOAD_PATH << File.join(Config::CONFIG['libdir'], 'ruby/1.9') -end -# ODOT - -with_large_stack { require 'psych.rb' } - -Psych::Parser -Psych::Handler - -require 'ruboto' - -ruboto_import_widgets :Button, :LinearLayout, :TextView - -$activity.handle_create do |bundle| - setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ') - - setup_content do - linear_layout :orientation => LinearLayout::VERTICAL do - @decoded_view = text_view :id => 42, :text => with_large_stack { Psych.load('--- foo') } - # TODO(uwe): Simplify when we stop supporting Psych in Ruby 1.8 mode - @encoded_view = text_view(:id => 43, :text => with_large_stack { Psych.dump('foo') }) unless RUBY_VERSION < '1.9' - end - end - -end diff --git a/test/handle_activity/psych_activity_test.rb b/test/handle_activity/psych_activity_test.rb deleted file mode 100644 index 71b13ba2..00000000 --- a/test/handle_activity/psych_activity_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -activity org.ruboto.test_app.PsychActivity - -setup do |activity| - start = Time.now - loop do - @text_view = activity.findViewById(42) - break if @text_view || (Time.now - start > 60) - sleep 1 - end - assert @text_view -end - -test('psych_encode_decode') do |activity| - assert_equal 'foo', activity.find_view_by_id(42).text.to_s - #assert_equal "--- foo\n...\n", activity.find_view_by_id(43).text.to_s -end diff --git a/test/handle_activity/stack_activity.rb b/test/handle_activity/stack_activity.rb deleted file mode 100644 index bace6013..00000000 --- a/test/handle_activity/stack_activity.rb +++ /dev/null @@ -1,24 +0,0 @@ -STACK_DEPTH_SCRIPT = java.lang.Thread.current_thread.stack_trace.length.to_s - -raise "Stack level: #{STACK_DEPTH_SCRIPT}" rescue puts $!.message + "\n" + $!.backtrace.join("\n") - -require 'ruboto' - -ruboto_import_widgets :Button, :LinearLayout, :TextView - -$activity.handle_create do |bundle| - STACK_DEPTH_HANDLE_CREATE = java.lang.Thread.current_thread.stack_trace.length.to_s - setTitle File.basename(__FILE__).chomp('_activity.rb').split('_').map{|s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ') - - setup_content do - STACK_DEPTH_SETUP_CONTENT = java.lang.Thread.current_thread.stack_trace.length.to_s - linear_layout :orientation => LinearLayout::VERTICAL do - STACK_DEPTH_LINEAR_LAYOUT = java.lang.Thread.current_thread.stack_trace.length.to_s - @script_view = text_view :id => 42, :text => STACK_DEPTH_SCRIPT - @handle_create_view = text_view :id => 43, :text => STACK_DEPTH_HANDLE_CREATE - @setup_content_view = text_view :id => 44, :text => STACK_DEPTH_SETUP_CONTENT - @linear_layout_view = text_view :id => 45, :text => STACK_DEPTH_LINEAR_LAYOUT - end - end - -end diff --git a/test/handle_activity/stack_activity_test.rb b/test/handle_activity/stack_activity_test.rb deleted file mode 100644 index 32594dc6..00000000 --- a/test/handle_activity/stack_activity_test.rb +++ /dev/null @@ -1,47 +0,0 @@ -activity org.ruboto.test_app.StackActivity - -setup do |activity| - start = Time.now - loop do - @text_view = activity.findViewById(42) - break if @text_view || (Time.now - start > 60) - sleep 1 - end - assert @text_view -end - -# ANDROID: 15, PLATFORM: STANDALONE, JRuby: 1.6.7 '44697894' expected, but got '44687793' -# ANDROID: 15, PLATFORM: 0.4.8.dev, JRuby: 1.7.0.preview2 '[44, 68, 77, 93]' expected, but got '[44, 67, 76, 92]' -# ANDROID: 10, PLATFORM: STANDALONE, JRuby: 1.7.0.preview2 '[43, 67, 76, 92]' expected, but got '[43, 66, 75, 91]' -# ANDROID: 15, PLATFORM: STANDALONE, JRuby: 1.7.0.preview2 '[44, 68, 77, 93]' expected, but got '[44, 67, 76, 92]' -# ANDROID: 15, PLATFORM: STANDALONE, JRuby: 1.7.0 '[44, 68, 77, 93]' expected, but got '[44, 67, 76, 92]' -test('stack depth') do |activity| - os_offset = {13 => 1, 15 => 1, 16 => 1}[android.os.Build::VERSION::SDK_INT].to_i - if org.ruboto.JRubyAdapter.uses_platform_apk? - jruby_offset = { - '0.4.7' => [0, 0, 0, 0], - '0.4.8.dev' => [0, -1, -1, -1], - '0.4.8' => [0, -1, -1, -1], - '0.4.9' => [0, -1, -1, -1], - }[org.ruboto.JRubyAdapter.platform_version_name] || [0, 0, 0, 0] - else # STANDALONE - jruby_offset = { - '1.7.0.dev' => [1, 0, 0, 0], - '1.7.0.preview1' => [0, -1, -1, -1], - '1.7.0.preview2' => [0, -1, -1, -1], - '1.7.0' => [0, -1, -1, -1], - '1.7.1.dev' => [0, -1, -1, -1], - }[org.jruby.runtime.Constants::VERSION] || [0, 0, 0, 0] - end - version_message ="ANDROID: #{android.os.Build::VERSION::SDK_INT}, PLATFORM: #{org.ruboto.JRubyAdapter.uses_platform_apk ? org.ruboto.JRubyAdapter.platform_version_name : 'STANDALONE'}, JRuby: #{org.jruby.runtime.Constants::VERSION}" - expected = [43 + os_offset + jruby_offset[0], - 67 + os_offset + jruby_offset[1], - 76 + os_offset + jruby_offset[2], - 92 + os_offset + jruby_offset[3]] - actual = [activity.find_view_by_id(42).text.to_i, - activity.find_view_by_id(43).text.to_i, - activity.find_view_by_id(44).text.to_i, - activity.find_view_by_id(45).text.to_i] - assert_equal expected, actual, version_message - puts "handle stack: #{version_message} #{actual.inspect}" -end diff --git a/test/ruboto_gen_test.rb b/test/ruboto_gen_test.rb index 83283e0c..ff9d3907 100755 --- a/test/ruboto_gen_test.rb +++ b/test/ruboto_gen_test.rb @@ -56,16 +56,16 @@ def test_new_apk_size_is_within_limits version << ", ANDROID_TARGET: #{ANDROID_TARGET}" if RUBOTO_PLATFORM == 'STANDALONE' upper_limit = { - '1.6.7' => ANDROID_TARGET < 15 ? 5800.0 : 5900.0, + '1.6.7' => 5900.0, + '1.6.8' => 5900.0, '1.7.0' => ANDROID_TARGET < 15 ? 7400.0 : 7600.0, '1.7.1.dev' => ANDROID_TARGET < 15 ? 7400.0 : 7600.0, }[JRUBY_JARS_VERSION.to_s] || 7600.0 version << ", JRuby: #{JRUBY_JARS_VERSION.to_s}" else upper_limit = { - 7 => 67.0, - 10 => 64.0, - 15 => 68.0, + 10 => 62.0, + 15 => 63.0, }[ANDROID_TARGET] || 64.0 end lower_limit = upper_limit * 0.9