meetup 2013:01: uwe kubosh - ruboto - jruby on android

102
1 Saturday, January 26, 13

Upload: gdgoslo

Post on 15-Nov-2014

267 views

Category:

Technology


1 download

DESCRIPTION

Android has made great advances the last couple of years, and is one of the major actors in the phone and tablet markets. The main programming language on Android is Java. Android offers a comprehensive API to apps running on the Dalvik VM. The API covers a large part of the Java standard library in addition to Android specific APIs. Android includes tooling to convert Java .class files to Dalvik VM compatible class files. Ruboto uses JRuby to allow you to run Ruby scripts on the Dalvik VM. Using Ruby code, you have access to the complete Android API. This presentation will introduce the different parts of Ruboto.

TRANSCRIPT

Page 1: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

1Saturday, January 26, 13

Page 2: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Ruboto

JRuby on Android

1Saturday, January 26, 13

Page 3: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Uwe Kubosch

Work at Datek Wireless in Norway

Ruboto core developer

JRuby rookie committer

2Saturday, January 26, 13

Page 4: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Ruboto?

Platform for developing Android apps using Ruby

Builds on JRuby and the Android SDK

Application and component generators

Test framework

Compact GUI definition

3Saturday, January 26, 13

Page 5: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

_why Ruboto?

Write Ruby instead of Java/XML

Use Ruby libraries (gems)

Focus on testing

Faster development cycles

4Saturday, January 26, 13

Page 6: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Topics covered

History

Ruboto IRB

Installation & development tools

Hello world!

Demos

Limitations

Roadmap

5Saturday, January 26, 13

Page 7: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Activity: A screen

View: A screen component

Service: Background process

Intent: Definition of action

BroadcastReceiver: Listener for Intents

Android basics/terms

6Saturday, January 26, 13

Page 8: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

History 2009

PoC by Charles Nutter (headius) February 24, 2009

ruboto-irb by headius August 1, 2009

7Saturday, January 26, 13

Page 9: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

History 2009

PoC by Charles Nutter (headius) February 24, 2009

ruboto-irb by headius August 1, 2009

7Saturday, January 26, 13

Page 10: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

History 2009

PoC by Charles Nutter (headius) February 24, 2009

ruboto-irb by headius August 1, 2009

7Saturday, January 26, 13

Page 11: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

History 2009

PoC by Charles Nutter (headius) February 24, 2009

ruboto-irb by headius August 1, 2009

7Saturday, January 26, 13

Page 12: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

History 2009

PoC by Charles Nutter (headius) February 24, 2009

ruboto-irb by headius August 1, 2009

7Saturday, January 26, 13

Page 13: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Demo: OpenGL

8Saturday, January 26, 13

Page 14: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Demo: OpenGL

class Cube def initialize one = 0x10000 vertices = [ -one,-one,-one,one,-one,-one,one,one,-one,-one,one,-one,-one,-one,one,one,-one,one,one,one,one,-one,one,one ] colors = [ 0,0,0,one,one,0,0,one,one,one,0,one,0,one,0,one,0,0,one,one,one,0,one,one,one,one,one,one,0,one,one,one ] indices = [ 0, 4, 5, 0, 5, 1, 1, 5, 6, 1, 6, 2, 2, 6, 7, 2, 7, 3, 3, 7, 4, 3, 4, 0, 4, 7, 6, 4, 6, 5, 3, 0, 1, 3, 1, 2 ] vbb = ByteBuffer.allocateDirect(vertices.length*4) vbb.order(ByteOrder.nativeOrder) @vertex_buffer = vbb.asIntBuffer @vertex_buffer.put(vertices.to_java(:int)) @vertex_buffer.position(0) cbb = ByteBuffer.allocateDirect(colors.length*4) cbb.order(ByteOrder.nativeOrder) @color_buffer = cbb.asIntBuffer @color_buffer.put(colors.to_java(:int)) @color_buffer.position(0) @index_buffer = ByteBuffer.allocateDirect(indices.length) @index_buffer.put(indices.to_java(:byte)) @index_buffer.position(0) end def draw(gl) gl.glFrontFace(GL10::GL_CW) gl.glVertexPointer(3, GL10::GL_FIXED, 0, @vertex_buffer) gl.glColorPointer(4, GL10::GL_FIXED, 0, @color_buffer) gl.glDrawElements(GL10::GL_TRIANGLES, 36, GL10::GL_UNSIGNED_BYTE, @index_buffer) end end

class RubotoGLSurfaceViewRenderer def initialize @translucent_background = false @cube = Cube.new @angle = 0.0 @offset = 1.2 end def onDrawFrame(gl) gl.glClear(GL10::GL_COLOR_BUFFER_BIT | GL10::GL_DEPTH_BUFFER_BIT) gl.glMatrixMode(GL10::GL_MODELVIEW) gl.glLoadIdentity gl.glTranslatef(0, 0, -3.0) gl.glRotatef(@angle, 0, 1, 0) gl.glRotatef(@angle*0.25, 1, 0, 0) gl.glEnableClientState(GL10::GL_VERTEX_ARRAY) gl.glEnableClientState(GL10::GL_COLOR_ARRAY) @cube.draw(gl) gl.glRotatef(@angle*2.0, 0, 1, 1) gl.glTranslatef(0.5, 0.5, 0.5) @cube.draw(gl) @angle += @offset end def onSurfaceChanged(gl, width, height) gl.glViewport(0, 0, width, height) ratio = width.to_f / height.to_f gl.glMatrixMode(GL10::GL_PROJECTION) gl.glLoadIdentity gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10) end def onSurfaceCreated(gl, config) gl.glDisable(GL10::GL_DITHER) gl.glHint(GL10::GL_PERSPECTIVE_CORRECTION_HINT, GL10::GL_FASTEST) if (@translucent_background) gl.glClearColor(0,0,0,0) else gl.glClearColor(1,1,1,1) end gl.glEnable(GL10::GL_CULL_FACE) gl.glShadeModel(GL10::GL_SMOOTH) gl.glEnable(GL10::GL_DEPTH_TEST) end def changeAngle @offset = -@offset end end

