What's happened to IRB?

132 views
Skip to first unread message

G Shogie

unread,
Jan 11, 2017, 3:18:06 PM1/11/17
to Ruboto (JRuby on Android)
Hi all,
I'm an OLD retired software developer (mostly C on PCs and Linux). I got a couple of Android tablets to play with but was dismayed by the verbose complexity of Java. But then I was delighted several years ago to finally find Rubotu IRB - a system where I could do development ON the tablet and immediately run the script. I've made a couple of moderate-sized scripts which work with IRB on a Nook HD+ with a CyanogenMod card running 4.1.

But now I have a new Android cell phone (LG Phoenix 2 with Android 6.0) and tried to put Ruboto on it. It sort of works, but an important problem is that menus don't. The demo scripts which show how to do menus never receive a call to 'onCreateOptionsMenu.' The old demos have not been updated, so I don't know if I need to enter the realm of AppCompat(?) I have found the examples by KC Erb to be helpful, but not for menus on this device. I did see the UP arrow in the Toolbar with one of his examples.

A second issue is that I have a concern about the state of IRB. The APK I have is now about three years old. The version I have is 0.9.1 - which is the latest version I can find anywhere. The IRB which used to be on Google Play is no longer there, and the current version of Ruboto there does not even MENTION IRB! There are several problems in IRB which I could mention, but is anyone still supporting this extremely helpful app?

thanks much from this relative noobie,
Gary

donV

unread,
Jan 12, 2017, 10:05:25 AM1/12/17
to Ruboto (JRuby on Android)
Hi Gary!

Glad to hear of your use and interest in Ruboto.  I use and love it myself.  Ruby is my preferred language for programming.

I'd be happy to update the examples you are interested in, but I do not have time to update them all.  Hopefully others can help out.  All the examples are available to be updated by anyone, on the WIKI or in the source repo or on the web site.

Concretely, I use "onCreateOptionsMenu" in some of my apps, and it will work on Android 6 also, but the methods are deprecated and not activated by default when generating an app for new versions of Android.

You can try generating your app for an older version of Android, but I recommend targeting as new as possible version for your needs.

The fix you probably need is to add the missing methods to your `src/org/ruboto/RubotoActivity.java` file.  Maybe it is already there, and all you need to do is remove the `/* ... */` comments.

```java
public boolean onCreateOptionsMenu(android.view.Menu menu) {
if (ScriptLoader.isCalledFromJRuby()) return super.onCreateOptionsMenu(menu);
if (!JRubyAdapter.isInitialized()) {
Log.i("Method called before JRuby runtime was initialized: RubotoActivity#onCreateOptionsMenu");
return super.onCreateOptionsMenu(menu);
}
String rubyClassName = scriptInfo.getRubyClassName();
if (rubyClassName == null) return super.onCreateOptionsMenu(menu);
if ((Boolean)JRubyAdapter.runScriptlet(rubyClassName + ".instance_methods(false).any?{|m| m.to_sym == :onCreateOptionsMenu}")) {
return (Boolean) JRubyAdapter.runRubyMethod(Boolean.class, scriptInfo.getRubyInstance(), "onCreateOptionsMenu", menu);
} else {
if ((Boolean)JRubyAdapter.runScriptlet(rubyClassName + ".instance_methods(false).any?{|m| m.to_sym == :on_create_options_menu}")) {
return (Boolean) JRubyAdapter.runRubyMethod(Boolean.class, scriptInfo.getRubyInstance(), "on_create_options_menu", menu);
} else {
if ((Boolean)JRubyAdapter.runScriptlet(rubyClassName + ".instance_methods(true).any?{|m| m.to_sym == :on_create_options_menu}")) {
return (Boolean) JRubyAdapter.runRubyMethod(Boolean.class, scriptInfo.getRubyInstance(), "on_create_options_menu", menu);
} else {
return (Boolean) JRubyAdapter.runRubyMethod(Boolean.class, scriptInfo.getRubyInstance(), "onCreateOptionsMenu", menu);
}
}
}
}
```

Using `onCreateOptionsMenu` on the `Activity` is good and simple, but it has been replaced by using `Fragments`:


Hopefully this will get you going.

Ruboto IRB on Google Play was flagged as "modifying its own apk" and removed.  This can be appealed, but I do not have the time or energy to do that.  I do not use Ruboto IRB myself.

I use `rake boing` for rapid source updates.  `rake boing` will push any Ruby source changes to the device and reload the code in-place and just refresh the current Activity.  This takes a second or two and is my default way of developing.

Hope this helps.  Ask if you have more questions, and please contribute in any of the documentation or code.  No contribution is too small :)

G Shogie

unread,
Jan 12, 2017, 2:31:35 PM1/12/17
to Ruboto (JRuby on Android)
donV, thanks much for your prompy reply.
Now I know someone is still attending to Ruboto.

