Skip to content

Commit

Permalink
* Issues #281 #282 #290 and #291 Remove legacy callback callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
donv committed Nov 18, 2012
1 parent e58402c commit 6ba6111
Show file tree
Hide file tree
Showing 51 changed files with 80 additions and 1,303 deletions.
19 changes: 0 additions & 19 deletions 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);
}

}
9 changes: 1 addition & 8 deletions assets/src/InheritingClass.java
Expand Up @@ -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);
Expand All @@ -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

}
10 changes: 1 addition & 9 deletions assets/src/RubotoActivity.java
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
48 changes: 18 additions & 30 deletions assets/src/RubotoBroadcastReceiver.java
Expand Up @@ -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;
}
Expand All @@ -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();
}
Expand Down
10 changes: 1 addition & 9 deletions assets/src/RubotoService.java
Expand Up @@ -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;
Expand All @@ -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()) {
Expand Down
3 changes: 0 additions & 3 deletions assets/src/org/ruboto/RubotoComponent.java
Expand Up @@ -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();
}
15 changes: 0 additions & 15 deletions assets/src/org/ruboto/ScriptInfo.java
Expand Up @@ -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);
Expand Down
15 changes: 0 additions & 15 deletions assets/src/org/ruboto/ScriptLoader.java
Expand Up @@ -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();
Expand Down
25 changes: 0 additions & 25 deletions assets/src/ruboto.rb

This file was deleted.

55 changes: 15 additions & 40 deletions assets/src/ruboto/activity.rb
Expand Up @@ -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.
Expand All @@ -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

Expand Down Expand Up @@ -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)

0 comments on commit 6ba6111

Please sign in to comment.