ruboto_generate(android.opengl.GLSurfaceView => "TouchSurfaceView") class TouchSurfaceView def initialize(context) super context self.initialize_ruboto_callbacks do def on_touch_event(event) if event.getAction == MotionEvent::ACTION_DOWN @renderer.changeAngle request_render end return true end end end def renderer= renderer @renderer = renderer super renderer end end

$activity.start_ruboto_activity "$glsurface" do setTitle "GLSurfaceView" def on_create(bundle) @surface_view = TouchSurfaceView.new(self) @surface_view.renderer = RubotoGLSurfaceViewRenderer.new self.content_view = @surface_view end def on_resume @surface_view.on_resume end def on_pause @surface_view.on_pause end end

8Saturday, January 26, 13

Page 15: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Demo: OpenGL

9Saturday, January 26, 13

Page 16: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

History 2010

ruboto-core : GSoC 2010 by Daniel Jackoway

Version 0.0.3 released December 19, 2010

10Saturday, January 26, 13

Page 17: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

History 2011

Testing framework: Feb 13, 2011 (my first contribution)

Bundler support: may 21, 2011

New Logo & Icons by RedNifre: july 20, 2011

RubotoCore platform package: august 2011

Rename to just “ruboto”: december 24, 2011

11Saturday, January 26, 13

Page 18: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

History 2011

Testing framework: Feb 13, 2011 (my first contribution)

Bundler support: may 21, 2011

New Logo & Icons by RedNifre: july 20, 2011

RubotoCore platform package: august 2011

Rename to just “ruboto”: december 24, 2011

11Saturday, January 26, 13

Page 19: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

History 2012

Class oriented component definition, 2012

On-device generation of subclasses may 10, 2012

Subclassing of Java classes (next release)

12Saturday, January 26, 13

Page 20: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

History 2012

Class oriented component definition, 2012

On-device generation of subclasses may 10, 2012

Subclassing of Java classes (next release)

$activity.handle_create do |bundle| setTitle ‘Hello World!’ setup_content do linear_layout :orientation => LinearLayout::VERTICAL do @text_view = text_view :text => 'What hath Matz wrought?' button :text => ‘Click me!’, :width => :wrap_content, :id => 43 end end handle_click do |view| if view.id == 43 @text_view.setText 'What hath Matz wrought!' toast 'Flipped a bit via butterfly' end end end

12Saturday, January 26, 13

Page 21: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

History 2012

Class oriented component definition, 2012

On-device generation of subclasses may 10, 2012

Subclassing of Java classes (next release)

$activity.handle_create do |bundle| setTitle ‘Hello World!’ setup_content do linear_layout :orientation => LinearLayout::VERTICAL do @text_view = text_view :text => 'What hath Matz wrought?' button :text => ‘Click me!’, :width => :wrap_content, :id => 43 end end handle_click do |view| if view.id == 43 @text_view.setText 'What hath Matz wrought!' toast 'Flipped a bit via butterfly' end end end

$activity.start_ruboto_activity do def on_create(bundle) setTitle ‘Hello World!’

click_handler = proc do |view| @text_view.setText 'What hath Matz wrought!' toast 'Flipped a bit via butterfly' end self.content_view = linear_layout :orientation => LinearLayout::VERTICAL do @text_view = text_view :text => 'What hath Matz wrought?' button :text => ‘Click me!, :width => :wrap_content, :on_click_listener => click_handler end end end

12Saturday, January 26, 13

Page 22: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

History 2012

Class oriented component definition, 2012

On-device generation of subclasses may 10, 2012

Subclassing of Java classes (next release)

$activity.handle_create do |bundle| setTitle ‘Hello World!’ setup_content do linear_layout :orientation => LinearLayout::VERTICAL do @text_view = text_view :text => 'What hath Matz wrought?' button :text => ‘Click me!’, :width => :wrap_content, :id => 43 end end handle_click do |view| if view.id == 43 @text_view.setText 'What hath Matz wrought!' toast 'Flipped a bit via butterfly' end end end

$activity.start_ruboto_activity do def on_create(bundle) setTitle ‘Hello World!’

click_handler = proc do |view| @text_view.setText 'What hath Matz wrought!' toast 'Flipped a bit via butterfly' end self.content_view = linear_layout :orientation => LinearLayout::VERTICAL do @text_view = text_view :text => 'What hath Matz wrought?' button :text => ‘Click me!, :width => :wrap_content, :on_click_listener => click_handler end end end

class ImageButtonActivity def on_create(bundle) super set_title ‘Hello World!’ click_handler = proc do |view| @text_view.setText 'What hath Matz wrought!' toast 'Flipped a bit via butterfly' end self.content_view = linear_layout :orientation => :vertical do @text_view = text_view :text => 'What hath Matz wrought?' button :text => ‘Click me!’, :width => :wrap_content, :id => 43, :on_click_listener => click_handler end end end

12Saturday, January 26, 13

Page 23: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

History 2012

Class oriented component definition, 2012

On-device generation of subclasses may 10, 2012

Subclassing of Java classes (next release)

13Saturday, January 26, 13

Page 24: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

History 2012

Class oriented component definition, 2012

On-device generation of subclasses may 10, 2012

Subclassing of Java classes (next release)

require 'ruboto/generate' ruboto_generate("android.widget.ArrayAdapter" => $package_name + ".MyArrayAdapter")

adapter = MyArrayAdapter.new(self, android.R.layout.simple_list_item_1 , [...]) adapter.initialize_ruboto_callbacks do def get_view(position, convert_view, parent) @inflater ||= context.getSystemService(Context::LAYOUT_INFLATER_SERVICE) row = convert_view ? convert_view : @inflater.inflate(mResource, nil) row.findViewById(mFieldId).text = get_item(position) row end end