On Thursday, January 12, 2017 at 7:05:25 AM UTC-8, donV wrote:
...
Concretely, I use "onCreateOptionsMenu" in some of my apps, and it will work on Android 6 also, but the methods are deprecated and not activated by default when generating an app for new versions of Android.

To clarify, I ONLY use Ruboto IRB, since I do programming ON the tablet/phone without an AIDE.

The fix you probably need is to add the missing methods to your `src/org/ruboto/RubotoActivity.java` file.

As above, I don't do any java, and got into Ruboto to avoid it!   ;^P
I don't know that there are any 'missing' methods; there are no error messages saying so. Its just that my `onCreateOptionsMenu` is never called. I saw a post about delays in initializing Ruby so I tried the recommended menu in the second activity tack, but without benefit.

Using `onCreateOptionsMenu` on the `Activity` is good and simple, but it has been replaced by using `Fragments`:

I'll have to look into fragments as you suggest. Note that the page above on ui/menus STILL says to use
onCreateOptionsMenu. I could use option buttons, but I want to avoid needing to redraw the screen display, which is CPU-intensive for my apps.

Another idea - since I was able to see the UP arrow in DC Erb's action bar example, I might try adding a 'fake' action overflow icon on the right side and proc to display a popup menu when clicked.
Or is it possible to call invalidateOptionsMenu( 'nil' )  to force later menu creation?

At this point I'm used to some frustrations and doing workarounds for 40 years.
But does the above seem silly?
cheers,
Gary


G Shogie

unread,
Jul 3, 2017, 1:45:18 PM7/3/17
to Ruboto (JRuby on Android)
donV et al,

I digested the material about Dialog Fragments in the links above.
I then found it not too large a task to convert my menu code to use DFs in Ruboto-IRB.
I even developed techniques to support multi-level menus and text input.
It wasn't real pretty (involving some global variables) but it worked.
And it was compatible between Android 6 on my new LG phone and Android 4 on my tablet.
So far so good...

However, now I have a new problem!
A couple of weeks ago the LG phone auto-updated to Android 7.
(I know, maybe I should have turned off auto-update, against the provider's advice. But I was not given ANY clue about just what the update was going to do.)
The result is that now my new menu-simulating code using Dialog Fragments is broken.
In addition, Android 7 gives an error in the online tutorial here:
   https://github.com/ruboto/ruboto/wiki/Tutorial%3A-dialogfragment
I managed to rescue it using the Custom Dialog code example in demo-android-api.rb
( https://github.com/ruboto/ruboto-irb/blob/master/assets/demo-scripts/demo-android-api.rb )
But while perusing the sections in that demo file, I saw some other problems.
The example graphics demos for both Arcs and Sensors also no longer work.
Hint: the common syntax in these three broken sections is the "<" operator, for sub-classing.

I'm including a partial error trace from the Dialog Fragment demo.
The first line shows the 'ft' variable just before the new dialog is created.
ft: BackStackEntry{57d88bb}
java.lang.reflect.Method.invoke(Native Method)
org.ruboto.JRubyAdapter.runRubyMethod(JRubyAdapter.java:50)
org.ruboto.ScriptLoader.callOnCreate(ScriptLoader.java:123)
org.ruboto.RubotoActivity.onCreate(RubotoActivity.java:57)
android.app.Activity.performCreate(Activity.java:6757)

So, is there a 'require' or 'java-import' I can add to still use Dialog Fragments?
Is there a general problem for inheritance in Ruboto under Android 7?
Anyone have any thoughts on continuing support for Ruboto-IRB?
regards,
Gary


donV

unread,
Jul 9, 2017, 4:07:39 AM7/9/17
to Ruboto (JRuby on Android)
Hi Gary!

I converted one of our production apps to run on JRuby 9K + Android 7 last week.  I do still have a problem with subclassing a Java class from Ruby.  I have postponed looking at it until https://github.com/jruby/jruby/pull/4589 is merged.

Gary, can you make a GitHub project that demonstrates the problem?  That makes it easier to debug and experiment.

G_ Shogie

unread,
Sep 17, 2020, 8:04:36 PM9/17/20
to Ruboto (JRuby on Android)
Hi again.
Any progress on the inheritance ( subclassing ) bug in Ruboto-IRB?
I have been able to write some graphics apps without "< View" using this code:
  def do_bitmap( w, h )
    @bm = Bitmap.createBitmap( w, h,
        Bitmap::Config::ARGB_8888 ) # ok
    @bm.eraseColor Color::BLUE
    @i_v.setScaleType( # i_v is in contents
     ImageView::ScaleType::CENTER )
    @i_v.setImageBitmap(@bm) # ok
    @canvas = Canvas.new(@bm)
  end

But the output graphics do not appear until all graphics commands are finished.
So the display is not dynamic as I would wish and  'invalidate()' is unknown.
(This also happens with a 'tk' version of programs on Windows PCs.)
I have looked, but is there a call which would purge the graphics buffer?
Or maybe a callback which would inform me when it is done?
regards and thanks,
Gary
Reply all
Reply to author
Forward
0 new messages