Using Ruby in Android Development

22
[email protected] Using Ruby for 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 of Using Ruby in Android Development

Page 1: Using Ruby in Android Development

[email protected]

Using Ruby for Android

Development

Page 2: Using Ruby in Android Development

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[email protected]

Page 22: Using Ruby in Android Development

Rhomobile – Mobilize Your Enterprise Apps