13Saturday, January 26, 13

Page 25: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

History 2012

Class oriented component definition, 2012

On-device generation of subclasses may 10, 2012

Subclassing of Java classes (next release)

require 'ruboto/generate' ruboto_generate("android.widget.ArrayAdapter" => $package_name + ".MyArrayAdapter")

adapter = MyArrayAdapter.new(self, android.R.layout.simple_list_item_1 , [...]) adapter.initialize_ruboto_callbacks do def get_view(position, convert_view, parent) @inflater ||= context.getSystemService(Context::LAYOUT_INFLATER_SERVICE) row = convert_view ? convert_view : @inflater.inflate(mResource, nil) row.findViewById(mFieldId).text = get_item(position) row end end

class MyArrayAdapter < android.widget.ArrayAdapter def get_view(position, convert_view, parent) @inflater ||= context.getSystemService(Context::LAYOUT_INFLATER_SERVICE) row = convert_view ? convert_view : @inflater.inflate(mResource, nil) row.findViewById(mFieldId).text = get_item(position) row end end

adapter = MyArrayAdapter.new(self, android.R.layout.simple_list_item_1, [...])

13Saturday, January 26, 13

Page 26: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Installation

Android toolset: Java JDK, Apache ANT, Android SDK + Platform SDK

A Ruby implementation

[sudo] gem install ruboto

14Saturday, January 26, 13

Page 27: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Tooling

The “ruboto” command

Rake

15Saturday, January 26, 13

Page 28: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Tooling - create project

ruboto gen app --package my.cool.super_app

16Saturday, January 26, 13

Page 29: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Tooling - create project

The “ruboto” command

ruboto gem app --package my.cool.

Rake based

$ ruboto gen app --package my.cool.super_appGenerating Android app SuperApp in /Users/uwe/workspace/jruby/super_app......Added file super_app/src/my/cool/super_app/SuperAppActivity.java...Added file super_app/res/values/strings.xmlAdded file super_app/res/layout/main.xmlAdded file super_app/AndroidManifest.xmlAdded file super_app/build.xmlAdded file super_app/proguard-project.txtRemoved file src/my/cool/super_app/SuperAppActivity.javaRemoved file res/layout/main.xml...Added file /Users/uwe/workspace/jruby/super_app/src/my/cool/super_app/SuperAppActivity.java.Added file /Users/uwe/workspace/jruby/super_app/src/super_app_activity.rb.Added file /Users/uwe/workspace/jruby/super_app/test/src/super_app_activity_test.rb.

17Saturday, January 26, 13

Page 30: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Tooling - create component

ruboto gen class Activity --name MyActivity

18Saturday, January 26, 13

Page 31: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Tooling - create component

ruboto gen class Activity --name MyActivity

$ ruboto gen class Activity --name MyActivityAdded file /Users/uwe/workspace/jruby/hello_world/src/presentation/hello_world/MyActivity.java.Added file /Users/uwe/workspace/jruby/hello_world/src/my_activity.rb.Added file /Users/uwe/workspace/jruby/hello_world/test/src/my_activity_test.rb.Added activity to manifest.

19Saturday, January 26, 13

Page 32: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Tooling - build APK

rake debug

rake release

20Saturday, January 26, 13

Page 33: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Tooling - Install and run APK

rake install

rake start

rake install start

rake update_scripts:restart

21Saturday, January 26, 13

Page 36: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

GUI Editor

Eclipse

24Saturday, January 26, 13

Page 37: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Hello World!

25Saturday, January 26, 13

Page 38: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Hello world!

26Saturday, January 26, 13

Page 39: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Hello world!

$ android create project --target android-8 --path hello_world --package presentation.hello_world --activity HelloWorldActivityGenerates file src/presentation/HelloWorldActivity.java

26Saturday, January 26, 13

Page 40: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Hello world!

$ android create project --target android-8 --path hello_world --package presentation.hello_world --activity HelloWorldActivityGenerates file src/presentation/HelloWorldActivity.java

26Saturday, January 26, 13

Page 41: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Hello world!

$ android create project --target android-8 --pat...Generates file src/presentation/HelloWorldActivity.java

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

27Saturday, January 26, 13

Page 42: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Hello world!

$ android create project --target android-8 --pat...Generates file src/presentation/HelloWorldActivity.java

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" >

<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="@string/hello_world" tools:context=".HelloWorldActivity" android:textSize="46dip" />

<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:layout_marginTop="75dp" android:onClick="changeIt" android:text="Say hello" />

</LinearLayout>

27Saturday, January 26, 13

Page 43: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Hello world!

$ android create project --target android-8 --pat...Generates file src/presentation/HelloWorldActivity.java

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

27Saturday, January 26, 13

Page 44: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Hello world!

$ android create project --target android-8 --pat...Generates file src/presentation/HelloWorldActivity.java

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

$ android create project --target android-8 --pat...Generates file src/presentation/HelloWorldActivity.java

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

28Saturday, January 26, 13

Page 45: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Hello world!

$ android create project --target android-8 --pat...Generates file src/presentation/HelloWorldActivity.java

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

$ android create project --target android-8 --pat...Generates file src/presentation/HelloWorldActivity.java

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

28Saturday, January 26, 13

Page 46: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Hello world!

$ android create project --target android-8 --pat...Generates file src/presentation/HelloWorldActivity.java

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

$ android create project --target android-8 --pat...Generates file src/presentation/HelloWorldActivity.java

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

29Saturday, January 26, 13

Page 47: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Hello world!

$ android create project --target android-8 --pat...Generates file src/presentation/HelloWorldActivity.java

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

$ android create project --target android-8 --pat...Generates file src/presentation/HelloWorldActivity.java

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

$ ruboto gen app --package presentation.hello_worldGenerates file src/hello_world_activity.rb

