[sudo] gem install rhosync Write a “source adapter” - AnDevCon

tunisianbromidrosisInternet και Εφαρμογές Web

5 Φεβ 2013 (πριν από 4 χρόνια και 4 μήνες)

144 εμφανίσεις

adam@rhomobile.com

Using Ruby for

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…



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



Rhomobile


Mobilize Your Enterprise Apps

Ruboto

http://github.com/ruboto


Ruboto
-
core


[sudo] gem install ruboto
-
core


Ruboto
-
core
-
irb


Ruboto
-
demos




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 do

handle_click do |view|

Rhomobile


Mobilize Your Enterprise Apps

How It Works

YourActivity < RubotoActivity < Activity


RubotoActivity implements callbacks


They tell Ruby to exec blocks, pass params along

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

Rhomobile


Mobilize Your Enterprise Apps

Ruboto
-
core


Goals


Anything you can do with Java


Zero Java


Zero XML


Support plugins

Rhomobile


Mobilize Your Enterprise Apps

Ruboto Install


JDK


JRuby (rvm)


Android SDK


Generate an emulator


gem install ruboto
-
core

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

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

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’


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

Rhomobile


Mobilize Your Enterprise Apps

Install


$ rake install # builds .apk, installs to emulator


$ rake; adb
-
d install
-
r bin/*
-
debug.apk

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…


Rhomobile


Mobilize Your Enterprise Apps

Rhodes Architecture


RhoSync

Server

your app code

RhoSync

client

ORM (Rhom)

Rhodes components

Ruby

executor

HTML

templates

model

controller

model

HTML

templates

controller

Backend

app

source

adapter

source

adapter

Backend

app

model

model

We provide:

You
write:

Rhodes

app

generator

Backend

app

Device

capabilities

smartphone device

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

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



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

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


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


adam@rhomobile.com