Using Ruby in Android Development


Published on

Discusses four tools that can be used to build Android smartphone apps. Specifically IRB for scripting on the device, Ruboto for building arbitrary apps, Rhodes (a framework which includes a fast compiled Ruby) and RhoSync (a mobile app integration server which uses Ruby)

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Using Ruby in Android Development

  1. 1. Using Ruby for AndroidDevelopment<br />
  2. 2. Background<br />Android is a big step forward in mobile operating systems<br />But… Java?<br />Dynamic script languages are more productive<br />And don’t have to be too slow<br />Four main ways to leverage Ruby…<br />
  3. 3. Leveraging Ruby for Android<br />Scripting: automate phone tasks and testing<br />“From scratch” app development <br />replace Java<br />Framework development<br />Less Ruby, compiled Ruby<br />App integration<br />Full Ruby via server<br />
  4. 4. Ruboto<br /><br />Ruboto-core<br />[sudo] gem install ruboto-core<br />Ruboto-core-irb<br />Ruboto-demos<br />* Ruboto slides here derived from earlier presentations by Daniel Jackoway. Apologies for missing attribution in original post. <br />
  5. 5. Android in Ruby<br />public void Activity.onCreate(Bundle bundle)<br />public void Activity.onPause()<br />public void onClick(View view)<br />handle_create do |bundle|<br />handle_pause do<br />handle_click do |view|<br />
  6. 6. How It Works<br />YourActivity < RubotoActivity < Activity<br /><ul><li>RubotoActivity implements callbacks
  7. 7. They tell Ruby to exec blocks, pass params along</li></li></ul><li>Ruby for Scripting: IRB<br /><ul><li>
  8. 8. Activities only
  9. 9. Can’t ship .apk</li></li></ul><li>Ruboto-core<br /><ul><li>Goals
  10. 10. Anything you can do with Java
  11. 11. Zero Java
  12. 12. Zero XML
  13. 13. Support plugins</li></li></ul><li>Ruboto Install<br /><ul><li>JDK
  14. 14. JRuby (rvm)
  15. 15. Android SDK
  16. 16. Generate an emulator
  17. 17. gem install ruboto-core</li></li></ul><li>Ruboto App Generation<br /><ul><li>$ ruboto gen app
  18. 18. $ --package com.adamblum.andevcon
  19. 19. $ --path andevcon # where app files go
  20. 20. $ --name andevcon # Name of app
  21. 21. $ --target android-8 # Froyo
  22. 22. $ --activity MyActivity # Name of Activity</li></li></ul><li>Ruboto App Generation<br /><ul><li>$ ruboto gen app
  23. 23. $ --package com.adamblum.andevcon
  24. 24. $ --path andevcon # where app files go
  25. 25. $ --name andevcon # Name of app
  26. 26. $ --target android-8 # Froyo
  27. 27. $ --activity MyActivity # Name of Activity</li></li></ul><li>Ruboto Activity<br /><ul><li>assets/scripts/my_activity.rb
  28. 28. require 'ruboto.rb’
  29. 29. ruboto_import_widgets :TextView,
  30. 30. :LinearLayout, :Button
  31. 31. $activity.handle_create do |bundle|
  32. 32. setTitle 'This is the Title’</li></li></ul><li>Ruboto Activity (continued)<br /><ul><li>setup_content do
  33. 33. linear_layout :orientation => LinearLayout::VERTICAL do
  34. 34. @text_view = text_view :text => "What hath Matz wrought?"
  35. 35. button :text => "M-x butterfly", :width => :wrap_content
  36. 36. end
  37. 37. end
  38. 38. handle_click do |view|
  39. 39. if view.getText == 'M-x butterfly'
  40. 40. @text_view.setText "What hath Matz wrought!"
  41. 41. toast 'Flipped a bit via butterfly'
  42. 42. end
  43. 43. end
  44. 44. end</li></li></ul><li>Install<br /><ul><li>$ rake install # builds .apk, installs to emulator
  45. 45. $ rake; adb -d install -r bin/*-debug.apk</li></li></ul><li>Ruby for An App Framework…Rhodes<br />Portability<br />Write it once and it runs on all smartphones: BlackBerry, iPhone, Windows Mobile, Android, Symbian, Win32<br />Leverage Your Web Skills<br />Build the app quickly in HTML and Ruby<br />Offline Use and Easy Backend Integration<br />Work with synchronized local data when offline<br />Easily connect to any backend app through web services<br />Exploit device capabilities<br />GPS, PIM data, camera, push/SMS, native mapping, barcode, signature capture, …<br />Enterprise Security Compliant<br />Encrypt data on the device, remote wipe of device, secure authentication…<br />
  46. 46. Rhodes Architecture<br />your app code<br />You write:<br />RhoSync<br />Server<br />model<br />model<br />HTML <br />templates<br />controller<br />Rhodes<br />app<br />generator<br />Backend<br />app<br />source<br />adapter<br />model<br />model<br />HTML <br />templates<br />controller<br />Backend<br />app<br />source<br />adapter<br />Rhodes components<br />ORM (Rhom)<br />Ruby<br />executor<br />We provide:<br />Device<br />capabilities<br />RhoSync <br />client<br />Backend<br />app<br />smartphone device<br />
  47. 47. Rhodes vs. Competition<br />Only one that supports all devices<br />Only one with synchronized data<br />Only MVC framework<br />First Ruby on the device<br />First and only hosted development service for mobile<br />
  48. 48. Ruby for App Integration…RhoSync<br />[sudo] gem install rhosync<br />Write a “source adapter” <br />Query<br />Create<br />Update <br />Delete<br />Eliminates many tasks in app integration<br />No device integration/connection code (assumes in database)<br />Removes data storage step<br />If its Rails backend, not even source adapter is necessary<br />Better user experience<br />Data is realtime updated<br />No wait for data to be retrieved<br />
  49. 49. RhoSync Source Adapter<br />rhosync app YourApp<br />cdYourApp<br />rhosync source Product<br />Generates …<br />class Product <SourceAdapter<br />def query(params=nil)<br /> # TODO: Query your backend data source and assign the records <br /> # to a nested hash structure called @result. For example:<br />end<br /> def create(create_hash,blob=nil)<br /> # TODO: Create a new record in your backend data source<br />end<br />end<br />
  50. 50. RhoHub<br />First and only “Development as a Service for mobile”<br />More than 10,000 developers signed up in the last year<br />~100 more per day<br />Hosted development – WRITE APPS FOR IPHONES FROM WINDOWS<br />Web-based IDE for ease of use<br />Build for all smartphones online – no need to install SDKs<br />Hosted runtime<br />No need to set up RhoSync server<br />Collaboration <br />Work with other developers <br />on same project over the web<br />
  51. 51. Resources<br /><ul><li>
  52. 52.
  53. 53.
  54. 54.
  55. 55.
  56. 56.</li></li></ul><li>