29Saturday, January 26, 13

Page 48: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Hello world!

$ android create project --target android-8 --pat...Generates file src/presentation/HelloWorldActivity.java

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

$ android create project --target android-8 --pat...Generates file src/presentation/HelloWorldActivity.java

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

$ ruboto gen app --package presentation.hello_worldGenerates file src/hello_world_activity.rb

29Saturday, January 26, 13

Page 49: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Hello world!

$ ruboto gen app --package presentation.hello_worldGenerates file src/hello_world_activity.rb

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

$ android create project --target android-8 --pat...Generates file src/presentation/HelloWorldActivity.java

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

30Saturday, January 26, 13

Page 50: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstance State); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

Hello world!

class HelloWorldActivity def on_create(bundle) super setContentView R.layout.activity_hello_world end def change_it(view) tv = findViewById(AndroidIds::textView1) tv.text = "Hello JavaZone!" end end

31Saturday, January 26, 13

Page 51: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Hello world!

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" >

<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="@string/hello_world" tools:context=".HelloWorldActivity" android:textSize="46dip" />

<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:layout_marginTop="75dp" android:onClick="changeIt" android:text="Say hello" />

</LinearLayout>

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstance State); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

32Saturday, January 26, 13

Page 52: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" >

<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="@string/hello_world" tools:context=".HelloWorldActivity" android:textSize="46dip" />

<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:layout_marginTop="75dp" android:onClick="changeIt" android:text="Say hello" />

</LinearLayout>

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.widget.TextView;

public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstance State); setContentView(R.layout.activity_hello_world); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); }}

33Saturday, January 26, 13

Page 53: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

@Override public void onClick(View v) { changeIt(v); }}

34Saturday, January 26, 13

Page 54: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

@Override public void onClick(View v) { changeIt(v); }}

35Saturday, January 26, 13

Page 55: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

@Override public void onClick(View v) { changeIt(v); }}

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

@Override public void onClick(View v) { changeIt(v); }}

36Saturday, January 26, 13

Page 56: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

@Override public void onClick(View v) { changeIt(v); }}

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

@Override public void onClick(View v) { changeIt(v); }}

37Saturday, January 26, 13

Page 57: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

@Override public void onClick(View v) { changeIt(v); }}

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

@Override public void onClick(View v) { changeIt(v); }}

38Saturday, January 26, 13

Page 58: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

@Override public void onClick(View v) { changeIt(v); }}

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

@Override public void onClick(View v) { changeIt(v); }}

39Saturday, January 26, 13

Page 59: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

@Override public void onClick(View v) { changeIt(v); }}

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

@Override public void onClick(View v) { changeIt(v); }}

40Saturday, January 26, 13

Page 60: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.app.Activity;import android.view.Gravity;

import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

class HelloWorldActivity extends Activity implements OnClickListener

public onCreate( savedInstanceState) { super.onCreate(savedInstanceState); layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); btn = new Button(this); btn.setText("Say hello"); btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public changeIt( view) { tv = findViewById(42); tv.setText("Hello JavaZone!"); }

public onClick( v) { changeIt(v); }end

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

@Override public void onClick(View v) { changeIt(v); }}

41Saturday, January 26, 13

Page 61: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.app.Activity;import android.view.Gravity;

import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

class HelloWorldActivity extends Activity implements OnClickListener

public onCreate( savedInstanceState) { super.onCreate(savedInstanceState); layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); btn = new Button(this); btn.setText("Say hello"); btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public changeIt( view) { tv = findViewById(42); tv.setText("Hello JavaZone!"); }

public onClick( v) { changeIt(v); }end

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

@Override public void onClick(View v) { changeIt(v); }}

42Saturday, January 26, 13

Page 62: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.app.Activity;import android.view.Gravity;

import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

class HelloWorldActivity extends Activity implements OnClickListener

def onCreate( savedInstanceState) super.onCreate(savedInstanceState); layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); btn = new Button(this); btn.setText("Say hello"); btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); end

def changeIt( view) tv = findViewById(42); tv.setText("Hello JavaZone!"); end

def onClick( v) changeIt(v); endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

43Saturday, January 26, 13

Page 63: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.app.Activity;import android.view.Gravity;

import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

class HelloWorldActivity extends Activity implements OnClickListener

def onCreate( savedInstanceState) super.onCreate(savedInstanceState); layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); btn = new Button(this); btn.setText("Say hello"); btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); end

def changeIt( view) tv = findViewById(42); tv.setText("Hello JavaZone!"); end

def onClick( v) changeIt(v); endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

44Saturday, January 26, 13

Page 64: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.app.Activity;import android.view.Gravity;

import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

class HelloWorldActivity extends Activity implements OnClickListener

def onCreate( savedInstanceState) super.onCreate(savedInstanceState); layout = LinearLayout.new(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(this); tv.setId(42); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); btn = Button.new(this); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); end

def changeIt( view) tv = findViewById(42); tv.setText("Hello JavaZone!"); end

def onClick( v) changeIt(v); endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

45Saturday, January 26, 13

Page 65: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.app.Activity;import android.view.Gravity;

import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

class HelloWorldActivity extends Activity implements OnClickListener

def onCreate( savedInstanceState) super.onCreate(savedInstanceState); layout = LinearLayout.new(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(this); tv.setId(42); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); btn = Button.new(this); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); end

def changeIt( view) tv = findViewById(42); tv.setText("Hello JavaZone!"); end

def onClick( v) changeIt(v); endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

46Saturday, January 26, 13

Page 66: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.app.Activity;import android.view.Gravity;

import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

class HelloWorldActivity extends Activity implements OnClickListener

def onCreate( savedInstanceState) super.onCreate(savedInstanceState); layout = LinearLayout.new(self); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self); tv.setId(42); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); btn = Button.new(self); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(self); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); end

