Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android
Upcoming SlideShare
Loading in...5
×
 

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

on

  • 216 views

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 ...

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.

Statistics

Views

Total Views
216
Views on SlideShare
215
Embed Views
1

Actions

Likes
0
Downloads
1
Comments
0

1 Embed 1

http://www.docseek.net 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android Presentation Transcript

    • Saturday, January 26, 13 1
    • Ruboto JRuby on AndroidSaturday, January 26, 13 1
    • Uwe Kubosch Work at Datek Wireless in Norway Ruboto core developer JRuby rookie committerSaturday, January 26, 13 2
    • Ruboto? Platform for developing Android apps using Ruby Builds on JRuby and the Android SDK Application and component generators Test framework Compact GUI definitionSaturday, January 26, 13 3
    • _why Ruboto? Write Ruby instead of Java/XML Use Ruby libraries (gems) Focus on testing Faster development cyclesSaturday, January 26, 13 4
    • Topics covered History Ruboto IRB Installation & development tools Hello world! Demos Limitations RoadmapSaturday, January 26, 13 5
    • Android basics/terms Activity: A screen View: A screen component Service: Background process Intent: Definition of action BroadcastReceiver: Listener for IntentsSaturday, January 26, 13 6
    • History 2009 PoC by Charles Nutter (headius) February 24, 2009 ruboto-irb by headius August 1, 2009Saturday, January 26, 13 7
    • History 2009 PoC by Charles Nutter (headius) February 24, 2009 ruboto-irb by headius August 1, 2009Saturday, January 26, 13 7
    • History 2009 PoC by Charles Nutter (headius) February 24, 2009 ruboto-irb by headius August 1, 2009Saturday, January 26, 13 7
    • History 2009 PoC by Charles Nutter (headius) February 24, 2009 ruboto-irb by headius August 1, 2009Saturday, January 26, 13 7
    • History 2009 PoC by Charles Nutter (headius) February 24, 2009 ruboto-irb by headius August 1, 2009Saturday, January 26, 13 7
    • Demo: OpenGLSaturday, January 26, 13 8
    • class Cube class RubotoGLSurfaceViewRenderer def initialize def initialize @translucent_background = false one = 0x10000 @cube = Cube.new vertices = [ @angle = 0.0 -one,-one,-one,one,-one,-one,one,one,-one,-one,one,-one,-one,- @offset = 1.2 one,one,one,-one,one,one,one,one,-one,one,one end ] colors = [ def onDrawFrame(gl) 0,0,0,one,one,0,0,one,one,one,0,one,0,one,0,one, gl.glClear(GL10::GL_COLOR_BUFFER_BIT | GL10::GL_DEPTH_BUFFER_BIT) gl.glMatrixMode(GL10::GL_MODELVIEW) 0,0,one,one,one,0,one,one,one,one,one,one,0,one,one,one gl.glLoadIdentity ] gl.glTranslatef(0, 0, -3.0) indices = [ gl.glRotatef(@angle, 0, 1, 0) 0, 4, 5, 0, 5, 1, 1, 5, 6, 1, 6, 2, 2, 6, 7, 2, 7, 3, 3, 7, 4, gl.glRotatef(@angle*0.25, 1, 0, 0) 3, 4, 0, 4, 7, 6, 4, 6, 5, 3, 0, 1, 3, 1, 2 gl.glEnableClientState(GL10::GL_VERTEX_ARRAY) ] gl.glEnableClientState(GL10::GL_COLOR_ARRAY) @cube.draw(gl) gl.glRotatef(@angle*2.0, 0, 1, 1) vbb = ByteBuffer.allocateDirect(vertices.length*4) gl.glTranslatef(0.5, 0.5, 0.5) vbb.order(ByteOrder.nativeOrder) @cube.draw(gl) @vertex_buffer = vbb.asIntBuffer @angle += @offset @vertex_buffer.put(vertices.to_java(:int)) end Demo: OpenGL @vertex_buffer.position(0) def onSurfaceChanged(gl, width, height) cbb = ByteBuffer.allocateDirect(colors.length*4) gl.glViewport(0, 0, width, height) ratio = width.to_f / height.to_f cbb.order(ByteOrder.nativeOrder) ruboto_generate(android.opengl.GLSurfaceView => "TouchSurfaceView") gl.glMatrixMode(GL10::GL_PROJECTION) @color_buffer = cbb.asIntBuffer gl.glLoadIdentity @color_buffer.put(colors.to_java(:int)) class TouchSurfaceView gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10) @color_buffer.position(0) def initialize(context) end super context @index_buffer = ByteBuffer.allocateDirect(indices.length) def onSurfaceCreated(gl, config) $activity.start_ruboto_activity "$glsurface" do @index_buffer.put(indices.to_java(:byte)) gl.glDisable(GL10::GL_DITHER) setTitle "GLSurfaceView" self.initialize_ruboto_callbacks do gl.glHint(GL10::GL_PERSPECTIVE_CORRECTION_HINT, GL10::GL_FASTEST) @index_buffer.position(0) def on_touch_event(event) if (@translucent_background) end if event.getAction == MotionEvent::ACTION_DOWN def on_create(bundle) gl.glClearColor(0,0,0,0) @renderer.changeAngle @surface_view = TouchSurfaceView.new(self) else def draw(gl) request_render @surface_view.renderer = RubotoGLSurfaceViewRenderer.new gl.glClearColor(1,1,1,1) gl.glFrontFace(GL10::GL_CW) end end self.content_view = @surface_view gl.glVertexPointer(3, GL10::GL_FIXED, 0, @vertex_buffer) gl.glEnable(GL10::GL_CULL_FACE) end return true gl.glColorPointer(4, GL10::GL_FIXED, 0, @color_buffer) gl.glShadeModel(GL10::GL_SMOOTH) end gl.glEnable(GL10::GL_DEPTH_TEST) gl.glDrawElements(GL10::GL_TRIANGLES, 36, GL10::GL_UNSIGNED_BYTE, end def on_resume end @index_buffer) end @surface_view.on_resume end end def changeAngle end def renderer= renderer @offset = -@offset @renderer = renderer end def on_pause end @surface_view.on_pause super renderer end end end endSaturday, January 26, 13 8
    • Demo: OpenGLSaturday, January 26, 13 9
    • History 2010 ruboto-core : GSoC 2010 by Daniel Jackoway Version 0.0.3 released December 19, 2010Saturday, January 26, 13 10
    • History 2011 Testing framework: Feb 13, Rename to just “ruboto”: 2011 (my first contribution) december 24, 2011 Bundler support: may 21, 2011 New Logo & Icons by RedNifre: july 20, 2011 RubotoCore platform package: august 2011Saturday, January 26, 13 11
    • History 2011 Testing framework: Feb 13, Rename to just “ruboto”: 2011 (my first contribution) december 24, 2011 Bundler support: may 21, 2011 New Logo & Icons by RedNifre: july 20, 2011 RubotoCore platform package: august 2011Saturday, January 26, 13 11
    • History 2012 Class oriented component definition, 2012 On-device generation of subclasses may 10, 2012 Subclassing of Java classes (next release)Saturday, January 26, 13 12
    • History 2012 $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 Class oriented component definition, 2012 end end handle_click do |view| if view.id == 43 On-device generation of subclasses may 10, @text_view.setText What hath Matz wrought! toast Flipped a bit via butterfly end 2012 end end Subclassing of Java classes (next release)Saturday, January 26, 13 12
    • $activity.handle_create do |bundle| History 2012 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 $activity.start_ruboto_activity do @text_view.setText Whaton_create(bundle) def hath Matz wrought! toast Flipped a bit via butterfly setTitle ‘Hello World!’ end end click_handler = proc do |view| end @text_view.setText What hath Matz wrought! toast Flipped a bit via butterfly Class oriented component definition, 2012 end self.content_view = linear_layout :orientation => LinearLayout::VERTICAL do @text_view = text_view :text => What hath Matz wrought? On-device generation of subclasses may 10, button :text => ‘Click me!, :width => :wrap_content, end :on_click_listener => click_handler 2012 end end Subclassing of Java classes (next release)Saturday, January 26, 13 12
    • $activity.handle_create do |bundle| $activity.start_ruboto_activity do History 2012 setTitle ‘Hello World!’ def on_create(bundle) setup_content do setTitle ‘Hello World!’ linear_layout :orientation => LinearLayout::VERTICAL do click_handler = proc do |view| @text_view = text_view :text => What hath Matz wrought? @text_view.setText What hath Matz wrought! button :text => ‘Click me!’, :width => :wrap_content, :id => 43 end toast Flipped a bit via butterfly end end handle_click do |view| self.content_view = if view.id == 43 class ImageButtonActivity linear_layout :orientation => LinearLayout::VERTICAL do def on_create(bundle) @text_view.setText What hath Matz wrought! @text_view = text_view :text => What hath Matz wrought? super toast Flipped a bit via butterfly button :text => ‘Click me!, :width => :wrap_content, end set_title ‘Hello World!’ :on_click_listener => click_handler end end end click_handler = proc do |view| end @text_view.setTextend What hath Matz wrought! toast Flipped a bit via butterfly Class oriented component definition, 2012 end self.content_view = linear_layout :orientation => :vertical do On-device generation of subclasses may 10, @text_view = text_view :text => What hath Matz wrought? button :text => ‘Click me!’, :width => :wrap_content, :id => 43, :on_click_listener => click_handler 2012 end end end Subclassing of Java classes (next release)Saturday, January 26, 13 12
    • History 2012 Class oriented component definition, 2012 On-device generation of subclasses may 10, 2012 Subclassing of Java classes (next release)Saturday, January 26, 13 13
    • History 2012 require ruboto/generate ruboto_generate("android.widget.ArrayAdapter" => $package_name + ".MyArrayAdapter") adapter = MyArrayAdapter.new(self, android.R.layout.simple_list_item_1 , [...]) Class oriented component definition, 2012 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) On-device generation of subclasses may 10, row end end 2012 Subclassing of Java classes (next release)Saturday, January 26, 13 13
    • require ruboto/generate History 2012 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) Class oriented component definition, 2012 row.findViewById(mFieldId).text = get_item(position) row end end On-device generation of subclasses may 10, adapter = MyArrayAdapter.new(self, android.R.layout.simple_list_item_1, [...]) 2012 Subclassing of Java classes (next release)Saturday, January 26, 13 13
    • Installation Android toolset: Java JDK, Apache ANT, Android SDK + Platform SDK A Ruby implementation [sudo] gem install rubotoSaturday, January 26, 13 14
    • Tooling The “ruboto” command RakeSaturday, January 26, 13 15
    • Tooling - create project ruboto gen app --package my.cool.super_appSaturday, January 26, 13 16
    • Tooling - create project $ ruboto gen app --package my.cool.super_app Generating 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.xml Added file super_app/res/layout/main.xml The “ruboto” command Added file super_app/AndroidManifest.xml Added file super_app/build.xml Added file super_app/proguard-project.txt ruboto gem app --package my.cool. Removed file src/my/cool/super_app/SuperAppActivity.java Removed file res/layout/main.xml ... Rake based 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.Saturday, January 26, 13 17
    • Tooling - create component ruboto gen class Activity --name MyActivitySaturday, January 26, 13 18
    • Tooling - create component $ ruboto gen class Activity --name MyActivity Added 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. ruboto gen class Activity --name MyActivitySaturday, January 26, 13 19
    • Tooling - build APK rake debug rake releaseSaturday, January 26, 13 20
    • Tooling - Install and run APK rake install rake start rake install start rake update_scripts:restartSaturday, January 26, 13 21
    • Eclipse http://download.eclipse.org/ releases/juno https://dl-ssl.google.com/ android/eclipse/Saturday, January 26, 13 22
    • Eclipse http://download.eclipse.org/ releases/juno https://dl-ssl.google.com/ android/eclipse/Saturday, January 26, 13 23
    • Eclipse GUI EditorSaturday, January 26, 13 24
    • Hello World!Saturday, January 26, 13 25
    • Hello world!Saturday, January 26, 13 26
    • Hello world! $ android create project --target android-8 --path hello_world --package presentation.hello_world --activity HelloWorldActivity Generates file src/presentation/HelloWorldActivity.javaSaturday, January 26, 13 26
    • Hello world! $ android create project --target android-8 --path hello_world --package presentation.hello_world --activity HelloWorldActiv Generates file src/presentation/HelloWorldActivity.javaSaturday, January 26, 13 26
    • 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!"); } }Saturday, January 26, 13 27
    • Hello world! <?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 create project --target android-8 --pat... android:orientation="vertical" Generates file src/presentation/HelloWorldActivity.java android:layout_width="match_parent" package com.example.examplejavaxml; android:layout_height="match_parent" android:gravity="center" > import android.os.Bundle; import android.app.Activity; <TextView import android.view.View; android:id="@+id/textView1" import android.widget.TextView; android:layout_width="wrap_content" android:layout_height="wrap_content" public class HelloWorldActivity extends Activity { @Override android:gravity="center" android:text="@string/hello_world" public void onCreate(Bundle savedInstanceState) { tools:context=".HelloWorldActivity" super.onCreate(savedInstanceState); android:textSize="46dip" /> setContentView(R.layout.activity_hello_world); } <Button public void changeIt(View view)android:id="@+id/button1" { TextView tv = (TextView) findViewById(R.id.textView1); android:layout_width="wrap_content" tv.setText("Hello JavaZone!"); android:layout_height="wrap_content" } android:gravity="center" } android:layout_marginTop="75dp" android:onClick="changeIt" android:text="Say hello" /> </LinearLayout>Saturday, January 26, 13 27
    • 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!"); } }Saturday, January 26, 13 27
    • 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!"); } }Saturday, January 26, 13 28
    • Hello world! $ android create project --target android-8 --pat... $ android create project --target android-8 --pat... Generates file src/presentation/HelloWorldActivity.java Generates file src/presentation/HelloWorldActivity.java package com.example.examplejavaxml; package com.example.examplejavaxml; import android.os.Bundle; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.View; import android.view.View; import android.widget.TextView; import android.widget.TextView; public class HelloWorldActivity extends Activity { public class HelloWorldActivity extends Activity { @Override @Override public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); setContentView(R.layout.activity_hello_world); } } public void changeIt(View view) { public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); } } } }Saturday, January 26, 13 28
    • Hello world! $ android create project --target android-8 --pat... $ android create project --target android-8 --pat... Generates file src/presentation/HelloWorldActivity.java Generates file src/presentation/HelloWorldActivity.java package com.example.examplejavaxml; package com.example.examplejavaxml; import android.os.Bundle; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.View; import android.view.View; import android.widget.TextView; import android.widget.TextView; public class HelloWorldActivity extends Activity { public class HelloWorldActivity extends Activity { @Override @Override public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); setContentView(R.layout.activity_hello_world); } } public void changeIt(View view) { public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); } } } }Saturday, January 26, 13 29
    • Hello world! $ android create project --target android-8 --pat... $ android create project --target android-8 --pat... Generates file src/presentation/HelloWorldActivity.java Generates file src/presentation/HelloWorldActivity.java package com.example.examplejavaxml; package com.example.examplejavaxml; import android.os.Bundle; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.View; import android.view.View; import android.widget.TextView; import android.widget.TextView; public class HelloWorldActivity extends Activity { public class HelloWorldActivity extends Activity { @Override @Override $ ruboto gen app --package presentation.hello_world public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) { Generates file src/hello_world_activity.rb super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); setContentView(R.layout.activity_hello_world); } } public void changeIt(View view) { public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); } } } }Saturday, January 26, 13 29
    • Hello world! $ ruboto gen appproject --target android-8 --pat... $ android create --package presentation.hello_world $ android create project --target android-8 --pat... Generates file src/presentation/HelloWorldActivity.java Generates file src/presentation/HelloWorldActivity.java Generates file src/hello_world_activity.rb package com.example.examplejavaxml; package com.example.examplejavaxml; import android.os.Bundle; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.View; import android.view.View; import android.widget.TextView; import android.widget.TextView; public class HelloWorldActivity extends Activity { public class HelloWorldActivity extends Activity { @Override @Override public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); setContentView(R.layout.activity_hello_world); } } public void changeIt(View view) { public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); } } } }Saturday, January 26, 13 29
    • Hello world! $ ruboto gen app --package presentation.hello_world $ android create project --target android-8 --pat... Generates file src/hello_world_activity.rb Generates file src/presentation/HelloWorldActivity.java package com.example.examplejavaxml; package com.example.examplejavaxml; import android.os.Bundle; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.View; import android.view.View; import android.widget.TextView; import android.widget.TextView; public class HelloWorldActivity extends Activity { public class HelloWorldActivity extends Activity { @Override @Override public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); setContentView(R.layout.activity_hello_world); } } public void changeIt(View view) { public void changeIt(View view) { TextView tv = (TextView) findViewById(R.id.textView1); TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); } } } }Saturday, January 26, 13 30
    • Hello world! package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.view.View; import android.widget.TextView; class HelloWorldActivity public class HelloWorldActivity extends Activity { def on_create(bundle) @Override super public void onCreate(Bundle savedInstanceState) { setContentView R.layout.activity_hello_world super.onCreate(savedInstance State); end setContentView(R.layout.activity_hello_world); } def change_it(view) tv = findViewById(AndroidIds::textView1) public void changeIt(View view) { tv.text = "Hello JavaZone!" TextView tv = (TextView) findViewById(R.id.textView1); end tv.setText("Hello JavaZone!"); end } }Saturday, January 26, 13 31
    • Hello world! <LinearLayout package com.example.examplejavaxml; xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" import android.os.Bundle; android:orientation="vertical" import android.app.Activity; android:layout_width="match_parent" import android.view.View; android:layout_height="match_parent" import android.widget.TextView; android:gravity="center" > public class HelloWorldActivity extends Activity { <TextView @Override android:id="@+id/textView1" public void onCreate(Bundle savedInstanceState) { android:layout_width="wrap_content" super.onCreate(savedInstance State); android:layout_height="wrap_content" setContentView(R.layout.activity_hello_world); android:gravity="center" } android:text="@string/hello_world" tools:context=".HelloWorldActivity" public void changeIt(View view) { android:textSize="46dip" /> TextView tv = (TextView) findViewById(R.id.textView1); tv.setText("Hello JavaZone!"); <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>Saturday, January 26, 13 32
    • <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!"); } }Saturday, January 26, 13 33
    • 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); } }Saturday, January 26, 13 34
    • 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); } }Saturday, January 26, 13 35
    • 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); } }Saturday, January 26, 13 36
    • package com.example.examplejavaxml; package com.example.examplejavaxml; import android.os.Bundle; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.Gravity; import android.view.Gravity; import android.view.View; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.TextView; public class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements OnClickListener { OnClickListener { @Override @Override public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); TextView tv = new TextView(this); tv.setId(42); tv.setId(42); tv.setText("Hello World!"); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); tv.setTextSize(46); Button btn = new Button(this); Button btn = new Button(this); btn.setText("Say hello"); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(tv, tvlp); layout.addView(btn, btnlp); layout.addView(btn, btnlp); setContentView(layout); setContentView(layout); } } public void changeIt(View view) { public void changeIt(View view) { TextView tv = (TextView) findViewById(42); TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); } } @Override @Override public void onClick(View v) { public void onClick(View v) { changeIt(v); changeIt(v); } } } }Saturday, January 26, 13 37
    • package com.example.examplejavaxml; package com.example.examplejavaxml; import android.os.Bundle; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.Gravity; import android.view.Gravity; import android.view.View; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.TextView; public class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements OnClickListener { OnClickListener { @Override @Override public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); TextView tv = new TextView(this); tv.setId(42); tv.setId(42); tv.setText("Hello World!"); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); tv.setTextSize(46); Button btn = new Button(this); Button btn = new Button(this); btn.setText("Say hello"); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(tv, tvlp); layout.addView(btn, btnlp); layout.addView(btn, btnlp); setContentView(layout); setContentView(layout); } } public void changeIt(View view) { public void changeIt(View view) { TextView tv = (TextView) findViewById(42); TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); } } @Override @Override public void onClick(View v) { public void onClick(View v) { changeIt(v); changeIt(v); } } } }Saturday, January 26, 13 38
    • package com.example.examplejavaxml; import android.os.Bundle; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.Gravity; import android.view.Gravity; import android.view.View; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.TextView; public class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements OnClickListener { OnClickListener { @Override @Override public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); TextView tv = new TextView(this); tv.setId(42); tv.setId(42); tv.setText("Hello World!"); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); tv.setTextSize(46); Button btn = new Button(this); Button btn = new Button(this); btn.setText("Say hello"); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(tv, tvlp); layout.addView(btn, btnlp); layout.addView(btn, btnlp); setContentView(layout); setContentView(layout); } } public void changeIt(View view) { public void changeIt(View view) { TextView tv = (TextView) findViewById(42); TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); } } @Override @Override public void onClick(View v) { public void onClick(View v) { changeIt(v); changeIt(v); } } } }Saturday, January 26, 13 39
    • package com.example.examplejavaxml; import android.os.Bundle; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.Gravity; import android.view.Gravity; import android.view.View; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.TextView; public class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements OnClickListener { OnClickListener { @Override @Override public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); TextView tv = new TextView(this); tv.setId(42); tv.setId(42); tv.setText("Hello World!"); tv.setText("Hello World!"); LayoutParams tvlp = new LayoutParams( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); tv.setTextSize(46); Button btn = new Button(this); Button btn = new Button(this); btn.setText("Say hello"); btn.setText("Say hello"); LayoutParams btnlp = new LayoutParams( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(tv, tvlp); layout.addView(btn, btnlp); layout.addView(btn, btnlp); setContentView(layout); setContentView(layout); } } public void changeIt(View view) { public void changeIt(View view) { TextView tv = (TextView) findViewById(42); TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); } } @Override @Override public void onClick(View v) { public void onClick(View v) { changeIt(v); changeIt(v); } } } }Saturday, January 26, 13 40
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.Gravity; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.TextView; class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements OnClickListener OnClickListener { @Override public onCreate( savedInstanceState) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL); tv = new TextView(this); TextView tv = new TextView(this); tv.setId(42); tv.setId(42); tv.setText("Hello World!"); tv.setText("Hello World!"); tvlp = new LayoutParams( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); tv.setTextSize(46); btn = new Button(this); Button btn = new Button(this); btn.setText("Say hello"); btn.setText("Say hello"); btnlp = new LayoutParams( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(tv, tvlp); layout.addView(btn, btnlp); layout.addView(btn, btnlp); setContentView(layout); setContentView(layout); } } public changeIt( view) { public void changeIt(View view) { tv = findViewById(42); TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); } } @Override public onClick( v) { public void onClick(View v) { changeIt(v); changeIt(v); } } end }Saturday, January 26, 13 41
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.Gravity; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.TextView; class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements OnClickListener OnClickListener { @Override public onCreate( savedInstanceState) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL); tv = new TextView(this); TextView tv = new TextView(this); tv.setId(42); tv.setId(42); tv.setText("Hello World!"); tv.setText("Hello World!"); tvlp = new LayoutParams( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); tv.setTextSize(46); btn = new Button(this); Button btn = new Button(this); btn.setText("Say hello"); btn.setText("Say hello"); btnlp = new LayoutParams( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(tv, tvlp); layout.addView(btn, btnlp); layout.addView(btn, btnlp); setContentView(layout); setContentView(layout); } } public changeIt( view) { public void changeIt(View view) { tv = findViewById(42); TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); } } @Override public onClick( v) { public void onClick(View v) { changeIt(v); changeIt(v); } } end }Saturday, January 26, 13 42
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.Gravity; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.TextView; class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements OnClickListener OnClickListener { @Override def onCreate( savedInstanceState) public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL); tv = new TextView(this); TextView tv = new TextView(this); tv.setId(42); tv.setId(42); tv.setText("Hello World!"); tv.setText("Hello World!"); tvlp = new LayoutParams( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); tv.setTextSize(46); btn = new Button(this); Button btn = new Button(this); btn.setText("Say hello"); btn.setText("Say hello"); btnlp = new LayoutParams( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(tv, tvlp); layout.addView(btn, btnlp); layout.addView(btn, btnlp); setContentView(layout); setContentView(layout); end } def changeIt( view) public void changeIt(View view) { tv = findViewById(42); TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); end } ! @Override def onClick( v) ! public void onClick(View v) { changeIt(v); ! ! changeIt(v); end ! } end }Saturday, January 26, 13 43
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.Gravity; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.TextView; class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements OnClickListener OnClickListener { @Override def onCreate( savedInstanceState) public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL); tv = new TextView(this); TextView tv = new TextView(this); tv.setId(42); tv.setId(42); tv.setText("Hello World!"); tv.setText("Hello World!"); tvlp = new LayoutParams( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); tv.setTextSize(46); btn = new Button(this); Button btn = new Button(this); btn.setText("Say hello"); btn.setText("Say hello"); btnlp = new LayoutParams( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(tv, tvlp); layout.addView(btn, btnlp); layout.addView(btn, btnlp); setContentView(layout); setContentView(layout); end } def changeIt( view) public void changeIt(View view) { tv = findViewById(42); TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); end } ! @Override def onClick( v) ! public void onClick(View v) { changeIt(v); ! ! changeIt(v); end ! } end }Saturday, January 26, 13 44
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.Gravity; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.TextView; class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements OnClickListener OnClickListener { @Override def onCreate( savedInstanceState) public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); layout = LinearLayout.new(this); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(this); TextView tv = new TextView(this); tv.setId(42); tv.setId(42); tv.setText("Hello World!"); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); tv.setTextSize(46); btn = Button.new(this); Button btn = new Button(this); btn.setText("Say hello"); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(tv, tvlp); layout.addView(btn, btnlp); layout.addView(btn, btnlp); setContentView(layout); setContentView(layout); end } def changeIt( view) public void changeIt(View view) { tv = findViewById(42); TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); end } ! @Override def onClick( v) ! public void onClick(View v) { changeIt(v); ! ! changeIt(v); end ! } end }Saturday, January 26, 13 45
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.Gravity; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.TextView; class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements OnClickListener OnClickListener { @Override def onCreate( savedInstanceState) public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); layout = LinearLayout.new(this); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(this); TextView tv = new TextView(this); tv.setId(42); tv.setId(42); tv.setText("Hello World!"); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); tv.setTextSize(46); btn = Button.new(this); Button btn = new Button(this); btn.setText("Say hello"); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(this); btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(tv, tvlp); layout.addView(btn, btnlp); layout.addView(btn, btnlp); setContentView(layout); setContentView(layout); end } def changeIt( view) public void changeIt(View view) { tv = findViewById(42); TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); end } ! @Override def onClick( v) ! public void onClick(View v) { changeIt(v); ! ! changeIt(v); end ! } end }Saturday, January 26, 13 46
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.Gravity; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.TextView; class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements OnClickListener OnClickListener { @Override def onCreate( savedInstanceState) public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); layout = LinearLayout.new(self); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self); TextView tv = new TextView(this); tv.setId(42); tv.setId(42); tv.setText("Hello World!"); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); tv.setTextSize(46); btn = Button.new(self); Button btn = new Button(this); btn.setText("Say hello"); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(self); btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(tv, tvlp); layout.addView(btn, btnlp); layout.addView(btn, btnlp); setContentView(layout); setContentView(layout); end } def changeIt( view) public void changeIt(View view) { tv = findViewById(42); TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); end } ! @Override def onClick( v) ! public void onClick(View v) { changeIt(v); ! ! changeIt(v); end ! } end }Saturday, January 26, 13 47
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.Gravity; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.TextView; class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements OnClickListener OnClickListener { @Override def onCreate( savedInstanceState) public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); layout = LinearLayout.new(self); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self); TextView tv = new TextView(this); tv.setId(42); tv.setId(42); tv.setText("Hello World!"); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); tv.setTextSize(46); btn = Button.new(self); Button btn = new Button(this); btn.setText("Say hello"); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(self); btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(tv, tvlp); layout.addView(btn, btnlp); layout.addView(btn, btnlp); setContentView(layout); setContentView(layout); end } def changeIt( view) public void changeIt(View view) { tv = findViewById(42); TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); end } ! @Override def onClick( v) ! public void onClick(View v) { changeIt(v); ! ! changeIt(v); end ! } end }Saturday, January 26, 13 48
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.Gravity; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.TextView; class HelloWorldActivity < Activity public class HelloWorldActivity extends Activity implements OnClickListener { @Override def onCreate( savedInstanceState) public void onCreate(Bundle savedInstanceState) { super; super.onCreate(savedInstanceState); layout = LinearLayout.new(self); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self); TextView tv = new TextView(this); tv.setId(42); tv.setId(42); tv.setText("Hello World!"); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); tv.setTextSize(46); btn = Button.new(self); Button btn = new Button(this); btn.setText("Say hello"); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(self); btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(tv, tvlp); layout.addView(btn, btnlp); layout.addView(btn, btnlp); setContentView(layout); setContentView(layout); end } def changeIt( view) public void changeIt(View view) { tv = findViewById(42); TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); end } ! @Override def onClick( v) ! public void onClick(View v) { changeIt(v); ! ! changeIt(v); end ! } end }Saturday, January 26, 13 49
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.Gravity; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.TextView; class HelloWorldActivity < Activity public class HelloWorldActivity extends Activity implements OnClickListener { @Override def onCreate( savedInstanceState) public void onCreate(Bundle savedInstanceState) { super; super.onCreate(savedInstanceState); layout = LinearLayout.new(self); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self); TextView tv = new TextView(this); tv.setId(42); tv.setId(42); tv.setText("Hello World!"); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); tv.setTextSize(46); btn = Button.new(self); Button btn = new Button(this); btn.setText("Say hello"); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(self); btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(tv, tvlp); layout.addView(btn, btnlp); layout.addView(btn, btnlp); setContentView(layout); setContentView(layout); end } def changeIt( view) public void changeIt(View view) { tv = findViewById(42); TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); end } ! @Override def onClick( v) ! public void onClick(View v) { changeIt(v); ! ! changeIt(v); end ! } end }Saturday, January 26, 13 50
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.Gravity; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.TextView; class HelloWorldActivity < Activity public class HelloWorldActivity extends Activity implements OnClickListener { @Override def onCreate( savedInstanceState) public void onCreate(Bundle savedInstanceState) { super; super.onCreate(savedInstanceState); layout = LinearLayout.new(self); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity::CENTER); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout::VERTICAL); layout.setOrientation(LinearLayout.VERTICAL); tv = TextView(self).new; TextView tv = new TextView(this); tv.setId(42); tv.setId(42); tv.setText("Hello World!"); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams tvlp = new LayoutParams( LayoutParams::WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams::WRAP_CONTENT); LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity::CENTER; tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); tv.setTextSize(46); btn = Button.new(self); Button btn = new Button(this); btn.setText("Say hello"); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams btnlp = new LayoutParams( LayoutParams::WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams::WRAP_CONTENT); LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.topMargin = 75; btnlp.gravity = Gravity::CENTER; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(self); btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(tv, tvlp); layout.addView(btn, btnlp); layout.addView(btn, btnlp); setContentView(layout); setContentView(layout); end } def changeIt( view) public void changeIt(View view) { tv = findViewById(42); TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); end } ! @Override def onClick( v) ! public void onClick(View v) { changeIt(v); ! ! changeIt(v); end ! } end }Saturday, January 26, 13 51
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.Gravity; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.TextView; class HelloWorldActivity < Activity public class HelloWorldActivity extends Activity implements OnClickListener { @Override def onCreate(savedInstanceState) public void onCreate(Bundle savedInstanceState) { super; super.onCreate(savedInstanceState); layout = LinearLayout.new(self); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self); TextView tv = new TextView(this); tv.setId(42); tv.setId(42); tv.setText("Hello World!"); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); tv.setTextSize(46); btn = Button.new(self); Button btn = new Button(this); btn.setText("Say hello"); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(self); btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(tv, tvlp); layout.addView(btn, btnlp); layout.addView(btn, btnlp); setContentView(layout); setContentView(layout); end } def changeIt(view) public void changeIt(View view) { tv = findViewById(42); TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); end } ! @Override def onClick(v) ! public void onClick(View v) { changeIt(v); ! ! changeIt(v); end ! } end }Saturday, January 26, 13 52
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.app.Activity; import android.view.Gravity; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; import android.widget.TextView; class HelloWorldActivity < Activity public class HelloWorldActivity extends Activity implements OnClickListener { @Override def onCreate(savedInstanceState) public void onCreate(Bundle savedInstanceState) { super; super.onCreate(savedInstanceState); layout = LinearLayout.new(self); LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self); TextView tv = new TextView(this); tv.setId(42); tv.setId(42); tv.setText("Hello World!"); tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER; tv.setTextSize(46); tv.setTextSize(46); btn = Button.new(self); Button btn = new Button(this); btn.setText("Say hello"); btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75; btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(self); btn.setOnClickListener(this); layout.addView(tv, tvlp); layout.addView(tv, tvlp); layout.addView(btn, btnlp); layout.addView(btn, btnlp); setContentView(layout); setContentView(layout); end } def changeIt(view) public void changeIt(View view) { tv = findViewById(42); TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!"); end } ! @Override def onClick(v) ! public void onClick(View v) { changeIt(v); ! ! changeIt(v); end ! } end }Saturday, January 26, 13 53
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity import android.app.Activity; import android.view.Gravity import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button import android.widget.Button; import android.widget.LinearLayout import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams import android.widget.LinearLayout.LayoutParams; import android.widget.TextView import android.widget.TextView; class HelloWorldActivity < Activity public class HelloWorldActivity extends Activity implements OnClickListener { @Override def onCreate(savedInstanceState) public void onCreate(Bundle savedInstanceState) { super super.onCreate(savedInstanceState); layout = LinearLayout.new(self) LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER) layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL) layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self) TextView tv = new TextView(this); tv.setId(42) tv.setId(42); tv.setText("Hello World!") tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER tvlp.gravity = Gravity.CENTER; tv.setTextSize(46) tv.setTextSize(46); btn = Button.new(self) Button btn = new Button(this); btn.setText("Say hello") btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75 btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(self) btn.setOnClickListener(this); layout.addView(tv, tvlp) layout.addView(tv, tvlp); layout.addView(btn, btnlp) layout.addView(btn, btnlp); setContentView(layout) setContentView(layout); end } def changeIt(view) public void changeIt(View view) { tv = findViewById(42) TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!") tv.setText("Hello JavaZone!"); end } ! @Override def onClick(v) ! public void onClick(View v) { changeIt(v) ! ! changeIt(v); end ! } end }Saturday, January 26, 13 54
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity import android.app.Activity; import android.view.Gravity import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button import android.widget.Button; import android.widget.LinearLayout import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams import android.widget.LinearLayout.LayoutParams; import android.widget.TextView import android.widget.TextView; class HelloWorldActivity < Activity public class HelloWorldActivity extends Activity implements OnClickListener { @Override def onCreate(savedInstanceState) public void onCreate(Bundle savedInstanceState) { super super.onCreate(savedInstanceState); layout = LinearLayout.new(self) LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER) layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL) layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self) TextView tv = new TextView(this); tv.setId(42) tv.setId(42); tv.setText("Hello World!") tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER tvlp.gravity = Gravity.CENTER; tv.setTextSize(46) tv.setTextSize(46); btn = Button.new(self) Button btn = new Button(this); btn.setText("Say hello") btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75 btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(self) btn.setOnClickListener(this); layout.addView(tv, tvlp) layout.addView(tv, tvlp); layout.addView(btn, btnlp) layout.addView(btn, btnlp); setContentView(layout) setContentView(layout); end } def changeIt(view) public void changeIt(View view) { tv = findViewById(42) TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!") tv.setText("Hello JavaZone!"); end } ! @Override def onClick(v) ! public void onClick(View v) { changeIt(v) ! ! changeIt(v); end ! } end }Saturday, January 26, 13 55
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.view.Gravity import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button import android.widget.Button; import android.widget.LinearLayout import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams import android.widget.LinearLayout.LayoutParams; import android.widget.TextView import android.widget.TextView; class HelloWorldActivity public class HelloWorldActivity extends Activity implements OnClickListener { @Override def onCreate(savedInstanceState) public void onCreate(Bundle savedInstanceState) { super super.onCreate(savedInstanceState); layout = LinearLayout.new(self) LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER) layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL) layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self) TextView tv = new TextView(this); tv.setId(42) tv.setId(42); tv.setText("Hello World!") tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER tvlp.gravity = Gravity.CENTER; tv.setTextSize(46) tv.setTextSize(46); btn = Button.new(self) Button btn = new Button(this); btn.setText("Say hello") btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75 btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(self) btn.setOnClickListener(this); layout.addView(tv, tvlp) layout.addView(tv, tvlp); layout.addView(btn, btnlp) layout.addView(btn, btnlp); setContentView(layout) setContentView(layout); end } def changeIt(view) public void changeIt(View view) { tv = findViewById(42) TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!") tv.setText("Hello JavaZone!"); end } ! @Override def onClick(v) ! public void onClick(View v) { changeIt(v) ! ! changeIt(v); end ! } end }Saturday, January 26, 13 56
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.view.Gravity import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button import android.widget.Button; import android.widget.LinearLayout import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams import android.widget.LinearLayout.LayoutParams; import android.widget.TextView import android.widget.TextView; class HelloWorldActivity public class HelloWorldActivity extends Activity implements OnClickListener { @Override def onCreate(savedInstanceState) public void onCreate(Bundle savedInstanceState) { super super.onCreate(savedInstanceState); layout = LinearLayout.new(self) LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER) layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.VERTICAL) layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self) TextView tv = new TextView(this); tv.setId(42) tv.setId(42); tv.setText("Hello World!") tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER tvlp.gravity = Gravity.CENTER; tv.setTextSize(46) tv.setTextSize(46); btn = Button.new(self) Button btn = new Button(this); btn.setText("Say hello") btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75 btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER btnlp.gravity = Gravity.CENTER; btn.setOnClickListener(self) btn.setOnClickListener(this); layout.addView(tv, tvlp) layout.addView(tv, tvlp); layout.addView(btn, btnlp) layout.addView(btn, btnlp); setContentView(layout) setContentView(layout); end } def changeIt(view) public void changeIt(View view) { tv = findViewById(42) TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!") tv.setText("Hello JavaZone!"); end } ! @Override def onClick(v) ! public void onClick(View v) { changeIt(v) ! ! changeIt(v); end ! } end }Saturday, January 26, 13 57
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.view.Gravity import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button import android.widget.Button; import android.widget.LinearLayout import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams import android.widget.LinearLayout.LayoutParams; import android.widget.TextView import android.widget.TextView; class HelloWorldActivity public class HelloWorldActivity extends Activity implements OnClickListener { @Override def on_create(savedInstanceState) public void onCreate(Bundle savedInstanceState) { super super.onCreate(savedInstanceState); layout = LinearLayout.new(self) LinearLayout layout = new LinearLayout(this); layout.gravity = Gravity.CENTER layout.setGravity(Gravity.CENTER); layout.orientation = LinearLayout.VERTICAL layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self) TextView tv = new TextView(this); tv.id = 42 tv.setId(42); tv.text = "Hello World!" tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER tvlp.gravity = Gravity.CENTER; tv.text_size = 46 tv.setTextSize(46); btn = Button.new(self) Button btn = new Button(this); btn.text = "Say hello" btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75 btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER btnlp.gravity = Gravity.CENTER; btn.on_click_listener = self btn.setOnClickListener(this); layout.add_view(tv, tvlp) layout.addView(tv, tvlp); layout.add_view(btn, btnlp) layout.addView(btn, btnlp); setContentView(layout) setContentView(layout); end } def change_it(view) public void changeIt(View view) { tv = find_view_by_id(42) TextView tv = (TextView) findViewById(42); tv.text = "Hello JavaZone!" tv.setText("Hello JavaZone!"); end } ! @Override def on_click(v) ! public void onClick(View v) { change_it(v) ! ! changeIt(v); end ! } end }Saturday, January 26, 13 58
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.view.Gravity import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button import android.widget.Button; import android.widget.LinearLayout import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams import android.widget.LinearLayout.LayoutParams; import android.widget.TextView import android.widget.TextView; class HelloWorldActivity public class HelloWorldActivity extends Activity implements OnClickListener { @Override def on_create(savedInstanceState) public void onCreate(Bundle savedInstanceState) { super super.onCreate(savedInstanceState); layout = LinearLayout.new(self) LinearLayout layout = new LinearLayout(this); layout.gravity = Gravity.CENTER layout.setGravity(Gravity.CENTER); layout.orientation = LinearLayout.VERTICAL layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self) TextView tv = new TextView(this); tv.id = 42 tv.setId(42); tv.text = "Hello World!" tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER tvlp.gravity = Gravity.CENTER; tv.text_size = 46 tv.setTextSize(46); btn = Button.new(self) Button btn = new Button(this); btn.text = "Say hello" btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75 btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER btnlp.gravity = Gravity.CENTER; btn.on_click_listener = self btn.setOnClickListener(this); layout.add_view(tv, tvlp) layout.addView(tv, tvlp); layout.add_view(btn, btnlp) layout.addView(btn, btnlp); setContentView(layout) setContentView(layout); end } def change_it(view) public void changeIt(View view) { tv = find_view_by_id(42) TextView tv = (TextView) findViewById(42); tv.text = "Hello JavaZone!" tv.setText("Hello JavaZone!"); end } ! @Override def on_click(v) ! public void onClick(View v) { change_it(v) ! ! changeIt(v); end ! } end }Saturday, January 26, 13 59
    • package com.example.examplejavaxml; import android.os.Bundle; import android.app.Activity; import android.view.Gravity import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button import android.widget.Button; import android.widget.LinearLayout import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams import android.widget.LinearLayout.LayoutParams; import android.widget.TextView import android.widget.TextView; class HelloWorldActivity public class HelloWorldActivity extends Activity implements OnClickListener { @Override def on_create(savedInstanceState) public void onCreate(Bundle savedInstanceState) { super super.onCreate(savedInstanceState); layout = LinearLayout.new(self) LinearLayout layout = new LinearLayout(this); layout.gravity = Gravity.CENTER layout.setGravity(Gravity.CENTER); layout.orientation = LinearLayout.VERTICAL layout.setOrientation(LinearLayout.VERTICAL); tv = TextView.new(self) TextView tv = new TextView(this); tv.id = 42 tv.setId(42); tv.text = "Hello World!" tv.setText("Hello World!"); tvlp = LayoutParams.new( LayoutParams tvlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) LayoutParams.WRAP_CONTENT); tvlp.gravity = Gravity.CENTER tvlp.gravity = Gravity.CENTER; tv.text_size = 46 tv.setTextSize(46); btn = Button.new(self) Button btn = new Button(this); btn.text = "Say hello" btn.setText("Say hello"); btnlp = LayoutParams.new( LayoutParams btnlp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) LayoutParams.WRAP_CONTENT); btnlp.topMargin = 75 btnlp.topMargin = 75; btnlp.gravity = Gravity.CENTER btnlp.gravity = Gravity.CENTER; btn.on_click_listener = self btn.setOnClickListener(this); layout.add_view(tv, tvlp) layout.addView(tv, tvlp); layout.add_view(btn, btnlp) layout.addView(btn, btnlp); setContentView(layout) setContentView(layout); end } def change_it(view) public void changeIt(View view) { tv = find_view_by_id(42) TextView tv = (TextView) findViewById(42); tv.text = "Hello JavaZone!" tv.setText("Hello JavaZone!"); end } ! @Override def on_click(v) ! public void onClick(View v) { change_it(v) ! ! changeIt(v); end ! } end }Saturday, January 26, 13 60
    • 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; require ruboto/widget import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; ruboto_import_widgets :Button, :LinearLayout, :TextView import android.widget.TextView; class HelloWorldActivity public class HelloWorldActivity extends Activity implements OnClickListener { @Override def on_create(savedInstanceState) public void onCreate(Bundle savedInstanceState) { super super.onCreate(savedInstanceState); self.content_view = LinearLayout layout = new LinearLayout(this); linear_layout gravity: :center, orientation: :vertical do layout.setGravity(Gravity.CENTER); text_view text: Hello World!, id: 42, layout.setOrientation(LinearLayout.VERTICAL); text_size: 46, width: :wrap_content, TextView tv = new TextView(this); height: :wrap_content, gravity: :center tv.setId(42); button id: 43, text: "Say hello", width: :wrap_content, tv.setText("Hello World!"); height: :wrap_content, gravity: :center, LayoutParams tvlp = new LayoutParams( margins: [0,75,0,0], LayoutParams.WRAP_CONTENT, on_click_listener: self LayoutParams.WRAP_CONTENT); end 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); end } def change_it(view) public void changeIt(View view) { tv = find_view_by_id(42) TextView tv = (TextView) findViewById(42); tv.text = "Hello JavaZone!" tv.setText("Hello JavaZone!"); end } ! @Override def on_click(v) ! public void onClick(View v) { change_it(v) ! ! changeIt(v); end ! } end }Saturday, January 26, 13 61
    • 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; require ruboto/widget import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; ruboto_import_widgets :Button, :LinearLayout, :TextView import android.widget.TextView; class HelloWorldActivity public class HelloWorldActivity extends Activity implements OnClickListener { @Override def on_create(savedInstanceState) public void onCreate(Bundle savedInstanceState) { super super.onCreate(savedInstanceState); self.content_view = LinearLayout layout = new LinearLayout(this); linear_layout gravity: :center, orientation: :vertical do layout.setGravity(Gravity.CENTER); text_view text: Hello World!, id: 42, layout.setOrientation(LinearLayout.VERTICAL); text_size: 46, width: :wrap_content, TextView tv = new TextView(this); height: :wrap_content, gravity: :center tv.setId(42); button id: 43, text: "Say hello", width: :wrap_content, tv.setText("Hello World!"); height: :wrap_content, gravity: :center, LayoutParams tvlp = new LayoutParams( margins: [0,75,0,0], LayoutParams.WRAP_CONTENT, on_click_listener: self LayoutParams.WRAP_CONTENT); end 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); end } def change_it(view) public void changeIt(View view) { tv = find_view_by_id(42) TextView tv = (TextView) findViewById(42); tv.text = "Hello JavaZone!" tv.setText("Hello JavaZone!"); end } ! @Override def on_click(v) ! public void onClick(View v) { change_it(v) ! ! changeIt(v); end ! } end }Saturday, January 26, 13 62
    • 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; require ruboto/widget import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; ruboto_import_widgets :Button, :LinearLayout, :TextView import android.widget.TextView; class HelloWorldActivity public class HelloWorldActivity extends Activity implements OnClickListener { @Override def on_create(savedInstanceState) public void onCreate(Bundle savedInstanceState) { super super.onCreate(savedInstanceState); self.content_view = LinearLayout layout = new LinearLayout(this); linear_layout gravity: :center, orientation: :vertical do layout.setGravity(Gravity.CENTER); text_view text: Hello World!, id: 42, layout.setOrientation(LinearLayout.VERTICAL); text_size: 46, width: :wrap_content, TextView tv = new TextView(this); height: :wrap_content, gravity: :center tv.setId(42); button id: 43, text: "Say hello", width: :wrap_content, tv.setText("Hello World!"); height: :wrap_content, gravity: :center, LayoutParams tvlp = new LayoutParams( margins: [0,75,0,0], LayoutParams.WRAP_CONTENT, on_click_listener: self LayoutParams.WRAP_CONTENT); end 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); end } def change_it(view) public void changeIt(View view) { tv = find_view_by_id(42) TextView tv = (TextView) findViewById(42); tv.text = "Hello JavaZone!" tv.setText("Hello JavaZone!"); end } ! @Override def on_click(v) ! public void onClick(View v) { change_it(v) ! ! changeIt(v); end ! } end }Saturday, January 26, 13 63
    • 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; require ruboto/widget import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; ruboto_import_widgets :Button, :LinearLayout, :TextView import android.widget.TextView; class HelloWorldActivity public class HelloWorldActivity extends Activity implements OnClickListener { @Override def on_create(savedInstanceState) public void onCreate(Bundle savedInstanceState) { super super.onCreate(savedInstanceState); self.content_view = LinearLayout layout = new LinearLayout(this); linear_layout gravity: :center, orientation: :vertical do layout.setGravity(Gravity.CENTER); text_view text: Hello World!, id: 42, layout.setOrientation(LinearLayout.VERTICAL); text_size: 46, width: :wrap_content, TextView tv = new TextView(this); height: :wrap_content, gravity: :center tv.setId(42); button id: 43, text: "Say hello", width: :wrap_content, tv.setText("Hello World!"); height: :wrap_content, gravity: :center, LayoutParams tvlp = new LayoutParams( margins: [0,75,0,0], LayoutParams.WRAP_CONTENT, on_click_listener: self LayoutParams.WRAP_CONTENT); end 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); end } def change_it(view) public void changeIt(View view) { tv = find_view_by_id(42) TextView tv = (TextView) findViewById(42); tv.text = "Hello JavaZone!" tv.setText("Hello JavaZone!"); end } ! @Override def on_click(v) ! public void onClick(View v) { change_it(v) ! ! changeIt(v); end ! } end }Saturday, January 26, 13 64
    • 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; require ruboto/widget import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; ruboto_import_widgets :Button, :LinearLayout, :TextView import android.widget.TextView; class HelloWorldActivity public class HelloWorldActivity extends Activity implements OnClickListener { @Override def on_create(savedInstanceState) public void onCreate(Bundle savedInstanceState) { super super.onCreate(savedInstanceState); self.content_view = LinearLayout layout = new LinearLayout(this); linear_layout gravity: :center, orientation: :vertical do layout.setGravity(Gravity.CENTER); @tv = text_view text: Hello World!, id: 42, layout.setOrientation(LinearLayout.VERTICAL); text_size: 46, width: :wrap_content, TextView tv = new TextView(this); height: :wrap_content, gravity: :center tv.setId(42); button id: 43, text: "Say hello", width: :wrap_content, tv.setText("Hello World!"); height: :wrap_content, gravity: :center, LayoutParams tvlp = new LayoutParams( margins: [0,75,0,0], LayoutParams.WRAP_CONTENT, on_click_listener: proc{@tv.text = ‘Hello JavaZone’} LayoutParams.WRAP_CONTENT); end 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); end } public void changeIt(View view) { TextView tv = (TextView) findViewById(42); tv.setText("Hello JavaZone!"); } ! @Override ! public void onClick(View v) { ! ! changeIt(v); ! } end }Saturday, January 26, 13 65
    • 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; require ruboto/widget import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; ruboto_import_widgets :Button, :LinearLayout, :TextView import android.widget.TextView; class HelloWorldActivity public class HelloWorldActivity extends Activity implements def on_create(savedInstanceState) OnClickListener { super @Override self.content_view = public void onCreate(Bundle savedInstanceState) { linear_layout gravity: :center, orientation: :vertical do super.onCreate(savedInstanceState); @tv = text_view text: Hello World!, id: 42, LinearLayout layout = new LinearLayout(this); text_size: 46, width: :wrap_content, layout.setGravity(Gravity.CENTER); height: :wrap_content, gravity: :center layout.setOrientation(LinearLayout.VERTICAL); button id: 43, text: Say hello, width: :wrap_content, TextView tv = new TextView(this); height: :wrap_content, gravity: :center, tv.setId(42); margins: [0,75,0,0], tv.setText("Hello World!"); on_click_listener: proc{@tv.text = Hello JavaZone} LayoutParams tvlp = new LayoutParams( end LayoutParams.WRAP_CONTENT, end LayoutParams.WRAP_CONTENT); end 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); ! } }Saturday, January 26, 13 66
    • 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; require ruboto/widget import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; ruboto_import_widgets :Button, :LinearLayout, :TextView import android.widget.TextView; class HelloWorldActivity public class HelloWorldActivity extends Activity implements def on_create(savedInstanceState) OnClickListener { super @Override self.content_view = public void onCreate(Bundle savedInstanceState) { linear_layout gravity: :center, orientation: :vertical do super.onCreate(savedInstanceState); @tv = text_view text: Hello World!, id: 42, LinearLayout layout = new LinearLayout(this); text_size: 46, width: :wrap_content, layout.setGravity(Gravity.CENTER); height: :wrap_content, gravity: :center layout.setOrientation(LinearLayout.VERTICAL); button id: 43, text: Say hello, width: :wrap_content, TextView tv = new TextView(this); height: :wrap_content, gravity: :center, tv.setId(42); margins: [0,75,0,0], tv.setText("Hello World!"); on_click_listener: proc{@tv.text = Hello JavaZone} LayoutParams tvlp = new LayoutParams( end LayoutParams.WRAP_CONTENT, end LayoutParams.WRAP_CONTENT); end 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); ! } }Saturday, January 26, 13 67
    • require ruboto/widget package com.example.examplejavaxml; ruboto_import_widgets :Button, :LinearLayout, :TextView import android.os.Bundle; import android.app.Activity; class HelloWorldActivity import android.view.Gravity; def on_create(savedInstanceState) import android.view.View; super import android.view.View.OnClickListener; self.content_view = import android.widget.Button; linear_layout gravity: :center, orientation: :vertical do import android.widget.LinearLayout; @tv = text_view text: Hello World!, id: 42, import android.widget.LinearLayout.LayoutParams; text_size: 46, width: :wrap_content, import android.widget.TextView; height: :wrap_content, gravity: :center button id: 43, text: Say hello, width: :wrap_content, public class HelloWorldActivity extends Activity implements height: :wrap_content, gravity: :center, OnClickListener { margins: [0,75,0,0], @Override on_click_listener: proc{@tv.text = Hello JavaZone} public void onCreate(Bundle savedInstanceState) { end super.onCreate(savedInstanceState); end LinearLayout layout = new LinearLayout(this); end 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); ! } }Saturday, January 26, 13 67
    • Examples Make a call Show webpage SpycamSaturday, January 26, 13 68
    • 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 end endSaturday, January 26, 13 69
    • 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 end endaSaturday, January 26, 13 70
    • Spycam Access the camera Show the camera image Start a WEBrick web server Serve a new image on each requestSaturday, January 26, 13 71
    • require  ruboto/activity require  monitor require  ruboto/widget require  camera_helper require  spycam_server Spycam require  ruboto/util/stack import  android.util.Log class  SpycamServer import  android.view.Surface    extend  MonitorMixin import  android.view.WindowManager    PORT  =  4567 ruboto_import_widgets  :Button,  :LinearLayout,  :ScrollView,  :TextView    DOC_ROOT  =  "#{$activity.files_dir.absolute_path}/" ruboto_import_widget  :SurfaceView,  "android.view"    @@server  =  nil class  SpycamActivity    def  self.start(activity,  server_status_view)    def  on_create(bundle) class  CameraHelper        Thread.with_large_stack(512)  do        rotation  =  {    def  self.take_picture(activity)            synchronize  do                Surface::ROTATION_0  =>  0,Surface::ROTATION_90  =>          activity.camera_status  =  "Set  volume..."                if  @@server.nil? 90,Surface::ROTATION_180  =>  180,Surface::ROTATION_270  =>  270        am  =                      activity.run_on_ui_thread  {  server_status_view.text  =          }[window_manager.default_display.rotation] activity.getSystemService(android.content.Context::AUDIO_SERVICE) "Loading"  }        self.title  =  "Spycam  #{rotation}"        old_volume  =                      require  webrick Access the camera        #   am.get_stream_volume(android.media.AudioManager::STREAM_SYSTEM)                    activity.run_on_ui_thread  {  server_status_view.text  =   self.setRequestedOrientation(android.content.pm.ActivityInfo::SCREEN_OR        am.set_stream_volume(android.media.AudioManager::STREAM_SYSTEM,  0,   "Loaded"  } IENTATION_PORTRAIT) 0)                    @@server  =  WEBrick::HTTPServer.new(:Port  =>          window.add_flags(WindowManager::LayoutParams::FLAG_KEEP_SCREEN_ON) PORT,  :DocumentRoot  =>  DOC_ROOT)        activity.camera_status  =  "Taking  picture..."        setContentView(linear_layout(:orientation  =>  :vertical)  do        picture_taken  =  false                    @@server.mount_proc(/)  do  |req,  resp| Show the camera image            linear_layout  do        $camera.take_picture(nil,  nil)  do  |data,  camera|                        case  req.path                text_view  :text  =>  "Server:  "            $camera_data  =  String.from_java_bytes(data)                        when  /,  index.html                @server_status_view  =  text_view            activity.camera_status  =  "Gotcha!"                            CameraHelper.take_picture(activity)            end                            resp.content_type  =  "text/html"            linear_layout  do            $camera.start_preview                            resp.body  =  <html> Start a WEBrick web server                text_view  :text  =>  "Picture:  "            am.set_stream_volume(android.media.AudioManager::STREAM_SYSTEM,                                                              <head>                @camera_status_view  =  text_view old_volume,  0)                                                                <title>Spycam</title>            end            picture_taken  =  true                                                            </head>        end                                                            <body>            sv  =  surface_view        sleep  0.1  until  picture_taken                                                                <a  href="/"><img  src="latest.jpg"></a>            sv.holder.add_callback  RubotoSurfaceHolderCallback.new(rotation)    end                                                            </body> Serve a new image on each            #  Deprecated,  but  still  required  for  older  API  version end                                                        </html>            sv.holder.set_type                              raise  WEBrick::HTTPStatus::OK android.view.SurfaceHolder::SURFACE_TYPE_PUSH_BUFFERS request                        when  /latest.jpg        end)                            resp.content_type  =  "image/jpg"    end                            resp.body  =  $camera_data                                $camera_data  =  nil    def  set_camera_status(value)                            raise  WEBrick::HTTPStatus::OK        @camera_status_view.text  =  value                        else    end                            resp.body  =  "Unknown  path:  #{req.path.inspect}"                            raise  WEBrick::HTTPStatus::NotFound    def  camera_status=(value)                        end        run_on_ui_thread  {  $activity.set_camera_status  value  }                    end    end                    server  =  @@server                    Thread.new{server.start}    def  on_resume                  endSaturday, January 26, 13        SpycamServer.start(self,  @server_status_view)                activity.run_on_ui_thread  {  server_status_view.text  =  "WEBrick   71
    • Demo: SpycamSaturday, January 26, 13 72
    • Limitations Startup time Tiny stack on main thread Runtime size No AOT/JIT compilationSaturday, January 26, 13 73
    • Status Ruboto is in production! Monthly releases. Still improving the API Support Android 2.1 - 4.2 5 active developers, more welcome!Saturday, January 26, 13 74
    • Status Ruboto is in production! Monthly releases. Still improving the API Support Android 2.1 - 4.2 5 active developers, more welcome!Saturday, January 26, 13 74
    • Status Ruboto is in production! Monthly releases. Still improving the API Support Android 2.1 - 4.2 5 active developers, more welcome!Saturday, January 26, 13 74
    • 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 pluginSaturday, January 26, 13 75
    • Demo (if time allows) Ruboto IRB ServerSaturday, January 26, 13 76
    • Contributors welcome! ruboto.orgSaturday, January 26, 13 77
    • Questions?Saturday, January 26, 13 78
    • Thank you!Saturday, January 26, 13 79