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