def changeIt( view) tv = findViewById(42); tv.setText("Hello JavaZone!"); end

def onClick( v) changeIt(v); endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

47Saturday, January 26, 13

Page 67: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.app.Activity;import android.view.Gravity;

import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

class HelloWorldActivity extends Activity implements OnClickListener

def onCreate( savedInstanceState) super.onCreate(savedInstanceState); layout = LinearLayout.new(self); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self); tv.setId(42); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); btn = Button.new(self); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(self); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); end

def changeIt( view) tv = findViewById(42); tv.setText("Hello JavaZone!"); end

def onClick( v) changeIt(v); endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

48Saturday, January 26, 13

Page 68: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.app.Activity;import android.view.Gravity;

import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

class HelloWorldActivity < Activity

def onCreate( savedInstanceState) super; layout = LinearLayout.new(self); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self); tv.setId(42); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); btn = Button.new(self); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(self); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); end

def changeIt( view) tv = findViewById(42); tv.setText("Hello JavaZone!"); end

def onClick( v) changeIt(v); endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

49Saturday, January 26, 13

Page 69: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.app.Activity;import android.view.Gravity;

import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

class HelloWorldActivity < Activity

def onCreate( savedInstanceState) super; layout = LinearLayout.new(self); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self); tv.setId(42); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); btn = Button.new(self); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(self); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); end

def changeIt( view) tv = findViewById(42); tv.setText("Hello JavaZone!"); end

def onClick( v) changeIt(v); endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

50Saturday, January 26, 13

Page 70: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.app.Activity;import android.view.Gravity;

import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

class HelloWorldActivity < Activity

def onCreate( savedInstanceState) super; layout = LinearLayout.new(self); layout.setGravity(Gravity::CENTER); layout.setOrientation(LinearLayout::VERTICAL); tv = TextView(self).new; tv.setId(42); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams::WRAP_CONTENT, LayoutParams::WRAP_CONTENT); tvlp.gravity = Gravity::CENTER; tv.setTextSize(46); btn = Button.new(self); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams::WRAP_CONTENT, LayoutParams::WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity::CENTER; btn.setOnClickListener(self); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); end

def changeIt( view) tv = findViewById(42); tv.setText("Hello JavaZone!"); end

def onClick( v) changeIt(v); endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

51Saturday, January 26, 13

Page 71: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.app.Activity;import android.view.Gravity;

import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

class HelloWorldActivity < Activity

def onCreate(savedInstanceState) super; layout = LinearLayout.new(self); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self); tv.setId(42); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); btn = Button.new(self); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(self); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); end

def changeIt(view) tv = findViewById(42); tv.setText("Hello JavaZone!"); end

def onClick(v) changeIt(v); endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

52Saturday, January 26, 13

Page 72: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.app.Activity;import android.view.Gravity;

import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

class HelloWorldActivity < Activity

def onCreate(savedInstanceState) super; layout = LinearLayout.new(self); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self); tv.setId(42); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); btn = Button.new(self); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(self); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); end

def changeIt(view) tv = findViewById(42); tv.setText("Hello JavaZone!"); end

def onClick(v) changeIt(v); endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

53Saturday, January 26, 13

Page 73: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.app.Activityimport android.view.Gravity

import android.widget.Buttonimport android.widget.LinearLayoutimport android.widget.LinearLayout.LayoutParamsimport android.widget.TextView

class HelloWorldActivity < Activity

def onCreate(savedInstanceState) super layout = LinearLayout.new(self) layout.setGravity(Gravity.CENTER) layout.setOrientation(LinearLayout.VERTICAL) tv = TextView.new(self) tv.setId(42) tv.setText("Hello World!") tvlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) tvlp.gravity = Gravity.CENTER tv.setTextSize(46) btn = Button.new(self) btn.setText("Say hello") btnlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) btnlp.topMargin = 75 btnlp.gravity = Gravity.CENTER btn.setOnClickListener(self) layout.addView(tv, tvlp) layout.addView(btn, btnlp) setContentView(layout) end

def changeIt(view) tv = findViewById(42) tv.setText("Hello JavaZone!") end

def onClick(v) changeIt(v) endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

54Saturday, January 26, 13

Page 74: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.app.Activityimport android.view.Gravity

import android.widget.Buttonimport android.widget.LinearLayoutimport android.widget.LinearLayout.LayoutParamsimport android.widget.TextView

class HelloWorldActivity < Activity

def onCreate(savedInstanceState) super layout = LinearLayout.new(self) layout.setGravity(Gravity.CENTER) layout.setOrientation(LinearLayout.VERTICAL) tv = TextView.new(self) tv.setId(42) tv.setText("Hello World!") tvlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) tvlp.gravity = Gravity.CENTER tv.setTextSize(46) btn = Button.new(self) btn.setText("Say hello") btnlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) btnlp.topMargin = 75 btnlp.gravity = Gravity.CENTER btn.setOnClickListener(self) layout.addView(tv, tvlp) layout.addView(btn, btnlp) setContentView(layout) end

def changeIt(view) tv = findViewById(42) tv.setText("Hello JavaZone!") end

def onClick(v) changeIt(v) endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

55Saturday, January 26, 13

Page 75: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.view.Gravity

import android.widget.Buttonimport android.widget.LinearLayoutimport android.widget.LinearLayout.LayoutParamsimport android.widget.TextView

class HelloWorldActivity

def onCreate(savedInstanceState) super layout = LinearLayout.new(self) layout.setGravity(Gravity.CENTER) layout.setOrientation(LinearLayout.VERTICAL) tv = TextView.new(self) tv.setId(42) tv.setText("Hello World!") tvlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) tvlp.gravity = Gravity.CENTER tv.setTextSize(46) btn = Button.new(self) btn.setText("Say hello") btnlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) btnlp.topMargin = 75 btnlp.gravity = Gravity.CENTER btn.setOnClickListener(self) layout.addView(tv, tvlp) layout.addView(btn, btnlp) setContentView(layout) end

def changeIt(view) tv = findViewById(42) tv.setText("Hello JavaZone!") end

def onClick(v) changeIt(v) endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

56Saturday, January 26, 13

Page 76: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.view.Gravity

import android.widget.Buttonimport android.widget.LinearLayoutimport android.widget.LinearLayout.LayoutParamsimport android.widget.TextView

class HelloWorldActivity

def onCreate(savedInstanceState) super layout = LinearLayout.new(self) layout.setGravity(Gravity.CENTER) layout.setOrientation(LinearLayout.VERTICAL) tv = TextView.new(self) tv.setId(42) tv.setText("Hello World!") tvlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) tvlp.gravity = Gravity.CENTER tv.setTextSize(46) btn = Button.new(self) btn.setText("Say hello") btnlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) btnlp.topMargin = 75 btnlp.gravity = Gravity.CENTER btn.setOnClickListener(self) layout.addView(tv, tvlp) layout.addView(btn, btnlp) setContentView(layout) end

def changeIt(view) tv = findViewById(42) tv.setText("Hello JavaZone!") end

def onClick(v) changeIt(v) endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

57Saturday, January 26, 13

Page 77: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.view.Gravity

import android.widget.Buttonimport android.widget.LinearLayoutimport android.widget.LinearLayout.LayoutParamsimport android.widget.TextView

class HelloWorldActivity

def on_create(savedInstanceState) super layout = LinearLayout.new(self) layout.gravity = Gravity.CENTER layout.orientation = LinearLayout.VERTICAL tv = TextView.new(self) tv.id = 42 tv.text = "Hello World!" tvlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) tvlp.gravity = Gravity.CENTER tv.text_size = 46 btn = Button.new(self) btn.text = "Say hello" btnlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) btnlp.topMargin = 75 btnlp.gravity = Gravity.CENTER btn.on_click_listener = self layout.add_view(tv, tvlp) layout.add_view(btn, btnlp) setContentView(layout) end

def change_it(view) tv = find_view_by_id(42) tv.text = "Hello JavaZone!" end

def on_click(v) change_it(v) endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

58Saturday, January 26, 13

Page 78: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.view.Gravity

import android.widget.Buttonimport android.widget.LinearLayoutimport android.widget.LinearLayout.LayoutParamsimport android.widget.TextView

class HelloWorldActivity

def on_create(savedInstanceState) super layout = LinearLayout.new(self) layout.gravity = Gravity.CENTER layout.orientation = LinearLayout.VERTICAL tv = TextView.new(self) tv.id = 42 tv.text = "Hello World!" tvlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) tvlp.gravity = Gravity.CENTER tv.text_size = 46 btn = Button.new(self) btn.text = "Say hello" btnlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) btnlp.topMargin = 75 btnlp.gravity = Gravity.CENTER btn.on_click_listener = self layout.add_view(tv, tvlp) layout.add_view(btn, btnlp) setContentView(layout) end

def change_it(view) tv = find_view_by_id(42) tv.text = "Hello JavaZone!" end

def on_click(v) change_it(v) endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

59Saturday, January 26, 13

Page 79: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

import android.view.Gravity

import android.widget.Buttonimport android.widget.LinearLayoutimport android.widget.LinearLayout.LayoutParamsimport android.widget.TextView

class HelloWorldActivity

def on_create(savedInstanceState) super layout = LinearLayout.new(self) layout.gravity = Gravity.CENTER layout.orientation = LinearLayout.VERTICAL tv = TextView.new(self) tv.id = 42 tv.text = "Hello World!" tvlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) tvlp.gravity = Gravity.CENTER tv.text_size = 46 btn = Button.new(self) btn.text = "Say hello" btnlp = LayoutParams.new( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) btnlp.topMargin = 75 btnlp.gravity = Gravity.CENTER btn.on_click_listener = self layout.add_view(tv, tvlp) layout.add_view(btn, btnlp) setContentView(layout) end

def change_it(view) tv = find_view_by_id(42) tv.text = "Hello JavaZone!" end

def on_click(v) change_it(v) endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

60Saturday, January 26, 13

Page 80: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

require 'ruboto/widget'

ruboto_import_widgets :Button, :LinearLayout, :TextView

class HelloWorldActivity

def on_create(savedInstanceState) super self.content_view = linear_layout gravity: :center, orientation: :vertical do text_view text: 'Hello World!', id: 42, text_size: 46, width: :wrap_content, height: :wrap_content, gravity: :center button id: 43, text: "Say hello", width: :wrap_content, height: :wrap_content, gravity: :center, margins: [0,75,0,0], on_click_listener: self end

end

def change_it(view) tv = find_view_by_id(42) tv.text = "Hello JavaZone!" end

def on_click(v) change_it(v) endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

61Saturday, January 26, 13

Page 81: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

require 'ruboto/widget'

ruboto_import_widgets :Button, :LinearLayout, :TextView

class HelloWorldActivity

def on_create(savedInstanceState) super self.content_view = linear_layout gravity: :center, orientation: :vertical do text_view text: 'Hello World!', id: 42, text_size: 46, width: :wrap_content, height: :wrap_content, gravity: :center button id: 43, text: "Say hello", width: :wrap_content, height: :wrap_content, gravity: :center, margins: [0,75,0,0], on_click_listener: self end

end

def change_it(view) tv = find_view_by_id(42) tv.text = "Hello JavaZone!" end

def on_click(v) change_it(v) endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

62Saturday, January 26, 13

Page 82: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

require 'ruboto/widget'

ruboto_import_widgets :Button, :LinearLayout, :TextView

class HelloWorldActivity

def on_create(savedInstanceState) super self.content_view = linear_layout gravity: :center, orientation: :vertical do text_view text: 'Hello World!', id: 42, text_size: 46, width: :wrap_content, height: :wrap_content, gravity: :center button id: 43, text: "Say hello", width: :wrap_content, height: :wrap_content, gravity: :center, margins: [0,75,0,0], on_click_listener: self end

end

def change_it(view) tv = find_view_by_id(42) tv.text = "Hello JavaZone!" end

def on_click(v) change_it(v) endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

63Saturday, January 26, 13

Page 83: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

require 'ruboto/widget'

ruboto_import_widgets :Button, :LinearLayout, :TextView

class HelloWorldActivity

def on_create(savedInstanceState) super self.content_view = linear_layout gravity: :center, orientation: :vertical do text_view text: 'Hello World!', id: 42, text_size: 46, width: :wrap_content, height: :wrap_content, gravity: :center button id: 43, text: "Say hello", width: :wrap_content, height: :wrap_content, gravity: :center, margins: [0,75,0,0], on_click_listener: self end

end

def change_it(view) tv = find_view_by_id(42) tv.text = "Hello JavaZone!" end

def on_click(v) change_it(v) endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

64Saturday, January 26, 13

Page 84: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

require 'ruboto/widget'

ruboto_import_widgets :Button, :LinearLayout, :TextView

class HelloWorldActivity

def on_create(savedInstanceState) super self.content_view = linear_layout gravity: :center, orientation: :vertical do @tv = text_view text: 'Hello World!', id: 42, text_size: 46, width: :wrap_content, height: :wrap_content, gravity: :center button id: 43, text: "Say hello", width: :wrap_content, height: :wrap_content, gravity: :center, margins: [0,75,0,0], on_click_listener: proc{@tv.text = ‘Hello JavaZone’} end

end

end

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

65Saturday, January 26, 13

Page 85: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

require 'ruboto/widget'

ruboto_import_widgets :Button, :LinearLayout, :TextView

class HelloWorldActivity def on_create(savedInstanceState) super self.content_view = linear_layout gravity: :center, orientation: :vertical do @tv = text_view text: 'Hello World!', id: 42, text_size: 46, width: :wrap_content, height: :wrap_content, gravity: :center button id: 43, text: 'Say hello', width: :wrap_content, height: :wrap_content, gravity: :center, margins: [0,75,0,0], on_click_listener: proc{@tv.text = 'Hello JavaZone'} end endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

66Saturday, January 26, 13

Page 86: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

require 'ruboto/widget'

ruboto_import_widgets :Button, :LinearLayout, :TextView

class HelloWorldActivity def on_create(savedInstanceState) super self.content_view = linear_layout gravity: :center, orientation: :vertical do @tv = text_view text: 'Hello World!', id: 42, text_size: 46, width: :wrap_content, height: :wrap_content, gravity: :center button id: 43, text: 'Say hello', width: :wrap_content, height: :wrap_content, gravity: :center, margins: [0,75,0,0], on_click_listener: proc{@tv.text = 'Hello JavaZone'} end endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

67Saturday, January 26, 13

Page 87: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

require 'ruboto/widget'

ruboto_import_widgets :Button, :LinearLayout, :TextView

class HelloWorldActivity def on_create(savedInstanceState) super self.content_view = linear_layout gravity: :center, orientation: :vertical do @tv = text_view text: 'Hello World!', id: 42, text_size: 46, width: :wrap_content, height: :wrap_content, gravity: :center button id: 43, text: 'Say hello', width: :wrap_content, height: :wrap_content, gravity: :center, margins: [0,75,0,0], on_click_listener: proc{@tv.text = 'Hello JavaZone'} end endend

package com.example.examplejavaxml;

import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;

public class HelloWorldActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setId(42); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); Button btn = new Button(this); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(btn, btnlp); setContentView(layout); }

public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); }

! @Override! public void onClick(View v) {! ! changeIt(v);! }}

67Saturday, January 26, 13

Page 88: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Examples

Make a call

Show webpage

Spycam

68Saturday, January 26, 13

Page 89: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Display a web page

import "android.content.Intent"import "android.net.Uri"

class RubotoHomePageActivity def on_resume intent = Intent.new(Intent::ACTION_VIEW) uri = Uri.parse("http://ruboto.org/") intent.setData(uri) startActivity(intent) finish endend

69Saturday, January 26, 13

Page 90: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Phone home

import "android.content.Intent"import "android.net.Uri"

class PhoneHomeActivity def on_resume intent = Intent.new(Intent::ACTION_CALL) uri = Uri.parse("tel:5551234") intent.setData(uri) startActivity(intent) finish endenda

70Saturday, January 26, 13

Page 91: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Spycam

Access the camera

Show the camera image

Start a WEBrick web server

Serve a new image on each request

71Saturday, January 26, 13

Page 92: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Spycam

Access the camera

Show the camera image

Start a WEBrick web server

Serve a new image on each request

require  'monitor'require  'camera_helper'require  'ruboto/util/stack'

class  SpycamServer    extend  MonitorMixin

   PORT  =  4567    DOC_ROOT  =  "#{$activity.files_dir.absolute_path}/"

   @@server  =  nil    def  self.start(activity,  server_status_view)        Thread.with_large_stack(512)  do            synchronize  do                if  @@server.nil?                    activity.run_on_ui_thread  {  server_status_view.text  =  "Loading"  }                    require  'webrick'                    activity.run_on_ui_thread  {  server_status_view.text  =  "Loaded"  }                    @@server  =  WEBrick::HTTPServer.new(:Port  =>  PORT,  :DocumentRoot  =>  DOC_ROOT)

                   @@server.mount_proc('/')  do  |req,  resp|                        case  req.path                        when  '/',  'index.html'                            CameraHelper.take_picture(activity)                            resp.content_type  =  "text/html"                            resp.body  =  '<html>                                                            <head>                                                                <title>Spycam</title>                                                            </head>                                                            <body>                                                                <a  href="/"><img  src="latest.jpg"></a>                                                            </body>                                                        </html>'                            raise  WEBrick::HTTPStatus::OK                        when  '/latest.jpg'                            resp.content_type  =  "image/jpg"                            resp.body  =  $camera_data                            $camera_data  =  nil                            raise  WEBrick::HTTPStatus::OK                        else                            resp.body  =  "Unknown  path:  #{req.path.inspect}"                            raise  WEBrick::HTTPStatus::NotFound                        end                    end                    server  =  @@server                    Thread.new{server.start}                end                activity.run_on_ui_thread  {  server_status_view.text  =  "WEBrick  started  on  http://#{get_local_ip_address}:#{PORT}/"  }            end        end    end

   def  self.stop        synchronize  do            if  @@server                @@server.shutdown                sleep  0.1  until  @@server.status  ==  :Stop                @@server  =  nil            end        end    end

   private

   def  self.get_local_ip_address        ip  =  $context.get_system_service($context.class::WIFI_SERVICE).connection_info.ip_address        return  "localhost"  if  ip  ==  0        [0,  8,  16,  24].map{|n|  ((ip  >>  n)  &  0xff).to_s}.join(".")    end

end

require  'ruboto/activity'require  'ruboto/widget'require  'spycam_server'

import  android.util.Logimport  android.view.Surfaceimport  android.view.WindowManager

ruboto_import_widgets  :Button,  :LinearLayout,  :ScrollView,  :TextViewruboto_import_widget  :SurfaceView,  "android.view"

class  SpycamActivity    def  on_create(bundle)        rotation  =  {                Surface::ROTATION_0  =>  0,Surface::ROTATION_90  =>  90,Surface::ROTATION_180  =>  180,Surface::ROTATION_270  =>  270        }[window_manager.default_display.rotation]        self.title  =  "Spycam  #{rotation}"        #  self.setRequestedOrientation(android.content.pm.ActivityInfo::SCREEN_ORIENTATION_PORTRAIT)        window.add_flags(WindowManager::LayoutParams::FLAG_KEEP_SCREEN_ON)

       setContentView(linear_layout(:orientation  =>  :vertical)  do            linear_layout  do                text_view  :text  =>  "Server:  "                @server_status_view  =  text_view            end            linear_layout  do                text_view  :text  =>  "Picture:  "                @camera_status_view  =  text_view            end

           sv  =  surface_view            sv.holder.add_callback  RubotoSurfaceHolderCallback.new(rotation)            #  Deprecated,  but  still  required  for  older  API  version            sv.holder.set_type  android.view.SurfaceHolder::SURFACE_TYPE_PUSH_BUFFERS        end)    end        def  set_camera_status(value)        @camera_status_view.text  =  value    end

   def  camera_status=(value)        run_on_ui_thread  {  $activity.set_camera_status  value  }    end

   def  on_resume          SpycamServer.start(self,  @server_status_view)    end

   def  on_pause        SpycamServer.stop    end

end

class  RubotoSurfaceHolderCallback    def  initialize(roation)        @rotation  =  roation    end

   def  surfaceCreated(holder)        $camera  =  android.hardware.Camera.open        parameters  =  $camera.parameters        parameters.picture_format  =  android.graphics.PixelFormat::JPEG        parameters.rotation  =  (360  +  (90  -‐  @rotation))  %  360        parameters.set_picture_size(640,  480)        $camera.parameters  =  parameters        $camera.preview_display  =  holder        $camera.display_orientation  =  (360  +  (90  -‐  @rotation))  %  360        $camera.start_preview    end

   def  surfaceChanged(holder,  format,  width,  height)    end

   def  surfaceDestroyed(holder)        $camera.stop_preview        $camera.release          $camera  =  nil    endend

class  CameraHelper    def  self.take_picture(activity)        activity.camera_status  =  "Set  volume..."        am  =  activity.getSystemService(android.content.Context::AUDIO_SERVICE)        old_volume  =  am.get_stream_volume(android.media.AudioManager::STREAM_SYSTEM)        am.set_stream_volume(android.media.AudioManager::STREAM_SYSTEM,  0,  0)

       activity.camera_status  =  "Taking  picture..."        picture_taken  =  false        $camera.take_picture(nil,  nil)  do  |data,  camera|            $camera_data  =  String.from_java_bytes(data)            activity.camera_status  =  "Gotcha!"

           $camera.start_preview            am.set_stream_volume(android.media.AudioManager::STREAM_SYSTEM,  old_volume,  0)            picture_taken  =  true        end        sleep  0.1  until  picture_taken    endend

71Saturday, January 26, 13

Page 93: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Demo: Spycam

72Saturday, January 26, 13

Page 94: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Limitations

Startup time

Tiny stack on main thread

Runtime size

No AOT/JIT compilation

73Saturday, January 26, 13

Page 95: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Status

Ruboto is in production!

Monthly releases.

Still improving the API

Support Android 2.1 - 4.2

5 active developers, more welcome!

74Saturday, January 26, 13

Page 96: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Status

Ruboto is in production!

Monthly releases.

Still improving the API

Support Android 2.1 - 4.2

5 active developers, more welcome!

74Saturday, January 26, 13

Page 97: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Status

Ruboto is in production!

Monthly releases.

Still improving the API

Support Android 2.1 - 4.2

5 active developers, more welcome!

74Saturday, January 26, 13

Page 98: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Roadmap

1.0.0 release this year

Dalvik backend for the IR compiler

AOT Compilation / IR Persistence

Mirah integration ( http://www.mirah.org )

FFI support

Eclipse plugin

75Saturday, January 26, 13

Page 99: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Demo (if time allows) Ruboto IRB Server

76Saturday, January 26, 13

Page 100: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Contributors welcome!ruboto.org

77Saturday, January 26, 13

Page 101: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Questions?

78Saturday, January 26, 13

Page 102: Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android

Thank you!

79Saturday, January 26, 13